diff options
author | Mu Qiao <qiaomuf@gentoo.org> | 2012-02-28 15:22:55 +0800 |
---|---|---|
committer | Mu Qiao <qiaomuf@gentoo.org> | 2012-02-28 15:22:55 +0800 |
commit | 565c53e2416f102a845e78b96360f6e39f5d1637 (patch) | |
tree | ecb0dde8ea0a8528adfe5cee0c012041319c3aa2 | |
parent | Parser&Walker: respect precedence in builtin test (diff) | |
download | libbash-565c53e2416f102a845e78b96360f6e39f5d1637.tar.gz libbash-565c53e2416f102a845e78b96360f6e39f5d1637.tar.bz2 libbash-565c53e2416f102a845e78b96360f6e39f5d1637.zip |
Parser&Walker: allow multiple arithmetic expressions
-rw-r--r-- | bashast/bashast.g | 18 | ||||
-rw-r--r-- | bashast/features_script/features.sh.ast | 2 | ||||
-rw-r--r-- | bashast/features_script/features.sh.walker.tokens | 2 | ||||
-rw-r--r-- | bashast/gunit/arith_main.gunit | 157 | ||||
-rw-r--r-- | bashast/gunit/array.gunit | 20 | ||||
-rw-r--r-- | bashast/gunit/assoc_array.gunit | 12 | ||||
-rw-r--r-- | bashast/gunit/compound.gunit | 18 | ||||
-rw-r--r-- | bashast/gunit/expansions.gunit | 6 | ||||
-rw-r--r-- | bashast/gunit/param_main.gunit | 13 | ||||
-rw-r--r-- | bashast/libbashWalker.g | 22 | ||||
-rw-r--r-- | scripts/arithmetic_assignment.bash | 5 | ||||
-rw-r--r-- | scripts/command_execution.bash | 1 | ||||
-rw-r--r-- | scripts/compound_command.bash | 5 | ||||
-rw-r--r-- | scripts/var_def.bash | 4 | ||||
-rw-r--r-- | scripts/var_expansion.bash | 2 |
15 files changed, 161 insertions, 126 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index 8286a00..ded2fab 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -68,6 +68,7 @@ tokens{ REDIR; ARITHMETIC_CONDITION; ARITHMETIC_EXPRESSION; + ARITHMETIC; KEYWORD_TEST; BUILTIN_TEST; MATCH_ANY_EXCEPT; @@ -525,11 +526,11 @@ for_expr ) DO wspace command_list semiel DONE -> ^(FOR name for_each_value* command_list) | LLPAREN EOL? // initilization - (BLANK? init=arithmetic BLANK?|BLANK)? + (BLANK? init=arithmetics BLANK?|BLANK)? // condition - (SEMIC (BLANK? fcond=arithmetic BLANK?|BLANK)? SEMIC|DOUBLE_SEMIC) + (SEMIC (BLANK? fcond=arithmetics BLANK?|BLANK)? SEMIC|DOUBLE_SEMIC) // modification - (BLANK? mod=arithmetic)? wspace? RPAREN RPAREN semiel DO wspace command_list semiel DONE + (BLANK? mod=arithmetics)? wspace? RPAREN RPAREN semiel DO wspace command_list semiel DONE -> ^(CFOR ^(FOR_INIT $init)? ^(FOR_COND $fcond)? command_list ^(FOR_MOD $mod)?) ); for_each_value @@ -585,7 +586,7 @@ current_shell : LBRACE wspace command_list semiel RBRACE -> ^(CURRENT_SHELL command_list); arithmetic_expression - : LLPAREN wspace? arithmetic wspace? RPAREN RPAREN -> ^(ARITHMETIC_EXPRESSION arithmetic); + : LLPAREN wspace? arithmetics wspace? RPAREN RPAREN -> ^(ARITHMETIC_EXPRESSION arithmetics); condition_comparison : condition_expr -> ^(COMPOUND_COND condition_expr); @@ -841,9 +842,12 @@ parameter_expansion | COLON BLANK? ( os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)? - -> ^(OFFSET variable_name $os ^($len)?) + // It will make the tree parser's work easier if OFFSET is used as the root of arithmetic. + // Otherwise, the tree parser can see several arithmetic expressions but can not tell + // which one is for offset and which one is for length. + -> ^(OFFSET variable_name ^(OFFSET $os) ^(OFFSET ^($len))?) | COLON BLANK? len=explicit_arithmetic - -> ^(OFFSET variable_name NUMBER["0"] ^($len)?) + -> ^(OFFSET variable_name ^(OFFSET NUMBER["0"]) ^(OFFSET ^($len))?) ) | parameter_delete_operator parameter_delete_pattern -> ^(parameter_delete_operator variable_name parameter_delete_pattern) @@ -962,7 +966,7 @@ arithmetic_part | DOLLAR LSQUARE BLANK? arithmetics BLANK? RSQUARE -> arithmetics; arithmetics - : arithmetic (COMMA! BLANK!? arithmetic)*; + : arithmetic (COMMA BLANK? arithmetic)* -> ^(ARITHMETIC arithmetic)+; arithmetics_test : arithmetics EOF!; diff --git a/bashast/features_script/features.sh.ast b/bashast/features_script/features.sh.ast index fc0eb4c..60d71b3 100644 --- a/bashast/features_script/features.sh.ast +++ b/bashast/features_script/features.sh.ast @@ -1 +1 @@ -(LIST (COMMAND (FUNCTION (STRING lots_o_echo) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The number of tests that have failed : (VAR_REF failedtests)))) (COMMAND (STRING echo) (STRING (SINGLE_QUOTED_STRING '$failedtests'))) (COMMAND (STRING echo) (STRING (VAR_REF failedtests))))))) (COMMAND (FUNCTION (STRING do_some_arith) (CURRENT_SHELL (LIST (COMMAND (ARITHMETIC_EXPRESSION (* 5 4))) (COMMAND (ARITHMETIC_EXPRESSION (** 5 4))) (COMMAND (ARITHMETIC_EXPRESSION (+ (VAR_REF failedtests) (/ 5 4)))) (COMMAND (ARITHMETIC_EXPRESSION (+ (VAR_REF z) (MINUS_SIGN 3)))))))) (COMMAND (FUNCTION (STRING arrays) (SUBSHELL (LIST (COMMAND (VARIABLE_DEFINITIONS (= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d))))) (COMMAND (STRING echo) (STRING (VAR_REF (asdf 3)))) (COMMAND (VARIABLE_DEFINITIONS (= foo (ARRAY (STRING (COMMAND_SUB `echo 6`)) (STRING b) (STRING c) (STRING d))))) (COMMAND (VARIABLE_DEFINITIONS (= (arr (VAR_REF foo)) (STRING 3)))) (COMMAND (VARIABLE_DEFINITIONS (= bar (ARRAY (STRING a) (STRING b) (= 5 (STRING c)))))))))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING a) (STRING b)))) (COMMAND (STRING echo) (STRING (BRACE_EXP (.. a d)))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING (BRACE_EXP (STRING a) (STRING b))) (STRING c) (STRING d)))) (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c)))) (COMMAND (STRING (COMMAND_SUB $(echo foobar)))) (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING gunit) (REDIR >> (STRING filelist)))) (COMMAND (case (STRING (COMMAND_SUB `echo asdf`)) (CASE_PATTERN (BRANCH gz) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING yay)))) (CASE_PATTERN (BRANCH bzip) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING three)))) (CASE_PATTERN (BRANCH MATCH_ALL) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING woo)))))) (COMMAND (for each (STRING (COMMAND_SUB `ls |grep log`)) (LIST (COMMAND (STRING echo) (STRING (VAR_REF each))) (COMMAND (STRING cat) (STRING each))))) (COMMAND (CFOR (FOR_INIT (+ 5 3)) (FOR_COND (+ 6 2)) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (+ 3 1)))) (COMMAND (select each (STRING (COMMAND_SUB `ls |grep output`)) (LIST (COMMAND (STRING echo) (STRING asdf) (REDIR 2 > (STRING / dev / null)))))) (COMMAND (IF_STATEMENT (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COMMAND (STRING echo) (STRING yay)))))) (COMMAND (until (LIST (COMMAND (COMPOUND_COND (KEYWORD_TEST (a (STRING this / is . afile)))))) (LIST (COMMAND (STRING touch) (STRING this / is . afile))))) (COMMAND (while (LIST (COMMAND (COMPOUND_COND (BUILTIN_TEST (n (STRING foobar)))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file found)))))) (COMMAND (IF_STATEMENT (if (LIST (COMMAND (COMPOUND_COND (BUILTIN_TEST (eq (STRING 5) (STRING 6)))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING something ' s wrong))))))) (COMMAND (STRING echo) (STRING this) (STRING command) (STRING has) (STRING multiple) (STRING arguments)) (COMMAND (STRING wc) (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . words))))) (|| (&& (&& (&& (COMMAND (STRING cd) (STRING build)) (COMMAND (STRING . / configure))) (COMMAND (STRING make))) (COMMAND (STRING make_install))) (COMMAND (STRING echo) (STRING fail))) (COMMAND (STRING cd) (STRING / usr / bin)) (| (COMMAND (STRING ls) (STRING - al)) (COMMAND (STRING grep) (STRING more))) (COMMAND (VARIABLE_DEFINITIONS (= asdf (STRING parameters)))) (COMMAND (STRING (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo))))) (COMMAND (STRING (VAR_REF (OFFSET asdf 8)))) (COMMAND (STRING (VAR_REF (! asdf *)))) (COMMAND (STRING (VAR_REF (! asdf @)))) (COMMAND (STRING (VAR_REF (# foo)))) (COMMAND (STRING (VAR_REF (REPLACE_FIRST replaice (STRING with) (STRING pattern))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_START asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_END asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_END asdf (STRING bar))))) (COMMAND (STRING (VAR_REF 1)) (STRING (VAR_REF @)) (STRING (VAR_REF *))) (COMMAND (STRING (VAR_REF ?))) (COMMAND (STRING (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar))))) (COMMAND (VARIABLE_DEFINITIONS (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -))))))) (| (COMMAND (STRING cat) (STRING asdf)) (COMMAND (STRING grep) (STRING three) (REDIR 2 >& (FILE_DESCRIPTOR 1)) (REDIR > (STRING / dev / null)))) (COMMAND (STRING echo) (STRING asdf) (REDIR >> (STRING APPEND))) (COMMAND (STRING echo) (STRING cat) (<<< (STRING word)))) +(LIST (COMMAND (FUNCTION (STRING lots_o_echo) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The number of tests that have failed : (VAR_REF failedtests)))) (COMMAND (STRING echo) (STRING (SINGLE_QUOTED_STRING '$failedtests'))) (COMMAND (STRING echo) (STRING (VAR_REF failedtests))))))) (COMMAND (FUNCTION (STRING do_some_arith) (CURRENT_SHELL (LIST (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (* 5 4)))) (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (** 5 4)))) (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (+ (VAR_REF failedtests) (/ 5 4))))) (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (+ (VAR_REF z) (MINUS_SIGN 3))))))))) (COMMAND (FUNCTION (STRING arrays) (SUBSHELL (LIST (COMMAND (VARIABLE_DEFINITIONS (= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d))))) (COMMAND (STRING echo) (STRING (VAR_REF (asdf (ARITHMETIC 3))))) (COMMAND (VARIABLE_DEFINITIONS (= foo (ARRAY (STRING (COMMAND_SUB `echo 6`)) (STRING b) (STRING c) (STRING d))))) (COMMAND (VARIABLE_DEFINITIONS (= (arr (ARITHMETIC (VAR_REF foo))) (STRING 3)))) (COMMAND (VARIABLE_DEFINITIONS (= bar (ARRAY (STRING a) (STRING b) (= (ARITHMETIC 5) (STRING c)))))))))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING a) (STRING b)))) (COMMAND (STRING echo) (STRING (BRACE_EXP (.. a d)))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING (BRACE_EXP (STRING a) (STRING b))) (STRING c) (STRING d)))) (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c)))) (COMMAND (STRING (COMMAND_SUB $(echo foobar)))) (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING gunit) (REDIR >> (STRING filelist)))) (COMMAND (case (STRING (COMMAND_SUB `echo asdf`)) (CASE_PATTERN (BRANCH gz) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING yay)))) (CASE_PATTERN (BRANCH bzip) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING three)))) (CASE_PATTERN (BRANCH MATCH_ALL) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING woo)))))) (COMMAND (for each (STRING (COMMAND_SUB `ls |grep log`)) (LIST (COMMAND (STRING echo) (STRING (VAR_REF each))) (COMMAND (STRING cat) (STRING each))))) (COMMAND (CFOR (FOR_INIT (ARITHMETIC (+ 5 3))) (FOR_COND (ARITHMETIC (+ 6 2))) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (ARITHMETIC (+ 3 1))))) (COMMAND (select each (STRING (COMMAND_SUB `ls |grep output`)) (LIST (COMMAND (STRING echo) (STRING asdf) (REDIR 2 > (STRING / dev / null)))))) (COMMAND (IF_STATEMENT (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COMMAND (STRING echo) (STRING yay)))))) (COMMAND (until (LIST (COMMAND (COMPOUND_COND (KEYWORD_TEST (a (STRING this / is . afile)))))) (LIST (COMMAND (STRING touch) (STRING this / is . afile))))) (COMMAND (while (LIST (COMMAND (COMPOUND_COND (BUILTIN_TEST (n (STRING foobar)))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file found)))))) (COMMAND (IF_STATEMENT (if (LIST (COMMAND (COMPOUND_COND (BUILTIN_TEST (eq (STRING 5) (STRING 6)))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING something ' s wrong))))))) (COMMAND (STRING echo) (STRING this) (STRING command) (STRING has) (STRING multiple) (STRING arguments)) (COMMAND (STRING wc) (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . words))))) (|| (&& (&& (&& (COMMAND (STRING cd) (STRING build)) (COMMAND (STRING . / configure))) (COMMAND (STRING make))) (COMMAND (STRING make_install))) (COMMAND (STRING echo) (STRING fail))) (COMMAND (STRING cd) (STRING / usr / bin)) (| (COMMAND (STRING ls) (STRING - al)) (COMMAND (STRING grep) (STRING more))) (COMMAND (VARIABLE_DEFINITIONS (= asdf (STRING parameters)))) (COMMAND (STRING (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo))))) (COMMAND (STRING (VAR_REF (OFFSET asdf (OFFSET (ARITHMETIC 8)))))) (COMMAND (STRING (VAR_REF (! asdf *)))) (COMMAND (STRING (VAR_REF (! asdf @)))) (COMMAND (STRING (VAR_REF (# foo)))) (COMMAND (STRING (VAR_REF (REPLACE_FIRST replaice (STRING with) (STRING pattern))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_START asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_END asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_END asdf (STRING bar))))) (COMMAND (STRING (VAR_REF 1)) (STRING (VAR_REF @)) (STRING (VAR_REF *))) (COMMAND (STRING (VAR_REF ?))) (COMMAND (STRING (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar))))) (COMMAND (VARIABLE_DEFINITIONS (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -))))))) (| (COMMAND (STRING cat) (STRING asdf)) (COMMAND (STRING grep) (STRING three) (REDIR 2 >& (FILE_DESCRIPTOR 1)) (REDIR > (STRING / dev / null)))) (COMMAND (STRING echo) (STRING asdf) (REDIR >> (STRING APPEND))) (COMMAND (STRING echo) (STRING cat) (<<< (STRING word)))) diff --git a/bashast/features_script/features.sh.walker.tokens b/bashast/features_script/features.sh.walker.tokens index 7082afd..8b92d49 100644 --- a/bashast/features_script/features.sh.walker.tokens +++ b/bashast/features_script/features.sh.walker.tokens @@ -1,2 +1,2 @@ -LIST DOWN COMMAND DOWN FUNCTION DOWN STRING DOWN NAME UP CURRENT_SHELL DOWN LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN DOUBLE_QUOTED_STRING DOWN NAME BLANK NAME BLANK NAME BLANK NAME BLANK NAME BLANK NAME BLANK NAME COLON BLANK VAR_REF DOWN NAME UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN SINGLE_QUOTED_STRING DOWN SINGLE_QUOTED_STRING_TOKEN UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN VAR_REF DOWN NAME UP UP UP UP UP UP UP COMMAND DOWN FUNCTION DOWN STRING DOWN NAME UP CURRENT_SHELL DOWN LIST DOWN COMMAND DOWN ARITHMETIC_EXPRESSION DOWN TIMES DOWN DIGIT DIGIT UP UP UP COMMAND DOWN ARITHMETIC_EXPRESSION DOWN EXP DOWN DIGIT DIGIT UP UP UP COMMAND DOWN ARITHMETIC_EXPRESSION DOWN PLUS DOWN VAR_REF DOWN NAME UP SLASH DOWN DIGIT DIGIT UP UP UP UP COMMAND DOWN ARITHMETIC_EXPRESSION DOWN PLUS DOWN VAR_REF DOWN LETTER UP MINUS_SIGN DOWN DIGIT UP UP UP UP UP UP UP UP COMMAND DOWN FUNCTION DOWN STRING DOWN NAME UP SUBSHELL DOWN LIST DOWN COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME ARRAY DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN VAR_REF DOWN NAME DOWN DIGIT UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME ARRAY DOWN STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP STRING DOWN LETTER UP STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME DOWN VAR_REF DOWN NAME UP UP STRING DOWN DIGIT UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME ARRAY DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP EQUALS DOWN DIGIT STRING DOWN LETTER UP UP UP UP UP UP UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN BRACE_EXP DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN BRACE_EXP DOWN DOTDOT DOWN LETTER LETTER UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN BRACE_EXP DOWN STRING DOWN BRACE_EXP DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN LETTER BRACE_EXP DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP COMMAND DOWN STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_PAREN UP UP UP PIPE DOWN COMMAND DOWN STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN OP STRING DOWN NAME UP UP UP UP COMMAND DOWN CASE DOWN STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP CASE_PATTERN DOWN BRANCH DOWN NAME UP CASE_COMMAND LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP CASE_PATTERN DOWN BRANCH DOWN NAME UP CASE_COMMAND LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP CASE_PATTERN DOWN BRANCH DOWN MATCH_ALL UP CASE_COMMAND LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP UP COMMAND DOWN FOR DOWN NAME STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN VAR_REF DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN CFOR DOWN FOR_INIT DOWN PLUS DOWN DIGIT DIGIT UP UP FOR_COND DOWN PLUS DOWN DIGIT DIGIT UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP FOR_MOD DOWN PLUS DOWN DIGIT DIGIT UP UP UP UP COMMAND DOWN SELECT DOWN NAME STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN DIGIT GREATER_THAN STRING DOWN SLASH NAME SLASH NAME UP UP UP UP UP UP COMMAND DOWN IF_STATEMENT DOWN IF DOWN LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP UP COMMAND DOWN UNTIL DOWN LIST DOWN COMMAND DOWN COMPOUND_COND DOWN KEYWORD_TEST DOWN LETTER DOWN STRING DOWN NAME SLASH NAME DOT NAME UP UP UP UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME SLASH NAME DOT NAME UP UP UP UP UP COMMAND DOWN WHILE DOWN LIST DOWN COMMAND DOWN COMPOUND_COND DOWN BUILTIN_TEST DOWN LETTER DOWN STRING DOWN NAME UP UP UP UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN DOUBLE_QUOTED_STRING DOWN NAME BLANK NAME UP UP UP UP UP UP COMMAND DOWN IF_STATEMENT DOWN IF DOWN LIST DOWN COMMAND DOWN COMPOUND_COND DOWN BUILTIN_TEST DOWN NAME DOWN STRING DOWN DIGIT UP STRING DOWN DIGIT UP UP UP UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN DOUBLE_QUOTED_STRING DOWN NAME SQUOTE LETTER BLANK NAME UP UP UP UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN NAME UP PROCESS_SUBSTITUTION DOWN LESS_THAN LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN SLASH NAME SLASH NAME SLASH NAME SLASH NAME DOT NAME UP UP UP UP UP LOGICOR DOWN LOGICAND DOWN LOGICAND DOWN LOGICAND DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN DOT SLASH NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN SLASH NAME SLASH NAME UP UP PIPE DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN MINUS NAME UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME STRING DOWN NAME UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN USE_DEFAULT_WHEN_UNSET_OR_NULL DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN OFFSET DOWN NAME DIGIT UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN BANG DOWN NAME TIMES UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN BANG DOWN NAME AT UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN POUND DOWN NAME UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_FIRST DOWN NAME STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN LAZY_REMOVE_AT_START DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_AT_START DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN LAZY_REMOVE_AT_END DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN LAZY_REMOVE_AT_END DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN DIGIT UP UP STRING DOWN VAR_REF DOWN AT UP UP STRING DOWN VAR_REF DOWN TIMES UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN QMARK UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_ALL DOWN NAME STRING DOWN DOT UP STRING DOWN UNDERSCORE UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_AT_START DOWN NAME STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_AT_END DOWN NAME STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME STRING DOWN VAR_REF DOWN REPLACE_FIRST DOWN NAME STRING DOWN NAME MINUS UP UP UP UP UP UP UP PIPE DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN DIGIT OP FILE_DESCRIPTOR DOWN DIGIT UP UP REDIR DOWN GREATER_THAN STRING DOWN SLASH NAME SLASH NAME UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN OP STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP HERE_STRING_OP DOWN BLANK STRING DOWN NAME UP UP UP UP +LIST DOWN COMMAND DOWN FUNCTION DOWN STRING DOWN NAME UP CURRENT_SHELL DOWN LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN DOUBLE_QUOTED_STRING DOWN NAME BLANK NAME BLANK NAME BLANK NAME BLANK NAME BLANK NAME BLANK NAME COLON BLANK VAR_REF DOWN NAME UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN SINGLE_QUOTED_STRING DOWN SINGLE_QUOTED_STRING_TOKEN UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN VAR_REF DOWN NAME UP UP UP UP UP UP UP COMMAND DOWN FUNCTION DOWN STRING DOWN NAME UP CURRENT_SHELL DOWN LIST DOWN COMMAND DOWN ARITHMETIC_EXPRESSION DOWN ARITHMETIC DOWN TIMES DOWN DIGIT DIGIT UP UP UP UP COMMAND DOWN ARITHMETIC_EXPRESSION DOWN ARITHMETIC DOWN EXP DOWN DIGIT DIGIT UP UP UP UP COMMAND DOWN ARITHMETIC_EXPRESSION DOWN ARITHMETIC DOWN PLUS DOWN VAR_REF DOWN NAME UP SLASH DOWN DIGIT DIGIT UP UP UP UP UP COMMAND DOWN ARITHMETIC_EXPRESSION DOWN ARITHMETIC DOWN PLUS DOWN VAR_REF DOWN LETTER UP MINUS_SIGN DOWN DIGIT UP UP UP UP UP UP UP UP UP COMMAND DOWN FUNCTION DOWN STRING DOWN NAME UP SUBSHELL DOWN LIST DOWN COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME ARRAY DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN VAR_REF DOWN NAME DOWN ARITHMETIC DOWN DIGIT UP UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME ARRAY DOWN STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP STRING DOWN LETTER UP STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME DOWN ARITHMETIC DOWN VAR_REF DOWN NAME UP UP UP STRING DOWN DIGIT UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME ARRAY DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP EQUALS DOWN ARITHMETIC DOWN DIGIT UP STRING DOWN LETTER UP UP UP UP UP UP UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN BRACE_EXP DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN BRACE_EXP DOWN DOTDOT DOWN LETTER LETTER UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN BRACE_EXP DOWN STRING DOWN BRACE_EXP DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN LETTER BRACE_EXP DOWN STRING DOWN LETTER UP STRING DOWN LETTER UP UP UP UP COMMAND DOWN STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_PAREN UP UP UP PIPE DOWN COMMAND DOWN STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN OP STRING DOWN NAME UP UP UP UP COMMAND DOWN CASE DOWN STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP CASE_PATTERN DOWN BRANCH DOWN NAME UP CASE_COMMAND LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP CASE_PATTERN DOWN BRANCH DOWN NAME UP CASE_COMMAND LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP CASE_PATTERN DOWN BRANCH DOWN MATCH_ALL UP CASE_COMMAND LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP UP COMMAND DOWN FOR DOWN NAME STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN VAR_REF DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN CFOR DOWN FOR_INIT DOWN ARITHMETIC DOWN PLUS DOWN DIGIT DIGIT UP UP UP FOR_COND DOWN ARITHMETIC DOWN PLUS DOWN DIGIT DIGIT UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP FOR_MOD DOWN ARITHMETIC DOWN PLUS DOWN DIGIT DIGIT UP UP UP UP UP COMMAND DOWN SELECT DOWN NAME STRING DOWN COMMAND_SUB DOWN COMMAND_SUBSTITUTION_TICK UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN DIGIT GREATER_THAN STRING DOWN SLASH NAME SLASH NAME UP UP UP UP UP UP COMMAND DOWN IF_STATEMENT DOWN IF DOWN LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP UP COMMAND DOWN UNTIL DOWN LIST DOWN COMMAND DOWN COMPOUND_COND DOWN KEYWORD_TEST DOWN LETTER DOWN STRING DOWN NAME SLASH NAME DOT NAME UP UP UP UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME SLASH NAME DOT NAME UP UP UP UP UP COMMAND DOWN WHILE DOWN LIST DOWN COMMAND DOWN COMPOUND_COND DOWN BUILTIN_TEST DOWN LETTER DOWN STRING DOWN NAME UP UP UP UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN DOUBLE_QUOTED_STRING DOWN NAME BLANK NAME UP UP UP UP UP UP COMMAND DOWN IF_STATEMENT DOWN IF DOWN LIST DOWN COMMAND DOWN COMPOUND_COND DOWN BUILTIN_TEST DOWN NAME DOWN STRING DOWN DIGIT UP STRING DOWN DIGIT UP UP UP UP UP UP LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN DOUBLE_QUOTED_STRING DOWN NAME SQUOTE LETTER BLANK NAME UP UP UP UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN NAME UP PROCESS_SUBSTITUTION DOWN LESS_THAN LIST DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN SLASH NAME SLASH NAME SLASH NAME SLASH NAME DOT NAME UP UP UP UP UP LOGICOR DOWN LOGICAND DOWN LOGICAND DOWN LOGICAND DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN DOT SLASH NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN SLASH NAME SLASH NAME UP UP PIPE DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN MINUS NAME UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME STRING DOWN NAME UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN USE_DEFAULT_WHEN_UNSET_OR_NULL DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN OFFSET DOWN NAME OFFSET DOWN ARITHMETIC DOWN DIGIT UP UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN BANG DOWN NAME TIMES UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN BANG DOWN NAME AT UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN POUND DOWN NAME UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_FIRST DOWN NAME STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN LAZY_REMOVE_AT_START DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_AT_START DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN LAZY_REMOVE_AT_END DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN LAZY_REMOVE_AT_END DOWN NAME STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN DIGIT UP UP STRING DOWN VAR_REF DOWN AT UP UP STRING DOWN VAR_REF DOWN TIMES UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN QMARK UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_ALL DOWN NAME STRING DOWN DOT UP STRING DOWN UNDERSCORE UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_AT_START DOWN NAME STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN STRING DOWN VAR_REF DOWN REPLACE_AT_END DOWN NAME STRING DOWN NAME UP STRING DOWN NAME UP UP UP UP UP COMMAND DOWN VARIABLE_DEFINITIONS DOWN EQUALS DOWN NAME STRING DOWN VAR_REF DOWN REPLACE_FIRST DOWN NAME STRING DOWN NAME MINUS UP UP UP UP UP UP UP PIPE DOWN COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN DIGIT OP FILE_DESCRIPTOR DOWN DIGIT UP UP REDIR DOWN GREATER_THAN STRING DOWN SLASH NAME SLASH NAME UP UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP REDIR DOWN OP STRING DOWN NAME UP UP UP COMMAND DOWN STRING DOWN NAME UP STRING DOWN NAME UP HERE_STRING_OP DOWN BLANK STRING DOWN NAME UP UP UP UP diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit index 7e04dc3..5e33c87 100644 --- a/bashast/gunit/arith_main.gunit +++ b/bashast/gunit/arith_main.gunit @@ -23,117 +23,118 @@ gunit java_libbash; arithmetics_test: //primary: -"3" -> "3" -"foo" -> (VAR_REF foo) -"foo[1]" -> (VAR_REF (foo 1)) +"3" -> (ARITHMETIC 3) +"foo" -> (ARITHMETIC (VAR_REF foo)) +"foo[1]" -> (ARITHMETIC (VAR_REF (foo (ARITHMETIC 1)))) //unary: -"3" -> "3" -"b--" -> (POST_DECR (VAR_REF b)) -"i++" -> (POST_INCR (VAR_REF i)) +"3" -> (ARITHMETIC 3) +"b--" -> (ARITHMETIC (POST_DECR (VAR_REF b))) +"i++" -> (ARITHMETIC (POST_INCR (VAR_REF i))) //pre_inc_dec: -"++i" -> (PRE_INCR (VAR_REF i)) -"--b" -> (PRE_DECR (VAR_REF b)) +"++i" -> (ARITHMETIC (PRE_INCR (VAR_REF i))) +"--b" -> (ARITHMETIC (PRE_DECR (VAR_REF b))) //unary: -"6" -> "6" -"+9" -> (PLUS_SIGN 9) -"-15" -> (MINUS_SIGN 15) -"++ z" -> (PRE_INCR (VAR_REF z)) -"f--" -> (POST_DECR (VAR_REF f)) -"~8" -> (~ 8) -"!8" -> (! 8) -"!!8" -> (! (! 8)) -"--8" -> (PRE_DECR 8) +"6" -> (ARITHMETIC 6) +"+9" -> (ARITHMETIC (PLUS_SIGN 9)) +"-15" -> (ARITHMETIC (MINUS_SIGN 15)) +"++ z" -> (ARITHMETIC (PRE_INCR (VAR_REF z))) +"f--" -> (ARITHMETIC (POST_DECR (VAR_REF f))) +"~8" -> (ARITHMETIC (~ 8)) +"!8" -> (ARITHMETIC (! 8)) +"!!8" -> (ARITHMETIC (! (! 8))) +"--8" -> (ARITHMETIC (PRE_DECR 8)) //exponential: -"8" -> "8" -"6**2" -> (** 6 2) -"-5**+4" -> (** (MINUS_SIGN 5) (PLUS_SIGN 4)) +"8" -> (ARITHMETIC 8) +"6**2" -> (ARITHMETIC (** 6 2)) +"-5**+4" -> (ARITHMETIC (** (MINUS_SIGN 5) (PLUS_SIGN 4))) //times_division_modulus: -"9" -> "9" -"7 * 9" -> (* 7 9) -"7 / 9" -> (/ 7 9) -"7 % 9" -> (% 7 9) -"6*4*3" -> (* (* 6 4) 3) -"6*4/3" -> (/ (* 6 4) 3) -"6%4*3" -> (* (% 6 4) 3) -"7/3**6" -> (/ 7 (** 3 6)) -"7/-3**6" -> (/ 7 (** (MINUS_SIGN 3) 6)) +"9" -> (ARITHMETIC 9) +"7 * 9" -> (ARITHMETIC (* 7 9)) +"7 / 9" -> (ARITHMETIC (/ 7 9)) +"7 % 9" -> (ARITHMETIC (% 7 9)) +"6*4*3" -> (ARITHMETIC (* (* 6 4) 3)) +"6*4/3" -> (ARITHMETIC (/ (* 6 4) 3)) +"6%4*3" -> (ARITHMETIC (* (% 6 4) 3)) +"7/3**6" -> (ARITHMETIC (/ 7 (** 3 6))) +"7/-3**6" -> (ARITHMETIC (/ 7 (** (MINUS_SIGN 3) 6))) //addsub: -"10" -> "10" -"9+27" -> (+ 9 27) -"9-27" -> (- 9 27) -"9-27+8" -> (+ (- 9 27) 8) -"9-35*-2" -> (- 9 (* 35 (MINUS_SIGN 2))) -"9*5+2" -> (+ (* 9 5) 2) +"10" -> (ARITHMETIC 10) +"9+27" -> (ARITHMETIC (+ 9 27)) +"9-27" -> (ARITHMETIC (- 9 27)) +"9-27+8" -> (ARITHMETIC (+ (- 9 27) 8)) +"9-35*-2" -> (ARITHMETIC (- 9 (* 35 (MINUS_SIGN 2)))) +"9*5+2" -> (ARITHMETIC (+ (* 9 5) 2)) //shifts: -"16" -> "16" -"16+2>>3" -> (>> (+ 16 2) 3) -"16+2<<3" -> (<< (+ 16 2) 3) +"16" -> (ARITHMETIC 16) +"16+2>>3" -> (ARITHMETIC (>> (+ 16 2) 3)) +"16+2<<3" -> (ARITHMETIC (<< (+ 16 2) 3)) //compare: -"17" ->"17" -"19<20" -> (< 19 20) -"19!=20" -> (NOT_EQUALS 19 20) -"19==20" -> (EQUALS_TO 19 20) +"17" ->(ARITHMETIC 17) +"19<20" -> (ARITHMETIC (< 19 20)) +"19!=20" -> (ARITHMETIC (NOT_EQUALS 19 20)) +"19==20" -> (ARITHMETIC (EQUALS_TO 19 20)) //bitwiseand: -"17" -> "17" -"17 & 15" -> (& 17 15) +"17" -> (ARITHMETIC 17) +"17 & 15" -> (ARITHMETIC (& 17 15)) //bitwisexor: -"17" -> "17" -"17 ^ 15" -> (^ 17 15) +"17" -> (ARITHMETIC 17) +"17 ^ 15" -> (ARITHMETIC (^ 17 15)) //bitwiseor: -"17" -> "17" -"17 | 15" -> (| 17 15) +"17" -> (ARITHMETIC 17) +"17 | 15" -> (ARITHMETIC (| 17 15)) //logicand: -"17" -> "17" -"17 && 15" -> (&& 17 15) +"17" -> (ARITHMETIC 17) +"17 && 15" -> (ARITHMETIC (&& 17 15)) //logicor: -"17" -> "17" -"17 || 15" -> (|| 17 15) +"17" -> (ARITHMETIC 17) +"17 || 15" -> (ARITHMETIC (|| 17 15)) //arithmetic: -"foo=5+3" -> (= foo (+ 5 3)) -"foo[5]=5+3" -> (= (foo 5) (+ 5 3)) -"${foo[5]}=3" -> (= (VAR_REF (VAR_REF (foo 5))) 3) -"${foo[5]}*=3" -> (MUL_ASSIGN (VAR_REF (VAR_REF (foo 5))) 3) -"${foo[5]}^=3" -> (XOR_ASSIGN (VAR_REF (VAR_REF (foo 5))) 3) -"var *= 5" -> (MUL_ASSIGN var 5) -"var /= 5" -> (DIVIDE_ASSIGN var 5) -"var %= 5" -> (MOD_ASSIGN var 5) -"asdf += 5" -> (PLUS_ASSIGN asdf 5) -"var -= 5" -> (MINUS_ASSIGN var 5) -"var <<= 5" -> (LSHIFT_ASSIGN var 5) -"var >>= 5" -> (RSHIFT_ASSIGN var 5) -"var &= 5" -> (AND_ASSIGN var 5) -"var ^= 5" -> (XOR_ASSIGN var 5) -"var |= 5" -> (OR_ASSIGN var 5) +"foo=5+3" -> (ARITHMETIC (= foo (+ 5 3))) +"foo[5]=5+3" -> (ARITHMETIC (= (foo (ARITHMETIC 5)) (+ 5 3))) +"${foo[5]}=3" -> (ARITHMETIC (= (VAR_REF (VAR_REF (foo (ARITHMETIC 5)))) 3)) +"${foo[5]}*=3" -> (ARITHMETIC (MUL_ASSIGN (VAR_REF (VAR_REF (foo (ARITHMETIC 5)))) 3)) +"${foo[5]}^=3" -> (ARITHMETIC (XOR_ASSIGN (VAR_REF (VAR_REF (foo (ARITHMETIC 5)))) 3)) +"var *= 5" -> (ARITHMETIC (MUL_ASSIGN var 5)) +"var /= 5" -> (ARITHMETIC (DIVIDE_ASSIGN var 5)) +"var %= 5" -> (ARITHMETIC (MOD_ASSIGN var 5)) +"asdf += 5" -> (ARITHMETIC (PLUS_ASSIGN asdf 5)) +"var -= 5" -> (ARITHMETIC (MINUS_ASSIGN var 5)) +"var <<= 5" -> (ARITHMETIC (LSHIFT_ASSIGN var 5)) +"var >>= 5" -> (ARITHMETIC (RSHIFT_ASSIGN var 5)) +"var &= 5" -> (ARITHMETIC (AND_ASSIGN var 5)) +"var ^= 5" -> (ARITHMETIC (XOR_ASSIGN var 5)) +"var |= 5" -> (ARITHMETIC (OR_ASSIGN var 5)) "3=7" FAIL -"13"->"13" -"5?7:2"->(ARITHMETIC_CONDITION 5 7 2) -"(4-3)?0:1"->(ARITHMETIC_CONDITION (- 4 3) 0 1) +"13"->(ARITHMETIC 13) +"5?7:2"->(ARITHMETIC (ARITHMETIC_CONDITION 5 7 2)) +"(4-3)?0:1"-> (ARITHMETIC (ARITHMETIC_CONDITION (ARITHMETIC (- 4 3)) 0 1)) +"(4-3)?(0,2):1"-> (ARITHMETIC (ARITHMETIC_CONDITION (ARITHMETIC (- 4 3)) (ARITHMETIC 0) (ARITHMETIC 2) 1)) //arithmetics: -"~ 10" -> (~ 10) +"~ 10" -> (ARITHMETIC (~ 10)) arithmetic_expansion: -"$((5+4, 3+2, a*b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b))) -"$[1]" -> (ARITHMETIC_EXPRESSION 1) -"$(($((1))))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC_EXPRESSION 1)) +"$((5+4, 3+2, a*b))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 5 4)) (ARITHMETIC (+ 3 2)) (ARITHMETIC (* (VAR_REF a) (VAR_REF b)))) +"$[1]" -> (ARITHMETIC_EXPRESSION (ARITHMETIC 1)) +"$(($((1))))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC (ARITHMETIC_EXPRESSION (ARITHMETIC 1)))) start: -"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2))))) -"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (PRE_INCR (VAR_REF i)))))) -"echo $(( ++i ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (PRE_INCR (VAR_REF i)))))) -"echo \"The solution is: $(( 3+2 ))\""-> (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The solution is : (ARITHMETIC_EXPRESSION (+ 3 2)))))) +"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 3 2)))))) +"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (ARITHMETIC (PRE_INCR (VAR_REF i))))))) +"echo $(( ++i ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (ARITHMETIC (PRE_INCR (VAR_REF i))))))) +"echo \"The solution is: $(( 3+2 ))\""-> (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The solution is : (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 3 2))))))) diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit index 514eb53..ddfdfeb 100644 --- a/bashast/gunit/array.gunit +++ b/bashast/gunit/array.gunit @@ -36,22 +36,22 @@ builtin_variable_definitions: variable_reference: "$asdf" -> (VAR_REF asdf) -"${asdf[0]:-default}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL (asdf 0) (STRING default))) -"${asdf[3]}" -> (VAR_REF (asdf 3)) -"${asdf[4] }" -> (VAR_REF (asdf 4)) -"${asdf[i*2]}" -> (VAR_REF (asdf (* (VAR_REF i) 2))) -"${asdf[1]:2:2}" -> (VAR_REF (OFFSET (asdf 1) 2 2)) -"${asdf[2]##word}" -> (VAR_REF (REPLACE_AT_START (asdf 2) (STRING word))) -"${asdf[3]%%word}" -> (VAR_REF (REPLACE_AT_END (asdf 3) (STRING word))) -"${asdf[4]//pattern}" -> (VAR_REF (REPLACE_ALL (asdf 4) (STRING pattern))) +"${asdf[0]:-default}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL (asdf (ARITHMETIC 0)) (STRING default))) +"${asdf[3]}" -> (VAR_REF (asdf (ARITHMETIC 3))) +"${asdf[4] }" -> (VAR_REF (asdf (ARITHMETIC 4))) +"${asdf[i*2]}" -> (VAR_REF (asdf (ARITHMETIC (* (VAR_REF i) 2)))) +"${asdf[1]:2:2}" -> (VAR_REF (OFFSET (asdf (ARITHMETIC 1)) (OFFSET (ARITHMETIC 2)) (OFFSET (ARITHMETIC 2)))) +"${asdf[2]##word}" -> (VAR_REF (REPLACE_AT_START (asdf (ARITHMETIC 2)) (STRING word))) +"${asdf[3]%%word}" -> (VAR_REF (REPLACE_AT_END (asdf (ARITHMETIC 3)) (STRING word))) +"${asdf[4]//pattern}" -> (VAR_REF (REPLACE_ALL (asdf (ARITHMETIC 4)) (STRING pattern))) "${asdf}" -> (VAR_REF asdf) "${#asdf[0]}" -> (VAR_REF (# (asdf 0))) -"${#asdf[ $i ]}" -> (VAR_REF (# (asdf (VAR_REF i)))) +"${#asdf[ $i ]}" -> (VAR_REF (# (asdf (ARITHMETIC (VAR_REF i))))) "${asdf[@]}" -> (VAR_REF (ARRAY asdf @)) "${asdf[*]}" -> (VAR_REF (ARRAY asdf *)) "${#asdf[@]}" -> (VAR_REF (# (asdf ARRAY_SIZE))) "${#asdf[*]}" -> (VAR_REF (# (asdf ARRAY_SIZE))) -"${asdf[@]:0:1}" -> (VAR_REF (OFFSET (ARRAY asdf @) 0 1)) +"${asdf[@]:0:1}" -> (VAR_REF (OFFSET (ARRAY asdf @) (OFFSET (ARITHMETIC 0)) (OFFSET (ARITHMETIC 1)))) "${asdf[*]#path}" -> (VAR_REF (LAZY_REMOVE_AT_START (ARRAY asdf *) (STRING path))) "${asdf[@]%word}" -> (VAR_REF (LAZY_REMOVE_AT_END (ARRAY asdf @) (STRING word))) "${asdf[*]/pattern/string}" -> (VAR_REF (REPLACE_FIRST (ARRAY asdf *) (STRING pattern) (STRING string))) diff --git a/bashast/gunit/assoc_array.gunit b/bashast/gunit/assoc_array.gunit index ab58374..5af1c11 100644 --- a/bashast/gunit/assoc_array.gunit +++ b/bashast/gunit/assoc_array.gunit @@ -19,10 +19,10 @@ gunit java_libbash; variable_definition_atom: -"arr[foo]=\"asdf\"" -> (= (arr (VAR_REF foo)) (STRING (DOUBLE_QUOTED_STRING asdf))) -"arr=(a b [4]=c)" -> (= arr (ARRAY (STRING a) (STRING b) (= 4 (STRING c)))) -"asdf[idx]=${var}" -> (= (asdf (VAR_REF idx)) (STRING (VAR_REF var))) -"asdf[++i]=${var}" -> (= (asdf (PRE_INCR (VAR_REF i))) (STRING (VAR_REF var))) -"asdf[++i,j]=${var}" -> (= (asdf (PRE_INCR (VAR_REF i)) (VAR_REF j)) (STRING (VAR_REF var))) -"asdf[$((i))]=${var}" -> (= (asdf (VAR_REF i)) (STRING (VAR_REF var))) +"arr[foo]=\"asdf\"" -> (= (arr (ARITHMETIC (VAR_REF foo))) (STRING (DOUBLE_QUOTED_STRING asdf))) +"arr=(a b [4]=c)" -> (= arr (ARRAY (STRING a) (STRING b) (= (ARITHMETIC 4) (STRING c)))) +"asdf[idx]=${var}" -> (= (asdf (ARITHMETIC (VAR_REF idx))) (STRING (VAR_REF var))) +"asdf[++i]=${var}" -> (= (asdf (ARITHMETIC (PRE_INCR (VAR_REF i)))) (STRING (VAR_REF var))) +"asdf[++i,j]=${var}" -> (= (asdf (ARITHMETIC (PRE_INCR (VAR_REF i))) (ARITHMETIC (VAR_REF j))) (STRING (VAR_REF var))) +"asdf[$((i))]=${var}" -> (= (asdf (ARITHMETIC (VAR_REF i))) (STRING (VAR_REF var))) "asdf[1]=(a b c)" FAIL diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit index c5d6845..f3ec44f 100644 --- a/bashast/gunit/compound.gunit +++ b/bashast/gunit/compound.gunit @@ -35,8 +35,8 @@ condition_comparison: "[ asdf \> qwert ]" -> (COMPOUND_COND (BUILTIN_TEST (\> (STRING asdf) (STRING qwert)))) arithmetic_expression: -"((5+3))" -> (ARITHMETIC_EXPRESSION (+ 5 3)) -"(( 5+3 ))" -> (ARITHMETIC_EXPRESSION (+ 5 3)) +"((5+3))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 5 3))) +"(( 5+3, 2 ))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 5 3)) (ARITHMETIC 2)) current_shell: "{ time cat; }" -> (CURRENT_SHELL (LIST (COMMAND (STRING cat) time))) @@ -97,10 +97,10 @@ done" -> (for each (STRING (COMMAND_SUB `ls |grep log`)) (LIST (COMMAND (STRING "for i in foo$var bar ; do echo $i; done" -> (for i (STRING foo (VAR_REF var)) (STRING bar) (LIST (COMMAND (STRING echo) (STRING (VAR_REF i))))) "for each in `ls |grep log`; do echo file done" FAIL -"for ((5+3;5+3;5+3)); do echo yay; done" -> (CFOR (FOR_INIT (+ 5 3)) (FOR_COND (+ 5 3)) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (+ 5 3))) -"for ((5+3; ;5+3)); do echo yay; done" -> (CFOR (FOR_INIT (+ 5 3)) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (+ 5 3))) -"for ((;5+3 ;5+3)); do echo yay; done" -> (CFOR (FOR_COND (+ 5 3)) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (+ 5 3))) -"for ((5+3;;5+3)); do echo yay; done" -> (CFOR (FOR_INIT (+ 5 3)) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (+ 5 3))) +"for ((5+3,2;5+3;5+3)); do echo yay; done" -> (CFOR (FOR_INIT (ARITHMETIC (+ 5 3)) (ARITHMETIC 2)) (FOR_COND (ARITHMETIC (+ 5 3))) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (ARITHMETIC (+ 5 3)))) +"for ((5+3; ;5+3)); do echo yay; done" -> (CFOR (FOR_INIT (ARITHMETIC (+ 5 3))) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (ARITHMETIC (+ 5 3)))) +"for ((;5+3 ;5+3)); do echo yay; done" -> (CFOR (FOR_COND (ARITHMETIC (+ 5 3))) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (ARITHMETIC (+ 5 3)))) +"for ((5+3;;5+3)); do echo yay; done" -> (CFOR (FOR_INIT (ARITHMETIC (+ 5 3))) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (ARITHMETIC (+ 5 3)))) select_expr: "select each in `ls |grep log`; do @@ -143,7 +143,7 @@ while_expr: echo \"file found\" done" -> (while (LIST (COMMAND (STRING echo) (STRING true))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file found))))) "while echo true; do echo \"file found\"; done" -> (while (LIST (COMMAND (STRING echo) (STRING true))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file found))))) -"while(( 1>0 )); do echo ok; done" -> (while (LIST (COMMAND (ARITHMETIC_EXPRESSION (> 1 0)))) (LIST (COMMAND (STRING echo) (STRING ok)))) +"while(( 1>0 )); do echo ok; done" -> (while (LIST (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (> 1 0))))) (LIST (COMMAND (STRING echo) (STRING ok)))) "while echo true`; do echo file done" FAIL "while [[ -n \"$ver_str\" ]] ; do echo true @@ -186,12 +186,12 @@ esac" -> (case (STRING (DOUBLE_QUOTED_STRING (VAR_REF 1))) (CASE_PATTERN (BRANCH command: "[[ asdf > qwert ]] > /dev/null" -> (COMMAND (COMPOUND_COND (KEYWORD_TEST (> (STRING asdf) (STRING qwert)))) (REDIR > (STRING / dev / null))) -"(( 5+3 )) > /dev/null" -> (COMMAND (ARITHMETIC_EXPRESSION (+ 5 3)) (REDIR > (STRING / dev / null))) +"(( 5+3 )) > /dev/null" -> (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 5 3))) (REDIR > (STRING / dev / null))) "{ time cat; } > /dev/null" -> (COMMAND (CURRENT_SHELL (LIST (COMMAND (STRING cat) time))) (REDIR > (STRING / dev / null))) "(time cat) > /dev/null" -> (COMMAND (SUBSHELL (LIST (COMMAND (STRING cat) time))) (REDIR > (STRING / dev / null))) "case a in esac >/dev/null" -> (COMMAND (case (STRING a) CASE_PATTERN) (REDIR > (STRING / dev / null))) "for i in foo$var bar; do echo $i; done >/dev/null" -> (COMMAND (for i (STRING foo (VAR_REF var)) (STRING bar) (LIST (COMMAND (STRING echo) (STRING (VAR_REF i))))) (REDIR > (STRING / dev / null))) -"for ((5+3;;5+3)); do echo yay; done >/dev/null" -> (COMMAND (CFOR (FOR_INIT (+ 5 3)) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (+ 5 3))) (REDIR > (STRING / dev / null))) +"for ((5+3;;5+3)); do echo yay; done >/dev/null" -> (COMMAND (CFOR (FOR_INIT (ARITHMETIC (+ 5 3))) (LIST (COMMAND (STRING echo) (STRING yay))) (FOR_MOD (ARITHMETIC (+ 5 3)))) (REDIR > (STRING / dev / null))) "select each in `ls |grep log`; do echo \"file found\"; done >/dev/null" -> (COMMAND (select each (STRING (COMMAND_SUB `ls |grep log`)) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file found))))) (REDIR > (STRING / dev / null))) "if echo yay2; diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit index a1733e8..543012e 100644 --- a/bashast/gunit/expansions.gunit +++ b/bashast/gunit/expansions.gunit @@ -20,8 +20,8 @@ gunit java_libbash; command_list: "echo a{b,c,d}" -> (LIST (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c) (STRING d))))) -"((5+5))" -> (LIST (COMMAND (ARITHMETIC_EXPRESSION (+ 5 5)))) -"(( 4 + asdf ))" -> (LIST (COMMAND (ARITHMETIC_EXPRESSION (+ 4 (VAR_REF asdf))))) +"((5+5))" -> (LIST (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 5 5))))) +"(( 4 + asdf ))" -> (LIST (COMMAND (ARITHMETIC_EXPRESSION (ARITHMETIC (+ 4 (VAR_REF asdf)))))) "[[ while=while ]] && echo true" -> (LIST (&& (COMMAND (COMPOUND_COND (KEYWORD_TEST (STRING while = while)))) (COMMAND (STRING echo) (STRING true)))) "[[ while = while ]] && echo true" -> (LIST (&& (COMMAND (COMPOUND_COND (KEYWORD_TEST (= (STRING while) (STRING while))))) (COMMAND (STRING echo) (STRING true)))) "for each in `ls |grep output`; do @@ -30,4 +30,4 @@ done" -> (LIST (COMMAND (for each (STRING (COMMAND_SUB `ls |grep output`)) (LIST "wc <(cat /usr/share/dict/linux.words)" -> (LIST (COMMAND (STRING wc) (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . words)))))) all_expansions: -"abc $(ab) ${ab} $((ab)) `ab` \"ab\" 'ab'" -> (STRING abc (COMMAND_SUB $(ab)) (VAR_REF ab) (ARITHMETIC_EXPRESSION (VAR_REF ab)) (COMMAND_SUB `ab`) (DOUBLE_QUOTED_STRING ab) 'ab') +"abc $(ab) ${ab} $((ab)) `ab` \"ab\" 'ab'" -> (STRING abc (COMMAND_SUB $(ab)) (VAR_REF ab) (ARITHMETIC_EXPRESSION (ARITHMETIC (VAR_REF ab))) (COMMAND_SUB `ab`) (DOUBLE_QUOTED_STRING ab) 'ab') diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit index 422b7ac..4e30458 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -28,12 +28,13 @@ variable_reference: "${asdf:-public_html}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING public_html))) "${asdf='foo'}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET asdf (STRING 'foo'))) "${asdf:=}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING EMPTY_EXPANSION_VALUE))) -"${bar:7}" -> (VAR_REF (OFFSET bar 7)) -"${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10))) -"${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5))) -"${foo:5:2}" -> (VAR_REF (OFFSET foo 5 2)) -"${foo::2}" -> (VAR_REF (OFFSET foo 0 2)) -"${foo:$((5)):$((2))}" -> (VAR_REF (OFFSET foo 5 2)) +"${bar:7}" -> (VAR_REF (OFFSET bar (OFFSET (ARITHMETIC 7)))) +"${bar: -10}" -> (VAR_REF (OFFSET bar (OFFSET (ARITHMETIC (MINUS_SIGN 10))))) +"${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (OFFSET (ARITHMETIC (ARITHMETIC (+ (MINUS_SIGN 10) 5)))))) +"${bar:(-10 + 5, 3)}" -> (VAR_REF (OFFSET bar (OFFSET (ARITHMETIC (ARITHMETIC (+ (MINUS_SIGN 10) 5)) (ARITHMETIC 3))))) +"${foo:5:2}" -> (VAR_REF (OFFSET foo (OFFSET (ARITHMETIC 5)) (OFFSET (ARITHMETIC 2)))) +"${foo::2}" -> (VAR_REF (OFFSET foo (OFFSET 0) (OFFSET (ARITHMETIC 2)))) +"${foo:$((5)):$((2))}" -> (VAR_REF (OFFSET foo (OFFSET (ARITHMETIC 5)) (OFFSET (ARITHMETIC 2)))) "${!asdf*}" -> (VAR_REF (! asdf *)) "${!asdf@}" -> (VAR_REF (! asdf @)) "${!asdf[*]}" -> (VAR_REF (LIST_EXPAND asdf *)) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 7c7afaf..9b2281d 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -506,16 +506,19 @@ var_expansion returns[std::string libbash_value] libbash_value = walker->do_alternate_expansion(walker->is_unset($var_name.libbash_value), libbash_word); } - |(^(OFFSET array_name arithmetics arithmetics)) => ^(OFFSET libbash_name=array_name offset=arithmetics length=arithmetics) { + |(^(OFFSET array_name ^(OFFSET arithmetics) ^(OFFSET arithmetics))) => + ^(OFFSET libbash_name=array_name ^(OFFSET offset=arithmetics) ^(OFFSET length=arithmetics)) { libbash_value = walker->do_subarray_expansion(libbash_name, offset, length); } - |(^(OFFSET array_name offset=arithmetics)) => ^(OFFSET libbash_name=array_name offset=arithmetics) { + |(^(OFFSET array_name ^(OFFSET offset=arithmetics))) => + ^(OFFSET libbash_name=array_name ^(OFFSET offset=arithmetics)) { libbash_value = walker->do_subarray_expansion(libbash_name, offset); } - |(^(OFFSET var_name arithmetics arithmetics)) => ^(OFFSET var_name offset=arithmetics length=arithmetics) { + |(^(OFFSET var_name ^(OFFSET arithmetics) ^(OFFSET arithmetics))) => + ^(OFFSET var_name ^(OFFSET offset=arithmetics) ^(OFFSET length=arithmetics)) { libbash_value = walker->do_substring_expansion($var_name.libbash_value, offset, length, $var_name.index); } - |^(OFFSET var_name offset=arithmetics) { + |^(OFFSET var_name ^(OFFSET offset=arithmetics)) { libbash_value = walker->do_substring_expansion($var_name.libbash_value, offset, $var_name.index); } |^(POUND( @@ -1097,7 +1100,18 @@ primary returns[std::string libbash_value, unsigned index] // shell arithmetic // http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04 + +// We need to branches here because we have to deal with the following two expressions: +// (( a=123 )) +// (( a=(b=123, 4) )) arithmetics returns[long value] + :((ARITHMETIC) => result=arithmetic_part { $value = result; })+ + |result=arithmetic { $value = result; }; + +arithmetic_part returns[long value] + :^(ARITHMETIC result=arithmetics { $value = result; }); + +arithmetic returns[long value] :^(LOGICOR l=arithmetics { if(l) { diff --git a/scripts/arithmetic_assignment.bash b/scripts/arithmetic_assignment.bash index 49f6751..d4e678e 100644 --- a/scripts/arithmetic_assignment.bash +++ b/scripts/arithmetic_assignment.bash @@ -23,4 +23,7 @@ d=2 e="1+2" echo $(($a + $b)) echo $(($a + $e)) - +(( a=1 )) +echo $a +(( a=(b=2,3) )) +echo $a $b diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash index a10d229..e400409 100644 --- a/scripts/command_execution.bash +++ b/scripts/command_execution.bash @@ -78,3 +78,4 @@ o Hello\ echo \`\(\)\$\>\<\` export SRC_URI="${SRC_URI} http://www.oracle.com/technology/products/berkeley-db/db/update/${MY_PV}/patch.${MY_PV}.${i}" > /dev/null +(( i=1, j=2)) && echo $i $j diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash index ece5504..0db8ff8 100644 --- a/scripts/compound_command.bash +++ b/scripts/compound_command.bash @@ -351,3 +351,8 @@ case $target in ;; esac echo "case end" + +for((i=1,j=2;i!=2&&j!=4;++i)) +do + echo $i $j +done diff --git a/scripts/var_def.bash b/scripts/var_def.bash index 09c07c6..e757b16 100644 --- a/scripts/var_def.bash +++ b/scripts/var_def.bash @@ -31,6 +31,10 @@ echo ${ARRAY02[@]} ARRAY02[2]=4 ARRAY02[3]=5 echo ${ARRAY02[@]} +ARRAY02[3,2]=4 +echo ${ARRAY02[@]} +echo ${ARRAY02[2]} +echo ${ARRAY02[3]} EMPTY= echo $EMPTY PARTIAL[5]=5 diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash index 9f442b1..5f0bfca 100644 --- a/scripts/var_expansion.bash +++ b/scripts/var_expansion.bash @@ -17,6 +17,8 @@ echo ${FOO009: -2} echo ${FOO009:100} echo ${FOO009: -100} echo ${FOO009:(-5 + 5)} +echo ${FOO009:(-5 + 5,0)} +echo ${FOO009:(-5 + 5,1)} echo ${NOT_EXIST:0} echo ${FOO009:0:2} echo ${FOO009:2:2} |