aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-07-28 16:44:53 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-08-02 15:52:19 +0800
commit7ee597c631c9ece2d73e81df0726c6dbc8288fd7 (patch)
tree371ecd19a51e69a7a6a9c7117328cac53737df9f
parentParser: support ${?} (diff)
downloadlibbash-7ee597c631c9ece2d73e81df0726c6dbc8288fd7.tar.gz
libbash-7ee597c631c9ece2d73e81df0726c6dbc8288fd7.tar.bz2
libbash-7ee597c631c9ece2d73e81df0726c6dbc8288fd7.zip
Parser: make spaces around < and > optional
Only < and > is optional for keyword test. Some unit tests in cond_main.gunit are fixed.
-rw-r--r--bashast/bashast.g10
-rw-r--r--bashast/gunit/cond_main.gunit8
2 files changed, 10 insertions, 8 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f2d5c3c..8486619 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -596,7 +596,7 @@ keyword_condition_binary
(
(BLANK EQUALS TILDE) => BLANK EQUALS TILDE BLANK bash_pattern_part
-> ^(MATCH_REGULAR_EXPRESSION condition_part ^(STRING bash_pattern_part))
- | BLANK keyword_binary_string_operator BLANK right=condition_part
+ | keyword_binary_string_operator right=condition_part
-> ^(keyword_binary_string_operator condition_part $right)
| BLANK (BANG EQUALS) BLANK extended_pattern_match+
-> ^(NOT_MATCH_PATTERN condition_part ^(STRING extended_pattern_match+))
@@ -619,10 +619,10 @@ scope {
| ~(BLANK|EOL|LOGICAND|LOGICOR|LPAREN|RPAREN)
)+;
keyword_binary_string_operator
- : binary_operator
- | EQUALS
- | LESS_THAN
- | GREATER_THAN;
+ : BLANK! binary_operator BLANK!
+ | BLANK! EQUALS BLANK!
+ | BLANK!? LESS_THAN BLANK!?
+ | BLANK!? GREATER_THAN BLANK!?;
builtin_condition
: ((BANG) => builtin_negation_primary|builtin_keyword_condition_primary)
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index e4810a9..7b0aee5 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -31,6 +31,8 @@ condition_expr:
"[ a == b ]" -> (BUILTIN_TEST (= (STRING a) (STRING b)))
"[ a != b ]" -> (BUILTIN_TEST (NOT_EQUALS (STRING a) (STRING b)))
"[[ \"${DISTUTILS_SRC_TEST}\" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]]" -> (KEYWORD_TEST (MATCH_REGULAR_EXPRESSION (STRING (DOUBLE_QUOTED_STRING (VAR_REF DISTUTILS_SRC_TEST))) (STRING ^ ( setup \ . py | nosetests | py \ . test | trial ( \ . * ) ? ) $)))
-"[ -n "$FROM_LANG" -a -n "$TO_LANG" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC a (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF FROM_LANG)))) (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF TO_LANG))))))
-"[ -n "$FROM_LANG" -o -n "$TO_LANG" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC o (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF FROM_LANG)))) (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF TO_LANG))))))
-"[[ "${element}" =~ (^[^[:space:]]+\ .) ]]" -> (KEYWORD_TEST (MATCH_REGULAR_EXPRESSION (STRING (DOUBLE_QUOTED_STRING (VAR_REF element))) (STRING ( ^ [ ^ [ : space : ] ] + \ . ))))
+"[ -n \"$FROM_LANG\" -a -n \"$TO_LANG\" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC a (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF FROM_LANG)))) (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF TO_LANG))))))
+"[ -n \"$FROM_LANG\" -o -n \"$TO_LANG\" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC o (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF FROM_LANG)))) (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF TO_LANG))))))
+"[[ \"${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)))