* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-03-30 12:48 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-03-30 12:48 UTC (permalink / raw
To: gentoo-commits
commit: 3bee8e8ccb14837ee561471759536fc7065fc330
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 28 14:38:32 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Mar 29 12:19:24 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3bee8e8c
Split ARITH_ASSIGN into independent tokens
It would be easier for the walker to deal with arithmetic assignment if
the ARITH_ASSIGN is splitted into independent tokens.
---
bashast/bashast.g | 16 ++++++++++++----
bashast/gunit/arith_main.gunit | 9 +++++++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index ef87271..948b839 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -364,7 +364,7 @@ ns_str_part
//Parts of strings, no slashes, no reserved words
ns_str_part_no_res
: num
- | name|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|BOP|UOP|TEST_EXPR|'_'|TILDE|INC|DEC|ARITH_ASSIGN|ESC_CHAR|CARET;
+ | name|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|BOP|UOP|TEST_EXPR|'_'|TILDE|INC|DEC|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN|ESC_CHAR|CARET;
//strings with no slashes, used in certain variable expansions
ns_str : ns_str_part* -> ^(STRING ns_str_part*);
//Allowable parts of double quoted strings
@@ -493,7 +493,7 @@ logicor : logicand (BLANK!* LOGICOR^ BLANK!* logicand)*;
arithmetic_condition
: cnd=logicor QMARK t=logicor COLON f=logicor -> ^(ARITHMETIC_CONDITION $cnd $t $f);
arithmetic_assignment
- : (name BLANK!* (EQUALS^|ARITH_ASSIGN^) BLANK!*)? logicor;
+ : (name BLANK!* (EQUALS|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN)^ BLANK!*)? logicor;
//process substitution
proc_sub: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN BLANK* clist BLANK* RPAREN -> ^(PROC_SUB $dir clist);
//the biggie: functions
@@ -561,8 +561,16 @@ LESS_THAN : '<';
GREATER_THAN : '>';
LSHIFT : '<<';
RSHIFT : '>>';
-ARITH_ASSIGN
- : (TIMES|SLASH|PCT|PLUS|MINUS|LSHIFT|RSHIFT|AMP|CARET|PIPE) EQUALS;
+MUL_ASSIGN : '*=';
+DIVIDE_ASSIGN : '/=';
+MOD_ASSIGN : '%=';
+PLUS_ASSIGN : '+=';
+MINUS_ASSIGN : '-=';
+LSHIFT_ASSIGN : '<<=';
+RSHIFT_ASSIGN : '>>=';
+AND_ASSIGN : '&=';
+XOR_ASSIGN : '^=';
+OR_ASSIGN : '|=';
//some separators
SEMIC : ';';
DOUBLE_SEMIC
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 0c39c9c..ff7f678 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -100,7 +100,16 @@ logicor:
arithmetic_assignment:
"13"->"13"
"foo=5+3" -> (= foo (+ 5 3))
+"var *= 5" -> (*= var 5)
+"var /= 5" -> (/= var 5)
+"var %= 5" -> (%= var 5)
"asdf += 5" -> (+= asdf 5)
+"var -= 5" -> (-= var 5)
+"var <<= 5" -> (<<= var 5)
+"var >>= 5" -> (>>= var 5)
+"var &= 5" -> (&= var 5)
+"var ^= 5" -> (^= var 5)
+"var |= 5" -> (|= var 5)
arithmetic_condition:
"5?7:2"->(ARITHMETIC_CONDITION 5 7 2)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-06 7:43 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-06 7:43 UTC (permalink / raw
To: gentoo-commits
commit: 9ad65f4f20c373da2517bef333ae4b4c664e1504
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 5 13:22:39 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 6 00:53:24 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9ad65f4f
Use arithmetic inside substring expansion
Bash manual claims that length and offset are arithmetic expressions.
Meanwhile, a negative offset must be separated from the colon by at
least one space to avoid being confused with the :- expansion. So a
wspace rule is added. Arithmetic expression inside substring expansion
with $(()) around is not supported yet.
---
bashast/bashast.g | 2 +-
bashast/gunit/param_main.gunit | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2659ef5..60ad096 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -254,7 +254,7 @@ var_ref
| DOLLAR '_' -> ^(VAR_REF '_');
//Variable expansions
var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ word
- | var_name COLON os=num (COLON len=num)? -> ^(OFFSET var_name $os ^($len)?)
+ | var_name COLON wspace* LPAREN? os=arithmetic RPAREN? (COLON len=arithmetic)? -> ^(OFFSET var_name $os ^($len)?)
| BANG^ var_name (TIMES|AT)
| BANG var_name LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name $op)
| POUND^ var_name
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 769f19f..a582179 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -23,6 +23,8 @@ var_ref:
"${asdf}" -> (VAR_REF asdf)
"${asdf:-foo}" -> (VAR_REF (:- asdf (STRING foo)))
"${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))
"${!asdf*}" -> (VAR_REF (! asdf *))
"${!asdf@}" -> (VAR_REF (! asdf @))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-07 7:48 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-07 7:48 UTC (permalink / raw
To: gentoo-commits
commit: 3dfa3cb77a9770a2969e0e1178b1f39c7df56ba7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 6 10:30:18 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Apr 7 03:22:49 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3dfa3cb7
Only allow number and name to appear in variable name
Previous grammar allows '@' and '*' to appear in variable name
which is not legal. These characters are used for special purpose.
---
bashast/bashast.g | 6 ++++--
bashast/gunit/param_main.gunit | 2 ++
bashast/libbashWalker.g | 2 +-
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 60ad096..01cc0df 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -269,9 +269,11 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| var_name SLASH PCT ns_str SLASH? -> ^(REPLACE_LAST var_name ns_str)
| var_name SLASH ns_str SLASH? -> ^(REPLACE_FIRST var_name ns_str)
| arr_var_ref
- | var_name;
+ | var_name
+ | TIMES
+ | AT;
//Allowable variable names in the variable expansion
-var_name: num|name|TIMES|AT;
+var_name: num|name;
//Referencing an array variable
arr_var_ref
: name^ LSQUARE! DIGIT+ RSQUARE!;
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index a582179..eb49309 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -32,6 +32,8 @@ var_ref:
"${!asdf[@]}" -> (VAR_REF (LIST_EXPAND asdf @))
"${#foo}" -> (VAR_REF (# foo))
"${foo#bar}" -> (VAR_REF (# foo (STRING bar)))
+"${fo*o#bar}" FAIL
+"${fo@o#bar}" FAIL
"${foo##bar}" -> (VAR_REF (## foo (STRING bar)))
"${foo%bar}" -> (VAR_REF (% foo (STRING bar)))
"${foo%%bar}" -> (VAR_REF (%% foo (STRING bar)))
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 52d0109..825987a 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -84,7 +84,7 @@ var_name returns[std::string libbash_value]
@after {
$libbash_value = walker->get_string($var_name.start);
}:
- num|name|TIMES|AT;
+ num|name;
var_expansion returns[std::string libbash_value]:
^(USE_DEFAULT var_name libbash_word=word) {
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-07 16:45 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-07 16:45 UTC (permalink / raw
To: gentoo-commits
commit: f551e21a770aceabed6cd6630d7c1f73d66e50e1
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Thu Apr 7 12:46:19 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Apr 7 16:39:28 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f551e21a
Make function names stricter
The grammar allowed all kinds of strings like single quoted strings as
function names. Bash has much stricter rules for function names. This
drastically reduces memory usage as backtracking is needed less.
---
bashast/bashast.g | 4 ++--
bashast/gunit/function.gunit | 13 +++++++------
bashast/gunit/simp_prog.gunit | 2 +-
3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2c72c44..e76aa0f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -488,8 +488,8 @@ arithmetic_assignment
//process substitution
proc_sub: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN BLANK* clist BLANK* RPAREN -> ^(PROC_SUB $dir clist);
//the biggie: functions
-function: FUNCTION BLANK+ fname (BLANK* parens)? wspace compound_command redirect* -> ^(FUNCTION fname compound_command redirect*)
- | fname BLANK* parens wspace compound_command redirect* -> ^(FUNCTION["function"] fname compound_command redirect*);
+function: FUNCTION BLANK+ name (BLANK* parens)? wspace compound_command redirect* -> ^(FUNCTION name compound_command redirect*)
+ | name BLANK* parens wspace compound_command redirect* -> ^(FUNCTION["function"] name compound_command redirect*);
parens : LPAREN BLANK* RPAREN;
name : NAME
| LETTER
diff --git a/bashast/gunit/function.gunit b/bashast/gunit/function.gunit
index 1ee5206..a861eab 100644
--- a/bashast/gunit/function.gunit
+++ b/bashast/gunit/function.gunit
@@ -21,14 +21,15 @@ gunit bashast;
function:
"function quit {
exit
-}" -> (function (STRING quit) (CURRSHELL (LIST (COMMAND (STRING exit)))))
+}" -> (function quit (CURRSHELL (LIST (COMMAND (STRING exit)))))
"function quit{ exit; }" FAIL
"function quit { exit }" FAIL
-"function quit { exit; }" -> (function (STRING quit) (CURRSHELL (LIST (COMMAND (STRING exit)))))
-"function foo() { :; }" -> (function (STRING foo) (CURRSHELL (LIST (COMMAND (STRING :)))))
-"foo() { :; }" -> (function (STRING foo) (CURRSHELL (LIST (COMMAND (STRING :)))))
+"function 'foo' { exit; }" FAIL
+"function quit { exit; }" -> (function quit (CURRSHELL (LIST (COMMAND (STRING exit)))))
+"function foo() { :; }" -> (function foo (CURRSHELL (LIST (COMMAND (STRING :)))))
+"foo() { :; }" -> (function foo (CURRSHELL (LIST (COMMAND (STRING :)))))
-"function quit { exit; } > /dev/null" -> (function (STRING quit) (CURRSHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
-"function help { echo hi; } 2> /dev/null" -> (function (STRING help) (CURRSHELL (LIST (COMMAND (STRING echo) (STRING hi)))) (REDIR 2 > (STRING / dev / null)))
+"function quit { exit; } > /dev/null" -> (function quit (CURRSHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
+"function help { echo hi; } 2> /dev/null" -> (function help (CURRSHELL (LIST (COMMAND (STRING echo) (STRING hi)))) (REDIR 2 > (STRING / dev / null)))
"function help { echo 3; } 2> /dev/null > output" OK
diff --git a/bashast/gunit/simp_prog.gunit b/bashast/gunit/simp_prog.gunit
index 50940f9..b86c4c4 100644
--- a/bashast/gunit/simp_prog.gunit
+++ b/bashast/gunit/simp_prog.gunit
@@ -35,4 +35,4 @@ hello () {
}
hello
quit
-echo foo" -> (LIST (function (STRING quit) (CURRSHELL (LIST (COMMAND (STRING exit))))) (function (STRING hello) (CURRSHELL (LIST (COMMAND (STRING echo) (STRING Hello !))))) (COMMAND (STRING hello)) (COMMAND (STRING quit)) (COMMAND (STRING echo) (STRING foo)))
+echo foo" -> (LIST (function quit (CURRSHELL (LIST (COMMAND (STRING exit))))) (function hello (CURRSHELL (LIST (COMMAND (STRING echo) (STRING Hello !))))) (COMMAND (STRING hello)) (COMMAND (STRING quit)) (COMMAND (STRING echo) (STRING foo)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-08 14:26 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-08 14:26 UTC (permalink / raw
To: gentoo-commits
commit: b28640eea98b8d3e691c83fece6ef66dcfa49976
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 8 13:41:29 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Apr 8 13:41:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b28640ee
Simplify $_ handling
The special variable doesn't need its own branch as the name rule
already covers it.
---
bashast/bashast.g | 3 +--
bashast/gunit/param_main.gunit | 2 ++
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 7f4bed5..e167f9f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -246,8 +246,7 @@ var_ref
| DOLLAR POUND -> ^(VAR_REF POUND)
| DOLLAR QMARK -> ^(VAR_REF QMARK)
| DOLLAR MINUS -> ^(VAR_REF MINUS)
- | DOLLAR BANG -> ^(VAR_REF BANG)
- | DOLLAR '_' -> ^(VAR_REF '_');
+ | DOLLAR BANG -> ^(VAR_REF BANG);
//Variable expansions
var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ word
| var_name COLON wspace* LPAREN? os=arithmetic RPAREN? (COLON len=arithmetic)? -> ^(OFFSET var_name $os ^($len)?)
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index eb49309..6668dd9 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -45,6 +45,8 @@ var_ref:
"${@}" -> (VAR_REF @)
"${3}" -> (VAR_REF 3)
"$?" -> (VAR_REF ?)
+"$_" -> (VAR_REF _)
+"${_}" -> (VAR_REF _)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_FIRST PV (STRING foo) (STRING bar)))
"${PV/%foo/bar}" -> (VAR_REF (REPLACE_LAST PV (STRING foo) (STRING bar)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-09 6:27 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-09 6:27 UTC (permalink / raw
To: gentoo-commits
commit: b398a6957cf171ba7f599e07d90379a29e727b3a
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 8 14:34:18 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Apr 8 14:34:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b398a695
Rename tdm to times_division_modulus
---
bashast/bashast.g | 5 +++--
bashast/gunit/arith_main.gunit | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index fde875d..c20cef4 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -466,8 +466,9 @@ negation
: (BANG^BLANK!?|TILDE^BLANK!?)?unary;
exponential
: negation (BLANK!* EXP^ BLANK!* negation)* ;
-tdm : exponential (BLANK!*(TIMES^|SLASH^|PCT^)BLANK!* exponential)*;
-addsub : tdm (BLANK!* (PLUS^|MINUS^)BLANK!* tdm)*;
+times_division_modulus
+ : exponential (BLANK!*(TIMES^|SLASH^|PCT^)BLANK!* exponential)*;
+addsub : times_division_modulus (BLANK!* (PLUS^|MINUS^)BLANK!* times_division_modulus)*;
shifts : addsub (BLANK!* (LSHIFT^|RSHIFT^) BLANK!* addsub)*;
compare : shifts (BLANK!* (LEQ^|GEQ^|LESS_THAN^|GREATER_THAN^)BLANK!* shifts)?;
bitwiseand
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 1444203..be91c42 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -49,7 +49,7 @@ exponential:
"6**2" -> (** 6 2)
"-5**+4" -> (** (MINUS_SIGN 5) (PLUS_SIGN 4))
-tdm:
+times_division_modulus:
"9" -> "9"
"7 * 9" -> (* 7 9)
"7 / 9" -> (/ 7 9)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-09 6:27 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-09 6:27 UTC (permalink / raw
To: gentoo-commits
commit: 95c2c86fdd4a52250393e05bbe5648367d5759ee
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 8 18:57:03 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Apr 9 06:13:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=95c2c86f
Improve brace expansion
The parser assumed brace expansion could only happen once for a word but
this not the case. Writing a{a,b}b{c,d} is valid bash and expands to
four words.
---
bashast/bashast.g | 15 ++++++---------
bashast/gunit/brace.gunit | 19 +++++++++----------
bashast/gunit/expansions.gunit | 2 +-
3 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index bf07b7f..5214b65 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -27,7 +27,6 @@ options
tokens{
ARG;
ARRAY;
- BRACE;
BRACE_EXP;
COMMAND_SUB;
CASE_PATTERN;
@@ -111,8 +110,7 @@ bash_command
: fname_no_res_word (BLANK+ arg)* -> ^(COMMAND fname_no_res_word arg*);
//An argument to a command
arg
- : brace_expansion
- | var_ref
+ : var_ref
| fname
| command_sub
| var_ref;
@@ -144,16 +142,14 @@ redir_op: AMP LESS_THAN -> OP["&<"]
| GREATER_THAN
| DIGIT redir_op;
brace_expansion
- : pre=fname? brace post=fname? -> ^(BRACE_EXP ($pre)? brace ($post)?);
-brace
- : LBRACE BLANK* brace_expansion_inside BLANK?RBRACE -> ^(BRACE brace_expansion_inside);
+ : LBRACE BLANK* brace_expansion_inside BLANK* RBRACE -> ^(BRACE_EXP brace_expansion_inside);
brace_expansion_inside
: commasep|range;
range : DIGIT DOTDOT^ DIGIT
| LETTER DOTDOT^ LETTER;
brace_expansion_part
- : fname
- | brace
+ : brace_expansion
+ | fname
| var_ref
| command_sub;
commasep: brace_expansion_part(COMMA! brace_expansion_part)+;
@@ -388,13 +384,14 @@ no_res_word_part
| var_ref
| command_sub
| arithmetic_expansion
+ | brace_expansion
| dqstr
| sqstr
| ns_str_part_no_res
| SLASH
| pattern_match_trigger;
//non-quoted string rule, allows expansions
-nqstr : (bracket_pattern_match|extended_pattern_match|var_ref|command_sub|arithmetic_expansion|dqstr|sqstr|(str_part str_part_with_pound*)|pattern_match_trigger|BANG)+;
+nqstr : (bracket_pattern_match|extended_pattern_match|var_ref|command_sub|arithmetic_expansion|brace_expansion|dqstr|sqstr|(str_part str_part_with_pound*)|pattern_match_trigger|BANG)+;
//double quoted string rule, allows expansions
dqstr : QUOTE dqstr_part* QUOTE -> ^(DOUBLE_QUOTED_STRING dqstr_part*);
dqstr_part
diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit
index a5a5620..937e594 100644
--- a/bashast/gunit/brace.gunit
+++ b/bashast/gunit/brace.gunit
@@ -18,14 +18,13 @@
*/
gunit bashast;
-brace:
-"{a,b}"-> (BRACE (STRING a) (STRING b))
-"{a,b,c}" -> (BRACE (STRING a) (STRING b) (STRING c))
-"{a..d}" -> (BRACE (.. a d))
-"{{a,b},c,d}" -> (BRACE (BRACE (STRING a) (STRING b)) (STRING c) (STRING d))
-
brace_expansion:
-"{a,b}" -> (BRACE_EXP (BRACE (STRING a) (STRING b)))
-"a{b,c}" -> (BRACE_EXP (STRING a) (BRACE (STRING b) (STRING c)))
-"{c..d}f" -> (BRACE_EXP (BRACE (.. c d)) (STRING f))
-"z{{a,b},c}" -> (BRACE_EXP (STRING z) (BRACE (BRACE (STRING a) (STRING b)) (STRING c)))
+"{a,b}"-> (BRACE_EXP (STRING a) (STRING b))
+"{a,b,c}" -> (BRACE_EXP (STRING a) (STRING b) (STRING c))
+"{a..d}" -> (BRACE_EXP (.. a d))
+"{{a,b},c,d}" -> (BRACE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d))
+
+arg:
+"a{b,c}" -> (STRING a (BRACE_EXP (STRING b) (STRING c)))
+"{c..d}f" -> (STRING (BRACE_EXP (.. c d)) f)
+"a{a,b}b{c,d}" -> (STRING a (BRACE_EXP (STRING a) (STRING b)) b (BRACE_EXP (STRING c) (STRING d)))
diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit
index 2bce986..252c6bf 100644
--- a/bashast/gunit/expansions.gunit
+++ b/bashast/gunit/expansions.gunit
@@ -19,7 +19,7 @@
gunit bashast;
list:
-"echo a{b,c,d}" -> (LIST (COMMAND (STRING echo) (BRACE_EXP (STRING a) (BRACE (STRING b) (STRING c) (STRING d)))))
+"echo a{b,c,d}" -> (LIST (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c) (STRING d)))))
"((5+5))" -> (LIST (COMPOUND_ARITH (+ 5 5)))
"(( 4 + $asdf ))" -> (LIST (COMPOUND_ARITH (+ 4 (VAR_REF asdf))))
"[[ while=while ]] && echo true" -> (LIST (&& (COMPOUND_COND (KEYWORD_TEST (= (STRING while) (STRING while)))) (COMMAND (STRING echo) (STRING true))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-09 6:27 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-09 6:27 UTC (permalink / raw
To: gentoo-commits
commit: 167e235cabb2528bc53e9d975053018c6b53fc04
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 8 18:00:17 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Apr 9 06:13:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=167e235c
Improve support for arithmetic expressions
Things like double negation $((!!a)) were not supported. Fixing this
resulted in bubbled changes elsewhere. The main change is that we have
less specialized tokens so that we don't end up with special tokens in
wrong contexts.
---
bashast/bashast.g | 44 +++++++++++++++++++----------------
bashast/gunit/arith_main.gunit | 22 +++++++++--------
bashast/gunit/compound.gunit | 6 ++--
bashast/gunit/cond_main.gunit | 8 +++---
bashast/gunit/continued_lines.gunit | 2 +-
bashast/gunit/fname.gunit | 6 ++--
bashast/gunit/list.gunit | 2 +-
bashast/gunit/simp_command.gunit | 2 +-
8 files changed, 49 insertions(+), 43 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2b4e713..bf07b7f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -98,7 +98,7 @@ pipeline
| BLANK!* time? (BANG BLANK!+)? command^ (BLANK!* PIPE^ BLANK!* command)*;
time : TIME^ BLANK!+ time_posix?;
time_posix
- : '-p' BLANK!+;
+ : TIME_POSIX BLANK!+;
//The structure of a command in bash
command
: EXPORT^ var_def+
@@ -286,7 +286,7 @@ cond_primary
keyword_cond_binary
: cond_part BLANK!* binary_str_op_keyword^ BLANK!? cond_part;
keyword_cond_unary
- : UOP^ BLANK!+ cond_part;
+ : uop^ BLANK!+ cond_part;
builtin_cond_primary
: LPAREN! BLANK!* builtin_cond BLANK!* RPAREN!
| builtin_cond_binary
@@ -295,7 +295,7 @@ builtin_cond_primary
builtin_cond_binary
: cond_part BLANK!* binary_string_op_builtin^ BLANK!? cond_part;
builtin_cond_unary
- : UOP^ BLANK!+ cond_part;
+ : uop^ BLANK!+ cond_part;
keyword_cond
: (negate_primary|cond_primary) (BLANK!* (LOGICOR^|LOGICAND^) BLANK!* keyword_cond)?;
builtin_cond
@@ -305,20 +305,22 @@ negate_primary
negate_builtin_primary
: BANG BLANK+ builtin_cond_primary -> ^(NEGATION builtin_cond_primary);
binary_str_op_keyword
- : BOP
+ : bop
| EQUALS EQUALS -> OP["=="]
| EQUALS
| BANG EQUALS -> OP["!="]
| LESS_THAN
| GREATER_THAN;
binary_string_op_builtin
- : BOP
+ : bop
| EQUALS
| BANG EQUALS -> OP["!="]
| ESC_LT
| ESC_GT;
+bop : MINUS! NAME^;
unary_cond
- : UOP^ BLANK! cond_part;
+ : uop^ BLANK! cond_part;
+uop : MINUS! LETTER;
//Allowable parts of conditions
cond_part: brace_expansion
| var_ref
@@ -363,7 +365,11 @@ ns_str_part
//Parts of strings, no slashes, no reserved words
ns_str_part_no_res
: num
- | name|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|BOP|UOP|TEST_EXPR|'_'|TILDE|INC|DEC|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN|ESC_CHAR|CARET;
+ | name
+ |OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|TEST_EXPR|'_'
+ |TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
+ |TIME_POSIX|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN
+ |OR_ASSIGN|ESC_CHAR|CARET;
//strings with no slashes, used in certain variable expansions
ns_str : ns_str_part* -> ^(STRING ns_str_part*);
//Generic strings/filenames.
@@ -452,20 +458,19 @@ primary : num
| name -> ^(VAR_REF name)
| LPAREN! (arithmetics) RPAREN!;
post_inc_dec
- : name BLANK?INC -> ^(POST_INCR name)
- | name BLANK?DEC -> ^(POST_DECR name);
+ : primary BLANK? PLUS PLUS -> ^(POST_INCR primary)
+ | primary BLANK? MINUS MINUS -> ^(POST_DECR primary);
pre_inc_dec
- : INC BLANK?name -> ^(PRE_INCR name)
- | DEC BLANK?name -> ^(PRE_DECR name);
+ : PLUS PLUS BLANK? primary -> ^(PRE_INCR primary)
+ | MINUS MINUS BLANK? primary -> ^(PRE_DECR primary);
unary : post_inc_dec
| pre_inc_dec
| primary
- | PLUS primary -> ^(PLUS_SIGN primary)
- | MINUS primary -> ^(MINUS_SIGN primary);
-negation
- : (BANG^BLANK!?|TILDE^BLANK!?)?unary;
+ | PLUS unary -> ^(PLUS_SIGN unary)
+ | MINUS unary -> ^(MINUS_SIGN unary)
+ | (TILDE|BANG)^ unary;
exponential
- : negation (BLANK!* EXP^ BLANK!* negation)* ;
+ : unary (BLANK!* EXP^ BLANK!* unary)* ;
times_division_modulus
: exponential (BLANK!* (TIMES^|SLASH^|PCT^) BLANK!* exponential)*;
addsub : times_division_modulus (BLANK!* (PLUS^|MINUS^)BLANK!* times_division_modulus)*;
@@ -540,8 +545,6 @@ TIMES : '*';
EQUALS : '=';
MINUS : '-';
PLUS : '+';
-INC : '++';
-DEC : '--';
EXP : '**';
AMP : '&';
LEQ : '<=';
@@ -600,8 +603,6 @@ TEST_EXPR : 'test';
LOGICAND
: '&&';
LOGICOR : '||';
-BOP : MINUS LETTER LETTER;
-UOP : MINUS LETTER;
//Some builtins
EXPORT : 'export';
//Tokens for strings
@@ -613,6 +614,9 @@ ESC_LPAREN
: '\\' LPAREN;
ESC_LT : '\\''<';
ESC_GT : '\\''>';
+//For pipeline
+TIME_POSIX
+ : '-p';
//Handle ANSI C escaped characters: escaped octal, escaped hex, escaped ctrl+ chars, then all others
ESC_CHAR: '\\' (('0'..'7')('0'..'7')('0'..'7')?|'x'('0'..'9'|'a'..'f'|'A'..'F')('0'..'9'|'a'..'f'|'A'..'F')?|'c'.|.);
NAME : (LETTER|'_')(ALPHANUM|'_')+;
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index be91c42..9010822 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -25,24 +25,26 @@ primary:
"3" -> "3"
post_inc_dec:
-"b--" -> (POST_DECR b)
-"i++" -> (POST_INCR i)
+"b--" -> (POST_DECR (VAR_REF b))
+"i++" -> (POST_INCR (VAR_REF i))
pre_inc_dec:
-"++i" -> (PRE_INCR i)
-"--b" -> (PRE_DECR b)
+"++i" -> (PRE_INCR (VAR_REF i))
+"--b" -> (PRE_DECR (VAR_REF b))
unary:
"6" -> "6"
"+9" -> (PLUS_SIGN 9)
"-15" -> (MINUS_SIGN 15)
-"++ z" -> (PRE_INCR z)
-"f--" -> (POST_DECR f)
-
-negation:
-"8" -> "8"
+"++ z" -> (PRE_INCR (VAR_REF z))
+"f--" -> (POST_DECR (VAR_REF f))
"~8" -> (~ 8)
"!8" -> (! 8)
+"!!8" -> (! (! 8))
+"--8" -> (PRE_DECR 8)
+"+++${a}" -> (PLUS_SIGN (PRE_INCR (VAR_REF a)))
+"++++${a}" -> (PLUS_SIGN (PLUS_SIGN (PRE_INCR (VAR_REF a))))
+"+-++${a}" -> (PLUS_SIGN (MINUS_SIGN (PRE_INCR (VAR_REF a))))
exponential:
"8" -> "8"
@@ -120,5 +122,5 @@ arithmetics:
start:
"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))
-"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (PRE_INCR 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))))))
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index 2e0c795..b8e8ef6 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -19,12 +19,12 @@
gunit bashast;
cond_comparison:
-"[[ -a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (-a (STRING this / is . afile))))
+"[[ -a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (a (STRING this / is . afile))))
"[[ -a this/is.afile]]" FAIL
"[[-a this/is.afile ]]" FAIL
"[[
--a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (-a (STRING this / is . afile))))
-"test ! -a this/is.afile" -> (COMPOUND_COND (BUILTIN_TEST (NEGATION (-a (STRING this / is . afile)))))
+-a this/is.afile ]]" -> (COMPOUND_COND (KEYWORD_TEST (a (STRING this / is . afile))))
+"test ! -a this/is.afile" -> (COMPOUND_COND (BUILTIN_TEST (NEGATION (a (STRING this / is . afile)))))
"[[ asdf > qwert ]]" -> (COMPOUND_COND (KEYWORD_TEST (> (STRING asdf) (STRING qwert))))
"[ asdf \> qwert ]" -> (COMPOUND_COND (BUILTIN_TEST (\> (STRING asdf) (STRING qwert))))
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 91eb883..b40322d 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -19,9 +19,9 @@
gunit bashast;
cond_expr:
-"[[ -a this/is.afile ]]" -> (KEYWORD_TEST (-a (STRING this / is . afile)))
-"[ -n \"yar53\" ]" -> (BUILTIN_TEST (-n (STRING (DOUBLE_QUOTED_STRING yar53))))
-"test 5 -eq 6" -> (BUILTIN_TEST (-eq 5 6))
-"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!= (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo))) (-a (STRING filename))))
+"[[ -a this/is.afile ]]" -> (KEYWORD_TEST (a (STRING this / is . afile)))
+"[ -n \"yar53\" ]" -> (BUILTIN_TEST (n (STRING (DOUBLE_QUOTED_STRING yar53))))
+"test 5 -eq 6" -> (BUILTIN_TEST (eq 5 6))
+"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!= (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo))) (a (STRING filename))))
"[[ true ]]" -> (KEYWORD_TEST (STRING true))
"[[ true && (false || three) ]]" -> (KEYWORD_TEST (&& (STRING true) (|| (STRING false) (STRING three))))
diff --git a/bashast/gunit/continued_lines.gunit b/bashast/gunit/continued_lines.gunit
index debbe1f..96f6ee4 100644
--- a/bashast/gunit/continued_lines.gunit
+++ b/bashast/gunit/continued_lines.gunit
@@ -26,4 +26,4 @@ o Hello\
"sed -i \
-e 's/three/\
- four/'" -> (LIST (COMMAND (STRING sed) (STRING -i) (STRING -e) (STRING (SINGLE_QUOTED_STRING s / three / four /))))
+ four/'" -> (LIST (COMMAND (STRING sed) (STRING - i) (STRING - e) (STRING (SINGLE_QUOTED_STRING s / three / four /))))
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 4596f23..0272c37 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -49,9 +49,9 @@ fname:
"tab\\ttab" -> "(STRING tab \\\t tab)"
"abc[def]" -> (STRING abc (MATCH_PATTERN def))
"a[]" -> (STRING a [ ])
-"ab[d-h]" -> (STRING ab (MATCH_PATTERN d -h))
-"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d -h))
-"ab[^d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d -h))
+"ab[d-h]" -> (STRING ab (MATCH_PATTERN d - h))
+"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
+"ab[^d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
"ab[]c]" -> (STRING ab (MATCH_PATTERN ] c))
"ab[:alpha:]" -> (STRING ab (MATCH_PATTERN : alpha :))
"ab[=c=]" -> (STRING ab (MATCH_PATTERN = c =))
diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit
index 04b3243..f21f014 100644
--- a/bashast/gunit/list.gunit
+++ b/bashast/gunit/list.gunit
@@ -22,7 +22,7 @@ list:
"make" -> (LIST (COMMAND (STRING make)))
"make && make modules_install;" -> (LIST (&& (COMMAND (STRING make)) (COMMAND (STRING make) (STRING modules_install))))
"make && make modules_install &" -> (LIST (&& (COMMAND (STRING make)) (COMMAND (STRING make) (STRING modules_install))))
-"cd /usr/bin; ls -al |grep more&& cp ./less ./more" -> (LIST (COMMAND (STRING cd) (STRING / usr / bin)) (&& (| (COMMAND (STRING ls) (STRING -al)) (COMMAND (STRING grep) (STRING more))) (COMMAND (STRING cp) (STRING . / less) (STRING . / more))))
+"cd /usr/bin; ls -al |grep more&& cp ./less ./more" -> (LIST (COMMAND (STRING cd) (STRING / usr / bin)) (&& (| (COMMAND (STRING ls) (STRING - al)) (COMMAND (STRING grep) (STRING more))) (COMMAND (STRING cp) (STRING . / less) (STRING . / more))))
"mkdir test
cd test
cp ../asdf.tar.gz .
diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
index 6f2c2a8..cd847a8 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -24,7 +24,7 @@ simple_command:
"asdf=5 cat out.log > result" -> (COMMAND (STRING cat) (STRING out . log) (= asdf 5) (REDIR > (STRING result)))
"cat results.log > asdf 2> /dev/null" -> (COMMAND (STRING cat) (STRING results . log) (REDIR > (STRING asdf)) (REDIR 2 > (STRING / dev / null)))
"i=3 g=4 h=18 grep asdf" -> (COMMAND (STRING grep) (STRING asdf) (= i 3) (= g 4) (= h 18))
-"./configure --prefix=/usr/local" -> (COMMAND (STRING . / configure) (STRING -- prefix = / usr / local))
+"./configure --prefix=/usr/local" -> (COMMAND (STRING . / configure) (STRING - -p refix = / usr / local))
"[[while" -> (COMMAND (STRING [ [ while))
"./foobär" -> (COMMAND (STRING . / foob ä r))
"cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Documents / todo . txt))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-09 6:27 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-09 6:27 UTC (permalink / raw
To: gentoo-commits
commit: 77260f935ead93c3ca7ca618841e87cffb321037
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 8 19:10:52 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Apr 9 06:13:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=77260f93
Remove warning from arithmetic_part
There's no need to list both alternatives as the first choice falls
through to the second any way.
---
bashast/bashast.g | 3 +--
bashast/gunit/arith_main.gunit | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index ec04917..64568c9 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -441,8 +441,7 @@ extended_pattern_match
arithmetic_expansion
: DOLLAR LLPAREN BLANK* arithmetic_part BLANK* RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetic_part);
arithmetic_part
- : arithmetics
- | arithmetic;
+ : arithmetics;
//The comma operator for arithmetic expansions
arithmetics
: arithmetic (BLANK!* COMMA! BLANK!* arithmetic)*;
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 9010822..5a29849 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -117,8 +117,8 @@ arithmetic_condition:
"5?7:2"->(ARITHMETIC_CONDITION 5 7 2)
"(4-3)?0:1"->(ARITHMETIC_CONDITION (- 4 3) 0 1)
-arithmetics:
-"5+4, 3+2, $a*$b" -> (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b))
+arithmetic_expansion:
+"$((5+4, 3+2, $a*$b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)))
start:
"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 5:21 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 5:21 UTC (permalink / raw
To: gentoo-commits
commit: 8f6a482aeb3abf9538ce9a0ae0e55fab9fbfb105
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 10 08:07:35 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 01:39:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=8f6a482a
Make space after while/until keyword optional
Space is optional between while/until keyword and the test-commands
so we make it optional in the grammar. Bug #362795
---
bashast/bashast.g | 4 ++--
bashast/gunit/compound.gunit | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2418a81..210912c 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -183,10 +183,10 @@ if_expr : IF wspace+ ag=clist BLANK* semiel THEN wspace+ iflist=clist BLANK? sem
elif_expr
: ELIF BLANK+ ag=clist BLANK* semiel THEN wspace+ iflist=clist BLANK* semiel -> ^(IF["if"] $ag $iflist);
while_expr
- : WHILE wspace istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(WHILE $istrue $dothis)
+ : WHILE wspace? istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(WHILE $istrue $dothis)
;
until_expr
- : UNTIL wspace istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(UNTIL $istrue $dothis)
+ : UNTIL wspace? istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(UNTIL $istrue $dothis)
;
case_expr
: CASE^ BLANK!+ word wspace! IN! wspace! (case_stmt wspace!)* last_case? ESAC!;
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index b8e8ef6..531e0ff 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -120,6 +120,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 (COMPOUND_ARITH (> 1 0))) (LIST (COMMAND (STRING echo) (STRING ok))))
"while echo true`; do echo file done" FAIL
until_expr:
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 5:21 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 5:21 UTC (permalink / raw
To: gentoo-commits
commit: e435f385e1c71e172b46f2860d37339fbac06506
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 10 03:15:02 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 01:39:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=e435f385
Fix EOL handling in functions wrt bug #362715
---
bashast/bashast.g | 2 +-
bashast/gunit/function.gunit | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 8aebc93..2418a81 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -327,7 +327,7 @@ cond_part: brace_expansion
| fname
| arithmetic;
//Rules for whitespace/line endings
-wspace : BLANK+|EOL;
+wspace : BLANK+|EOL+;
semiel : (SEMIC|EOL) BLANK*;
//definition of word. this is just going to grow...
diff --git a/bashast/gunit/function.gunit b/bashast/gunit/function.gunit
index a861eab..157c0a6 100644
--- a/bashast/gunit/function.gunit
+++ b/bashast/gunit/function.gunit
@@ -31,5 +31,8 @@ function:
"foo() { :; }" -> (function foo (CURRSHELL (LIST (COMMAND (STRING :)))))
"function quit { exit; } > /dev/null" -> (function quit (CURRSHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
+"function quit {
+ # comment
+ exit; } > /dev/null" -> (function quit (CURRSHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
"function help { echo hi; } 2> /dev/null" -> (function help (CURRSHELL (LIST (COMMAND (STRING echo) (STRING hi)))) (REDIR 2 > (STRING / dev / null)))
"function help { echo 3; } 2> /dev/null > output" OK
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 5:21 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 5:21 UTC (permalink / raw
To: gentoo-commits
commit: 976e5bde79b1286fbf45f3ac2abcf124ade06d22
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 11 01:31:05 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 01:39:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=976e5bde
Add '#' to var_name wrt bug #362795
'#' is a valid variable name in variable expansion as it stands
for the number of arguments.
---
bashast/bashast.g | 2 +-
bashast/gunit/param_main.gunit | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index d8dfc77..31aa368 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -268,7 +268,7 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| TIMES
| AT;
//Allowable variable names in the variable expansion
-var_name: num|name;
+var_name: num|name|POUND;
//Referencing an array variable
arr_var_ref
: name^ LSQUARE! DIGIT+ RSQUARE!;
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index a865e16..c6194de 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -43,7 +43,9 @@ var_ref:
"$@" -> (VAR_REF @)
"$*" -> (VAR_REF *)
"${@}" -> (VAR_REF @)
+"${#}" -> (VAR_REF #)
"${!foo}" -> (VAR_REF (VAR_REF foo))
+"${!#}" -> (VAR_REF (VAR_REF #))
"${3}" -> (VAR_REF 3)
"$?" -> (VAR_REF ?)
"$_" -> (VAR_REF _)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 5:21 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 5:21 UTC (permalink / raw
To: gentoo-commits
commit: 6e084d90ad3e6dc14f503b6616b252467d968294
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 11 01:27:30 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 01:39:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=6e084d90
Support indirect reference wrt bug #362285
---
bashast/bashast.g | 1 +
bashast/gunit/param_main.gunit | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 210912c..d8dfc77 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -251,6 +251,7 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| var_name COLON wspace* LPAREN? os=arithmetic RPAREN? (COLON len=arithmetic)? -> ^(OFFSET var_name $os ^($len)?)
| BANG^ var_name (TIMES|AT)
| BANG var_name LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name $op)
+ | BANG var_name -> ^(VAR_REF var_name)
| POUND^ var_name
| var_name (POUND^|POUNDPOUND^) fname
| var_name (PCT^|PCTPCT^) fname
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 6668dd9..a865e16 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -43,6 +43,7 @@ var_ref:
"$@" -> (VAR_REF @)
"$*" -> (VAR_REF *)
"${@}" -> (VAR_REF @)
+"${!foo}" -> (VAR_REF (VAR_REF foo))
"${3}" -> (VAR_REF 3)
"$?" -> (VAR_REF ?)
"$_" -> (VAR_REF _)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 6:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 6:50 UTC (permalink / raw
To: gentoo-commits
commit: 184ba26c429d522defc8a4226627dd9487acc13b
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sun Apr 10 13:20:10 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 06:45:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=184ba26c
Fix exporting variables
The parser at some point has stopped supporting export FOO=bar. Now it's
fixed and covered by the test suite.
---
bashast/bashast.g | 2 +-
bashast/gunit/pipeline.gunit | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f44b235..0875ea5 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -101,7 +101,7 @@ time_posix
: TIME_POSIX BLANK!+;
//The structure of a command in bash
command
- : EXPORT^ var_def+
+ : EXPORT^ (BLANK!+ var_def)+
| compound_command
| simple_command;
//Simple bash commands
diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index f0eb428..4c29e8a 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -20,6 +20,7 @@ gunit bashast;
pipeline:
"cat asdf" -> (COMMAND (STRING cat) (STRING asdf))
+"export VAR=bar LAA=laa" -> (export (= VAR (STRING bar)) (= LAA (STRING laa)))
"time -p cat file" -> (COMMAND (STRING cat) (STRING file) (time -p))
"time cat file | grep search" -> (| (COMMAND (STRING cat) (STRING file) time) (COMMAND (STRING grep) (STRING search)))
"time -p cat | grep asdf | a.out" -> (| (| (COMMAND (STRING cat) (time -p)) (COMMAND (STRING grep) (STRING asdf))) (COMMAND (STRING a . out)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 6:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 6:50 UTC (permalink / raw
To: gentoo-commits
commit: b9e59583ae144082240a0345245da7aec204bf38
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sun Apr 10 13:54:52 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 06:45:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b9e59583
Don't handle export specially
export is a shell builtin so it should be handled like any other
command like echo.
---
bashast/bashast.g | 10 ++++------
bashast/gunit/pipeline.gunit | 3 ++-
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 0875ea5..3ded797 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -94,14 +94,13 @@ list_level_1
list_level_2
: list_level_1 ((BLANK!?SEMIC!|BLANK!?AMP^|(BLANK!? EOL!)+)BLANK!? list_level_1)*;
pipeline
- : var_def+
- | BLANK!* time? (BANG BLANK!+)? command^ (BLANK!* PIPE^ BLANK!* command)*;
+ : BLANK!* time? (BANG BLANK!+)? command^ (BLANK!* PIPE^ BLANK!* command)*;
time : TIME^ BLANK!+ time_posix?;
time_posix
: TIME_POSIX BLANK!+;
//The structure of a command in bash
command
- : EXPORT^ (BLANK!+ var_def)+
+ : var_def (BLANK!+ var_def)*
| compound_command
| simple_command;
//Simple bash commands
@@ -215,7 +214,8 @@ cond_comparison
: cond_expr -> ^(COMPOUND_COND cond_expr);
//Variables
//Defining a variable
-var_def : name LSQUARE BLANK? var_index BLANK* RSQUARE EQUALS value -> ^(EQUALS ^(name var_index) value)
+var_def
+ : name LSQUARE BLANK? var_index BLANK* RSQUARE EQUALS value -> ^(EQUALS ^(name var_index) value)
| name EQUALS^ value
| LET! name EQUALS^ arithmetic;
//Possible values of a variable
@@ -584,8 +584,6 @@ TEST_EXPR : 'test';
LOGICAND
: '&&';
LOGICOR : '||';
-//Some builtins
-EXPORT : 'export';
//Tokens for strings
CONTINUE_LINE
: (ESC EOL)+{$channel=HIDDEN;};
diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index 4c29e8a..7d69527 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -20,7 +20,8 @@ gunit bashast;
pipeline:
"cat asdf" -> (COMMAND (STRING cat) (STRING asdf))
-"export VAR=bar LAA=laa" -> (export (= VAR (STRING bar)) (= LAA (STRING laa)))
+"export VAR=bar LAA=laa" -> (COMMAND (STRING export) (STRING VAR = bar) (STRING LAA = laa))
+"LOCAL1=a LOCAL2=b export GLOBAL1=2 GLOBAL2 GLOBAL3" -> (COMMAND (STRING export) (STRING GLOBAL1 = 2) (STRING GLOBAL2) (STRING GLOBAL3) (= LOCAL1 (STRING a)) (= LOCAL2 (STRING b)))
"time -p cat file" -> (COMMAND (STRING cat) (STRING file) (time -p))
"time cat file | grep search" -> (| (COMMAND (STRING cat) (STRING file) time) (COMMAND (STRING grep) (STRING search)))
"time -p cat | grep asdf | a.out" -> (| (| (COMMAND (STRING cat) (time -p)) (COMMAND (STRING grep) (STRING asdf))) (COMMAND (STRING a . out)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 6:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 6:50 UTC (permalink / raw
To: gentoo-commits
commit: 1caaf7cda55268d34292bc4e579d861a03fc978c
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sun Apr 10 14:17:48 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 06:45:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=1caaf7cd
Better whitespace handling for while and friends
You are allowed to have whitespace before the semicolon in a while
expression. There's now a generic fix for this in the semiel rule.
---
bashast/bashast.g | 6 +++---
bashast/gunit/compound.gunit | 3 +++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 3ded797..1026169 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -176,11 +176,11 @@ for_expr: FOR BLANK+ name (wspace IN BLANK+ word)? semiel DO wspace* clist semie
;
sel_expr: SELECT BLANK+ name (wspace IN BLANK+ word)? semiel DO wspace* clist semiel DONE -> ^(SELECT name (word)? clist)
;
-if_expr : IF wspace+ ag=clist BLANK* semiel THEN wspace+ iflist=clist BLANK? semiel EOL* (elif_expr)* (ELSE wspace+ else_list=clist BLANK? semiel EOL*)? FI
+if_expr : IF wspace+ ag=clist semiel THEN wspace+ iflist=clist semiel EOL* (elif_expr)* (ELSE wspace+ else_list=clist semiel EOL*)? FI
-> ^(IF $ag $iflist (elif_expr)* ^($else_list)?)
;
elif_expr
- : ELIF BLANK+ ag=clist BLANK* semiel THEN wspace+ iflist=clist BLANK* semiel -> ^(IF["if"] $ag $iflist);
+ : ELIF BLANK+ ag=clist semiel THEN wspace+ iflist=clist semiel -> ^(IF["if"] $ag $iflist);
while_expr
: WHILE wspace? istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(WHILE $istrue $dothis)
;
@@ -329,7 +329,7 @@ cond_part: brace_expansion
| arithmetic;
//Rules for whitespace/line endings
wspace : BLANK+|EOL+;
-semiel : (SEMIC|EOL) BLANK*;
+semiel : BLANK* (SEMIC|EOL) BLANK*;
//definition of word. this is just going to grow...
word : (brace_expansion) => brace_expansion
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index 531e0ff..0814978 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -122,6 +122,9 @@ done" -> (while (LIST (COMMAND (STRING echo) (STRING true))) (LIST (COMMAND (STR
"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 (COMPOUND_ARITH (> 1 0))) (LIST (COMMAND (STRING echo) (STRING ok))))
"while echo true`; do echo file done" FAIL
+"while [[ -n \"$ver_str\" ]] ; do
+ echo true
+ done" -> (while (LIST (COMPOUND_COND (KEYWORD_TEST (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF ver_str))))))) (LIST (COMMAND (STRING echo) (STRING true))))
until_expr:
"until echo true; do
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-11 6:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-11 6:50 UTC (permalink / raw
To: gentoo-commits
commit: 9953ba4f79f12dacc0090c36adda3e7237148e50
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sun Apr 10 17:03:32 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 06:45:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9953ba4f
Improve explicit arithmetic expression places
In array indexes and parameter offset expansion you can use the longer
form of arithmetic expansion like foo[$((1))]=bar
---
bashast/bashast.g | 9 ++++++---
bashast/gunit/assoc_array.gunit | 1 +
bashast/gunit/param_main.gunit | 1 +
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 0a42b4e..a9ded45 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -215,7 +215,7 @@ cond_comparison
//Variables
//Defining a variable
var_def
- : name LSQUARE BLANK? arithmetics BLANK* RSQUARE EQUALS value -> ^(EQUALS ^(name arithmetics) value)
+ : name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS value -> ^(EQUALS ^(name explicit_arithmetic) value)
| name EQUALS^ value
| LET! name EQUALS^ arithmetic;
//Possible values of a variable
@@ -226,7 +226,7 @@ value : num
//allow the parser to create array variables
arr_val :
| (ag+=val wspace?)+ -> ^(ARRAY $ag+);
-val : LSQUARE! BLANK!* arithmetics BLANK!? RSQUARE! EQUALS^ pos_val
+val : LSQUARE! BLANK!* explicit_arithmetic BLANK!? RSQUARE! EQUALS^ pos_val
| pos_val;
pos_val : command_sub
| var_ref
@@ -245,7 +245,7 @@ var_ref
| DOLLAR BANG -> ^(VAR_REF BANG);
//Variable expansions
var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ word
- | var_name COLON wspace* LPAREN? os=arithmetic RPAREN? (COLON len=arithmetic)? -> ^(OFFSET var_name $os ^($len)?)
+ | var_name COLON wspace* LPAREN? os=explicit_arithmetic RPAREN? (COLON len=explicit_arithmetic)? -> ^(OFFSET var_name $os ^($len)?)
| BANG^ var_name (TIMES|AT)
| BANG var_name LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name $op)
| BANG var_name -> ^(VAR_REF var_name)
@@ -422,6 +422,9 @@ extended_pattern_match
//Arithmetic expansion
arithmetic_expansion
: DOLLAR LLPAREN BLANK* arithmetics BLANK* RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetics);
+//explicit arithmetic in places like array indexes
+explicit_arithmetic
+ : (DOLLAR LLPAREN BLANK*)? arithmetics (BLANK* RRPAREN)? -> arithmetics;
//The comma operator for arithmetic expansions
arithmetics
: arithmetic (BLANK!* COMMA! BLANK!* arithmetic)*;
diff --git a/bashast/gunit/assoc_array.gunit b/bashast/gunit/assoc_array.gunit
index cdc7b0c..c8043af 100644
--- a/bashast/gunit/assoc_array.gunit
+++ b/bashast/gunit/assoc_array.gunit
@@ -24,3 +24,4 @@ var_def:
"asdf[$idx]=${var}" -> (= (asdf (VAR_REF idx)) (VAR_REF var))
"asdf[++i]=${var}" -> (= (asdf (PRE_INCR (VAR_REF i))) (VAR_REF var))
"asdf[++i,j]=${var}" -> (= (asdf (PRE_INCR (VAR_REF i)) (VAR_REF j)) (VAR_REF var))
+"asdf[$((i))]=${var}" -> (= (asdf (VAR_REF i)) (VAR_REF var))
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index c6194de..4aee6d2 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -26,6 +26,7 @@ var_ref:
"${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:$((5)):$((2))}" -> (VAR_REF (OFFSET foo 5 2))
"${!asdf*}" -> (VAR_REF (! asdf *))
"${!asdf@}" -> (VAR_REF (! asdf @))
"${!asdf[*]}" -> (VAR_REF (LIST_EXPAND asdf *))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-12 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-12 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 12e31160ac9ea5d797a1637f1cae20d1284010da
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Mon Apr 11 14:37:16 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 06:23:20 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=12e31160
Support parsing array member sizes
The parser now supports the syntax to the length of array members and
the array itself. For example ${#arr[@]} is for the size of the array.
---
bashast/bashast.g | 10 ++++++++--
bashast/gunit/array.gunit | 5 +++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index b0b809d..9e1d012 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -27,6 +27,7 @@ options
tokens{
ARG;
ARRAY;
+ ARRAY_SIZE;
BRACE_EXP;
COMMAND_SUB;
CASE_PATTERN;
@@ -241,7 +242,6 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| BANG^ var_name (TIMES|AT)
| BANG var_name LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name $op)
| BANG var_name -> ^(VAR_REF var_name)
- | POUND^ var_name
| var_name (POUND^|POUNDPOUND^) fname
| var_name (PCT^|PCTPCT^) fname
| var_name SLASH POUND ns_str SLASH fname -> ^(REPLACE_FIRST var_name ns_str fname)
@@ -253,6 +253,7 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| var_name SLASH PCT ns_str SLASH? -> ^(REPLACE_LAST var_name ns_str)
| var_name SLASH ns_str SLASH? -> ^(REPLACE_FIRST var_name ns_str)
| arr_var_ref
+ | var_size_ref
| var_name
| TIMES
| AT;
@@ -260,7 +261,12 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
var_name: num|name|POUND;
//Referencing an array variable
arr_var_ref
- : name^ LSQUARE! DIGIT+ RSQUARE!;
+ : name^ LSQUARE! (DIGIT+|AT|TIMES) RSQUARE!;
+var_size_ref
+ : POUND^ name (LSQUARE! array_size_index RSQUARE!)?;
+array_size_index
+ : DIGIT+
+ | (AT|TIMES) -> ARRAY_SIZE;
//Conditional Expressions
cond_expr
: LSQUARE LSQUARE wspace keyword_cond wspace RSQUARE RSQUARE -> ^(KEYWORD_TEST keyword_cond)
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index 5fd47db..fd7b5d4 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -28,3 +28,8 @@ var_ref:
"${asdf[3]}" -> (VAR_REF (asdf 3))
"${asdf[4] }" -> (VAR_REF (asdf 4))
"${asdf}" -> (VAR_REF asdf)
+"${#asdf[0]}" -> (VAR_REF (# asdf 0))
+"${asdf[@]}" -> (VAR_REF (asdf @))
+"${asdf[*]}" -> (VAR_REF (asdf *))
+"${#asdf[@]}" -> (VAR_REF (# asdf ARRAY_SIZE))
+"${#asdf[*]}" -> (VAR_REF (# asdf ARRAY_SIZE))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-12 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-12 7:19 UTC (permalink / raw
To: gentoo-commits
commit: a13d96e4fd1354d2b0370503e81c61fd10cb4d7a
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Mon Apr 11 13:56:14 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 11 13:56:14 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a13d96e4
Forbid assigning lists to array members
Syntax like FOO[1]=(a b c) is not allowed by bash. Fixes bug #363027.
---
bashast/bashast.g | 3 ++-
bashast/gunit/assoc_array.gunit | 1 +
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index be93c21..b0b809d 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -211,8 +211,9 @@ cond_comparison
: cond_expr -> ^(COMPOUND_COND cond_expr);
//Variables
//Defining a variable
+//It's not legal to do FOO[1]=(a b c)
var_def
- : name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS value -> ^(EQUALS ^(name explicit_arithmetic) value)
+ : name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS fname -> ^(EQUALS ^(name explicit_arithmetic) fname)
| name EQUALS^ value;
//Possible values of a variable
value : fname
diff --git a/bashast/gunit/assoc_array.gunit b/bashast/gunit/assoc_array.gunit
index 5ac33fb..4bb4e05 100644
--- a/bashast/gunit/assoc_array.gunit
+++ b/bashast/gunit/assoc_array.gunit
@@ -25,3 +25,4 @@ var_def:
"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)))
+"asdf[1]=(a b c)" FAIL
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-12 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-12 7:19 UTC (permalink / raw
To: gentoo-commits
commit: fc8333e273165af0d86ede790afa84e8eac8d283
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue Apr 12 07:11:14 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 07:11:14 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=fc8333e2
Refer to array indexes with arithmetic expressions
You can refer to array members using arithmetic expressions like for
example ${arr[i+3]}.
---
bashast/bashast.g | 2 +-
bashast/gunit/array.gunit | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 510ef90..18f6913 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -259,7 +259,7 @@ parameter_replace_operator
//Allowable refences to values
//either directly or through array
var_name: num
- | name^ LSQUARE! (DIGIT+|AT|TIMES) RSQUARE!
+ | name^ LSQUARE! (AT|TIMES|explicit_arithmetic) RSQUARE!
| name
| POUND;
//with bang the array syntax is used for array indexes
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index d21ed6a..f1e87e0 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -28,6 +28,7 @@ var_ref:
"${asdf[0]:-default}" -> (VAR_REF (:- (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 (## (asdf 2) (STRING word)))
"${asdf[3]%%word}" -> (VAR_REF (%% (asdf 3) (STRING word)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-12 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-12 7:19 UTC (permalink / raw
To: gentoo-commits
commit: fa5f111a94abdbee5602537971491920dbb453b4
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Mon Apr 11 16:15:39 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 06:23:31 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=fa5f111a
Fix parameter expansion parsing for arrays
In man bash when it's talked about parameter you can put a reference to
an array member there so it's for example allowed to do
${asdf[0]:-default}. Now we support the different parameter expansions
for arrays.
---
bashast/bashast.g | 21 ++++++++++++---------
bashast/gunit/array.gunit | 9 +++++++++
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 8ba0400..6148318 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -239,13 +239,12 @@ var_ref
//Variable expansions
var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ word
| var_name COLON wspace* os=explicit_arithmetic (COLON len=explicit_arithmetic)? -> ^(OFFSET var_name $os ^($len)?)
- | BANG^ var_name (TIMES|AT)
- | BANG var_name LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name $op)
- | BANG var_name -> ^(VAR_REF var_name)
+ | BANG^ var_name_for_bang (TIMES|AT)
+ | BANG var_name_for_bang LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name_for_bang $op)
+ | BANG var_name_for_bang -> ^(VAR_REF var_name_for_bang)
| var_name (POUND^|POUNDPOUND^) fname
| var_name (PCT^|PCTPCT^) fname
| var_name parameter_replace_operator^ ns_str parameter_replace_string
- | arr_var_ref
| var_size_ref
| var_name
| TIMES
@@ -257,11 +256,15 @@ parameter_replace_operator
| SLASH PCT -> REPLACE_AT_END
| SLASH POUND -> REPLACE_AT_START
| SLASH -> REPLACE_FIRST;
-//Allowable variable names in the variable expansion
-var_name: num|name|POUND;
-//Referencing an array variable
-arr_var_ref
- : name^ LSQUARE! (DIGIT+|AT|TIMES) RSQUARE!;
+//Allowable refences to values
+//either directly or through array
+var_name: num
+ | name^ LSQUARE! (DIGIT+|AT|TIMES) RSQUARE!
+ | name
+ | POUND;
+//with bang the array syntax is used for array indexes
+var_name_for_bang
+ : num|name|POUND;
var_size_ref
: POUND^ name (LSQUARE! array_size_index RSQUARE!)?;
array_size_index
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index fd7b5d4..d21ed6a 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -25,11 +25,20 @@ var_def:
var_ref:
"$asdf" -> (VAR_REF asdf)
+"${asdf[0]:-default}" -> (VAR_REF (:- (asdf 0) (STRING default)))
"${asdf[3]}" -> (VAR_REF (asdf 3))
"${asdf[4] }" -> (VAR_REF (asdf 4))
+"${asdf[1]:2:2}" -> (VAR_REF (OFFSET (asdf 1) 2 2))
+"${asdf[2]##word}" -> (VAR_REF (## (asdf 2) (STRING word)))
+"${asdf[3]%%word}" -> (VAR_REF (%% (asdf 3) (STRING word)))
+"${asdf[4]//pattern}" -> (VAR_REF (REPLACE_ALL (asdf 4) (STRING pattern)))
"${asdf}" -> (VAR_REF asdf)
"${#asdf[0]}" -> (VAR_REF (# asdf 0))
"${asdf[@]}" -> (VAR_REF (asdf @))
"${asdf[*]}" -> (VAR_REF (asdf *))
"${#asdf[@]}" -> (VAR_REF (# asdf ARRAY_SIZE))
"${#asdf[*]}" -> (VAR_REF (# asdf ARRAY_SIZE))
+"${asdf[@]:0:1}" -> (VAR_REF (OFFSET (asdf @) 0 1))
+"${asdf[*]#path}" -> (VAR_REF (# (asdf *) (STRING path)))
+"${asdf[@]%word}" -> (VAR_REF (% (asdf @) (STRING word)))
+"${asdf[*]/pattern/string}" -> (VAR_REF (REPLACE_FIRST (asdf *) (STRING pattern) (STRING string)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-14 4:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-14 4:50 UTC (permalink / raw
To: gentoo-commits
commit: d2e5859fb891011512a206e48cec8acf4034dbaa
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 13 01:46:57 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 13 01:51:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d2e5859f
Unify variable reference AST for arrays
Array grammar generate (# name index) for ${#name[index]}, which is
different from the usual AST (# (name index)). Now it's unified.
---
bashast/bashast.g | 3 ++-
bashast/gunit/array.gunit | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index fc847a4..74fd5df 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -266,7 +266,8 @@ var_name: num
var_name_for_bang
: num|name|POUND;
var_size_ref
- : POUND^ name (LSQUARE! array_size_index RSQUARE!)?;
+ : POUND name LSQUARE array_size_index RSQUARE -> ^(POUND ^(name array_size_index))
+ | POUND^ name;
array_size_index
: DIGIT+
| (AT|TIMES) -> ARRAY_SIZE;
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index f1e87e0..ae5ad6d 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -34,11 +34,11 @@ var_ref:
"${asdf[3]%%word}" -> (VAR_REF (%% (asdf 3) (STRING word)))
"${asdf[4]//pattern}" -> (VAR_REF (REPLACE_ALL (asdf 4) (STRING pattern)))
"${asdf}" -> (VAR_REF asdf)
-"${#asdf[0]}" -> (VAR_REF (# asdf 0))
+"${#asdf[0]}" -> (VAR_REF (# (asdf 0)))
"${asdf[@]}" -> (VAR_REF (asdf @))
"${asdf[*]}" -> (VAR_REF (asdf *))
-"${#asdf[@]}" -> (VAR_REF (# asdf ARRAY_SIZE))
-"${#asdf[*]}" -> (VAR_REF (# asdf ARRAY_SIZE))
+"${#asdf[@]}" -> (VAR_REF (# (asdf ARRAY_SIZE)))
+"${#asdf[*]}" -> (VAR_REF (# (asdf ARRAY_SIZE)))
"${asdf[@]:0:1}" -> (VAR_REF (OFFSET (asdf @) 0 1))
"${asdf[*]#path}" -> (VAR_REF (# (asdf *) (STRING path)))
"${asdf[@]%word}" -> (VAR_REF (% (asdf @) (STRING word)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-14 4:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-14 4:50 UTC (permalink / raw
To: gentoo-commits
commit: f56ce8a14a3948fa900539344d5ed7c1edd7cf00
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 13 13:40:36 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Apr 14 01:20:34 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f56ce8a1
Support array element in arithmetic expansion
Array element reference and assignment in arithmetic expansion is
supported now.
---
bashast/bashast.g | 8 ++++++--
bashast/gunit/arith_main.gunit | 3 +++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 5fc5e7b..f15bec7 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -445,7 +445,7 @@ arithmetic
primary : num
| var_ref
| command_sub
- | name -> ^(VAR_REF name)
+ | var_name -> ^(VAR_REF var_name)
| LPAREN! (arithmetics) RPAREN!;
post_inc_dec
: primary BLANK? PLUS PLUS -> ^(POST_INCR primary)
@@ -477,8 +477,12 @@ logicor : logicand (BLANK!* LOGICOR^ BLANK!* logicand)*;
arithmetic_condition
: cnd=logicor QMARK t=logicor COLON f=logicor -> ^(ARITHMETIC_CONDITION $cnd $t $f);
+
+arithmetic_assignment_opterator
+ : EQUALS|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN;
+
arithmetic_assignment
- : (name BLANK!* (EQUALS|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN)^ BLANK!*)? logicor;
+ : (var_name BLANK!* arithmetic_assignment_opterator^ BLANK!*)? logicor;
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
//the biggie: functions
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 5a29849..219cc30 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -23,6 +23,8 @@ gunit bashast;
primary:
"3" -> "3"
+"foo" -> (VAR_REF foo)
+"foo[1]" -> (VAR_REF (foo 1))
post_inc_dec:
"b--" -> (POST_DECR (VAR_REF b))
@@ -102,6 +104,7 @@ logicor:
arithmetic_assignment:
"13"->"13"
"foo=5+3" -> (= foo (+ 5 3))
+"foo[5]=5+3" -> (= (foo 5) (+ 5 3))
"var *= 5" -> (*= var 5)
"var /= 5" -> (/= var 5)
"var %= 5" -> (%= var 5)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-14 4:50 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-14 4:50 UTC (permalink / raw
To: gentoo-commits
commit: f751b29c1b6a946da1aa14cdce85f31afeddda4b
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 13 14:18:59 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Apr 14 01:29:58 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f751b29c
Support arithmetic assignment for variable expansion
Our parser grammar didn't support arithmetic assignment inside
variable expansion like $((${foo[5]}=3)). Now it's supported.
---
bashast/bashast.g | 2 +-
bashast/gunit/arith_main.gunit | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 1ef7b1f..ca54570 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -484,7 +484,7 @@ arithmetic_assignment_opterator
: EQUALS|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN;
arithmetic_assignment
- : (var_name BLANK!* arithmetic_assignment_opterator^ BLANK!*)? logicor;
+ : ((var_name|arithmetic_var_ref) BLANK!* arithmetic_assignment_opterator^ BLANK!*)? logicor;
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
//the biggie: functions
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 8ead7ef..0f85d55 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -105,6 +105,9 @@ arithmetic_assignment:
"13"->"13"
"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" -> (*= (VAR_REF (VAR_REF (foo 5))) 3)
+"${foo[5]}^=3" -> (^= (VAR_REF (VAR_REF (foo 5))) 3)
"var *= 5" -> (*= var 5)
"var /= 5" -> (/= var 5)
"var %= 5" -> (%= var 5)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 351f71b0267b090cc5825fafeb9eef6ee102169f
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 12:53:58 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=351f71b0
Parser: other expansions inside pathname expansion
Pathname expansions like configu[e${a}] are now supported.
---
bashast/bashast.g | 8 +++++++-
bashast/gunit/fname.gunit | 1 +
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 4bd3447..d5c3415 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -413,7 +413,13 @@ bracket_pattern_match
//allowable patterns with bracket pattern matching
pattern_match
: pattern_class_match
- | str_part str_part_with_pound*;
+ | pattern_string_part+;
+pattern_string_part
+ : var_ref
+ | command_sub
+ | arithmetic_expansion
+ | ns_str_part;
+
//special class patterns to match: [:alpha:] etc
pattern_class_match
: LSQUARE COLON NAME COLON RSQUARE -> ^(CHARACTER_CLASS NAME)
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index e783504..eb8f080 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -48,6 +48,7 @@ fname:
"ctrlx\cx" -> (STRING ctrlx \ cx)
"tab\\ttab" -> "(STRING tab \\ \t tab)"
"abc[def]" -> (STRING abc (MATCH_PATTERN def))
+"abc[d${more}]" -> (STRING abc (MATCH_PATTERN d (VAR_REF more)))
"a[]" -> (STRING a [ ])
"ab[d-h]" -> (STRING ab (MATCH_PATTERN d - h))
"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 1f019750fae3c868c01104258c4184620338d674
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 12:55:09 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:21 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=1f019750
Parser: enable pound inside pathname expansion
You can now use POUND inside pathname expansion pattern matching like
abcd[#d]
---
bashast/bashast.g | 15 +++++----------
bashast/gunit/fname.gunit | 2 ++
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index d5c3415..e82b599 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -348,11 +348,6 @@ res_word_str
str_part
: ns_str_part
| SLASH;
-//Any allowable part of a string, with pounds
-str_part_with_pound
- : str_part
- | POUND
- | POUNDPOUND;
//Parts of strings, no slashes, no reserved words
ns_str_part
: num
@@ -361,16 +356,16 @@ ns_str_part
|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
|TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
|TIME_POSIX|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN
- |OR_ASSIGN|CARET;
+ |OR_ASSIGN|CARET|POUND|POUNDPOUND;
//strings with no slashes, used in certain variable expansions
ns_str : ns_str_part* -> ^(STRING ns_str_part*);
//Generic strings/filenames.
-fname : fname_part+ -> ^(STRING fname_part+);
+fname : (~POUND) => fname_part fname_part* -> ^(STRING fname_part+);
//A string that is NOT a bash reserved word
fname_no_res_word
- : nqstr_part+ fname_part* -> ^(STRING nqstr_part+ fname_part*);
+ : (~POUND) => nqstr_part+ fname_part* -> ^(STRING nqstr_part+ fname_part*);
fname_part
- : nqstr_part+
+ : nqstr_part
| res_word_str;
//non-quoted string part rule, allows expansions
nqstr_part
@@ -382,7 +377,7 @@ nqstr_part
| brace_expansion
| dqstr
| sqstr
- | str_part str_part_with_pound*
+ | str_part
| pattern_match_trigger
| BANG;
//double quoted string rule, allows expansions
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index eb8f080..126afe8 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -49,6 +49,8 @@ fname:
"tab\\ttab" -> "(STRING tab \\ \t tab)"
"abc[def]" -> (STRING abc (MATCH_PATTERN def))
"abc[d${more}]" -> (STRING abc (MATCH_PATTERN d (VAR_REF more)))
+"abc[#d]" -> (STRING abc (MATCH_PATTERN # d))
+"abc[d#]" -> (STRING abc (MATCH_PATTERN d #))
"a[]" -> (STRING a [ ])
"ab[d-h]" -> (STRING ab (MATCH_PATTERN d - h))
"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 85231f310fb9e247ab12c03bd362daa670536ea5
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 13:26:34 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:24 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=85231f31
Parser: fix for parameter expansion replacement
The pattern in things like ${var/pattern/word} follows the rules of
pathname expansion. Now the parser supports things like
${c[ <AT> ]//[-._]/ }
---
bashast/bashast.g | 6 +++---
bashast/gunit/param_main.gunit | 2 ++
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index e82b599..3d73cfb 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -244,11 +244,13 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| BANG var_name_for_bang -> ^(VAR_REF var_name_for_bang)
| var_name (POUND^|POUNDPOUND^) fname
| var_name (PCT^|PCTPCT^) fname
- | var_name parameter_replace_operator^ ns_str parameter_replace_string
+ | var_name parameter_replace_operator^ parameter_pattern parameter_replace_string
| var_size_ref
| var_name
| TIMES
| AT;
+parameter_pattern
+ : ((~SLASH) => fname_part)+ -> ^(STRING fname_part+);
parameter_replace_string
: (SLASH fname|SLASH)? -> fname?;
parameter_replace_operator
@@ -357,8 +359,6 @@ ns_str_part
|TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
|TIME_POSIX|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN
|OR_ASSIGN|CARET|POUND|POUNDPOUND;
-//strings with no slashes, used in certain variable expansions
-ns_str : ns_str_part* -> ^(STRING ns_str_part*);
//Generic strings/filenames.
fname : (~POUND) => fname_part fname_part* -> ^(STRING fname_part+);
//A string that is NOT a bash reserved word
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 8bdf402..0d9bd78 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -52,6 +52,8 @@ var_ref:
"$_" -> (VAR_REF _)
"${_}" -> (VAR_REF _)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
+"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_PATTERN - . _))))
+"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace))))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar)))
"${PV/%foo/bar}" -> (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 0827ad788f2799814598c6b013abc2a5da76c703
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 14:27:07 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:28 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=0827ad78
Parser: blanks in parameter replace pattern
We now support replacements like ${foo// }. The white space handling in
this area is still insufficient after this change but it gets us
further along in parsing versionator.
---
bashast/bashast.g | 4 +++-
bashast/gunit/param_main.gunit | 1 +
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 67353e3..a7d150c 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -253,7 +253,9 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| TIMES
| AT;
parameter_pattern
- : ((~SLASH) => fname_part)+ -> ^(STRING fname_part+);
+ : ((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
+parameter_pattern_part
+ : fname_part|BLANK;
parameter_replace_string
: (SLASH fname|SLASH)? -> fname?;
parameter_replace_operator
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 0d9bd78..8a14dec 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -52,6 +52,7 @@ var_ref:
"$_" -> (VAR_REF _)
"${_}" -> (VAR_REF _)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
+"${PV// }" -> (VAR_REF (REPLACE_ALL PV (STRING )))
"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_PATTERN - . _))))
"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace))))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: f865c8f07976609d8e318fbd4f38fb1088c2b6da
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 14:08:45 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:26 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f865c8f0
Parser: fix space after variable assignment
---
bashast/bashast.g | 9 ++++++---
bashast/gunit/list.gunit | 1 +
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 3d73cfb..67353e3 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -101,12 +101,15 @@ time_posix
: TIME_POSIX BLANK!+;
//The structure of a command in bash
command
- : var_def (BLANK!+ var_def)*
- | compound_command
+ : compound_command
| simple_command;
//Simple bash commands
simple_command
- : (var_def BLANK!+)* bash_command^ redirect*;
+ : variable_definitions BLANK!+ bash_command^ redirect*
+ | variable_definitions
+ | bash_command^ redirect*;
+variable_definitions
+ : var_def (BLANK!+ var_def)*;
bash_command
: fname_no_res_word (BLANK+ arg)* -> ^(COMMAND fname_no_res_word arg*);
//An argument to a command
diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit
index f21f014..3d2076a 100644
--- a/bashast/gunit/list.gunit
+++ b/bashast/gunit/list.gunit
@@ -38,3 +38,4 @@ cp arch/x86_64/boot/bzImage /boot/kernel" -> (LIST (COMMAND (STRING make)) (COMM
b=three
echo \"a b\"" -> (LIST (= a (STRING asdf)) (= b (STRING three)) (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING a b))))
"echo one && (echo two || echo three)" -> (LIST (&& (COMMAND (STRING echo) (STRING one)) (SUBSHELL (LIST (|| (COMMAND (STRING echo) (STRING two)) (COMMAND (STRING echo) (STRING three)))))))
+"FOO='bar' ;" -> (LIST (= FOO (STRING (SINGLE_QUOTED_STRING bar))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: a41e198778614972aa021d58c1539d6a8cdda8c5
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 15:18:46 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:35 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a41e1987
Parser: parameter replacements expansions take ;
You can now produce patterns like ${foo%; }. With this change we are able
to parse versionator.eclass fully.
---
bashast/bashast.g | 6 +++---
bashast/gunit/param_main.gunit | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 46a90c9..036cd3e 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -249,8 +249,8 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
| BANG^ var_name_for_bang (TIMES|AT)
| BANG var_name_for_bang LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name_for_bang $op)
| BANG var_name_for_bang -> ^(VAR_REF var_name_for_bang)
- | var_name (POUND^|POUNDPOUND^) fname
- | var_name (PCT^|PCTPCT^) fname
+ | var_name (POUND^|POUNDPOUND^) parameter_pattern
+ | var_name (PCT^|PCTPCT^) parameter_pattern
| var_name parameter_replace_operator^ parameter_pattern parameter_replace_string
| var_size_ref
| var_name
@@ -259,7 +259,7 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAULT)^ wor
parameter_pattern
: ((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
parameter_pattern_part
- : fname_part|BLANK;
+ : fname_part|BLANK|SEMIC;
parameter_replace_string
: (SLASH fname|SLASH)? -> fname?;
parameter_replace_operator
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 8a14dec..7394b66 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -38,6 +38,7 @@ var_ref:
"${foo##bar}" -> (VAR_REF (## foo (STRING bar)))
"${foo%bar}" -> (VAR_REF (% foo (STRING bar)))
"${foo%%bar}" -> (VAR_REF (%% foo (STRING bar)))
+"${foo%; *}" -> (VAR_REF (% foo (STRING ; *)))
"${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING pattern)))
//Test positional/special parameters
"$1" -> (VAR_REF 1)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 801acacccb7820663f6316d55e751a7912308556
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Apr 15 15:07:38 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:44:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=801acacc
Parser: support ;\n between commands
The parser did not accept the combination of semicolon and new lines
between commands. Now you can have as many new lines after semicolon as
you want.
---
bashast/bashast.g | 6 +++++-
bashast/gunit/list.gunit | 2 ++
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9e02ac2..46a90c9 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -93,7 +93,11 @@ list_level_1
: (function|pipeline) (BLANK!*(LOGICAND^|LOGICOR^)BLANK!* (function|pipeline))*;
// ';' '&' and EOL have lower operator precedence than '&&' and '||' so we need level2 here
list_level_2
- : list_level_1 ((BLANK!?SEMIC!|BLANK!?AMP^|(BLANK!? EOL!)+)BLANK!? list_level_1)*;
+ : list_level_1 (BLANK!? command_separator (BLANK!? EOL!)* BLANK!? list_level_1)*;
+command_separator
+ : SEMIC!
+ | AMP^
+ | EOL!;
pipeline
: BLANK!* time? (BANG BLANK!+)? command^ (BLANK!* PIPE^ BLANK!* command)*;
time : TIME^ BLANK!+ time_posix?;
diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit
index 3d2076a..c434032 100644
--- a/bashast/gunit/list.gunit
+++ b/bashast/gunit/list.gunit
@@ -39,3 +39,5 @@ b=three
echo \"a b\"" -> (LIST (= a (STRING asdf)) (= b (STRING three)) (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING a b))))
"echo one && (echo two || echo three)" -> (LIST (&& (COMMAND (STRING echo) (STRING one)) (SUBSHELL (LIST (|| (COMMAND (STRING echo) (STRING two)) (COMMAND (STRING echo) (STRING three)))))))
"FOO='bar' ;" -> (LIST (= FOO (STRING (SINGLE_QUOTED_STRING bar))))
+"true;
+true" -> (LIST (COMMAND (STRING true)) (COMMAND (STRING true)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 919e76b05e08ffeb8cdb34cbd453c0a5fa833276
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 14:02:48 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:03 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=919e76b0
Parser: handle extra ws at the enf of currshell
The parser couldn't handle extra lines with only white space at the end
of lists for current shell.
---
bashast/bashast.g | 2 +-
bashast/gunit/compound.gunit | 5 +++++
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index b318f3c..30af37d 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -215,7 +215,7 @@ case_pattern
subshell: LPAREN wspace? clist (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN -> ^(SUBSHELL clist);
//A grouping of commands executed in the current shell
currshell
- : LBRACE wspace clist semiel RBRACE -> ^(CURRSHELL clist);
+ : LBRACE wspace clist semiel wspace* RBRACE -> ^(CURRSHELL clist);
//comparison using arithmetic
arith_comparison
: LLPAREN wspace? arithmetic wspace? RRPAREN -> ^(COMPOUND_ARITH arithmetic);
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index 587d869..dfdacc5 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -36,6 +36,11 @@ currshell:
"{ time cat; }" -> (CURRSHELL (LIST (COMMAND (STRING cat) time)))
"{ time cat
}" -> (CURRSHELL (LIST (COMMAND (STRING cat) time)))
+// there's a tab on the empty line
+"{
+ echo
+
+}" -> (CURRSHELL (LIST (COMMAND (STRING echo))))
"{time cat}" FAIL
"{ time cat }" FAIL
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 196605139384079f1629cf02d7a91860878bbdf7
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 12:30:56 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:00 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=19660513
Parser: support commas in command arguments
Comma wasn't listed in the big bunch of tokens allowed in argument
strings. Now it's listed there and disallowed for use inside brace
expansion because it limits alternatives there.
---
bashast/bashast.g | 8 ++++++--
bashast/gunit/fname.gunit | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9619d64..468a460 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -160,7 +160,7 @@ range : DIGIT DOTDOT^ DIGIT
| LETTER DOTDOT^ LETTER;
brace_expansion_part
: brace_expansion
- | fname
+ | ((~COMMA) => fname_part)+ -> ^(STRING fname_part+)
| var_ref
| command_sub;
commasep: brace_expansion_part(COMMA! brace_expansion_part)+;
@@ -371,6 +371,9 @@ str_part
: ns_str_part
| SLASH;
//Parts of strings, no slashes, no reserved words
+//Using negation leads to code that doesn't compile with the C backend
+//Should be investigated and filed upstream
+//Problematic: ~(CASE|DO|DONE|ELIF|ELSE|ESAC|FI|FOR|FUNCTION|IF|IN|SELECT|THEN|UNTIL|WHILE|TIME)
ns_str_part
: num
| name
@@ -378,7 +381,8 @@ ns_str_part
|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
|TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
|TIME_POSIX|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN
- |OR_ASSIGN|CARET|POUND|POUNDPOUND;
+ |OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA;
+
//Generic strings/filenames.
fname : (~POUND) => fname_part fname_part* -> ^(STRING fname_part+);
//A string that is NOT a bash reserved word
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 126afe8..a5b1f7f 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -66,3 +66,4 @@ fname:
"ab[[.backslash.]]" -> (STRING ab (MATCH_PATTERN (COLLATING_SYMBOL backslash)))
"ab[12[:alpha:]]" -> (STRING ab (MATCH_PATTERN 12 (CHARACTER_CLASS alpha)))
"\"'foo'\"" -> (STRING (DOUBLE_QUOTED_STRING ' foo '))
+"--preserve=timestamps,mode" -> (STRING - -p reserve = timestamps , mode)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 32ea83a17790cfc700bce50cd91b8aa2129a6014
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 12:43:32 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:03 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=32ea83a1
Parser: empty atoms in brace expansion
With expressions like README{.txt,} you can expand to the word with and
without the extension. We now parse these expressions and mark the
result in the AST with a virtual token.
---
bashast/bashast.g | 4 +++-
bashast/gunit/brace.gunit | 1 +
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 468a460..b318f3c 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -29,6 +29,7 @@ tokens{
ARRAY;
ARRAY_SIZE;
BRACE_EXP;
+ EMPTY_BRACE_EXPANSION_ATOM;
COMMAND_SUB;
CASE_PATTERN;
SUBSHELL;
@@ -162,7 +163,8 @@ brace_expansion_part
: brace_expansion
| ((~COMMA) => fname_part)+ -> ^(STRING fname_part+)
| var_ref
- | command_sub;
+ | command_sub
+ | -> EMPTY_BRACE_EXPANSION_ATOM;
commasep: brace_expansion_part(COMMA! brace_expansion_part)+;
command_sub
: DOLLAR LPAREN BLANK* pipeline BLANK? RPAREN -> ^(COMMAND_SUB pipeline)
diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit
index 2030d58..c9a7ba9 100644
--- a/bashast/gunit/brace.gunit
+++ b/bashast/gunit/brace.gunit
@@ -23,6 +23,7 @@ brace_expansion:
"{a,b,c}" -> (BRACE_EXP (STRING a) (STRING b) (STRING c))
"{a..d}" -> (BRACE_EXP (.. a d))
"{{a,b},c,d}" -> (BRACE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d))
+"{.txt,,}" -> (BRACE_EXP (STRING . txt) EMPTY_BRACE_EXPANSION_ATOM EMPTY_BRACE_EXPANSION_ATOM)
fname:
"a{b,c}" -> (STRING a (BRACE_EXP (STRING b) (STRING c)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: bdf60a3a655fd1cb0234e9b14f8faedbfc5e0b4c
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 17:09:25 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=bdf60a3a
Parser: support numbers in function names
---
bashast/bashast.g | 2 +-
bashast/gunit/function.gunit | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index db04b03..98ef58f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -525,7 +525,7 @@ function: FUNCTION BLANK+ function_name (BLANK* parens)? wspace compound_command
//http://article.gmane.org/gmane.comp.shells.bash.bugs/16424
//the documented set is stricter but we need to have at least what's used in Gentoo
function_name
- : (MINUS|name)+;
+ : (MINUS|DIGIT|name)+;
parens : LPAREN BLANK* RPAREN;
name : NAME
| LETTER
diff --git a/bashast/gunit/function.gunit b/bashast/gunit/function.gunit
index b233b0a..c22821a 100644
--- a/bashast/gunit/function.gunit
+++ b/bashast/gunit/function.gunit
@@ -36,4 +36,4 @@ function:
exit; } > /dev/null" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
"function help { echo hi; } 2> /dev/null" -> (function (STRING help) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING hi)))) (REDIR 2 > (STRING / dev / null)))
"function help { echo 3; } 2> /dev/null > output" OK
-"foo-bar() { :; }" -> (function (STRING foo - bar) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
+"xorg-2_reconf_source() { :; }" -> (function (STRING xorg - 2 _reconf_source) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: cd818e41fb54894c6716edf2a14c5ee907a02528
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 16:51:48 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=cd818e41
Parser: escaped double quotes in dqstr
The parser now handles escaped double quotes inside double quoted
strings.
---
bashast/bashast.g | 9 +++++----
bashast/gunit/fname.gunit | 3 +++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 7b900cc..d82e7cf 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -409,10 +409,11 @@ nqstr_part
//double quoted string rule, allows expansions
dqstr : DQUOTE dqstr_part* DQUOTE -> ^(DOUBLE_QUOTED_STRING dqstr_part*);
dqstr_part
- : var_ref
- | command_sub
- | arithmetic_expansion
- | ~(DOLLAR|TICK|DQUOTE);
+ : var_ref
+ | command_sub
+ | arithmetic_expansion
+ | ESC DQUOTE
+ | ~(DOLLAR|TICK|DQUOTE);
//single quoted string rule, no expansions
sqstr_part
: ~SQUOTE*;
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index a5b1f7f..f048755 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -67,3 +67,6 @@ fname:
"ab[12[:alpha:]]" -> (STRING ab (MATCH_PATTERN 12 (CHARACTER_CLASS alpha)))
"\"'foo'\"" -> (STRING (DOUBLE_QUOTED_STRING ' foo '))
"--preserve=timestamps,mode" -> (STRING - -p reserve = timestamps , mode)
+
+dqstr:
+"\"\\\"\"" -> (DOUBLE_QUOTED_STRING \ ")
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 1d8b7e32a092a2abcd9d95282eb6c2d9df31f95d
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 16:31:14 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=1d8b7e32
Parser: deprecated syntax for arithmetic expansion
Eclasses seem to be using a deprecated form of arithmetic expansion with
square brackets that bash does not document anywhere. This is now
supported by the parser.
---
bashast/bashast.g | 8 ++++++--
bashast/gunit/arith_main.gunit | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 7939229..a3b7314 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -457,11 +457,15 @@ extended_pattern_match
| AT LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_EXACTLY_ONE fname+)
| BANG LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_NONE fname+);
//Arithmetic expansion
+//the square bracket from is deprecated
+//http://permalink.gmane.org/gmane.comp.shells.bash.bugs/14479
arithmetic_expansion
- : DOLLAR LLPAREN BLANK* arithmetics BLANK* RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetics);
+ : DOLLAR LLPAREN BLANK* arithmetics BLANK* RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetics)
+ | DOLLAR LSQUARE BLANK* arithmetics BLANK* RSQUARE -> ^(ARITHMETIC_EXPRESSION arithmetics);
//explicit arithmetic in places like array indexes
explicit_arithmetic
- : (DOLLAR LLPAREN BLANK*)? arithmetics (BLANK* RRPAREN)? -> arithmetics;
+ : (DOLLAR LLPAREN BLANK*)? arithmetics (BLANK* RRPAREN)? -> arithmetics
+ | (DOLLAR LSQUARE BLANK*)? arithmetics (BLANK* RSQUARE)? -> arithmetics;
//The comma operator for arithmetic expansions
arithmetics
: arithmetic (BLANK!* COMMA! BLANK!* arithmetic)*;
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 0f85d55..d8697af 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -125,6 +125,7 @@ arithmetic_condition:
arithmetic_expansion:
"$((5+4, 3+2, a*b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)))
+"$[1]" -> (ARITHMETIC_EXPRESSION 1)
start:
"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: e190a229b781b31134fd21af0c864ee3e3671919
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 19:05:59 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=e190a229
Parser: slash as word for delete operator
In parameter expansions now / works as the word to delete in expansions
like ${foo%/}.
---
bashast/bashast.g | 12 ++++++++----
bashast/gunit/param_main.gunit | 1 +
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 745b1ff..ade30a9 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -253,13 +253,17 @@ var_exp : var_name parameter_value_operator^ word
| BANG^ var_name_for_bang (TIMES|AT)
| BANG var_name_for_bang LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND var_name_for_bang $op)
| BANG var_name_for_bang -> ^(VAR_REF var_name_for_bang)
- | var_name (POUND^|POUNDPOUND^) parameter_pattern
- | var_name (PCT^|PCTPCT^) parameter_pattern
- | var_name parameter_replace_operator^ parameter_pattern parameter_replace_string
+ | var_name parameter_delete_operator parameter_pattern_part+ -> ^(parameter_delete_operator var_name ^(STRING parameter_pattern_part+))
+ | var_name parameter_replace_operator^ parameter_replace_pattern parameter_replace_string
| var_size_ref
| var_name
| TIMES
| AT;
+parameter_delete_operator
+ : POUND
+ | POUNDPOUND
+ | PCT
+ | PCTPCT;
parameter_value_operator
: COLON MINUS -> USE_DEFAULT_WHEN_UNSET_OR_NULL
| COLON EQUALS -> ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL
@@ -269,7 +273,7 @@ parameter_value_operator
| EQUALS -> ASSIGN_DEFAULT_WHEN_UNSET
| QMARK -> DISPLAY_ERROR_WHEN_UNSET
| PLUS -> USE_ALTERNATE_WHEN_UNSET;
-parameter_pattern
+parameter_replace_pattern
: ((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
parameter_pattern_part
: fname_part|BLANK|SEMIC;
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 1a68e5e..d14e4f1 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -40,6 +40,7 @@ var_ref:
"${foo%bar}" -> (VAR_REF (% foo (STRING bar)))
"${foo%%bar}" -> (VAR_REF (%% foo (STRING bar)))
"${foo%; *}" -> (VAR_REF (% foo (STRING ; *)))
+"${foo%/}" -> (VAR_REF (% foo (STRING /)))
"${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING pattern)))
//Test positional/special parameters
"$1" -> (VAR_REF 1)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: 3b1e7cbfed49e4c66e8dc85771003d10d02cbe24
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 17:16:09 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3b1e7cbf
Parser: fix ws handling for array assignment
The parser wasn't eating all kinds of white space between atoms of
assigning an array to a variable.
---
bashast/bashast.g | 4 ++--
bashast/gunit/array.gunit | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 98ef58f..3b1e4ed 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -229,10 +229,10 @@ var_def
| name EQUALS^ value?;
//Possible values of a variable
value : fname
- | LPAREN! wspace!? arr_val RPAREN!;
+ | LPAREN! wspace!* arr_val RPAREN!;
//allow the parser to create array variables
arr_val :
- | (ag+=array_atom wspace?)+ -> ^(ARRAY $ag+);
+ | (ag+=array_atom wspace*)+ -> ^(ARRAY $ag+);
array_atom
: LSQUARE! BLANK!* explicit_arithmetic BLANK!? RSQUARE! EQUALS^ fname
| fname;
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index d44217c..402e707 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -22,6 +22,10 @@ var_def:
"asdf=(a b c d)"->(= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d)))
"asdf=(`echo 6` b c d)"->(= asdf (ARRAY (STRING (COMMAND_SUB (COMMAND (STRING echo) (STRING 6)))) (STRING b) (STRING c) (STRING d)))
"asdf=(${P} b c d)"->(= asdf (ARRAY (STRING (VAR_REF P)) (STRING b) (STRING c) (STRING d)))
+"asdf=(
+ --disable-dependency-tracking
+ ${VAR}
+)" -> (= asdf (ARRAY (STRING - - disable - dependency - tracking) (STRING (VAR_REF VAR))))
var_ref:
"$asdf" -> (VAR_REF asdf)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-17 10:58 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-17 10:58 UTC (permalink / raw
To: gentoo-commits
commit: b680da3520a8fa589848a9c205b52688f3ca13e3
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr 16 18:11:54 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 17 10:57:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b680da35
Parser: function name rules from bash sources
Relax the function name rules so that now again most eclasses parse. The
implemention is done using negation so hopefully it doesn't break that
easily.
---
bashast/bashast.g | 7 +++++--
bashast/gunit/function.gunit | 8 ++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 3b1e4ed..745b1ff 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -523,9 +523,12 @@ process_substitution
function: FUNCTION BLANK+ function_name (BLANK* parens)? wspace compound_command redirect* -> ^(FUNCTION ^(STRING function_name) compound_command redirect*)
| function_name BLANK* parens wspace compound_command redirect* -> ^(FUNCTION["function"] ^(STRING function_name) compound_command redirect*);
//http://article.gmane.org/gmane.comp.shells.bash.bugs/16424
-//the documented set is stricter but we need to have at least what's used in Gentoo
+//the rules from bash 3.2 general.c:
+//Make sure that WORD is a valid shell identifier, i.e.
+//does not contain a dollar sign, nor is quoted in any way. Nor
+//does it consist of all digits.
function_name
- : (MINUS|DIGIT|name)+;
+ : (NUMBER|DIGIT)? ~(DOLLAR|SQUOTE|DQUOTE|LPAREN|RPAREN|BLANK|EOL|NUMBER|DIGIT) ~(DOLLAR|SQUOTE|DQUOTE|LPAREN|RPAREN|BLANK|EOL)*;
parens : LPAREN BLANK* RPAREN;
name : NAME
| LETTER
diff --git a/bashast/gunit/function.gunit b/bashast/gunit/function.gunit
index c22821a..a474273 100644
--- a/bashast/gunit/function.gunit
+++ b/bashast/gunit/function.gunit
@@ -37,3 +37,11 @@ function:
"function help { echo hi; } 2> /dev/null" -> (function (STRING help) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING hi)))) (REDIR 2 > (STRING / dev / null)))
"function help { echo 3; } 2> /dev/null > output" OK
"xorg-2_reconf_source() { :; }" -> (function (STRING xorg - 2 _reconf_source) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
+
+function_name:
+"xemacs-packages_src_unpack" OK
+"while" OK
+"aa'bb" FAIL
+"a\"" FAIL
+"333" FAIL
+"aa$aa" FAIL
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-20 11:26 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-20 11:26 UTC (permalink / raw
To: gentoo-commits
commit: f7ac14b579909831a9064143c5e720bbf341bdfe
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue Apr 19 15:16:45 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 20 11:22:37 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f7ac14b5
Parser: fix warnings from unary rule
---
bashast/bashast.g | 8 ++++----
bashast/gunit/arith_main.gunit | 3 +++
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 0842f54..1424429 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -494,10 +494,10 @@ pre_inc_dec
| MINUS MINUS BLANK? primary -> ^(PRE_DECR primary);
unary : post_inc_dec
| pre_inc_dec
- | BLANK!? primary
- | PLUS unary -> ^(PLUS_SIGN unary)
- | MINUS unary -> ^(MINUS_SIGN unary)
- | (TILDE|BANG)^ unary;
+ | primary
+ | PLUS BLANK* unary -> ^(PLUS_SIGN unary)
+ | MINUS BLANK* unary -> ^(MINUS_SIGN unary)
+ | (TILDE|BANG)^ BLANK!* unary;
exponential
: unary (BLANK!* EXP^ BLANK!* unary)* ;
times_division_modulus
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index d8697af..0531c49 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -123,6 +123,9 @@ arithmetic_condition:
"5?7:2"->(ARITHMETIC_CONDITION 5 7 2)
"(4-3)?0:1"->(ARITHMETIC_CONDITION (- 4 3) 0 1)
+arithmetics:
+"~ 10" -> (~ 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)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-20 11:26 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-20 11:26 UTC (permalink / raw
To: gentoo-commits
commit: e70dd9ef41f969157a7f27630d252d8742d4cbe2
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue Apr 19 15:27:26 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 20 11:22:37 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=e70dd9ef
Parser: prevent arithmetic assign to numbers
Within arithmetic expressions digits can't be variables so doing
$((3=7)) is not valid. Now we don't allow digits to match variable names
in arithmetic. This also silences warnings.
---
bashast/bashast.g | 12 ++++++++----
bashast/gunit/arith_main.gunit | 1 +
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 1424429..9c32d58 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -287,8 +287,12 @@ parameter_replace_operator
| SLASH -> REPLACE_FIRST;
//Allowable refences to values
//either directly or through array
-var_name: num
- | name^ LSQUARE! (AT|TIMES|explicit_arithmetic) RSQUARE!
+var_name
+ : num
+ | var_name_no_digit;
+//Inside arithmetic we can't allow digits
+var_name_no_digit
+ : name^ LSQUARE! (AT|TIMES|explicit_arithmetic) RSQUARE!
| name
| POUND;
//with bang the array syntax is used for array indexes
@@ -484,7 +488,7 @@ arithmetic_var_ref:
primary : num
| arithmetic_var_ref
| command_sub
- | var_name -> ^(VAR_REF var_name)
+ | var_name_no_digit -> ^(VAR_REF var_name_no_digit)
| LPAREN! (arithmetics) RPAREN!;
post_inc_dec
: primary BLANK? PLUS PLUS -> ^(POST_INCR primary)
@@ -521,7 +525,7 @@ arithmetic_assignment_opterator
: EQUALS|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN;
arithmetic_assignment
- : ((var_name|arithmetic_var_ref) BLANK!* arithmetic_assignment_opterator^ BLANK!*)? logicor;
+ : ((var_name_no_digit|arithmetic_var_ref) BLANK!* arithmetic_assignment_opterator^ BLANK!*)? logicor;
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
//the biggie: functions
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 0531c49..4490eb3 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -118,6 +118,7 @@ arithmetic_assignment:
"var &= 5" -> (&= var 5)
"var ^= 5" -> (^= var 5)
"var |= 5" -> (|= var 5)
+"3=7" FAIL
arithmetic_condition:
"5?7:2"->(ARITHMETIC_CONDITION 5 7 2)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-20 11:26 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-20 11:26 UTC (permalink / raw
To: gentoo-commits
commit: 2bb591fd2cc27fca8ce2c65eb3a3afbb58810e97
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue Apr 19 20:30:21 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 20 11:22:48 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2bb591fd
Parser: remove list rule
Having clist and list doing pretty much the same thing is confusing.
Removed the list rule and moved handling things in the end to the start
rule.
---
bashast/bashast.g | 4 +---
bashast/gunit/expansions.gunit | 2 +-
bashast/gunit/list.gunit | 2 +-
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 61c5914..0dc931f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -92,13 +92,11 @@ tokens{
MINUS_SIGN;
}
-start : (flcomment!)? EOL!* list^ ;
+start : (flcomment)? EOL* clist BLANK* (SEMIC|AMP|EOL)? -> clist;
//Because the comment token doesn't handle the first comment in a file if it's on the first line, have a parser rule for it
flcomment
: POUND ~(EOL)* EOL;
-list : list_level_2 BLANK* (SEMIC|AMP|EOL)? -> ^(LIST list_level_2);
clist
-options{greedy=false;}
: list_level_2 -> ^(LIST list_level_2);
list_level_1
: (function|pipeline) (BLANK!*(LOGICAND^|LOGICOR^)BLANK!* (function|pipeline))*;
diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit
index 4ea5924..bbfa37a 100644
--- a/bashast/gunit/expansions.gunit
+++ b/bashast/gunit/expansions.gunit
@@ -18,7 +18,7 @@
*/
gunit bashast;
-list:
+clist:
"echo a{b,c,d}" -> (LIST (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c) (STRING d)))))
"((5+5))" -> (LIST (COMPOUND_ARITH (+ 5 5)))
"(( 4 + asdf ))" -> (LIST (COMPOUND_ARITH (+ 4 (VAR_REF asdf))))
diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit
index 42836ca..76c46b2 100644
--- a/bashast/gunit/list.gunit
+++ b/bashast/gunit/list.gunit
@@ -18,7 +18,7 @@
*/
gunit bashast;
-list:
+start:
"make" -> (LIST (COMMAND (STRING make)))
"make && make modules_install;" -> (LIST (&& (COMMAND (STRING make)) (COMMAND (STRING make) (STRING modules_install))))
"make && make modules_install &" -> (LIST (&& (COMMAND (STRING make)) (COMMAND (STRING make) (STRING modules_install))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-04-27 15:11 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-04-27 15:11 UTC (permalink / raw
To: gentoo-commits
commit: d708238429d2687e5362d19e25b5e0bfc6f3eb06
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 27 14:52:45 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 27 14:58:44 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d7082384
Parser: support == and != in test built-in
Virtual token is used instead of OP['..'] because the previous one
can't be handled by tree grammar.
---
bashast/bashast.g | 7 +++++--
bashast/gunit/cond_main.gunit | 3 +++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9fcacc0..b079d07 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -94,6 +94,8 @@ tokens{
// Avoid ambiguity (being a sign or an operator)
PLUS_SIGN;
MINUS_SIGN;
+ // Operators
+ NOT_EQUALS;
}
start : (flcomment)? EOL* clist BLANK* (SEMIC|AMP|EOL)? -> clist;
@@ -335,7 +337,7 @@ builtin_cond_primary
| builtin_cond_unary
| fname;
builtin_cond_binary
- : cond_part BLANK!* binary_string_op_builtin^ BLANK!? cond_part;
+ : cond_part BLANK!* binary_string_op_builtin^ BLANK!* cond_part;
builtin_cond_unary
: uop^ BLANK!+ cond_part;
keyword_cond
@@ -355,8 +357,9 @@ binary_str_op_keyword
| GREATER_THAN;
binary_string_op_builtin
: bop
+ | EQUALS EQUALS -> EQUALS
| EQUALS
- | BANG EQUALS -> OP["!="]
+ | BANG EQUALS -> NOT_EQUALS
| ESC_LT
| ESC_GT;
bop : MINUS! NAME^;
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 159c734..78ebbf9 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -25,3 +25,6 @@ cond_expr:
"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!= (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo))) (a (STRING filename))))
"[[ true ]]" -> (KEYWORD_TEST (STRING true))
"[[ true && (false || three) ]]" -> (KEYWORD_TEST (&& (STRING true) (|| (STRING false) (STRING three))))
+"[ a = b ]" -> (BUILTIN_TEST (= (STRING a) (STRING b)))
+"[ a == b ]" -> (BUILTIN_TEST (= (STRING a) (STRING b)))
+"[ a != b ]" -> (BUILTIN_TEST (NOT_EQUALS (STRING a) (STRING b)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-05-07 12:25 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-05-07 12:25 UTC (permalink / raw
To: gentoo-commits
commit: 41079afae26d6203928c8647de87c63e28aeb6c3
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu May 5 12:40:59 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat May 7 07:01:28 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=41079afa
Parser: support defining local variables
---
bashast/bashast.g | 5 +++--
bashast/gunit/simp_command.gunit | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 3a84d29..51fe9a9 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -130,7 +130,7 @@ simple_command
| variable_definitions -> ^(VARIABLE_DEFINITIONS variable_definitions)
| bash_command^ redirect*;
variable_definitions
- : var_def (BLANK!+ var_def)*;
+ : (LOCAL BLANK!+)? var_def (BLANK!+ var_def)*;
bash_command
: fname_no_res_word (BLANK+ fname)* -> ^(COMMAND fname_no_res_word fname*);
redirect: BLANK!* here_string_op^ BLANK!* fname
@@ -388,7 +388,7 @@ options{k=1;backtrack=false;}
: DIGIT|NUMBER;
//A rule for filenames/strings
res_word_str
- : CASE|DO|DONE|ELIF|ELSE|ESAC|FI|FOR|FUNCTION|IF|IN|SELECT|THEN|UNTIL|WHILE|TIME;
+ : CASE|DO|DONE|ELIF|ELSE|ESAC|FI|FOR|FUNCTION|IF|IN|SELECT|THEN|UNTIL|WHILE|TIME|LOCAL;
//Any allowable part of a string, including slashes, no pounds
str_part
: ns_str_part
@@ -653,6 +653,7 @@ COLON : ':';
QMARK : '?';
//Operators for conditional statements
TEST_EXPR : 'test';
+LOCAL : 'local';
LOGICAND : '&&';
LOGICOR : '||';
//Tokens for strings
diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
index b2dc74a..0ec100f 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -29,3 +29,4 @@ simple_command:
"./foobär" -> (COMMAND (STRING . / foob ä r))
"cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Documents / todo . txt))
"dodir ${foo}/${bar}" -> (COMMAND (STRING dodir) (STRING (VAR_REF foo) / (VAR_REF bar)))
+"local a=123 b=(1 2 3)" -> (VARIABLE_DEFINITIONS local (= a (STRING 123)) (= b (ARRAY (STRING 1) (STRING 2) (STRING 3))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 495848c85f4c54af8fed466d09bd474fbdf37568
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue May 10 17:53:03 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue May 10 17:53:03 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=495848c8
Parser: rename MATCH_PATTERN to MATCH_ANY
The token is used to describe bracket pattern matching expressions where
any of the atoms inside the brackets can match to MATCH_ANY is a more
descriptive name.
---
bashast/bashast.g | 6 +++---
bashast/gunit/fname.gunit | 28 ++++++++++++++--------------
bashast/gunit/param_main.gunit | 2 +-
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 977e8c8..220d01f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -68,7 +68,7 @@ tokens{
EXTENDED_MATCH_NONE;
EXTENDED_MATCH_ANY;
EXTENDED_MATCH_AT_LEAST_ONE;
- MATCH_PATTERN;
+ MATCH_ANY;
MATCH_ANY_EXCEPT;
CHARACTER_CLASS;
EQUIVALENCE_CLASS;
@@ -450,9 +450,9 @@ pattern_match_trigger
//Pattern matching using brackets
bracket_pattern_match
: LSQUARE RSQUARE (BANG|CARET) pattern_match* RSQUARE -> ^(MATCH_ANY_EXCEPT RSQUARE pattern_match*)
- | LSQUARE RSQUARE pattern_match* RSQUARE -> ^(MATCH_PATTERN RSQUARE pattern_match*)
+ | LSQUARE RSQUARE pattern_match* RSQUARE -> ^(MATCH_ANY RSQUARE pattern_match*)
| LSQUARE (BANG|CARET) pattern_match+ RSQUARE -> ^(MATCH_ANY_EXCEPT pattern_match+)
- | LSQUARE pattern_match+ RSQUARE -> ^(MATCH_PATTERN pattern_match+);
+ | LSQUARE pattern_match+ RSQUARE -> ^(MATCH_ANY pattern_match+);
//allowable patterns with bracket pattern matching
pattern_match
: pattern_class_match
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index cfde61b..c12449b 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -47,24 +47,24 @@ fname:
"hex\xaF" -> (STRING hex \ xaF)
"ctrlx\cx" -> (STRING ctrlx \ cx)
"tab\\ttab" -> "(STRING tab \\ \t tab)"
-"abc[def]" -> (STRING abc (MATCH_PATTERN def))
-"abc[d${more}]" -> (STRING abc (MATCH_PATTERN d (VAR_REF more)))
-"abc[#d]" -> (STRING abc (MATCH_PATTERN # d))
-"abc[d#]" -> (STRING abc (MATCH_PATTERN d #))
+"abc[def]" -> (STRING abc (MATCH_ANY def))
+"abc[d${more}]" -> (STRING abc (MATCH_ANY d (VAR_REF more)))
+"abc[#d]" -> (STRING abc (MATCH_ANY # d))
+"abc[d#]" -> (STRING abc (MATCH_ANY d #))
"a[]" -> (STRING a [ ])
-"ab[d-h]" -> (STRING ab (MATCH_PATTERN d - h))
+"ab[d-h]" -> (STRING ab (MATCH_ANY d - h))
"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
"ab[^d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
-"ab[]c]" -> (STRING ab (MATCH_PATTERN ] c))
-"ab[:alpha:]" -> (STRING ab (MATCH_PATTERN : alpha :))
-"ab[=c=]" -> (STRING ab (MATCH_PATTERN = c =))
-"ab[.c.]" -> (STRING ab (MATCH_PATTERN . c .))
-"ab[[:alpha:]]" -> (STRING ab (MATCH_PATTERN (CHARACTER_CLASS alpha)))
-"ab[[:alpha:][:digit:]]" -> (STRING ab (MATCH_PATTERN (CHARACTER_CLASS alpha) (CHARACTER_CLASS digit)))
+"ab[]c]" -> (STRING ab (MATCH_ANY ] c))
+"ab[:alpha:]" -> (STRING ab (MATCH_ANY : alpha :))
+"ab[=c=]" -> (STRING ab (MATCH_ANY = c =))
+"ab[.c.]" -> (STRING ab (MATCH_ANY . c .))
+"ab[[:alpha:]]" -> (STRING ab (MATCH_ANY (CHARACTER_CLASS alpha)))
+"ab[[:alpha:][:digit:]]" -> (STRING ab (MATCH_ANY (CHARACTER_CLASS alpha) (CHARACTER_CLASS digit)))
"ab[^[:alpha:]]" -> (STRING ab (MATCH_ANY_EXCEPT (CHARACTER_CLASS alpha)))
-"ab[[=c=]]" -> (STRING ab (MATCH_PATTERN (EQUIVALENCE_CLASS c)))
-"ab[[.backslash.]]" -> (STRING ab (MATCH_PATTERN (COLLATING_SYMBOL backslash)))
-"ab[12[:alpha:]]" -> (STRING ab (MATCH_PATTERN 12 (CHARACTER_CLASS alpha)))
+"ab[[=c=]]" -> (STRING ab (MATCH_ANY (EQUIVALENCE_CLASS c)))
+"ab[[.backslash.]]" -> (STRING ab (MATCH_ANY (COLLATING_SYMBOL backslash)))
+"ab[12[:alpha:]]" -> (STRING ab (MATCH_ANY 12 (CHARACTER_CLASS alpha)))
"\"'foo'\"" -> (STRING (DOUBLE_QUOTED_STRING ' foo '))
"--preserve=timestamps,mode" -> (STRING - -p reserve = timestamps , mode)
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 91ed8be..54a2edb 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -56,7 +56,7 @@ var_ref:
"${_}" -> (VAR_REF _)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
"${PV// }" -> (VAR_REF (REPLACE_ALL PV (STRING )))
-"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_PATTERN - . _))))
+"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _))))
"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace))))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar)))
"${PV/%foo/bar}" -> (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 8624fcd7eb47f5c78d7f2dc577f6aac61786eb8f
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue May 10 15:48:02 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue May 10 15:48:02 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=8624fcd7
Parser: rename extended pattern matching tokens
Prefix tokens used in extended pattern matching with EXTENDED_ so it's
clear what tokens are related to extended pattern matching and normal
matching.
---
bashast/bashast.g | 20 ++++++++++----------
bashast/gunit/fname.gunit | 10 +++++-----
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 682d81b..977e8c8 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -63,11 +63,11 @@ tokens{
KEYWORD_TEST;
BUILTIN_TEST;
MATCH_ANY_EXCEPT;
- MATCH_EXACTLY_ONE;
- MATCH_AT_MOST_ONE;
- MATCH_NONE;
- MATCH_ANY;
- MATCH_AT_LEAST_ONE;
+ EXTENDED_MATCH_EXACTLY_ONE;
+ EXTENDED_MATCH_AT_MOST_ONE;
+ EXTENDED_MATCH_NONE;
+ EXTENDED_MATCH_ANY;
+ EXTENDED_MATCH_AT_LEAST_ONE;
MATCH_PATTERN;
MATCH_ANY_EXCEPT;
CHARACTER_CLASS;
@@ -473,11 +473,11 @@ pattern_char
: LETTER|DIGIT|OTHER|QMARK|COLON|AT|SEMIC|POUND|SLASH|BANG|TIMES|COMMA|PIPE|AMP|MINUS|PLUS|PCT|EQUALS|LSQUARE|RSQUARE|RPAREN|LPAREN|RBRACE|LBRACE|DOLLAR|TICK|DOT|LESS_THAN|GREATER_THAN|SQUOTE|DQUOTE;
//extended pattern matching
extended_pattern_match
- : QMARK LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_AT_MOST_ONE fname+)
- | TIMES LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_ANY fname+)
- | PLUS LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_AT_LEAST_ONE fname+)
- | AT LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_EXACTLY_ONE fname+)
- | BANG LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_NONE fname+);
+ : QMARK LPAREN fname (PIPE fname)* RPAREN -> ^(EXTENDED_MATCH_AT_MOST_ONE fname+)
+ | TIMES LPAREN fname (PIPE fname)* RPAREN -> ^(EXTENDED_MATCH_ANY fname+)
+ | PLUS LPAREN fname (PIPE fname)* RPAREN -> ^(EXTENDED_MATCH_AT_LEAST_ONE fname+)
+ | AT LPAREN fname (PIPE fname)* RPAREN -> ^(EXTENDED_MATCH_EXACTLY_ONE fname+)
+ | BANG LPAREN fname (PIPE fname)* RPAREN -> ^(EXTENDED_MATCH_NONE fname+);
//The base of the arithmetic operator. Used for order of operations
arithmetic_var_ref:
var_ref -> ^(VAR_REF var_ref);
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 467bd43..cfde61b 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -36,11 +36,11 @@ fname:
"'asdf\"asdf'" -> (STRING (SINGLE_QUOTED_STRING asdf " asdf))
"\"asdf'asdf\"" -> (STRING (DOUBLE_QUOTED_STRING asdf ' asdf))
"!/bin/bash" -> (STRING ! / bin / bash)
-"ab?(g|h)"-> (STRING ab (MATCH_AT_MOST_ONE (STRING g) (STRING h)))
-"ab*(gh|i)" -> (STRING ab (MATCH_ANY (STRING gh) (STRING i)))
-"ab+(gh|i)" -> (STRING ab (MATCH_AT_LEAST_ONE (STRING gh) (STRING i)))
-"ab@(gh|i)" -> (STRING ab (MATCH_EXACTLY_ONE (STRING gh) (STRING i)))
-"ab!(gh|i)" -> (STRING ab (MATCH_NONE (STRING gh) (STRING i)))
+"ab?(g|h)"-> (STRING ab (EXTENDED_MATCH_AT_MOST_ONE (STRING g) (STRING h)))
+"ab*(gh|i)" -> (STRING ab (EXTENDED_MATCH_ANY (STRING gh) (STRING i)))
+"ab+(gh|i)" -> (STRING ab (EXTENDED_MATCH_AT_LEAST_ONE (STRING gh) (STRING i)))
+"ab@(gh|i)" -> (STRING ab (EXTENDED_MATCH_EXACTLY_ONE (STRING gh) (STRING i)))
+"ab!(gh|i)" -> (STRING ab (EXTENDED_MATCH_NONE (STRING gh) (STRING i)))
"\"abc\"\'\"\'\"def\"" -> (STRING (DOUBLE_QUOTED_STRING abc) (SINGLE_QUOTED_STRING ") (DOUBLE_QUOTED_STRING def))
"my\ name\ is" -> (STRING my \ name \ is)
"octal\007" -> (STRING octal \ 007)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 68d05d5b690b4ce190b7f789705efd34eb5a4a30
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue May 10 15:19:40 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue May 10 15:19:40 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=68d05d5b
Parser: allow white space in replacement strings
Now the parser doesn't swallow white spaces from the replacement string
in variable expansion and they get reflected properly in the AST. Fixes
bug #364119.
---
bashast/bashast.g | 4 ++--
bashast/gunit/param_main.gunit | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 51fe9a9..682d81b 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -262,7 +262,7 @@ var_exp : var_name (
-> ^(OFFSET var_name $os ^($len)?)
| parameter_delete_operator parameter_pattern_part+
-> ^(parameter_delete_operator var_name ^(STRING parameter_pattern_part+))
- | parameter_replace_operator parameter_replace_pattern parameter_replace_string
+ | parameter_replace_operator parameter_replace_pattern (SLASH parameter_replace_string?)?
-> ^(parameter_replace_operator var_name parameter_replace_pattern parameter_replace_string?)
| -> var_name
)
@@ -294,7 +294,7 @@ parameter_replace_pattern
parameter_pattern_part
: fname_part|BLANK|SEMIC;
parameter_replace_string
- : (SLASH fname|SLASH)? -> fname?;
+ : parameter_pattern_part+ -> ^(STRING parameter_pattern_part+);
parameter_replace_operator
: SLASH SLASH -> REPLACE_ALL
| SLASH PCT -> REPLACE_AT_END
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 61cc140..91ed8be 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -60,6 +60,8 @@ var_ref:
"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace))))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar)))
"${PV/%foo/bar}" -> (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar)))
+"${PN/%spaces /more }" -> (VAR_REF (REPLACE_AT_END PN (STRING spaces ) (STRING more )))
+"${PN/wrong#/#correct}" -> (VAR_REF (REPLACE_FIRST PN (STRING wrong #) (STRING # correct)))
var_def:
"MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-05-22 21:00 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-05-22 21:00 UTC (permalink / raw
To: gentoo-commits
commit: a8be914d2ff0ff3516ed0ea1e9d775ba57c3c47d
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 16 12:24:09 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 22 16:11:39 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a8be914d
Parser: use tokens instead of "OP" for keyword test
OP["!="] can't be understand by the walker grammar so we use virtual
a token instead. "!=" and "==" trigger bash pattern matching.
---
bashast/bashast.g | 6 ++++--
bashast/gunit/cond_main.gunit | 4 +++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index c4156ec..2a8e20b 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -68,6 +68,8 @@ tokens{
EXTENDED_MATCH_NONE;
EXTENDED_MATCH_ANY;
EXTENDED_MATCH_AT_LEAST_ONE;
+ MATCH_PATTERN;
+ NOT_MATCH_PATTERN;
MATCH_ANY;
MATCH_ANY_EXCEPT;
MATCH_ALL;
@@ -354,9 +356,9 @@ negate_builtin_primary
: BANG BLANK+ builtin_cond_primary -> ^(NEGATION builtin_cond_primary);
binary_str_op_keyword
: bop
- | EQUALS EQUALS -> OP["=="]
+ | EQUALS EQUALS -> MATCH_PATTERN
| EQUALS
- | BANG EQUALS -> OP["!="]
+ | BANG EQUALS -> NOT_MATCH_PATTERN
| LESS_THAN
| GREATER_THAN;
binary_string_op_builtin
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 78ebbf9..eeef052 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -22,7 +22,9 @@ cond_expr:
"[[ -a this/is.afile ]]" -> (KEYWORD_TEST (a (STRING this / is . afile)))
"[ -n \"yar53\" ]" -> (BUILTIN_TEST (n (STRING (DOUBLE_QUOTED_STRING yar53))))
"test 5 -eq 6" -> (BUILTIN_TEST (eq (STRING 5) (STRING 6)))
-"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (!= (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo))) (a (STRING filename))))
+"[[ \"asdf\" != \"boo\" && -a filename ]]" -> (KEYWORD_TEST (&& (NOT_MATCH_PATTERN (STRING (DOUBLE_QUOTED_STRING asdf)) (STRING (DOUBLE_QUOTED_STRING boo))) (a (STRING filename))))
+"[[ a = b ]]" -> (KEYWORD_TEST (= (STRING a) (STRING b)))
+"[[ a == b ]]" -> (KEYWORD_TEST (MATCH_PATTERN (STRING a) (STRING b)))
"[[ true ]]" -> (KEYWORD_TEST (STRING true))
"[[ true && (false || three) ]]" -> (KEYWORD_TEST (&& (STRING true) (|| (STRING false) (STRING three))))
"[ a = b ]" -> (BUILTIN_TEST (= (STRING a) (STRING b)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-05-23 14:34 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-05-23 14:34 UTC (permalink / raw
To: gentoo-commits
commit: 9be9015b29fac3e2d2cc6d1f1e44e6de516b6e09
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat May 21 03:13:41 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 15:04:45 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9be9015b
Parser: fix function definition
When parentheses are provided after function name, the spaces after
the parentheses are optional. Now this is supported in the grammar.
---
bashast/bashast.g | 4 ++--
bashast/gunit/function.gunit | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index dd1c92d..404de43 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -553,8 +553,8 @@ arithmetic_expansion
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
//the biggie: functions
-function: FUNCTION BLANK+ function_name (BLANK* parens)? wspace compound_command redirect* -> ^(FUNCTION ^(STRING function_name) compound_command redirect*)
- | function_name BLANK* parens wspace compound_command redirect* -> ^(FUNCTION["function"] ^(STRING function_name) compound_command redirect*);
+function: FUNCTION BLANK+ function_name ((BLANK* parens wspace*)|wspace) compound_command redirect* -> ^(FUNCTION ^(STRING function_name) compound_command redirect*)
+ | function_name BLANK* parens wspace* compound_command redirect* -> ^(FUNCTION["function"] ^(STRING function_name) compound_command redirect*);
//http://article.gmane.org/gmane.comp.shells.bash.bugs/16424
//the rules from bash 3.2 general.c:
//Make sure that WORD is a valid shell identifier, i.e.
diff --git a/bashast/gunit/function.gunit b/bashast/gunit/function.gunit
index a474273..642318e 100644
--- a/bashast/gunit/function.gunit
+++ b/bashast/gunit/function.gunit
@@ -27,8 +27,10 @@ function:
"function quit { exit }" FAIL
"function 'foo' { exit; }" FAIL
"function quit { exit; }" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit)))))
-"function foo() { :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
-"foo() { :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
+"function foo() { :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
+"function foo(){ :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
+"foo() { :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
+"foo(){ :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
"function quit { exit; } > /dev/null" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
"function quit {
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-01 12:03 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-01 12:03 UTC (permalink / raw
To: gentoo-commits
commit: 97cf0f6388b74c3810325d17dd7b9f1b3610c02a
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 30 07:26:35 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 05:54:41 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=97cf0f63
Parser: support special variable $$
---
bashast/bashast.g | 2 ++
bashast/gunit/param_main.gunit | 2 ++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f9d5425..2e892c2 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -266,6 +266,7 @@ var_ref
| DOLLAR POUND -> ^(VAR_REF POUND)
| DOLLAR QMARK -> ^(VAR_REF QMARK)
| DOLLAR MINUS -> ^(VAR_REF MINUS)
+ | DOLLAR DOLLAR -> ^(VAR_REF DOLLAR)
| DOLLAR BANG -> ^(VAR_REF BANG);
//Variable expansions
var_exp : var_name (
@@ -317,6 +318,7 @@ var_name
: num
| var_name_no_digit
| TIMES
+ | DOLLAR
| AT;
//Inside arithmetic we can't allow digits
var_name_no_digit
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 5fd818e..cfbd92f 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -54,6 +54,8 @@ var_ref:
"$?" -> (VAR_REF ?)
"$_" -> (VAR_REF _)
"${_}" -> (VAR_REF _)
+"$$" -> (VAR_REF $)
+"${$}" -> (VAR_REF $)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
"${PV// }" -> (VAR_REF (REPLACE_ALL PV (STRING )))
"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-01 12:03 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-01 12:03 UTC (permalink / raw
To: gentoo-commits
commit: bf0e206d28d3cd9f5de4d63700a06c75d9581e23
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 30 08:30:18 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 06:11:32 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=bf0e206d
Parser: allow spaces at the end of arithmetic expansion
---
bashast/bashast.g | 4 ++--
bashast/gunit/arith_main.gunit | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 26d362f..c560644 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -554,8 +554,8 @@ explicit_arithmetic
//the square bracket from is deprecated
//http://permalink.gmane.org/gmane.comp.shells.bash.bugs/14479
arithmetic_expansion
- : DOLLAR LLPAREN BLANK* arithmetics RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetics)
- | DOLLAR LSQUARE BLANK* arithmetics RSQUARE -> ^(ARITHMETIC_EXPRESSION arithmetics);
+ : DOLLAR LLPAREN BLANK* arithmetics BLANK* RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetics)
+ | DOLLAR LSQUARE BLANK* arithmetics BLANK* RSQUARE -> ^(ARITHMETIC_EXPRESSION arithmetics);
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 4490eb3..b462450 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -134,4 +134,5 @@ arithmetic_expansion:
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))))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-01 12:03 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-01 12:03 UTC (permalink / raw
To: gentoo-commits
commit: 3316cbc65d294bd54022a86ed86433ae7a65fc93
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 30 09:25:00 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 06:12:20 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3316cbc6
Parser: fix brace expansion
We need to support expansions like {$a/$b,c}. The previous
implementation can not match $a/$b as a whole string. Now it's fixed.
---
bashast/bashast.g | 6 ++----
bashast/gunit/brace.gunit | 1 +
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 88a44cf..104dd36 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -180,10 +180,8 @@ brace_expansion_inside
range : DIGIT DOTDOT^ DIGIT
| LETTER DOTDOT^ LETTER;
brace_expansion_part
- : brace_expansion
- | ((~COMMA) => fname_part)+ -> ^(STRING fname_part+)
- | var_ref
- | command_sub
+ : (((~COMMA) => fname_part)+ -> ^(STRING fname_part+))+
+ | brace_expansion
| -> EMPTY_BRACE_EXPANSION_ATOM;
commasep: brace_expansion_part(COMMA! brace_expansion_part)+;
command_sub
diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit
index c9a7ba9..584face 100644
--- a/bashast/gunit/brace.gunit
+++ b/bashast/gunit/brace.gunit
@@ -20,6 +20,7 @@ gunit bashast;
brace_expansion:
"{a,b}"-> (BRACE_EXP (STRING a) (STRING b))
+"{$a/$b,b}"-> (BRACE_EXP (STRING (VAR_REF a) / (VAR_REF b)) (STRING b))
"{a,b,c}" -> (BRACE_EXP (STRING a) (STRING b) (STRING c))
"{a..d}" -> (BRACE_EXP (.. a d))
"{{a,b},c,d}" -> (BRACE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-01 12:03 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-01 12:03 UTC (permalink / raw
To: gentoo-commits
commit: 456744a2e9f0cae3231a02763ca852945c0e6c24
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 30 07:56:30 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 05:54:41 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=456744a2
Parser: support redirection for command group
Redirection in function definition is not necessary anymore as it
will be matched by command group.
---
bashast/bashast.g | 8 ++++----
bashast/gunit/function.gunit | 6 +++---
bashast/gunit/list.gunit | 2 ++
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2e892c2..26d362f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -231,10 +231,10 @@ case_pattern
| fname
| TIMES;
//A grouping of commands executed in a subshell
-subshell: LPAREN wspace? clist (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN -> ^(SUBSHELL clist);
+subshell: LPAREN wspace? clist (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN redirect* -> ^(SUBSHELL clist redirect*);
//A grouping of commands executed in the current shell
current_shell
- : LBRACE wspace clist semiel wspace* RBRACE -> ^(CURRENT_SHELL clist);
+ : LBRACE wspace clist semiel wspace* RBRACE redirect* -> ^(CURRENT_SHELL clist redirect*);
//comparison using arithmetic
arith_comparison
: LLPAREN wspace? arithmetic wspace? RRPAREN -> ^(COMPOUND_ARITH arithmetic);
@@ -560,8 +560,8 @@ arithmetic_expansion
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
//the biggie: functions
-function: FUNCTION BLANK+ function_name ((BLANK* parens wspace*)|wspace) compound_command redirect* -> ^(FUNCTION ^(STRING function_name) compound_command redirect*)
- | function_name BLANK* parens wspace* compound_command redirect* -> ^(FUNCTION["function"] ^(STRING function_name) compound_command redirect*);
+function: FUNCTION BLANK+ function_name ((BLANK* parens wspace*)|wspace) compound_command -> ^(FUNCTION ^(STRING function_name) compound_command)
+ | function_name BLANK* parens wspace* compound_command -> ^(FUNCTION["function"] ^(STRING function_name) compound_command);
//http://article.gmane.org/gmane.comp.shells.bash.bugs/16424
//the rules from bash 3.2 general.c:
//Make sure that WORD is a valid shell identifier, i.e.
diff --git a/bashast/gunit/function.gunit b/bashast/gunit/function.gunit
index 642318e..6ee6c68 100644
--- a/bashast/gunit/function.gunit
+++ b/bashast/gunit/function.gunit
@@ -32,11 +32,11 @@ function:
"foo() { :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
"foo(){ :; }" -> (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
-"function quit { exit; } > /dev/null" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
+"function quit { exit; } > /dev/null" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit))) (REDIR > (STRING / dev / null))))
"function quit {
# comment
- exit; } > /dev/null" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit)))) (REDIR > (STRING / dev / null)))
-"function help { echo hi; } 2> /dev/null" -> (function (STRING help) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING hi)))) (REDIR 2 > (STRING / dev / null)))
+ exit; } > /dev/null" -> (function (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit))) (REDIR > (STRING / dev / null))))
+"function help { echo hi; } 2> /dev/null" -> (function (STRING help) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING hi))) (REDIR 2 > (STRING / dev / null))))
"function help { echo 3; } 2> /dev/null > output" OK
"xorg-2_reconf_source() { :; }" -> (function (STRING xorg - 2 _reconf_source) (CURRENT_SHELL (LIST (COMMAND (STRING :)))))
diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit
index 76c46b2..dcb2754 100644
--- a/bashast/gunit/list.gunit
+++ b/bashast/gunit/list.gunit
@@ -41,3 +41,5 @@ echo \"a b\"" -> (LIST (VARIABLE_DEFINITIONS (= a (STRING asdf))) (VARIABLE_DEFI
"FOO='bar' ;" -> (LIST (VARIABLE_DEFINITIONS (= FOO (STRING (SINGLE_QUOTED_STRING bar)))))
"true;
true" -> (LIST (COMMAND (STRING true)) (COMMAND (STRING true)))
+"(echo hi > /dev/null) >> 1" -> (LIST (SUBSHELL (LIST (COMMAND (STRING echo) (STRING hi) (REDIR > (STRING / dev / null)))) (REDIR >> 1)))
+"{ echo hi > /dev/null; } >> 1" -> (LIST (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING hi) (REDIR > (STRING / dev / null)))) (REDIR >> 1)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-01 12:03 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-01 12:03 UTC (permalink / raw
To: gentoo-commits
commit: c3154deab71045fbcd6643c03d8de5b95f8e5379
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 30 09:54:47 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 06:12:20 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c3154dea
Parser: fix line break for compound expression
Semicolon and EOL are allowed to appear simultaneously as line break.
---
bashast/bashast.g | 2 +-
bashast/gunit/compound.gunit | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 104dd36..de8158a 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -387,7 +387,7 @@ cond_part: brace_expansion
| fname;
//Rules for whitespace/line endings
wspace : BLANK+|EOL+;
-semiel : BLANK* (SEMIC|EOL) BLANK*;
+semiel : BLANK* (SEMIC EOL?|EOL) BLANK*;
//definition of word. this is just going to grow...
word : (brace_expansion) => brace_expansion
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index a7ce999..6651be2 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -109,7 +109,8 @@ fi" -> (IF_STATEMENT (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COM
"if echo yay2; then echo yay ;fi" -> (IF_STATEMENT (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COMMAND (STRING echo) (STRING yay)))))
"if echo yay2 then echo yay; fi" FAIL
-"if echo yay2; then
+"if echo yay2;
+then
echo yay
elif echo yay3; then
echo boo
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-09 8:15 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-09 8:15 UTC (permalink / raw
To: gentoo-commits
commit: 9bf638ee90ebcfced60a9588228df11cc26813ad
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 4 10:14:13 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 08:38:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9bf638ee
Parser: support != in arithmetic expansion
---
bashast/bashast.g | 8 +++++++-
bashast/gunit/arith_main.gunit | 1 +
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f4e43ce..bea3740 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -521,7 +521,13 @@ times_division_modulus
: exponential ((TIMES^|SLASH^|PCT^) BLANK!* exponential)*;
addsub : times_division_modulus ((PLUS^|MINUS^) BLANK!* times_division_modulus)*;
shifts : addsub ((LSHIFT^|RSHIFT^) BLANK!* addsub)*;
-compare : shifts ((LEQ^|GEQ^|LESS_THAN^|GREATER_THAN^) BLANK!* shifts)?;
+compare : shifts (compare_operator^ BLANK!* shifts)?;
+compare_operator
+ : LEQ
+ | GEQ
+ | LESS_THAN
+ | GREATER_THAN
+ | BANG EQUALS -> NOT_EQUALS;
bitwiseand
: compare (AMP^ BLANK!* compare)*;
bitwisexor
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index b462450..2a440fc 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -80,6 +80,7 @@ shifts:
compare:
"17" ->"17"
"19<20" -> (< 19 20)
+"19!=20" -> (NOT_EQUALS 19 20)
bitwiseand:
"17" -> "17"
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-09 13:41 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-09 13:41 UTC (permalink / raw
To: gentoo-commits
commit: 6d0105614b316397162aa9167fcb2d88bb0782cf
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Thu Jun 9 12:42:09 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 12:42:09 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=6d010561
Parser: trailing white space in command lists
The redirect rule was stopping trailing white space from parsing
properly. With refactoring our grammar handles it properly.
---
bashast/bashast.g | 17 +++++++++--------
bashast/gunit/command_sub.gunit | 1 +
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9cd8ca1..4b132f5 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -131,9 +131,9 @@ command
| simple_command;
//Simple bash commands
simple_command
- : variable_definitions BLANK!+ bash_command^ redirect*
+ : variable_definitions BLANK!+ bash_command^ redirect?
| variable_definitions -> ^(VARIABLE_DEFINITIONS variable_definitions)
- | bash_command^ redirect*;
+ | bash_command^ redirect?;
variable_definitions
: var_def (BLANK!+ var_def)*
| LOCAL BLANK!+ local_item (BLANK!+ local_item)*
@@ -146,10 +146,11 @@ export_item
|name ->;
bash_command
: fname_no_res_word (BLANK+ fname)* -> ^(COMMAND fname_no_res_word fname*);
-redirect: BLANK!* here_string_op^ BLANK!* fname
- | BLANK!* here_doc_op^ BLANK!* fname EOL! heredoc
- | BLANK* redir_op BLANK* redir_dest -> ^(REDIR redir_op redir_dest)
- | BLANK!* process_substitution;
+redirect: (BLANK!* redirect_atom)*;
+redirect_atom: here_string_op^ BLANK!* fname
+ | here_doc_op^ BLANK!* fname EOL! heredoc
+ | redir_op BLANK* redir_dest -> ^(REDIR redir_op redir_dest)
+ | process_substitution;
redir_dest
: file_desc_as_file //handles file descriptors
| fname; //path to a file
@@ -229,10 +230,10 @@ case_pattern
| fname
| TIMES;
//A grouping of commands executed in a subshell
-subshell: LPAREN wspace? clist (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN redirect* -> ^(SUBSHELL clist redirect*);
+subshell: LPAREN wspace? clist (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN redirect? -> ^(SUBSHELL clist redirect?);
//A grouping of commands executed in the current shell
current_shell
- : LBRACE wspace clist semiel wspace* RBRACE redirect* -> ^(CURRENT_SHELL clist redirect*);
+ : LBRACE wspace clist semiel wspace* RBRACE redirect? -> ^(CURRENT_SHELL clist redirect?);
//comparison using arithmetic
arith_comparison
: LLPAREN wspace? arithmetic wspace? RRPAREN -> ^(COMPOUND_ARITH arithmetic);
diff --git a/bashast/gunit/command_sub.gunit b/bashast/gunit/command_sub.gunit
index 6cf07de..210ad63 100644
--- a/bashast/gunit/command_sub.gunit
+++ b/bashast/gunit/command_sub.gunit
@@ -21,5 +21,6 @@ gunit bashast;
command_sub:
"$(echo \"foo\")" -> (COMMAND_SUB (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING foo)))))
"$(ls |grep file)" -> (COMMAND_SUB (LIST (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING file)))))
+"$(CONTROL= command arg )" -> (COMMAND_SUB (LIST (COMMAND (STRING command) (STRING arg) (= CONTROL))))
"`cat output.log |grep error|cut`" -> (COMMAND_SUB (LIST (| (| (COMMAND (STRING cat) (STRING output . log)) (COMMAND (STRING grep) (STRING error))) (COMMAND (STRING cut)))))
"$(function foo() { echo 'hello'; }; foo)" -> (COMMAND_SUB (LIST (function (STRING foo) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING (SINGLE_QUOTED_STRING hello)))))) (COMMAND (STRING foo))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-09 13:41 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-09 13:41 UTC (permalink / raw
To: gentoo-commits
commit: 06f6705ed79411dfe9c08bbe0298b2b03c666ab5
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Thu Jun 9 12:06:57 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 12:06:57 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=06f6705e
Parser: fix ${var:-public_html}
-p is no longer a special token. This makes things simpler as you don't
need to prepare for it. When the time functionality is implemented in
walker it can check the letter given.
---
bashast/bashast.g | 7 ++-----
bashast/gunit/fname.gunit | 2 +-
bashast/gunit/param_main.gunit | 1 +
bashast/gunit/pipeline.gunit | 6 +++---
bashast/gunit/simp_command.gunit | 2 +-
5 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index bea3740..9cd8ca1 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -123,7 +123,7 @@ pipeline
: BLANK!* time? ((BANG) => (BANG BLANK!+))? command^ (BLANK!* PIPE^ BLANK!* command)*;
time : TIME^ BLANK!+ ((time_posix) => time_posix)?;
time_posix
- : TIME_POSIX BLANK!+;
+ : MINUS! LETTER BLANK!+;
//The structure of a command in bash
command
: compound_command
@@ -417,7 +417,7 @@ ns_str_part
| esc_char
|OTHER|EQUALS|PCT|PCTPCT|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
|TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
- |TIME_POSIX|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN
+ |LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN
|OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT|LOCAL;
//Generic strings/filenames.
@@ -689,9 +689,6 @@ ESC_LPAREN
: ESC LPAREN;
ESC_LT : ESC'<';
ESC_GT : ESC'>';
-//For pipeline
-TIME_POSIX
- : '-p';
//Handle ANSI C escaped characters: escaped octal, escaped hex, escaped ctrl+ chars, then all others
ESC : '\\';
UNDERSCORE : '_';
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index c12449b..799570d 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -66,7 +66,7 @@ fname:
"ab[[.backslash.]]" -> (STRING ab (MATCH_ANY (COLLATING_SYMBOL backslash)))
"ab[12[:alpha:]]" -> (STRING ab (MATCH_ANY 12 (CHARACTER_CLASS alpha)))
"\"'foo'\"" -> (STRING (DOUBLE_QUOTED_STRING ' foo '))
-"--preserve=timestamps,mode" -> (STRING - -p reserve = timestamps , mode)
+"--preserve=timestamps,mode" -> (STRING - - preserve = timestamps , mode)
dqstr:
"\"\\\"\"" -> (DOUBLE_QUOTED_STRING \ ")
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index fcd7d6d..67b26cf 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -22,6 +22,7 @@ var_ref:
"$asdf" -> (VAR_REF asdf)
"${asdf}" -> (VAR_REF asdf)
"${asdf:-foo}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo)))
+"${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 (SINGLE_QUOTED_STRING foo))))
"${asdf:=}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf STRING))
"${bar:7}" -> (VAR_REF (OFFSET bar 7))
diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index f2c0cb0..9b52c0a 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -22,10 +22,10 @@ pipeline:
"cat asdf" -> (COMMAND (STRING cat) (STRING asdf))
"export VAR=bar LAA=laa foo" -> (VARIABLE_DEFINITIONS (= VAR (STRING bar)) (= LAA (STRING laa)))
"LOCAL1=a LOCAL2=b export GLOBAL1=2 GLOBAL2 GLOBAL3" -> (COMMAND (STRING export) (STRING GLOBAL1 = 2) (STRING GLOBAL2) (STRING GLOBAL3) (= LOCAL1 (STRING a)) (= LOCAL2 (STRING b)))
-"time -p cat file" -> (COMMAND (STRING cat) (STRING file) (time -p))
+"time -p cat file" -> (COMMAND (STRING cat) (STRING file) (time p))
"time cat file | grep search" -> (| (COMMAND (STRING cat) (STRING file) time) (COMMAND (STRING grep) (STRING search)))
-"time -p cat | grep asdf | a.out" -> (| (| (COMMAND (STRING cat) (time -p)) (COMMAND (STRING grep) (STRING asdf))) (COMMAND (STRING a . out)))
-"time -p cat file |grep search >> log" -> (| (COMMAND (STRING cat) (STRING file) (time -p)) (COMMAND (STRING grep) (STRING search) (REDIR >> (STRING log))))
+"time -p cat | grep asdf | a.out" -> (| (| (COMMAND (STRING cat) (time p)) (COMMAND (STRING grep) (STRING asdf))) (COMMAND (STRING a . out)))
+"time -p cat file |grep search >> log" -> (| (COMMAND (STRING cat) (STRING file) (time p)) (COMMAND (STRING grep) (STRING search) (REDIR >> (STRING log))))
"if time cat; then
echo \"three\"
fi" -> (IF_STATEMENT (if (LIST (COMMAND (STRING cat) time)) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING three))))))
diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
index 235819c..6fb2946 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -24,7 +24,7 @@ simple_command:
"asdf=5 cat out.log > result" -> (COMMAND (STRING cat) (STRING out . log) (= asdf (STRING 5)) (REDIR > (STRING result)))
"cat results.log > asdf 2> /dev/null" -> (COMMAND (STRING cat) (STRING results . log) (REDIR > (STRING asdf)) (REDIR 2 > (STRING / dev / null)))
"i=3 g=4 h=18 grep asdf" -> (COMMAND (STRING grep) (STRING asdf) (= i (STRING 3)) (= g (STRING 4)) (= h (STRING 18)))
-"./configure --prefix=/usr/local" -> (COMMAND (STRING . / configure) (STRING - -p refix = / usr / local))
+"./configure --prefix=/usr/local" -> (COMMAND (STRING . / configure) (STRING - - prefix = / usr / local))
"[[while" -> (COMMAND (STRING [ [ while))
"./foobär" -> (COMMAND (STRING . / foob ä r))
"cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Documents / todo . txt))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-11 8:24 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-11 8:24 UTC (permalink / raw
To: gentoo-commits
commit: bb8cda9be17650ba4006fca9bae3274a4e55a809
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Thu Jun 9 14:14:33 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun 10 14:44:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=bb8cda9b
Parser: handle appending to arrays
The parser couldn't handle array+=(a b c) syntax.
---
bashast/bashast.g | 7 ++++---
bashast/gunit/array.gunit | 3 +++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index af5cfcf..a8d44d5 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -244,13 +244,14 @@ cond_comparison
var_def
: name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS fname? -> ^(EQUALS ^(name explicit_arithmetic) fname?)
| name EQUALS^ value?
+ | name PLUS_ASSIGN array_value -> ^(PLUS_ASSIGN name array_value)
| name PLUS_ASSIGN fname_part? -> ^(EQUALS name ^(STRING ^(VAR_REF name) fname_part?));
//Possible values of a variable
value : fname
- | LPAREN! wspace!* arr_val RPAREN!;
+ | array_value;
//allow the parser to create array variables
-arr_val :
- | (ag+=array_atom wspace*)+ -> ^(ARRAY $ag+);
+array_value
+ : LPAREN wspace* (array_atom wspace*)* RPAREN -> ^(ARRAY array_atom*);
array_atom
: (LSQUARE) => LSQUARE! BLANK!* explicit_arithmetic BLANK!? RSQUARE! EQUALS^ fname
| fname;
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index caa2615..eb11be8 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -26,6 +26,9 @@ var_def:
--disable-dependency-tracking
${VAR}
)" -> (= asdf (ARRAY (STRING - - disable - dependency - tracking) (STRING (VAR_REF VAR))))
+"asdf=()" -> (= asdf ARRAY)
+"asdf+=()" -> (+= asdf ARRAY)
+"asdf+=(a)" -> (+= asdf (ARRAY (STRING a)))
var_ref:
"$asdf" -> (VAR_REF asdf)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-11 8:24 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-11 8:24 UTC (permalink / raw
To: gentoo-commits
commit: aeb660f97b84a58a2afb9925f9321c55f406236a
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Thu Jun 9 21:02:57 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun 10 14:44:07 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=aeb660f9
Parser: builtin test doesn't do && or ||
&& and || are only available with [[.
---
bashast/bashast.g | 3 ++-
bashast/gunit/list.gunit | 1 +
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 269fcfd..2115620 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -360,7 +360,8 @@ builtin_cond_unary
keyword_cond
: (negate_primary|cond_primary) (BLANK!* (LOGICOR^|LOGICAND^) BLANK!* keyword_cond)?;
builtin_cond
- : (negate_builtin_primary|builtin_cond_primary) (BLANK!* (LOGICOR^|LOGICAND^) BLANK!* builtin_cond)?;
+ : negate_builtin_primary
+ | builtin_cond_primary;
negate_primary
: BANG BLANK+ cond_primary -> ^(NEGATION cond_primary);
negate_builtin_primary
diff --git a/bashast/gunit/list.gunit b/bashast/gunit/list.gunit
index 4beb325..edfc053 100644
--- a/bashast/gunit/list.gunit
+++ b/bashast/gunit/list.gunit
@@ -43,3 +43,4 @@ echo \"a b\"" -> (LIST (VARIABLE_DEFINITIONS (= a (STRING asdf))) (VARIABLE_DEFI
true" -> (LIST (COMMAND (STRING true)) (COMMAND (STRING true)))
"(echo hi > /dev/null) >> 1" -> (LIST (SUBSHELL (LIST (COMMAND (STRING echo) (STRING hi) (REDIR > (STRING / dev / null)))) (REDIR >> (FILE_DESCRIPTOR 1))))
"{ echo hi > /dev/null; } >> 1" -> (LIST (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING hi) (REDIR > (STRING / dev / null)))) (REDIR >> (FILE_DESCRIPTOR 1))))
+"test 1 -gt 0 || return 0" -> (LIST (|| (COMPOUND_COND (BUILTIN_TEST (gt (STRING 1) (STRING 0)))) (COMMAND (STRING return) (STRING 0))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-14 8:28 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-14 8:28 UTC (permalink / raw
To: gentoo-commits
commit: 330481c3c8d60d0e2456e5155b857738fc3ffa02
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Jun 11 12:15:19 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Jun 14 07:23:14 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=330481c3
Parser: fix brace expansion inside bracket pattern
We now support expressions like [{a,b}-c]*. As a side benefit code
complexity is reduced.
---
bashast/bashast.g | 19 ++++++++-----------
bashast/gunit/brace.gunit | 1 +
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2db45de..10e5556 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -455,21 +455,18 @@ pattern_match_trigger
| AT;
//Pattern matching using brackets
bracket_pattern_match
- : LSQUARE RSQUARE (BANG|CARET) pattern_match* RSQUARE -> ^(MATCH_ANY_EXCEPT RSQUARE pattern_match*)
- | LSQUARE RSQUARE pattern_match* RSQUARE -> ^(MATCH_ANY RSQUARE pattern_match*)
- | LSQUARE (BANG|CARET) pattern_match+ RSQUARE -> ^(MATCH_ANY_EXCEPT pattern_match+)
- | LSQUARE pattern_match+ RSQUARE -> ^(MATCH_ANY pattern_match+)
+ : LSQUARE RSQUARE (BANG|CARET) pattern_match RSQUARE -> ^(MATCH_ANY_EXCEPT RSQUARE pattern_match)
+ | LSQUARE RSQUARE pattern_match RSQUARE -> ^(MATCH_ANY RSQUARE pattern_match)
+ | LSQUARE (BANG|CARET) pattern_match RSQUARE -> ^(MATCH_ANY_EXCEPT pattern_match)
+ | LSQUARE pattern_match RSQUARE -> ^(MATCH_ANY pattern_match)
| TIMES -> MATCH_ALL
| QMARK -> MATCH_ONE;
-//allowable patterns with bracket pattern matching
pattern_match
+ : pattern_match_atom+;
+//allowable patterns with bracket pattern matching
+pattern_match_atom
: pattern_class_match
- | pattern_string_part+;
-pattern_string_part
- : var_ref
- | command_sub
- | arithmetic_expansion
- | ns_str_part;
+ | (~RSQUARE) => fname_part;
//special class patterns to match: [:alpha:] etc
pattern_class_match
diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit
index 1930560..4d5d6a5 100644
--- a/bashast/gunit/brace.gunit
+++ b/bashast/gunit/brace.gunit
@@ -31,3 +31,4 @@ fname:
"a{b,c}" -> (STRING a (BRACE_EXP (STRING b) (STRING c)))
"{c..d}f" -> (STRING (BRACE_EXP (.. c d)) f)
"a{a,b}b{c,d}" -> (STRING a (BRACE_EXP (STRING a) (STRING b)) b (BRACE_EXP (STRING c) (STRING d)))
+"[{a,b}-c]*" -> (STRING (MATCH_ANY (BRACE_EXP (STRING a) (STRING b)) - c) MATCH_ALL)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-14 8:28 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-14 8:28 UTC (permalink / raw
To: gentoo-commits
commit: 581066529adf685ca48bd7cdc2a2004a77141752
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Jun 11 13:08:39 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Jun 14 07:35:51 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=58106652
Parser: fix bracket pattern match negation
The negation operator is supposed to be right after the opening left
bracket. The right bracket will come after it when it's part of the
matched characters.
---
bashast/bashast.g | 16 ++++++----------
bashast/gunit/fname.gunit | 1 +
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 24b94f7..02a36ca 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -455,20 +455,16 @@ pattern_match_trigger
| AT;
//Pattern matching using brackets
bracket_pattern_match
- : LSQUARE! bracket_pattern_match_operator
+ : LSQUARE! bracket_pattern_match_operator^ pattern_match RSQUARE!
| TIMES -> MATCH_ALL
| QMARK -> MATCH_ONE;
bracket_pattern_match_operator
- : RSQUARE (BANG|CARET) pattern_match RSQUARE -> ^(MATCH_ANY_EXCEPT RSQUARE pattern_match)
- | RSQUARE pattern_match RSQUARE -> ^(MATCH_ANY RSQUARE pattern_match)
- | (BANG|CARET) pattern_match RSQUARE -> ^(MATCH_ANY_EXCEPT pattern_match)
- | pattern_match RSQUARE -> ^(MATCH_ANY pattern_match);
-pattern_match
- : pattern_match_atom+;
+ : (BANG) => BANG -> MATCH_ANY_EXCEPT
+ | (CARET) => CARET -> MATCH_ANY_EXCEPT
+ | -> MATCH_ANY;
//allowable patterns with bracket pattern matching
-pattern_match_atom
- : pattern_class_match
- | (~RSQUARE) => fname_part;
+pattern_match
+ : (pattern_class_match|fname_part) (pattern_class_match| (~RSQUARE) => fname_part)*;
//special class patterns to match: [:alpha:] etc
pattern_class_match
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 799570d..621b29d 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -56,6 +56,7 @@ fname:
"ab[!d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
"ab[^d-h]" -> (STRING ab (MATCH_ANY_EXCEPT d - h))
"ab[]c]" -> (STRING ab (MATCH_ANY ] c))
+"ab[]!]" -> (STRING ab (MATCH_ANY ] !))
"ab[:alpha:]" -> (STRING ab (MATCH_ANY : alpha :))
"ab[=c=]" -> (STRING ab (MATCH_ANY = c =))
"ab[.c.]" -> (STRING ab (MATCH_ANY . c .))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-15 21:18 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-15 21:18 UTC (permalink / raw
To: gentoo-commits
commit: 4440783734def67edd94c84b97660305f0647342
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 15 08:24:28 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 15 21:14:47 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=44407837
Parser: support escaped characters in double quotes
---
bashast/bashast.g | 4 +++-
bashast/gunit/fname.gunit | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index c9465b6..fd626b7 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -441,7 +441,9 @@ dqstr_part
: var_ref
| command_sub
| arithmetic_expansion
- | ESC DQUOTE
+ | ESC DQUOTE -> DQUOTE
+ | ESC TICK -> TICK
+ | ESC DOLLAR -> DOLLAR
| ~(DOLLAR|TICK|DQUOTE);
//single quoted string rule, no expansions
sqstr_part
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 621b29d..4627b46 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -70,4 +70,4 @@ fname:
"--preserve=timestamps,mode" -> (STRING - - preserve = timestamps , mode)
dqstr:
-"\"\\\"\"" -> (DOUBLE_QUOTED_STRING \ ")
+"\"\\\\\"\$\`\"" -> (DOUBLE_QUOTED_STRING \ " $ `)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-19 19:15 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-19 19:15 UTC (permalink / raw
To: gentoo-commits
commit: 02899a60a03eb3b24b26df3b8e801da59e614c33
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 14 07:49:27 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Jun 19 19:07:06 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=02899a60
Parser: support -a and -o in built-in test
Note that we don't respect the operator precedence for now. Fixing
that should have to involve semantic predicate.
---
bashast/bashast.g | 5 +++--
bashast/gunit/cond_main.gunit | 2 ++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index ca3abc9..571ed54 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -103,6 +103,7 @@ tokens{
MINUS_SIGN;
// Operators
NOT_EQUALS;
+ BUILTIN_LOGIC;
}
start : (flcomment)? EOL* clist BLANK* (SEMIC|AMP|EOL)? EOF -> clist;
@@ -364,8 +365,7 @@ builtin_cond_unary
keyword_cond
: (negate_primary|cond_primary) (BLANK!* (LOGICOR^|LOGICAND^) BLANK!* keyword_cond)?;
builtin_cond
- : negate_builtin_primary
- | builtin_cond_primary;
+ : (negate_builtin_primary|builtin_cond_primary) (BLANK!* builtin_logic_operator^ BLANK!* builtin_cond)?;
negate_primary
: BANG BLANK+ cond_primary -> ^(NEGATION cond_primary);
negate_builtin_primary
@@ -388,6 +388,7 @@ bop : MINUS! NAME^;
unary_cond
: uop^ BLANK! cond_part;
uop : MINUS! LETTER;
+builtin_logic_operator : uop -> ^(BUILTIN_LOGIC uop);
//Allowable parts of conditions
cond_part: brace_expansion
| fname;
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 2c1eee7..a17ae1e 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -31,3 +31,5 @@ cond_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))))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-21 13:20 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-21 13:20 UTC (permalink / raw
To: gentoo-commits
commit: 02be4fab385d753f3a98e77d89cc0c985072e2ad
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 08:24:41 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Jun 20 08:24:41 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=02be4fab
Parser: fix comment handling at the end of if block
---
bashast/bashast.g | 2 +-
bashast/gunit/compound.gunit | 7 +++++++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 571ed54..5bba0f9 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -209,7 +209,7 @@ for_expr: FOR BLANK+ name (wspace IN (BLANK+ fname)+)? semiel DO wspace* clist s
;
sel_expr: SELECT BLANK+ name (wspace IN BLANK+ fname)? semiel DO wspace* clist semiel DONE -> ^(SELECT name fname? clist)
;
-if_expr : IF wspace+ ag=clist semiel THEN wspace+ iflist=clist semiel EOL* (elif_expr)* (ELSE wspace+ else_list=clist semiel EOL*)? FI
+if_expr : IF wspace+ ag=clist semiel THEN wspace+ iflist=clist semiel wspace* (elif_expr)* (ELSE wspace+ else_list=clist semiel EOL*)? FI
-> ^(IF_STATEMENT ^(IF $ag $iflist) (elif_expr)* ^(ELSE $else_list)?)
;
elif_expr
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index 3ea38a6..c1e7a55 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -123,6 +123,13 @@ elif echo yay4; then echo hurrah
else echo darn
fi" -> (IF_STATEMENT (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COMMAND (STRING echo) (STRING yay)))) (if (LIST (COMMAND (STRING echo) (STRING yay3))) (LIST (COMMAND (STRING echo) (STRING boo)))) (if (LIST (COMMAND (STRING echo) (STRING yay4))) (LIST (COMMAND (STRING echo) (STRING hurrah)))) (else (LIST (COMMAND (STRING echo) (STRING darn)))))
+"if true; then
+ echo true
+ # comment
+ elif false; then
+ echo false
+ fi" -> (IF_STATEMENT (if (LIST (COMMAND (STRING true))) (LIST (COMMAND (STRING echo) (STRING true)))) (if (LIST (COMMAND (STRING false))) (LIST (COMMAND (STRING echo) (STRING false)))))
+
while_expr:
"while echo true; do
echo \"file found\"
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-21 13:20 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-21 13:20 UTC (permalink / raw
To: gentoo-commits
commit: 4eaae90c99ed22efe0b4f8e2e4b3d99a1613261e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 07:50:55 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Jun 21 13:08:08 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4eaae90c
Parser: support braces in command arguments
---
bashast/bashast.g | 6 +++++-
bashast/gunit/simp_command.gunit | 1 +
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 5bba0f9..b575027 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -149,7 +149,11 @@ export_item
:var_def
|name ->;
bash_command
- : fname_no_res_word (BLANK!+ fname)*;
+ : fname_no_res_word (BLANK!+ bash_command_arguments)*;
+bash_command_arguments
+ : bash_command_arguments_atom+ -> ^(STRING bash_command_arguments_atom+);
+bash_command_arguments_atom
+ : brace_expansion|LBRACE|RBRACE|fname_part;
redirect: (BLANK!* redirect_atom)*;
redirect_atom: here_string_op^ BLANK!* fname
| here_doc_op^ BLANK!* fname EOL! heredoc
diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
index 63c5372..76af49b 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -28,6 +28,7 @@ simple_command:
"cat ~/Documents/todo.txt" -> (STRING cat) (STRING ~ / Documents / todo . txt)
"dodir ${foo}/${bar}" -> (STRING dodir) (STRING (VAR_REF foo) / (VAR_REF bar))
"local a=123 b=(1 2 3) c" -> (VARIABLE_DEFINITIONS local (= a (STRING 123)) (= b (ARRAY (STRING 1) (STRING 2) (STRING 3))) (EQUALS c))
+"echo {}{}}{{{}}{{}" -> (STRING echo) (STRING { } { } } { { { } } { { })
command:
"asdf=5 cat out.log > result" -> (COMMAND (STRING cat) (STRING out . log) (= asdf (STRING 5)) (REDIR > (STRING result)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-06-21 13:26 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-06-21 13:26 UTC (permalink / raw
To: gentoo-commits
commit: 37a46717c4ee0585aef243437f6719b28c4d4fc5
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 14 14:17:59 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Jun 21 13:23:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=37a46717
Parser: simplify the AST of brace expansion
---
bashast/bashast.g | 3 +--
bashast/gunit/brace.gunit | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index b575027..d5ea5e3 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -30,7 +30,6 @@ tokens{
ARRAY;
ARRAY_SIZE;
BRACE_EXP;
- EMPTY_BRACE_EXPANSION_ATOM;
COMMAND_SUB;
CASE_PATTERN;
CASE_COMMAND;
@@ -189,7 +188,7 @@ range : DIGIT DOTDOT^ DIGIT
| LETTER DOTDOT^ LETTER;
brace_expansion_part
: (((~COMMA) => fname_part)+ -> ^(STRING fname_part+))+
- | -> EMPTY_BRACE_EXPANSION_ATOM;
+ | -> ^(STRING);
commasep: brace_expansion_part(COMMA! brace_expansion_part)+;
command_sub
: DOLLAR LPAREN clist BLANK? RPAREN -> ^(COMMAND_SUB clist)
diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit
index 4d5d6a5..bafb624 100644
--- a/bashast/gunit/brace.gunit
+++ b/bashast/gunit/brace.gunit
@@ -24,7 +24,7 @@ brace_expansion:
"{a,b,c}" -> (BRACE_EXP (STRING a) (STRING b) (STRING c))
"{a..d}" -> (BRACE_EXP (.. a d))
"{{a,b},c,d}" -> (BRACE_EXP (STRING (BRACE_EXP (STRING a) (STRING b))) (STRING c) (STRING d))
-"{.txt,,}" -> (BRACE_EXP (STRING . txt) EMPTY_BRACE_EXPANSION_ATOM EMPTY_BRACE_EXPANSION_ATOM)
+"{.txt,,}" -> (BRACE_EXP (STRING . txt) STRING STRING)
"{GNUmakefile,{M,m}akefile}" -> (BRACE_EXP (STRING GNUmakefile) (STRING (BRACE_EXP (STRING M) (STRING m)) akefile))
fname:
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-07-08 14:12 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-07-08 14:12 UTC (permalink / raw
To: gentoo-commits
commit: a8ab9f3adb10b3bed1c4ad22175d51faecad7979
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 6 11:38:06 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jul 8 14:08:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a8ab9f3a
Parser: support literal '$' in double quoted string
---
bashast/bashast.g | 2 +-
bashast/gunit/fname.gunit | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index b24ba88..9681cb1 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -546,7 +546,7 @@ dqstr_part
| ESC DQUOTE -> DQUOTE
| ESC TICK -> TICK
| ESC DOLLAR -> DOLLAR
- | ~(DOLLAR|TICK|DQUOTE);
+ | ~(TICK|DQUOTE);
//certain tokens that trigger pattern matching
pattern_match_trigger
: LSQUARE
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 5bacdb3..eb13235 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -69,6 +69,7 @@ fname:
"\"'foo'\"" -> (STRING (DOUBLE_QUOTED_STRING ' foo '))
"--preserve=timestamps,mode" -> (STRING - - preserve = timestamps , mode)
"$'asdf'" -> (STRING (ANSI_C_QUOTING 'asdf'))
+"\"abc#$/\"" -> (STRING (DOUBLE_QUOTED_STRING abc # $ /))
dqstr:
"\"\\\\\"\$\`\"" -> (DOUBLE_QUOTED_STRING \ " $ `)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-07-20 13:08 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-07-20 13:08 UTC (permalink / raw
To: gentoo-commits
commit: b697380ce491408052730c892c898fe669b1b8e7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 6 09:11:00 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jul 20 08:34:15 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b697380c
Parser: remove blank for the start of pipeline rule
Most rules that call pipeline will handle the leading blanks themselves.
---
bashast/bashast.g | 33 +++++++++++++++++----------------
bashast/gunit/expansions.gunit | 2 +-
2 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 1b4548e..32e79d5 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -164,11 +164,11 @@ tokens{
}
#endif
-start : (flcomment)? EOL* clist BLANK* (SEMIC|AMP|EOL)? EOF -> clist;
+start : (flcomment)? EOL* BLANK* command_list BLANK* (SEMIC|AMP|EOL)? EOF -> command_list;
//Because the comment token doesn't handle the first comment in a file if it's on the first line, have a parser rule for it
flcomment
: POUND ~(EOL)* EOL;
-clist
+command_list
: list_level_2 -> ^(LIST list_level_2);
list_level_1
: pipeline (BLANK!*(LOGICAND^|LOGICOR^)(BLANK!|EOL!)* pipeline)*;
@@ -180,7 +180,7 @@ command_separator
| AMP^
| EOL!;
pipeline
- : BLANK!* time? ((BANG) => (BANG BLANK!+))? command^ (BLANK!* PIPE^ BLANK!* command)*;
+ : time? ((BANG) => (BANG BLANK!+))? command^ (BLANK!* PIPE^ BLANK!* command)*;
time : TIME^ BLANK!+ ((time_posix) => time_posix)?;
time_posix
: MINUS! LETTER BLANK!+;
@@ -313,22 +313,23 @@ compound_command
| arithmetic_expression
| cond_comparison;
//Expressions allowed inside a compound command
-for_expr: FOR BLANK+ name (wspace IN (BLANK+ fname)+)? semiel DO wspace* clist semiel DONE -> ^(FOR name (fname+)? clist)
- | FOR BLANK* LLPAREN EOL? (BLANK* init=arithmetic BLANK*|BLANK+)? (SEMIC (BLANK? fcond=arithmetic BLANK*|BLANK+)? SEMIC|DOUBLE_SEMIC) (BLANK* mod=arithmetic)? wspace* RPAREN RPAREN semiel DO wspace clist semiel DONE
- -> ^(CFOR ^(FOR_INIT $init)? ^(FOR_COND $fcond)? clist ^(FOR_MOD $mod)?)
+for_expr: FOR BLANK+ name (wspace IN (BLANK+ fname)+)? semiel DO wspace* command_list semiel DONE
+ -> ^(FOR name (fname+)? command_list)
+ | FOR BLANK* LLPAREN EOL? (BLANK* init=arithmetic BLANK*|BLANK+)? (SEMIC (BLANK? fcond=arithmetic BLANK*|BLANK+)? SEMIC|DOUBLE_SEMIC) (BLANK* mod=arithmetic)? wspace* RPAREN RPAREN semiel DO wspace* command_list semiel DONE
+ -> ^(CFOR ^(FOR_INIT $init)? ^(FOR_COND $fcond)? command_list ^(FOR_MOD $mod)?)
;
-sel_expr: SELECT BLANK+ name (wspace IN BLANK+ fname)? semiel DO wspace* clist semiel DONE -> ^(SELECT name fname? clist)
+sel_expr: SELECT BLANK+ name (wspace IN BLANK+ fname)? semiel DO wspace* command_list semiel DONE -> ^(SELECT name fname? command_list)
;
-if_expr : IF wspace+ ag=clist semiel THEN wspace+ iflist=clist semiel wspace* (elif_expr)* (ELSE wspace+ else_list=clist semiel EOL*)? FI
+if_expr : IF wspace+ ag=command_list semiel THEN wspace+ iflist=command_list semiel wspace* (elif_expr)* (ELSE wspace+ else_list=command_list semiel EOL*)? FI
-> ^(IF_STATEMENT ^(IF $ag $iflist) (elif_expr)* ^(ELSE $else_list)?)
;
elif_expr
- : ELIF BLANK+ ag=clist semiel THEN wspace+ iflist=clist semiel -> ^(IF["if"] $ag $iflist);
+ : ELIF BLANK+ ag=command_list semiel THEN wspace+ iflist=command_list semiel -> ^(IF["if"] $ag $iflist);
while_expr
- : WHILE wspace? istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(WHILE $istrue $dothis)
+ : WHILE wspace* istrue=command_list semiel DO wspace* dothis=command_list semiel DONE -> ^(WHILE $istrue $dothis)
;
until_expr
- : UNTIL wspace? istrue=clist semiel DO wspace dothis=clist semiel DONE -> ^(UNTIL $istrue $dothis)
+ : UNTIL wspace* istrue=command_list semiel DO wspace* dothis=command_list semiel DONE -> ^(UNTIL $istrue $dothis)
;
// double semicolon is optional for the last alternative
case_expr
@@ -336,13 +337,13 @@ case_expr
case_body
: case_stmt (wspace* DOUBLE_SEMIC case_stmt)* wspace* DOUBLE_SEMIC? wspace* -> case_stmt*;
case_stmt
- : wspace* (LPAREN BLANK*)? fname (BLANK* PIPE BLANK? fname)* BLANK* RPAREN (wspace* clist)?
- -> ^(CASE_PATTERN fname+ (CASE_COMMAND clist)?);
+ : wspace* (LPAREN BLANK*)? fname (BLANK* PIPE BLANK? fname)* BLANK* RPAREN (wspace* command_list)?
+ -> ^(CASE_PATTERN fname+ (CASE_COMMAND command_list)?);
//A grouping of commands executed in a subshell
-subshell: LPAREN wspace? clist (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN -> ^(SUBSHELL clist );
+subshell: LPAREN wspace* command_list (BLANK* SEMIC)? (BLANK* EOL)* BLANK* RPAREN -> ^(SUBSHELL command_list);
//A grouping of commands executed in the current shell
current_shell
- : LBRACE wspace clist semiel wspace* RBRACE -> ^(CURRENT_SHELL clist);
+ : LBRACE wspace* command_list semiel wspace* RBRACE -> ^(CURRENT_SHELL command_list);
//Bash arithmetic expression (( expression ))
arithmetic_expression
: LLPAREN wspace? arithmetic wspace? RPAREN RPAREN -> ^(ARITHMETIC_EXPRESSION arithmetic);
@@ -658,7 +659,7 @@ arithmetic_expansion
| DOLLAR LSQUARE BLANK* arithmetics BLANK* RSQUARE -> ^(ARITHMETIC_EXPRESSION arithmetics);
process_substitution
- : (dir=LESS_THAN|dir=GREATER_THAN)LPAREN clist BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir clist);
+ : (dir=LESS_THAN|dir=GREATER_THAN)LPAREN BLANK* command_list BLANK* RPAREN -> ^(PROCESS_SUBSTITUTION $dir command_list);
esc_char: ESC (DIGIT DIGIT? DIGIT?|LETTER ALPHANUM ALPHANUM?|.);
//****************
diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit
index b10931d..2414e0a 100644
--- a/bashast/gunit/expansions.gunit
+++ b/bashast/gunit/expansions.gunit
@@ -18,7 +18,7 @@
*/
gunit java_libbash;
-clist:
+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)))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 4fe9d8a7e2655c54dccc651664eda0f22b761707
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 20 12:11:15 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jul 20 15:08:32 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4fe9d8a7
Parser: add rules to perform bash expansions
The rule will be called in the walker grammar to perform bash expansions
on raw strings.
---
bashast/bashast.g | 7 +++++++
bashast/gunit/expansions.gunit | 3 +++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f712f2e..c54adae 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -619,6 +619,13 @@ double_quoted_string_part
| (ESC DOLLAR) => ESC DOLLAR -> DOLLAR
| ~(TICK|DQUOTE);
+// Perform all kinds of expansions
+all_expansions
+ : expansion_atom+ -> ^(STRING expansion_atom+);
+expansion_atom
+ : (DQUOTE) => double_quoted_string
+ | double_quoted_string_part;
+
string_part
: ns_string_part
| SLASH;
diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit
index 24c3702..4608994 100644
--- a/bashast/gunit/expansions.gunit
+++ b/bashast/gunit/expansions.gunit
@@ -30,3 +30,6 @@ echo $each
done" -> (LIST (COMMAND (for each (STRING (COMMAND_SUB `ls |grep output`)) (LIST (COMMAND (STRING echo) (STRING (VAR_REF each)))))))
"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')
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: ee63385cbb090865646a14fd2c0dd9fd828ad525
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 20 12:26:22 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jul 20 15:15:45 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ee63385c
Parser: fix delete expansion
---
bashast/bashast.g | 6 ++++--
bashast/gunit/param_main.gunit | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index c54adae..9537a0e 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -711,8 +711,8 @@ parameter_expansion
-> ^(parameter_value_operator variable_name parameter_expansion_value)
| COLON BLANK? os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)?
-> ^(OFFSET variable_name $os ^($len)?)
- | parameter_delete_operator parameter_replace_pattern
- -> ^(parameter_delete_operator variable_name parameter_replace_pattern)
+ | parameter_delete_operator parameter_delete_pattern
+ -> ^(parameter_delete_operator variable_name parameter_delete_pattern)
| parameter_replace_operator parameter_replace_pattern (SLASH parameter_expansion_value)?
-> ^(parameter_replace_operator variable_name parameter_replace_pattern parameter_expansion_value?)
| BLANK? -> variable_name
@@ -741,6 +741,8 @@ parameter_value_operator
| PLUS -> USE_ALTERNATE_WHEN_UNSET;
parameter_replace_pattern
: ((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
+parameter_delete_pattern
+ : parameter_pattern_part+ -> ^(STRING parameter_pattern_part+);
parameter_pattern_part
: extended_pattern_match|BLANK|SEMIC;
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index f2b8cbb..677b566 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -42,7 +42,7 @@ variable_reference:
"${foo%bar}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING bar)))
"${foo%%bar}" -> (VAR_REF (REPLACE_AT_END foo (STRING bar)))
"${foo%; *}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING ; MATCH_ALL)))
-//"${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /)))
+"${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /)))
"${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING pattern)))
//Test positional/special parameters
"$1" -> (VAR_REF 1)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: c5a116f1794e061ea10335b12c6889676d92136b
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 09:08:33 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c5a116f1
Parser: allow empty value for sub-array expansion
Expansion like ${var::3} is allowed now.
---
bashast/bashast.g | 9 +++++++--
bashast/gunit/param_main.gunit | 1 +
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 14d7d10..7bb8a8b 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -724,8 +724,13 @@ parameter_expansion
(
(parameter_value_operator) => parameter_value_operator parameter_expansion_value
-> ^(parameter_value_operator variable_name parameter_expansion_value)
- | COLON BLANK? os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)?
- -> ^(OFFSET variable_name $os ^($len)?)
+ | COLON BLANK?
+ (
+ os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)?
+ -> ^(OFFSET variable_name $os ^($len)?)
+ | COLON BLANK? len=explicit_arithmetic
+ -> ^(OFFSET variable_name NUMBER["0"] ^($len)?)
+ )
| parameter_delete_operator parameter_delete_pattern
-> ^(parameter_delete_operator variable_name parameter_delete_pattern)
| parameter_replace_operator parameter_replace_pattern (SLASH parameter_expansion_value)?
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 677b566..306d3c6 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -29,6 +29,7 @@ variable_reference:
"${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))
"${!asdf*}" -> (VAR_REF (! asdf *))
"${!asdf@}" -> (VAR_REF (! asdf @))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 2dc5af830837a30b83a74c8ed4e918a3d7c5f3c3
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 09:20:13 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2dc5af83
Parser: support == in arithmetic comparison
---
bashast/bashast.g | 14 +++++++++++++-
bashast/gunit/arith_main.gunit | 1 +
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 7bb8a8b..fee25b6 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -113,6 +113,7 @@ tokens{
MINUS_SIGN;
NOT_EQUALS;
+ EQUALS_TO;
BUILTIN_LOGIC;
}
@@ -864,7 +865,17 @@ arithmetic
);
arithmetic_assignment_operator
- : EQUALS|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|OR_ASSIGN;
+ : {LA(1) == EQUALS && LA(2) != EQUALS}? => EQUALS
+ | MUL_ASSIGN
+ | DIVIDE_ASSIGN
+ | MOD_ASSIGN
+ | PLUS_ASSIGN
+ | MINUS_ASSIGN
+ | LSHIFT_ASSIGN
+ | RSHIFT_ASSIGN
+ | AND_ASSIGN
+ | XOR_ASSIGN
+ | OR_ASSIGN;
arithmetic_variable_reference
: variable_reference -> ^(VAR_REF variable_reference);
@@ -910,6 +921,7 @@ compare_operator
| GEQ
| LESS_THAN
| GREATER_THAN
+ | EQUALS EQUALS -> EQUALS_TO
| BANG EQUALS -> NOT_EQUALS;
bitwiseand
: compare (AMP^ BLANK!? compare)*;
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 1f1a089..5249b5a 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -80,6 +80,7 @@ arithmetics_test:
"17" ->"17"
"19<20" -> (< 19 20)
"19!=20" -> (NOT_EQUALS 19 20)
+"19==20" -> (EQUALS_TO 19 20)
//bitwiseand:
"17" -> "17"
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 45c86202bd9b8f6df72b58cd977c6ba87c80eeb7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 10:13:22 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=45c86202
Parser: allow blanks before semicolon for for_expr
---
bashast/bashast.g | 2 +-
bashast/gunit/compound.gunit | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index b380379..6204ed0 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -446,7 +446,7 @@ for_expr
(
name wspace
(
- IN for_each_value* (SEMIC|EOL) wspace?
+ IN for_each_value* BLANK? (SEMIC|EOL) wspace?
|SEMIC wspace?
|
) DO wspace command_list semiel DONE -> ^(FOR name for_each_value* command_list)
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index 18314bf..7270246 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -94,6 +94,7 @@ done" -> (for each (STRING (COMMAND_SUB `ls |grep log`)) (LIST (COMMAND (STRING
"for each in `ls |grep log`;do echo \"file found\"; done" -> (for each (STRING (COMMAND_SUB `ls |grep log`)) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file found)))))
"for i in 'foo' 'bar'; do echo $i; done" -> (for i (STRING (SINGLE_QUOTED_STRING 'foo')) (STRING (SINGLE_QUOTED_STRING 'bar')) (LIST (COMMAND (STRING echo) (STRING (VAR_REF i)))))
"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 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)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 48ca9661e8e8f6bab6e37cf912bf1b16e5d742e0
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 13:15:31 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=48ca9661
Parser: make the blanks before semicolon optional
This fixes case statement. The indentation for the rule is also fixed.
Unnecessary syntactic predicate is removed.
---
bashast/bashast.g | 6 +++---
bashast/gunit/compound.gunit | 3 +--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 6204ed0..b4804fa 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -498,10 +498,10 @@ scope {
);
case_statement
: wspace? (LPAREN BLANK?)? extended_pattern (BLANK? PIPE BLANK? extended_pattern)* BLANK? RPAREN
- wspace
+ (wspace command_list)?
(
- command_list wspace)? ( (DOUBLE_SEMIC ((wspace ESAC) => wspace ESAC {$case_body::case_end = true;})?)
- |(ESAC) => ESAC {$case_body::case_end = true;}
+ wspace? DOUBLE_SEMIC ((wspace ESAC) => wspace ESAC {$case_body::case_end = true;})?
+ |wspace ESAC {$case_body::case_end = true;}
)
-> ^(CASE_PATTERN extended_pattern+ (CASE_COMMAND command_list)?);
diff --git a/bashast/gunit/compound.gunit b/bashast/gunit/compound.gunit
index 7270246..c5d6845 100644
--- a/bashast/gunit/compound.gunit
+++ b/bashast/gunit/compound.gunit
@@ -166,8 +166,7 @@ esac" -> (case (STRING (DOUBLE_QUOTED_STRING (VAR_REF 1))) (CASE_PATTERN (BRANC
"case $asdf in
a)
-echo \"yay\"
-;;
+echo \"yay\";;
esac" -> (case (STRING (VAR_REF asdf)) (CASE_PATTERN (BRANCH a) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING yay))))))
"case asdf in
asdf)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 7c27bffcc90d0c6a5dccd1dbb4bf0db9c4ee6104
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 13:57:02 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=7c27bffc
Parser: remove tokens for += and -=
This makes ${a:-=} and ${a:+=} work properly.
---
bashast/bashast.g | 18 +++++++++---------
bashast/gunit/arith_main.gunit | 4 ++--
bashast/gunit/array.gunit | 4 ++--
bashast/gunit/param_main.gunit | 3 +++
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index b4804fa..0a9557e 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -111,6 +111,8 @@ tokens{
PLUS_SIGN;
MINUS_SIGN;
+ PLUS_ASSIGN;
+ MINUS_ASSIGN;
NOT_EQUALS;
EQUALS_TO;
@@ -311,7 +313,7 @@ command_atom
: (FOR|SELECT|IF|WHILE|UNTIL|CASE|LPAREN|LBRACE|LLPAREN|LSQUARE|TEST_EXPR) => compound_command
| 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_ASSIGN)|LOCAL|EXPORT) => variable_definitions
+ | (name (LSQUARE|EQUALS|PLUS EQUALS)|LOCAL|EXPORT) => variable_definitions
(
(BLANK bash_command) => BLANK bash_command -> bash_command variable_definitions
| -> ^(VARIABLE_DEFINITIONS variable_definitions)
@@ -351,7 +353,7 @@ command_atom
variable_definitions
: (
- variable_definition_atom ((BLANK name (LSQUARE|EQUALS|PLUS_ASSIGN)) => BLANK! variable_definition_atom)*
+ variable_definition_atom ((BLANK name (LSQUARE|EQUALS|PLUS EQUALS)) => BLANK! variable_definition_atom)*
| (LOCAL) => LOCAL BLANK! local_item ((BLANK name) => BLANK! local_item)*
| (EXPORT) => EXPORT! ((BLANK name) => BLANK! export_item)+
);
@@ -360,8 +362,8 @@ variable_definition_atom
: name LSQUARE BLANK? explicit_arithmetic BLANK? RSQUARE EQUALS string_expr?
-> ^(EQUALS ^(name explicit_arithmetic) string_expr?)
| name EQUALS value? -> ^(EQUALS name value?)
- | name PLUS_ASSIGN array_value -> ^(PLUS_ASSIGN name array_value)
- | name PLUS_ASSIGN string_expr_part?
+ | name PLUS EQUALS array_value -> ^(PLUS_ASSIGN name array_value)
+ | name PLUS EQUALS string_expr_part?
-> ^(EQUALS name ^(STRING ^(VAR_REF name) string_expr_part?));
value
: string_expr
@@ -658,7 +660,7 @@ string_part
ns_string_part
: num|name|escaped_character
|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
- |TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
+ |TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN
|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|LSQUARE|RSQUARE
|OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT|LOCAL|AT;
@@ -878,8 +880,8 @@ arithmetic_assignment_operator
| MUL_ASSIGN
| DIVIDE_ASSIGN
| MOD_ASSIGN
- | PLUS_ASSIGN
- | MINUS_ASSIGN
+ | PLUS EQUALS -> PLUS_ASSIGN
+ | MINUS EQUALS -> MINUS_ASSIGN
| LSHIFT_ASSIGN
| RSHIFT_ASSIGN
| AND_ASSIGN
@@ -993,8 +995,6 @@ RSHIFT : '>>';
MUL_ASSIGN : '*=';
DIVIDE_ASSIGN : '/=';
MOD_ASSIGN : '%=';
-PLUS_ASSIGN : '+=';
-MINUS_ASSIGN : '-=';
LSHIFT_ASSIGN : '<<=';
RSHIFT_ASSIGN : '>>=';
AND_ASSIGN : '&=';
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 5249b5a..c32ff21 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -111,8 +111,8 @@ arithmetics_test:
"var *= 5" -> (*= var 5)
"var /= 5" -> (/= var 5)
"var %= 5" -> (%= var 5)
-"asdf += 5" -> (+= asdf 5)
-"var -= 5" -> (-= var 5)
+"asdf += 5" -> (PLUS_ASSIGN asdf 5)
+"var -= 5" -> (MINUS_ASSIGN var 5)
"var <<= 5" -> (<<= var 5)
"var >>= 5" -> (>>= var 5)
"var &= 5" -> (&= var 5)
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index b3bdf3b..c304e7c 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -28,8 +28,8 @@ variable_definition_atom:
${VAR}
)" -> (= asdf (ARRAY (STRING - - disable - dependency - tracking) (STRING (VAR_REF VAR))))
"asdf=()" -> (= asdf ARRAY)
-"asdf+=()" -> (+= asdf ARRAY)
-"asdf+=(a)" -> (+= asdf (ARRAY (STRING a)))
+"asdf+=()" -> (PLUS_ASSIGN asdf ARRAY)
+"asdf+=(a)" -> (PLUS_ASSIGN asdf (ARRAY (STRING a)))
variable_reference:
"$asdf" -> (VAR_REF asdf)
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 306d3c6..0a56a57 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -22,6 +22,9 @@ variable_reference:
"$asdf" -> (VAR_REF asdf)
"${asdf}" -> (VAR_REF asdf)
"${asdf:-foo}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo)))
+"${asdf:-=}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING =)))
+"${asdf:+=}" -> (VAR_REF (USE_ALTERNATE_WHEN_UNSET_OR_NULL asdf (STRING =)))
+"${asdf:==}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING =)))
"${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)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 4241b112b64937a27b4ff04917fe6f497e98c123
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 07:48:16 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4241b112
Parser: fix the rule for expansion pattern
---
bashast/bashast.g | 60 +++++++++++++++++++++++----------------
bashast/gunit/param_main.gunit | 3 ++
2 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 610b495..fae2137 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -141,8 +141,10 @@ tokens{
C_INCLUDE #include "core/exceptions.h"
}
+#endif
@members
{
+#ifdef OUTPUT_C
static std::string get_string(pANTLR3_COMMON_TOKEN token)
{
if(!token || !token->start)
@@ -166,10 +168,7 @@ tokens{
{
(&(scope->here_document_word))->std::string::~string();
}
-}
#else
-@members
-{
boolean is_here_end(String here_document_word, int number_of_tokens) {
String word = "";
for(int i = 1; i <= number_of_tokens; ++i)
@@ -188,8 +187,37 @@ tokens{
int LA(int index) {
return input.LA(index);
}
-}
#endif
+#ifdef OUTPUT_C
+ bool is_special_token(int token)
+#else
+ boolean is_special_token(int token)
+#endif
+ {
+ return token == AMP
+ ||token == BLANK
+ // for bash redirection
+ ||token == LESS_THAN
+ ||token == GREATER_THAN
+ ||token == RSHIFT
+ // for end of command
+ ||token == SEMIC
+ ||token == EOL
+ // for sub shell
+ ||token == LPAREN
+ ||token == RPAREN
+ // for case statement
+ ||token == DOUBLE_SEMIC
+ // for logical operator
+ ||token == LOGICAND
+ ||token == LOGICOR
+ // for pipeline
+ ||token == PIPE
+ // for document and here string
+ ||token == HERE_STRING_OP
+ ||token == LSHIFT;
+ }
+}
start
: ((POUND) =>first_line_comment)? EOL* BLANK? command_list BLANK? (SEMIC|AMP|EOL)? EOF -> command_list;
@@ -326,28 +354,10 @@ command_atom
| (
{LA(1) == BLANK &&
(
- LA(2) != AMP
- // Resolve conflicts with bash redirection
- &&LA(2) != LESS_THAN
- &&LA(2) != GREATER_THAN
- &&LA(2) != RSHIFT
+ !is_special_token(LA(2))
+ // redirection
&&(LA(2) != DIGIT || (LA(3) != AMP && LA(3) != LESS_THAN
&& LA(3) != GREATER_THAN && LA(3) != RSHIFT))
- // Resolve conflicts with end of command
- &&LA(2) != SEMIC
- &&LA(2) != EOL
- // Resolve conflict with sub shell
- &&LA(2) != RPAREN
- // Resolve conflict with case statement
- &&LA(2) != DOUBLE_SEMIC
- // Resolve conflicts with logical operator
- &&LA(2) != LOGICAND
- &&LA(2) != LOGICOR
- // Resolve conflict with pipeline
- &&LA(2) != PIPE
- // Resolve conflicts with here document and here string
- &&LA(2) != HERE_STRING_OP
- &&LA(2) != LSHIFT
)}? => BLANK bash_command_arguments
)* -> string_expr_no_reserved_word bash_command_arguments*
);
@@ -784,7 +794,7 @@ parameter_replace_pattern
parameter_delete_pattern
: parameter_pattern_part+ -> ^(STRING parameter_pattern_part+);
parameter_pattern_part
- : extended_pattern_match|BLANK|SEMIC;
+ : extended_pattern_match|{is_special_token(LA(1))}? => .;
// TODO fix this rule
parameter_expansion_value
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 0a56a57..c83ccc2 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -47,6 +47,9 @@ variable_reference:
"${foo%%bar}" -> (VAR_REF (REPLACE_AT_END foo (STRING bar)))
"${foo%; *}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING ; MATCH_ALL)))
"${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /)))
+"${1%& <><<;
+();&&|<<<<<()*}" -> (VAR_REF (LAZY_REMOVE_AT_END 1 (STRING & < > << ;
+ ( ) ; && | <<< << ( ) MATCH_ALL)))
"${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING pattern)))
//Test positional/special parameters
"$1" -> (VAR_REF 1)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 81df82652238ccaff47b48f0c914a57fefb3b45c
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 03:50:01 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=81df8265
Parser: fix brace handling in regex
---
bashast/bashast.g | 3 +--
bashast/gunit/cond_main.gunit | 1 +
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 3b9b5bd..610b495 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -563,10 +563,9 @@ scope {
}
:(
(ESC BLANK) => ESC BLANK
- | (ESC RSQUARE) => ESC RSQUARE
| LPAREN { if(LA(-2) != ESC) $bash_pattern_part::parens++; }
| {$bash_pattern_part::parens != 0}? => RPAREN { if(LA(-2) != ESC) $bash_pattern_part::parens--; }
- | ~(BLANK|RSQUARE|EOL|LOGICAND|LOGICOR|LPAREN|RPAREN)
+ | ~(BLANK|EOL|LOGICAND|LOGICOR|LPAREN|RPAREN)
)+;
keyword_binary_string_operator
: binary_operator
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 4068c51..e4810a9 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -33,3 +33,4 @@ condition_expr:
"[[ \"${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 : ] ] + \ . ))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 97ed8ee45a88e47196024528b3da0c75077f05ba
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 14:16:18 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=97ed8ee4
Parser: allow filename expansion characters
---
bashast/bashast.g | 4 +++-
bashast/gunit/fname.gunit | 1 +
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 0a9557e..2709fc5 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -662,7 +662,9 @@ ns_string_part
|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
|TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN
|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|LSQUARE|RSQUARE
- |OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT|LOCAL|AT;
+ |OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT|LOCAL|AT
+ // The following is for filename expansion
+ |TIMES|QMARK;
escaped_character
: ESC
diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index f07b3db..3d60bc2 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -20,6 +20,7 @@ gunit java_libbash;
string_expr:
"+%Y%m%d" -> (STRING + % Y % m % d)
+"/tmp/a?b*" -> (STRING / tmp / a ? b *)
"\"http://www.gnu.org/software/autoconf/autoconf.html\"" -> (STRING (DOUBLE_QUOTED_STRING http : / / www . gnu . org / software / autoconf / autoconf . html))
"\"http://dev.gentoo.org/~mpagano/genpatches\"" -> (STRING (DOUBLE_QUOTED_STRING http : / / dev . gentoo . org / ~ mpagano / genpatches))
"\"\"" -> (STRING DOUBLE_QUOTED_STRING)
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 5287ca8176926e7335feb4472fea6da28fb7fe76
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 12:55:40 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:52:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=5287ca81
Parser: allow white spaces around array index
---
bashast/bashast.g | 2 +-
bashast/gunit/array.gunit | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9c34478..a6b2e59 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -842,7 +842,7 @@ variable_name
| POUND;
variable_name_no_digit
- : name LSQUARE explicit_arithmetic RSQUARE -> ^(name explicit_arithmetic)
+ : name LSQUARE BLANK? explicit_arithmetic BLANK? RSQUARE -> ^(name explicit_arithmetic)
| name;
variable_name_for_bang
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index 734343f..fe49511 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -46,6 +46,7 @@ variable_reference:
"${asdf[4]//pattern}" -> (VAR_REF (REPLACE_ALL (asdf 4) (STRING pattern)))
"${asdf}" -> (VAR_REF asdf)
"${#asdf[0]}" -> (VAR_REF (# (asdf 0)))
+"${#asdf[ $i ]}" -> (VAR_REF (# (asdf (VAR_REF i))))
"${asdf[@]}" -> (VAR_REF (ARRAY asdf @))
"${asdf[*]}" -> (VAR_REF (ARRAY asdf *))
"${#asdf[@]}" -> (VAR_REF (# (asdf ARRAY_SIZE)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 49d89ad38496785260af3e27a7d984550b8348c5
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 08:33:30 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:46:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=49d89ad3
Parser: remove tokens for assignment
These tokens would prevent the parser doing parameter expansions. Now
this is fixed.
---
bashast/bashast.g | 36 +++++++++++++++++-------------------
bashast/gunit/arith_main.gunit | 20 ++++++++++----------
bashast/gunit/param_main.gunit | 2 ++
3 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index c4ab527..7351a56 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -113,6 +113,14 @@ tokens{
MINUS_SIGN;
PLUS_ASSIGN;
MINUS_ASSIGN;
+ DIVIDE_ASSIGN;
+ MUL_ASSIGN;
+ MOD_ASSIGN;
+ LSHIFT_ASSIGN;
+ RSHIFT_ASSIGN;
+ AND_ASSIGN;
+ XOR_ASSIGN;
+ OR_ASSIGN;
NOT_EQUALS;
EQUALS_TO;
@@ -676,9 +684,7 @@ string_part
ns_string_part
: num|name|escaped_character
|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
- |TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN
- |LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|LSQUARE|RSQUARE
- |OR_ASSIGN|CARET|POUND|COMMA|EXPORT|LOCAL|AT
+ |TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT
// The following is for filename expansion
|TIMES|QMARK;
@@ -895,16 +901,16 @@ arithmetic
arithmetic_assignment_operator
: {LA(1) == EQUALS && LA(2) != EQUALS}? => EQUALS
- | MUL_ASSIGN
- | DIVIDE_ASSIGN
- | MOD_ASSIGN
+ | TIMES EQUALS -> MUL_ASSIGN
+ | SLASH EQUALS -> DIVIDE_ASSIGN
+ | PCT EQUALS -> MOD_ASSIGN
| PLUS EQUALS -> PLUS_ASSIGN
| MINUS EQUALS -> MINUS_ASSIGN
- | LSHIFT_ASSIGN
- | RSHIFT_ASSIGN
- | AND_ASSIGN
- | XOR_ASSIGN
- | OR_ASSIGN;
+ | LSHIFT EQUALS -> LSHIFT_ASSIGN
+ | RSHIFT EQUALS -> RSHIFT_ASSIGN
+ | AMP EQUALS -> AND_ASSIGN
+ | CARET EQUALS -> XOR_ASSIGN
+ | PIPE EQUALS -> OR_ASSIGN;
arithmetic_variable_reference
: variable_reference -> ^(VAR_REF variable_reference);
@@ -1010,14 +1016,6 @@ LESS_THAN : '<';
GREATER_THAN : '>';
LSHIFT : '<<';
RSHIFT : '>>';
-MUL_ASSIGN : '*=';
-DIVIDE_ASSIGN : '/=';
-MOD_ASSIGN : '%=';
-LSHIFT_ASSIGN : '<<=';
-RSHIFT_ASSIGN : '>>=';
-AND_ASSIGN : '&=';
-XOR_ASSIGN : '^=';
-OR_ASSIGN : '|=';
SEMIC : ';';
DOUBLE_SEMIC : ';;';
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index c32ff21..7620fd7 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -106,18 +106,18 @@ arithmetics_test:
"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" -> (*= (VAR_REF (VAR_REF (foo 5))) 3)
-"${foo[5]}^=3" -> (^= (VAR_REF (VAR_REF (foo 5))) 3)
-"var *= 5" -> (*= var 5)
-"var /= 5" -> (/= var 5)
-"var %= 5" -> (%= var 5)
+"${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" -> (<<= var 5)
-"var >>= 5" -> (>>= var 5)
-"var &= 5" -> (&= var 5)
-"var ^= 5" -> (^= var 5)
-"var |= 5" -> (|= 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)
"3=7" FAIL
"13"->"13"
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 27fc273..e73caf3 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -83,6 +83,8 @@ variable_reference:
"${#*}" -> (VAR_REF (# *))
"${##}" -> (VAR_REF (# #))
"${#$}" -> (VAR_REF (# $))
+"${a/=}" -> (VAR_REF (REPLACE_FIRST a (STRING =)))
+"${a%=}" -> (VAR_REF (LAZY_REMOVE_AT_END a (STRING =)))
variable_definition_atom:
"MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: f3e50b21917905fa908000a9bcb8f2fdff451f63
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 13:16:45 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:52:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f3e50b21
Parser: improve here document and here string
Here document and here string can be combined with bash redirection. Now
this is supported.
---
bashast/bashast.g | 6 +++---
bashast/gunit/redir.gunit | 5 +++++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index a6b2e59..39e6d54 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -255,7 +255,8 @@ redirection
: redirection_atom+;
redirection_atom
: redirection_operator BLANK? redirection_destination -> ^(REDIR redirection_operator redirection_destination)
- | BLANK!? process_substitution;
+ | BLANK!? process_substitution
+ | here_string;
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN BLANK* command_list BLANK* RPAREN
@@ -339,9 +340,8 @@ redirection_operator
command
: command_atom
(
- redirection -> ^(COMMAND command_atom redirection)
+ redirection here_document? -> ^(COMMAND command_atom redirection here_document?)
| here_document -> ^(COMMAND command_atom here_document)
- | here_string -> ^(COMMAND command_atom here_string)
| -> ^(COMMAND command_atom)
);
diff --git a/bashast/gunit/redir.gunit b/bashast/gunit/redir.gunit
index 882290f..d6aa599 100644
--- a/bashast/gunit/redir.gunit
+++ b/bashast/gunit/redir.gunit
@@ -28,6 +28,7 @@ redirection:
"< this.is.1input" -> (REDIR < (STRING this . is . 1 input))
" 3< \"input from file\"" -> (REDIR 3 < (STRING (DOUBLE_QUOTED_STRING input from file)))
" 2<&0" -> (REDIR 2 <& (FILE_DESCRIPTOR 0))
+"<<<\"#include <pthread.h>\" >& /dev/null" -> (<<< (STRING (DOUBLE_QUOTED_STRING # include < pthread . h >))) (REDIR >& (STRING / dev / null))
here_string:
"<<< herestring" -> (<<< (STRING herestring))
@@ -47,3 +48,7 @@ _EOF_.abc
" -> (LIST (COMMAND (STRING cat) (<< (STRING blah
blah
) (REDIR > (STRING / dev / null)))))
+"cat > /dev/null <<-END_LDSCRIPT
+GNU...
+END_LDSCRIPT" -> (LIST (COMMAND (STRING cat) (REDIR > (STRING / dev / null)) (<<- (STRING GNU .. .
+))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: bad292ded893e93c6d598d85fb111c05ffd599e5
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 13:51:34 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:52:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=bad292de
Parser: fix single quoted string in command sub
---
bashast/bashast.g | 1 +
bashast/gunit/command_sub.gunit | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 39e6d54..c987375 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -1076,6 +1076,7 @@ COMMAND_SUBSTITUTION_PAREN
return;
}
}
+ | SINGLE_QUOTED_STRING_TOKEN
| .
)+
));
diff --git a/bashast/gunit/command_sub.gunit b/bashast/gunit/command_sub.gunit
index 9998893..4b7b776 100644
--- a/bashast/gunit/command_sub.gunit
+++ b/bashast/gunit/command_sub.gunit
@@ -24,3 +24,4 @@ command_substitution:
"$(CONTROL= command arg )" -> (COMMAND_SUB $(CONTROL= command arg ))
"`cat output.log |grep error|cut`" -> (COMMAND_SUB `cat output.log |grep error|cut`)
"$(function foo() { echo 'hello'; }; foo)" -> (COMMAND_SUB $(function foo() { echo 'hello'; }; foo))
+"$(sed -n 's/^OUTPUT_FORMAT(\"\([^\"]*\)\",.*/\1/p')" OK
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 67e3dcb6e274e7f3764d622e8c4f2ac634784441
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 28 08:30:52 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:52:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=67e3dcb6
Parser: support ${?}
---
bashast/bashast.g | 1 +
bashast/gunit/param_main.gunit | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index d09138a..f2d5c3c 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -874,6 +874,7 @@ variable_name
| DOLLAR
| TIMES
| AT
+ | QMARK
| POUND;
variable_name_no_digit
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index e73caf3..422b7ac 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -57,6 +57,7 @@ variable_reference:
"$*" -> (VAR_REF *)
"${@}" -> (VAR_REF @)
"${#}" -> (VAR_REF #)
+"${?}" -> (VAR_REF ?)
"$#" -> (VAR_REF #)
"${!foo}" -> (VAR_REF (VAR_REF foo))
"${!#}" -> (VAR_REF (VAR_REF #))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 7ee597c631c9ece2d73e81df0726c6dbc8288fd7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 28 08:44:53 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:52:19 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=7ee597c6
Parser: make spaces around < and > optional
Only < and > is optional for keyword test. Some unit tests in
cond_main.gunit are fixed.
---
bashast/bashast.g | 10 +++++-----
bashast/gunit/cond_main.gunit | 8 +++++---
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)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 2bcc4ed9ea1b78036807a4c914003922343e7b04
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 28 08:00:11 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 07:52:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2bcc4ed9
Parser: support process sub as redirection dest
---
bashast/bashast.g | 9 +++++----
bashast/gunit/process_substitution.gunit | 6 ++++++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 818a598..d09138a 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -275,8 +275,8 @@ time_posix
redirection
: redirection_atom+;
redirection_atom
- : redirection_operator BLANK? redirection_destination -> ^(REDIR redirection_operator redirection_destination)
- | BLANK!? process_substitution
+ : redirection_operator redirection_destination -> ^(REDIR redirection_operator redirection_destination)
+ | BLANK! process_substitution
| here_string;
process_substitution
@@ -284,8 +284,9 @@ process_substitution
-> ^(PROCESS_SUBSTITUTION $dir command_list);
redirection_destination
- : (file_descriptor) => file_descriptor
- | string_expr;
+ : (BLANK? file_descriptor) => BLANK!? file_descriptor
+ | BLANK! process_substitution
+ | BLANK!? string_expr;
file_descriptor
: DIGIT -> ^(FILE_DESCRIPTOR DIGIT)
| DIGIT MINUS -> ^(FILE_DESCRIPTOR_MOVE DIGIT);
diff --git a/bashast/gunit/process_substitution.gunit b/bashast/gunit/process_substitution.gunit
index b0d2754..f7e0ec2 100644
--- a/bashast/gunit/process_substitution.gunit
+++ b/bashast/gunit/process_substitution.gunit
@@ -21,3 +21,9 @@ gunit java_libbash;
process_substitution:
"<( true )" -> (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING true))))
">(false)" -> (PROCESS_SUBSTITUTION > (LIST (COMMAND (STRING false))))
+
+command:
+"while read -d $'\0' -r nspkg_pth_file; do
+ nspkg_pth_files+=(\"${nspkg_pth_file}\")
+done < <(find \"${ED}\" -name \"*-nspkg.pth\" -type f -print0)" -> (COMMAND (while (LIST (COMMAND (STRING read) (STRING - d) (STRING (ANSI_C_QUOTING '\0')) (STRING - r) (STRING nspkg_pth_file))) (LIST (COMMAND (VARIABLE_DEFINITIONS (PLUS_ASSIGN nspkg_pth_files (ARRAY (STRING (DOUBLE_QUOTED_STRING (VAR_REF nspkg_pth_file))))))))) (REDIR < (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING find) (STRING (DOUBLE_QUOTED_STRING (VAR_REF ED))) (STRING - name) (STRING (DOUBLE_QUOTED_STRING * - nspkg . pth)) (STRING - type) (STRING f) (STRING - print0))))))
+"echo<(cat)" FAIL
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: c444c4bb2952b3b95269a9f7e05d730c2df50670
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 1 03:32:09 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar 1 03:32:09 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c444c4bb
Parser: support indirect ref in parameter expansion
---
bashast/gunit/param_main.gunit | 3 +++
bashast/libbashWalker.g | 15 +++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 4e30458..01ec853 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -87,6 +87,9 @@ variable_reference:
"${#$}" -> (VAR_REF (# $))
"${a/=}" -> (VAR_REF (REPLACE_FIRST a (STRING =)))
"${a%=}" -> (VAR_REF (LAZY_REMOVE_AT_END a (STRING =)))
+"${!#/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF #) (STRING a) (STRING bc)))
+"${!abc/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF abc) (STRING a) (STRING bc)))
+"${!123/a/bc}" -> (VAR_REF (REPLACE_FIRST (VAR_REF 123) (STRING a) (STRING bc)))
variable_definition_atom:
"MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 9b2281d..67a39fc 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -447,10 +447,25 @@ var_name returns[std::string libbash_value, unsigned index]
$libbash_value = $name.libbash_value;
$index = $name.index;
}
+ |^(VAR_REF libbash_string=var_name_for_bang) {
+ $libbash_value = walker->resolve<std::string>(libbash_string);
+ }
+ |^(VAR_REF POUND) { // for ${!#}
+ int index = walker->get_array_length("*");
+ $libbash_value = (index != 0 ? "*" : "0");
+ }
|MINUS {
$libbash_value = "-";
};
+var_name_for_bang returns[std::string libbash_value]
+ :libbash_string=num {
+ $libbash_value = libbash_string;
+ }
+ |name {
+ $libbash_value = $name.libbash_value;
+ };
+
array_name returns[std::string libbash_value]
:^(ARRAY name (AT|TIMES)) { $libbash_value = $name.libbash_value; }
// We do not care the difference between TIMES and AT for now
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: f026db51e71d8fc76c6fc0ecc78fc9d8113c03a9
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 1 07:21:05 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar 1 07:21:05 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f026db51
Parser: allow multiple operands in test expression
---
bashast/bashast.g | 8 ++++----
bashast/gunit/cond_main.gunit | 4 ++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 700f865..8d627c4 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -600,9 +600,9 @@ condition_expr
#endif
keyword_condition_and
- : keyword_condition_primary (BLANK!? LOGICAND^ BLANK!? keyword_condition_primary)?;
+ : keyword_condition_primary (BLANK!? LOGICAND^ BLANK!? keyword_condition_primary)*;
keyword_condition
- : keyword_condition_and (BLANK!? LOGICOR^ BLANK!? keyword_condition_and)?;
+ : keyword_condition_and (BLANK!? LOGICOR^ BLANK!? keyword_condition_and)*;
keyword_negation_primary
: BANG BLANK keyword_condition_primary -> ^(NEGATION keyword_condition_primary);
keyword_condition_primary
@@ -655,9 +655,9 @@ keyword_binary_string_operator
builtin_condition_and
- : builtin_condition_primary (builtin_logic_and^ BLANK! builtin_condition_primary)?;
+ : builtin_condition_primary (builtin_logic_and^ BLANK! builtin_condition_primary)*;
builtin_condition
- : builtin_condition_and (builtin_logic_or^ BLANK! builtin_condition_and)?;
+ : builtin_condition_and (builtin_logic_or^ BLANK! builtin_condition_and)*;
builtin_negation_primary
: BANG BLANK builtin_condition_primary -> ^(NEGATION builtin_condition_primary);
builtin_condition_primary
diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index bf86d7d..cb8ffef 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -34,9 +34,13 @@ condition_expr:
"[ -n \"$FROM_LANG\" -a -n \"$TO_LANG\" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC_AND (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_OR (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF FROM_LANG)))) (n (STRING (DOUBLE_QUOTED_STRING (VAR_REF TO_LANG))))))
"[ -n \"a\" -o -n \"a\" -a -n \"a\" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC_OR (n (STRING (DOUBLE_QUOTED_STRING a))) (BUILTIN_LOGIC_AND (n (STRING (DOUBLE_QUOTED_STRING a))) (n (STRING (DOUBLE_QUOTED_STRING a))))))
+"[ -n \"a\" -a -n \"a\" -a -n \"a\" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC_AND (BUILTIN_LOGIC_AND (n (STRING (DOUBLE_QUOTED_STRING a))) (n (STRING (DOUBLE_QUOTED_STRING a)))) (n (STRING (DOUBLE_QUOTED_STRING a)))))
+"[ -n \"a\" -o -n \"a\" -o -n \"a\" ]" -> (BUILTIN_TEST (BUILTIN_LOGIC_OR (BUILTIN_LOGIC_OR (n (STRING (DOUBLE_QUOTED_STRING a))) (n (STRING (DOUBLE_QUOTED_STRING a)))) (n (STRING (DOUBLE_QUOTED_STRING a)))))
"[[ \"${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))))
"[[ a == b || c == d && e == f ]]" -> (KEYWORD_TEST (|| (MATCH_PATTERN (STRING a) (STRING b)) (&& (MATCH_PATTERN (STRING c) (STRING d)) (MATCH_PATTERN (STRING e) (STRING f)))))
"[[ a == b && c == d || e == f ]]" -> (KEYWORD_TEST (|| (&& (MATCH_PATTERN (STRING a) (STRING b)) (MATCH_PATTERN (STRING c) (STRING d))) (MATCH_PATTERN (STRING e) (STRING f))))
+"[[ a == b && c == d && e == f ]]" -> (KEYWORD_TEST (&& (&& (MATCH_PATTERN (STRING a) (STRING b)) (MATCH_PATTERN (STRING c) (STRING d))) (MATCH_PATTERN (STRING e) (STRING f))))
+"[[ a == b || c == d || e == f ]]" -> (KEYWORD_TEST (|| (|| (MATCH_PATTERN (STRING a) (STRING b)) (MATCH_PATTERN (STRING c) (STRING d))) (MATCH_PATTERN (STRING e) (STRING f))))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 19f82f9686e67da79b9f265f8baf228223d069b4
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 1 08:30:32 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar 1 08:30:32 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=19f82f96
Parser: Allow EOLs in builtin array definition
---
bashast/bashast.g | 13 ++++++++++++-
bashast/gunit/array.gunit | 12 ++++++++++++
2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 73249ef..92f4f92 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -461,7 +461,18 @@ array_atom
);
builtin_variable_definition_item
- : ((~EOL) => expansion_base)+;
+scope {
+ int parens;
+}
+@init {
+ $builtin_variable_definition_item::parens = 0;
+}
+ : (
+ (LPAREN) => LPAREN { ++$builtin_variable_definition_item::parens; }
+ |(RPAREN) => RPAREN { --$builtin_variable_definition_item::parens; }
+ |(~EOL) => expansion_base
+ | {LA(1) == EOL && $builtin_variable_definition_item::parens > 0}? => EOL
+ )+;
#ifdef OUTPUT_C
builtin_variable_definitions[bool local]
diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit
index ddfdfeb..1958836 100644
--- a/bashast/gunit/array.gunit
+++ b/bashast/gunit/array.gunit
@@ -34,6 +34,18 @@ variable_definition_atom:
builtin_variable_definitions:
"asdf=(a b c d) ade acd=bde" -> (LIST (COMMAND (VARIABLE_DEFINITIONS (= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d))) (EQUALS ade (STRING (VAR_REF ade))) (= acd (STRING bde)))))
+builtin_variable_definition_item:
+"local cmakeargs=(
+ abc
+ def
+ ghi
+)" -> "local cmakeargs = ( \n abc \n def \n ghi \n )"
+"export cmakeargs=(
+ abc
+ def
+ ghi
+)" -> "export cmakeargs = ( \n abc \n def \n ghi \n )"
+
variable_reference:
"$asdf" -> (VAR_REF asdf)
"${asdf[0]:-default}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL (asdf (ARITHMETIC 0)) (STRING default)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 39fb7115a568844b3075ff1a6a775c919d428e0e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 26 08:24:07 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Mar 26 08:35:47 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=39fb7115
Parser: allow ';' after local and export
---
bashast/bashast.g | 2 +-
bashast/gunit/simp_prog.gunit | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index c6d7f34..c836047 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -471,7 +471,7 @@ scope {
: (
(LPAREN) => LPAREN { ++$builtin_variable_definition_item::parens; }
|(RPAREN) => RPAREN { --$builtin_variable_definition_item::parens; }
- |(~EOL) => expansion_base
+ |(~(EOL|SEMIC)) => expansion_base
| {LA(1) == EOL && $builtin_variable_definition_item::parens > 0}? => EOL
)+;
diff --git a/bashast/gunit/simp_prog.gunit b/bashast/gunit/simp_prog.gunit
index e765ab0..e44c1e5 100644
--- a/bashast/gunit/simp_prog.gunit
+++ b/bashast/gunit/simp_prog.gunit
@@ -36,3 +36,5 @@ hello () {
hello
quit
echo foo" -> (LIST (COMMAND (FUNCTION (STRING quit) (CURRENT_SHELL (LIST (COMMAND (STRING exit)))))) (COMMAND (FUNCTION (STRING hello) (CURRENT_SHELL (LIST (COMMAND (STRING echo) (STRING Hello !)))))) (COMMAND (STRING hello)) (COMMAND (STRING quit)) (COMMAND (STRING echo) (STRING foo)))
+
+"export abc;echo" -> (LIST (COMMAND (STRING export) (STRING abc)) (COMMAND (STRING echo)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/
@ 2012-08-19 14:35 Petteri Räty
0 siblings, 0 replies; 91+ messages in thread
From: Petteri Räty @ 2012-08-19 14:35 UTC (permalink / raw
To: gentoo-commits
commit: 10e8001655ed4e82eccdeb650f073d462a66ff78
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Tue Aug 7 03:16:45 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Aug 19 14:32:01 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=10e80016
Parser: Support line break after pipe
---
bashast/bashast.g | 2 +-
bashast/gunit/pipeline.gunit | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9fd3fdb..8943209 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -272,7 +272,7 @@ command_separator
| AMP^
| EOL!;
pipeline
- : time? ((BANG) => (BANG BLANK!))? command^ (BLANK!? PIPE^ BLANK!? command)*;
+ : time? ((BANG) => (BANG BLANK!))? command^ (BLANK!? PIPE^ wspace!? command)*;
time
: TIME^ BLANK! ((time_posix) => time_posix)?;
diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index b97ec3b..4a3a4f4 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -30,3 +30,4 @@ pipeline:
echo \"three\"
fi" -> (COMMAND (IF_STATEMENT (if (LIST (COMMAND (STRING cat) time)) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING three)))))))
"i=1 j=2" -> (COMMAND (VARIABLE_DEFINITIONS (= i (STRING 1)) (= j (STRING 2))))
+"cat foo |\ncat" -> (| (COMMAND (STRING cat) (STRING foo)) (COMMAND (STRING cat)))
^ permalink raw reply related [flat|nested] 91+ messages in thread
end of thread, other threads:[~2012-08-19 14:35 UTC | newest]
Thread overview: 91+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-01 12:03 [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/ Petteri Räty
-- strict thread matches above, loose matches on Subject: below --
2012-08-19 14:35 Petteri Räty
2012-06-03 9:08 Petteri Räty
2012-06-03 9:08 Petteri Räty
2012-06-03 9:08 Petteri Räty
2012-06-03 9:08 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-07-20 13:08 Petteri Räty
2011-07-08 14:12 Petteri Räty
2011-06-21 13:26 Petteri Räty
2011-06-21 13:20 Petteri Räty
2011-06-21 13:20 Petteri Räty
2011-06-19 19:15 Petteri Räty
2011-06-15 21:18 Petteri Räty
2011-06-14 8:28 Petteri Räty
2011-06-14 8:28 Petteri Räty
2011-06-11 8:24 Petteri Räty
2011-06-11 8:24 Petteri Räty
2011-06-09 13:41 Petteri Räty
2011-06-09 13:41 Petteri Räty
2011-06-09 8:15 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-06-01 12:03 Petteri Räty
2011-05-23 14:34 Petteri Räty
2011-05-22 21:00 Petteri Räty
2011-05-11 7:19 Petteri Räty
2011-05-11 7:19 Petteri Räty
2011-05-11 7:19 Petteri Räty
2011-05-07 12:25 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-17 10:58 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-11 6:50 Petteri Räty
2011-04-11 6:50 Petteri Räty
2011-04-11 6:50 Petteri Räty
2011-04-11 6:50 Petteri Räty
2011-04-11 5:21 Petteri Räty
2011-04-11 5:21 Petteri Räty
2011-04-11 5:21 Petteri Räty
2011-04-11 5:21 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-08 14:26 Petteri Räty
2011-04-07 16:45 Petteri Räty
2011-04-07 7:48 Petteri Räty
2011-04-06 7:43 Petteri Räty
2011-03-30 12:48 Petteri Räty
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox