Skip to content

add expression separator ; to support one line variable #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
9 changes: 7 additions & 2 deletions autoload/crunch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\n', 1)
let separator_magic = "\t \t \t\n"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to study this a bit before the merge and see if it's possible to not use the magic separator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I didn't get any better method to remember the positions of ; and \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))
Expand Down Expand Up @@ -108,7 +111,9 @@ 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"
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
Expand Down
9 changes: 9 additions & 0 deletions doc/crunch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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.

Expand Down
7 changes: 7 additions & 0 deletions test/operator.vader
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ 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
Expand Down