From 094a067a35fae5f2b24cd20afa106026f0d02167 Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Mon, 21 May 2018 15:05:18 -0400 Subject: [PATCH 1/6] add expression separator `;` to support one line variable --- autoload/crunch.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autoload/crunch.vim b/autoload/crunch.vim index 177e9d5..f7a583b 100644 --- a/autoload/crunch.vim +++ b/autoload/crunch.vim @@ -78,7 +78,7 @@ function! crunch#eval(exprs) abort "{{{2 " Decho '== Inizilation ==' let s:variables = deepcopy(g:crunch_user_variables, 0) - let expr_list = split(a:exprs, '\n', 1) + let expr_list = split(a:exprs, '\v;|\n', 1) " Decho 'expr_list = <'.string(expr_list).'>' for i in range(len(expr_list)) @@ -108,7 +108,11 @@ function! crunch#eval(exprs) abort "{{{2 let expr_list[i] = s:build_result(orig_expr, result) endfor " Decho string(expr_list).'= the expr_lines_list' - let expr_lines = join(expr_list, "\n") + let expr_separator = "\n" + if len(split(a:exprs, "\n")) <= 1 + let expr_separator = ";" + endif + let expr_lines = join(expr_list, expr_separator) " Decho expr_lines.'= the expr_lines' let s:variables = {} return expr_lines From 1d412b4c5e1422a87edfef1720b9a6b3007ca08b Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Mon, 21 May 2018 15:12:50 -0400 Subject: [PATCH 2/6] use single quote to fix ci --- autoload/crunch.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/crunch.vim b/autoload/crunch.vim index f7a583b..6ba7d54 100644 --- a/autoload/crunch.vim +++ b/autoload/crunch.vim @@ -110,7 +110,7 @@ function! crunch#eval(exprs) abort "{{{2 " Decho string(expr_list).'= the expr_lines_list' let expr_separator = "\n" if len(split(a:exprs, "\n")) <= 1 - let expr_separator = ";" + let expr_separator = ';' endif let expr_lines = join(expr_list, expr_separator) " Decho expr_lines.'= the expr_lines' From 57211c413e28d424bcbaad5095507fd34e15d5ff Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Wed, 23 May 2018 12:04:05 -0400 Subject: [PATCH 3/6] refactor: use magic string replace separator ';' --- autoload/crunch.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/crunch.vim b/autoload/crunch.vim index 6ba7d54..3e81a65 100644 --- a/autoload/crunch.vim +++ b/autoload/crunch.vim @@ -78,7 +78,10 @@ function! crunch#eval(exprs) abort "{{{2 " Decho '== Inizilation ==' let s:variables = deepcopy(g:crunch_user_variables, 0) - let expr_list = split(a:exprs, '\v;|\n', 1) + let separator_magic = "\t \t \t\n" + + let processed_exprs = substitute(a:exprs, ';', separator_magic, 'g') + let expr_list = split(processed_exprs, '\n', 1) " Decho 'expr_list = <'.string(expr_list).'>' for i in range(len(expr_list)) @@ -109,10 +112,8 @@ function! crunch#eval(exprs) abort "{{{2 endfor " Decho string(expr_list).'= the expr_lines_list' let expr_separator = "\n" - if len(split(a:exprs, "\n")) <= 1 - let expr_separator = ';' - endif let expr_lines = join(expr_list, expr_separator) + let expr_lines = substitute(expr_lines, separator_magic, ";", 'g') " Decho expr_lines.'= the expr_lines' let s:variables = {} return expr_lines From ea687cd88606dfd1251208fa58609c64d008b3b6 Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Wed, 23 May 2018 12:05:51 -0400 Subject: [PATCH 4/6] add example in doc and a test case; also fix a test case bug --- doc/crunch.txt | 9 +++++++++ test/operator.vader | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/crunch.txt b/doc/crunch.txt index 959da61..c13739d 100644 --- a/doc/crunch.txt +++ b/doc/crunch.txt @@ -159,6 +159,15 @@ evaluate the expressions and see the results. area = pow(radius,2)*pi = 78.5375 volume = pow(radius,3)*pi*4/3 = 523.583333 +Could use ";" to separate different expressions in one line. For the following +line: + +"a = 3; b = 7; c = a * b" + +When press `g=i"`, you will get: + +"a = 3; b = 7; c = a * b = 21" + ------------------------------------------------------------------------------ User defined variables. diff --git a/test/operator.vader b/test/operator.vader index 0d70a5f..4b0c573 100644 --- a/test/operator.vader +++ b/test/operator.vader @@ -20,10 +20,17 @@ Do (Test Operator: single line): Expect: 5*5 = 25 ############################################################################## +Given: + a = 3; b = 7; c = a*b +Do (Test Operator: single line with variable): + g== +Expect: + a = 3; b = 7; c = a*b = 21 +############################################################################## Given: 5*5 Do (Test Operator: inner word): - g=iW + wg=iW Expect: 5*5 = 25 ############################################################################## From 5216c278b757d4b75cbe6566c27b3d07d74601da Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Wed, 23 May 2018 12:13:51 -0400 Subject: [PATCH 5/6] refactor: use single quote for char --- autoload/crunch.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/crunch.vim b/autoload/crunch.vim index 3e81a65..ee4c2c8 100644 --- a/autoload/crunch.vim +++ b/autoload/crunch.vim @@ -113,7 +113,7 @@ function! crunch#eval(exprs) abort "{{{2 " Decho string(expr_list).'= the expr_lines_list' let expr_separator = "\n" let expr_lines = join(expr_list, expr_separator) - let expr_lines = substitute(expr_lines, separator_magic, ";", 'g') + let expr_lines = substitute(expr_lines, separator_magic, ';', 'g') " Decho expr_lines.'= the expr_lines' let s:variables = {} return expr_lines From 9bef6ac6b102cad821a43af1e0531eff322ae984 Mon Sep 17 00:00:00 2001 From: Ryan Carney Date: Wed, 23 May 2018 11:15:41 -0700 Subject: [PATCH 6/6] tests: add "Given:" that was accidentally removed. --- test/operator.vader | 1 + 1 file changed, 1 insertion(+) diff --git a/test/operator.vader b/test/operator.vader index 2401cb3..c2de4c8 100644 --- a/test/operator.vader +++ b/test/operator.vader @@ -27,6 +27,7 @@ Do (Test Operator: single line with variable): Expect: a = 3; b = 7; c = a*b = 21 ############################################################################## +Given: 5*5 Do (Test Operator: inner word): g=iW