aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bashast/bashast.g17
-rw-r--r--bashast/features_script/features.sh.tokens2
-rw-r--r--bashast/gunit/cond_main.gunit1
-rw-r--r--scripts/function_def.bash3
4 files changed, 18 insertions, 5 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 7dc9ad5..6d9ba7e 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -373,7 +373,13 @@ command
);
command_atom
- : (FOR|SELECT|IF|WHILE|UNTIL|CASE|LPAREN|LBRACE|LLPAREN|LSQUARE|TEST_EXPR) => compound_command
+ : {LA(1) == FOR|| LA(1) == SELECT|| LA(1) == IF|| LA(1) == WHILE|| LA(1) == UNTIL||
+ LA(1) == CASE|| LA(1) == LPAREN|| LA(1) == LBRACE|| LA(1) == LLPAREN|| LA(1) == LSQUARE||
+#ifdef OUTPUT_C
+ (LA(1) == NAME && LA(2) == BLANK && "test" == get_string(LT(1)))}? => compound_command
+#else
+ (LA(1) == NAME && LA(2) == BLANK && "test".equals(get_string(LT(1))))}? => compound_command
+#endif
| FUNCTION BLANK string_expr_no_reserved_word ((BLANK? parens wspace?)|wspace) compound_command
-> ^(FUNCTION string_expr_no_reserved_word compound_command)
| (name (LSQUARE|EQUALS|PLUS EQUALS)) => variable_definitions
@@ -581,7 +587,11 @@ condition_comparison
condition_expr
: LSQUARE LSQUARE wspace keyword_condition wspace RSQUARE RSQUARE -> ^(KEYWORD_TEST keyword_condition)
| LSQUARE wspace builtin_condition wspace RSQUARE -> ^(BUILTIN_TEST builtin_condition)
- | TEST_EXPR wspace? builtin_condition-> ^(BUILTIN_TEST builtin_condition);
+#ifdef OUTPUT_C
+ | {LA(1) == NAME && LA(2) == BLANK && get_string(LT(1)) == "test"}? => NAME wspace? builtin_condition-> ^(BUILTIN_TEST builtin_condition);
+#else
+ | {LA(1) == NAME && LA(2) == BLANK && "test".equals(get_string(LT(1)))}? => NAME wspace? builtin_condition-> ^(BUILTIN_TEST builtin_condition);
+#endif
keyword_condition
: ((BANG) => keyword_negation_primary|keyword_condition_primary) (BLANK!? (LOGICOR^|LOGICAND^) BLANK!? keyword_condition)?;
@@ -720,7 +730,7 @@ string_part
ns_string_part
: num|name|escaped_character
- |OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
+ |OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON
|TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT
// Escaped characters
|ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK
@@ -1084,7 +1094,6 @@ SLASH : '/';
COLON : ':';
QMARK : '?';
-TEST_EXPR : 'test ';
LOCAL : 'local';
EXPORT : 'export';
LOGICAND : '&&';
diff --git a/bashast/features_script/features.sh.tokens b/bashast/features_script/features.sh.tokens
index fc55123..f91800f 100644
--- a/bashast/features_script/features.sh.tokens
+++ b/bashast/features_script/features.sh.tokens
@@ -85,7 +85,7 @@
85 BLANK NAME BLANK DQUOTE NAME BLANK NAME DQUOTE EOL
86 DONE EOL
87
-88 IF BLANK TEST_EXPR DIGIT BLANK MINUS NAME BLANK DIGIT SEMIC BLANK THEN EOL
+88 IF BLANK NAME BLANK DIGIT BLANK MINUS NAME BLANK DIGIT SEMIC BLANK THEN EOL
89 BLANK NAME BLANK DQUOTE NAME SQUOTE LETTER BLANK NAME DQUOTE EOL
90 FI EOL
91
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 7b0aee5..fbf785e 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -36,3 +36,4 @@ condition_expr:
"[[ \"${element}\" =~ (^[^[:space:]]+\ .) ]]" -> (KEYWORD_TEST (MATCH_REGULAR_EXPRESSION (STRING (DOUBLE_QUOTED_STRING (VAR_REF element))) (STRING ( ^ [ ^ [ : space : ] ] + \ . ))))
"[[ a<b ]]" -> (KEYWORD_TEST (< (STRING a) (STRING b)))
"[[ a>b ]]" -> (KEYWORD_TEST (> (STRING a) (STRING b)))
+"[[ ${VIRTUALX_REQUIRED} == always || ${VIRTUALX_REQUIRED} == test ]]" -> (KEYWORD_TEST (|| (MATCH_PATTERN (STRING (VAR_REF VIRTUALX_REQUIRED)) (STRING always)) (MATCH_PATTERN (STRING (VAR_REF VIRTUALX_REQUIRED)) (STRING test))))
diff --git a/scripts/function_def.bash b/scripts/function_def.bash
index 6f463a4..3918896 100644
--- a/scripts/function_def.bash
+++ b/scripts/function_def.bash
@@ -74,6 +74,7 @@ func_positional_args() {
echo $*
}
func_positional_args 1 2 3
+IFS=" \t\n"
if true; then
function_in_compound_statement() {
@@ -93,3 +94,5 @@ function shift_test() {
}
shift_test 1 2
+test-flag-CC() { echo "CC" "$1"; }
+test-flag-CC abc