public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-05-22 21:00 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-05-22 21:00 UTC (permalink / raw
  To: gentoo-commits

commit:     2abce7d61e0e76f0e116b530ada1e2af244cf1f7
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed May 18 13:38:00 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 22 20:42:40 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2abce7d6

Builtin: support export built-in.

We do not support command env before the export built-in for now.
You also can't override the built-in by defining a function with
the same name as it's currently purely a parser level construct.

---
 bashast/bashast.g                     |    9 +++++++--
 bashast/gunit/pipeline.gunit          |    2 +-
 bashast/libbashWalker.g               |    5 +++++
 scripts/command_execution.bash        |    2 ++
 scripts/command_execution.bash.result |    4 ++++
 5 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2a8e20b..48ae78d 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -134,7 +134,11 @@ simple_command
 	|	variable_definitions -> ^(VARIABLE_DEFINITIONS variable_definitions)
 	|	bash_command^ redirect*;
 variable_definitions
-	:	(LOCAL BLANK!+)? var_def (BLANK!+ var_def)*;
+	:	(LOCAL BLANK!+)? var_def (BLANK!+ var_def)*
+	|	EXPORT! (BLANK!+ export_item)+;
+export_item
+	:var_def
+	|name ->;
 bash_command
 	:	fname_no_res_word (BLANK+ fname)* -> ^(COMMAND fname_no_res_word fname*);
 redirect:	BLANK!* here_string_op^ BLANK!* fname
@@ -408,7 +412,7 @@ 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|COMMA;
+	|OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT;
 
 //Generic strings/filenames.
 fname	:	(~POUND) => fname_part fname_part* -> ^(STRING fname_part+);
@@ -660,6 +664,7 @@ QMARK	:	'?';
 //Operators for conditional statements
 TEST_EXPR	:	'test';
 LOCAL	:	'local';
+EXPORT	:	'export';
 LOGICAND :	'&&';
 LOGICOR	:	'||';
 //Tokens for strings

diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index 8101566..f2c0cb0 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -20,7 +20,7 @@ gunit bashast;
 
 pipeline:
 "cat asdf" -> (COMMAND (STRING cat) (STRING asdf))
-"export VAR=bar LAA=laa" -> (COMMAND (STRING export) (STRING VAR = bar) (STRING LAA = laa))
+"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 cat file | grep search" -> (| (COMMAND (STRING cat) (STRING file) time) (COMMAND (STRING grep) (STRING search)))

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 1ae6616..d781a03 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -466,6 +466,11 @@ execute_command[const std::string& name, std::vector<std::string>& libbash_args]
 		{
 			walker->set_status(walker->execute_builtin(name, libbash_args));
 		}
+		else if(name == "export")
+		{
+			std::cerr << "We do not support command env before the export builtin." << std::endl;
+			walker->set_status(1);
+		}
 		else
 		{
 			std::cerr << name << " is not supported yet" << std::endl;

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 9e1901c..6e655e4 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -15,3 +15,5 @@ true || echo "wrong"
 echo "end"
 : ${DEFAULTED:="yes"}
 FOO="abc" echo "command environment"
+export FOO003=1 FOO004=abc FOO005=(1 2 3) FOO002
+abc=1 export foo

diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index 7ee093d..9f2ba11 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -4,6 +4,10 @@ right
 right
 end
 command environment
+We do not support command env before the export builtin.
 DEFAULTED=yes
 FOO001=hello
 FOO002=Hello World
+FOO003=1
+FOO004=abc
+FOO005=1 2 3



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-06-09  7:27 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-06-09  7:27 UTC (permalink / raw
  To: gentoo-commits

commit:     78352ef7a33076ff93e734bef200250a03d31c55
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Fri Jun  3 15:09:34 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun  3 15:09:34 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=78352ef7

Parser+Walker: empty word for parameter expansion

: ${CABAL_EXTRA_CONFIGURE_FLAGS:=} found in haskell-cabal.eclass now
works properly.

---
 bashast/bashast.g                 |    7 +++++--
 bashast/gunit/param_main.gunit    |    1 +
 bashast/libbashWalker.g           |    2 +-
 scripts/var_expansion.bash        |    1 +
 scripts/var_expansion.bash.result |    1 +
 5 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index edbadf5..d63bc09 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -268,8 +268,8 @@ var_ref
 	|	DOLLAR BANG -> ^(VAR_REF BANG);
 //Variable expansions
 var_exp	:	var_name (
-				  parameter_value_operator word
-					-> ^(parameter_value_operator var_name word)
+				  parameter_value_operator parameter_word
+					-> ^(parameter_value_operator var_name parameter_word)
 				| COLON wspace* os=explicit_arithmetic (COLON len=explicit_arithmetic)?
 					-> ^(OFFSET var_name $os ^($len)?)
 				| parameter_delete_operator parameter_pattern_part+
@@ -299,6 +299,9 @@ parameter_value_operator
 	|	EQUALS -> ASSIGN_DEFAULT_WHEN_UNSET
 	|	QMARK -> DISPLAY_ERROR_WHEN_UNSET
 	|	PLUS -> USE_ALTERNATE_WHEN_UNSET;
+parameter_word
+	:	word
+	|	-> ^(STRING);
 parameter_replace_pattern
 	:	((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
 parameter_pattern_part

diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index cfbd92f..4eb4968 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -23,6 +23,7 @@ var_ref:
 "${asdf}" -> (VAR_REF asdf)
 "${asdf:-foo}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo)))
 "${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))
 "${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10)))
 "${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5)))

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index de9810e..39b0a16 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -182,7 +182,7 @@ string_expr returns[std::string libbash_value, bool quoted]
 			$libbash_value += $string_part.libbash_value;
 			$quoted = $string_part.quoted;
 		}
-	)+);
+	)*);
 
 string_part returns[std::string libbash_value, bool quoted]
 @init {

diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 1419686..80157a9 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -96,3 +96,4 @@ target="abc*abc"
 echo ${target/*}
 echo ${target/'*'}
 echo ${target/"*"}
+: ${FOO089:=}

diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
index dac4d8e..94729b3 100644
--- a/scripts/var_expansion.bash.result
+++ b/scripts/var_expansion.bash.result
@@ -92,4 +92,5 @@ FOO085=1 2
 FOO086=5
 FOO087=4 5
 FOO088=filename 1 2 3 4 5
+FOO089=
 target=abc*abc



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-06-09  8:15 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-06-09  8:15 UTC (permalink / raw
  To: gentoo-commits

commit:     e38d31ade0ffe51dd0c0f6ebc3412f76d92fe832
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat Jun  4 09:47:59 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun  9 08:37:28 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=e38d31ad

Parser: improve variable expansion value handling

Some rules are refactored to call the parameter_expansion_value rule.
Now the space, semicolon and empty string in expansion value can be
correctly handled.

---
 bashast/bashast.g                 |   20 +++++++++-----------
 bashast/gunit/param_main.gunit    |    2 +-
 scripts/var_expansion.bash        |    4 ++--
 scripts/var_expansion.bash.result |    4 ++--
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index d75ef35..f4e43ce 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -268,14 +268,14 @@ var_ref
 	|	DOLLAR BANG -> ^(VAR_REF BANG);
 //Variable expansions
 var_exp	:	var_name (
-				  parameter_value_operator parameter_word
-					-> ^(parameter_value_operator var_name parameter_word)
+				parameter_value_operator parameter_expansion_value
+					-> ^(parameter_value_operator var_name parameter_expansion_value)
 				| COLON wspace* os=explicit_arithmetic (COLON len=explicit_arithmetic)?
 					-> ^(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 (SLASH parameter_replace_string?)?
-					-> ^(parameter_replace_operator var_name parameter_replace_pattern parameter_replace_string?)
+				| parameter_delete_operator parameter_expansion_value
+					-> ^(parameter_delete_operator var_name parameter_expansion_value)
+				| parameter_replace_operator parameter_replace_pattern (SLASH parameter_expansion_value?)?
+					-> ^(parameter_replace_operator var_name parameter_replace_pattern parameter_expansion_value?)
 				| -> var_name
 			 )
 	|	BANG var_name_for_bang  (
@@ -299,15 +299,13 @@ parameter_value_operator
 	|	EQUALS -> ASSIGN_DEFAULT_WHEN_UNSET
 	|	QMARK -> DISPLAY_ERROR_WHEN_UNSET
 	|	PLUS -> USE_ALTERNATE_WHEN_UNSET;
-parameter_word
-	:	word
-	|	-> ^(STRING);
 parameter_replace_pattern
 	:	((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
 parameter_pattern_part
 	:	fname_part|BLANK|SEMIC;
-parameter_replace_string
-	:	parameter_pattern_part+ -> ^(STRING parameter_pattern_part+);
+parameter_expansion_value
+	:	parameter_pattern_part+ -> ^(STRING parameter_pattern_part+)
+	|	-> ^(STRING);
 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 4eb4968..fcd7d6d 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -59,7 +59,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_ANY - . _))))
+"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _)) STRING))
 "${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)))

diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 80157a9..d38d8aa 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -8,7 +8,7 @@ FOO003=123
 FOO004=$EAPI
 FOO005=$(( 1+1 ))
 FOO006=${EAPI:=hello}
-FOO007=${FOO008:=hello}
+FOO007=${FOO008:=hello world}
 FOO009=${EAPI:+hello}
 FOO010=${NOT_EXIST:+hello}
 FOO011=${FOO009:0}
@@ -71,7 +71,7 @@ FOO068=${FOO039/#He/he}
 FOO069=${FOO039/#ello/i}
 FOO070=${FOO039/%ld/d}
 FOO071=${FOO039/%rl/r}
-FOO072=${FOO039/+(l)}
+FOO072=${FOO039/+(l)/}
 FOO073=${FOO039/+(l|e)}
 FOO074=${FOO039/*(l)}
 FOO075=${FOO039//*(l)}

diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
index 94729b3..c3f30c8 100644
--- a/scripts/var_expansion.bash.result
+++ b/scripts/var_expansion.bash.result
@@ -11,8 +11,8 @@ FOO003=123
 FOO004=3
 FOO005=2
 FOO006=3
-FOO007=hello
-FOO008=hello
+FOO007=hello world
+FOO008=hello world
 FOO009=hello
 FOO010=
 FOO011=hello



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
  To: gentoo-commits

commit:     c362dfac46df8e73df50a0694e59f5087104ad2b
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 19 14:24:07 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=c362dfac

Parser: fix parameter expansion value

Now the rule for expansion value follows bash manual. The delete
expansion is fixed to use the replace pattern rule rather than the
expansion value rule.

---
 bashast/bashast.g              |   27 +++++++++++++++++++++------
 bashast/gunit/param_main.gunit |   14 ++++++++------
 scripts/binary_arithmetic.bash |    2 +-
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index 032e3f9..3ca2bf8 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -107,6 +107,7 @@ tokens{
 	REPLACE_AT_END;
 	LAZY_REMOVE_AT_START;
 	LAZY_REMOVE_AT_END;
+	EMPTY_EXPANSION_VALUE;
 
 	PLUS_SIGN;
 	MINUS_SIGN;
@@ -686,7 +687,7 @@ pattern_char
 		|GREATER_THAN|SQUOTE|DQUOTE;
 
 variable_reference
-	:	DOLLAR LBRACE BLANK? parameter_expansion BLANK? RBRACE -> ^(VAR_REF parameter_expansion)
+	:	DOLLAR LBRACE parameter_expansion RBRACE -> ^(VAR_REF parameter_expansion)
 	|	DOLLAR name -> ^(VAR_REF name)
 	|	DOLLAR num -> ^(VAR_REF num)
 	|	DOLLAR TIMES -> ^(VAR_REF TIMES)
@@ -704,11 +705,11 @@ 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_expansion_value
-				-> ^(parameter_delete_operator variable_name parameter_expansion_value)
+			|	parameter_delete_operator parameter_replace_pattern
+				-> ^(parameter_delete_operator variable_name parameter_replace_pattern)
 			|	parameter_replace_operator parameter_replace_pattern (SLASH parameter_expansion_value)?
 				-> ^(parameter_replace_operator variable_name parameter_replace_pattern parameter_expansion_value?)
-			|	-> variable_name
+			|	BLANK? -> variable_name
 		)
 		|	BANG variable_name_for_bang
 			(
@@ -739,10 +740,24 @@ parameter_pattern_part
 
 // TODO fix this rule
 parameter_expansion_value
-	:	((~RBRACE) => parameter_expansion_value_atom)+ -> ^(STRING parameter_expansion_value_atom+);
+scope {
+	int num_of_braces;
+}
+	:	parameter_expansion_value_atom -> ^(STRING parameter_expansion_value_atom);
 
 parameter_expansion_value_atom
-	:	string_expr_part|BLANK;
+	:	(~RBRACE) =>
+			{$parameter_expansion_value::num_of_braces = 1;}
+			(
+				{$parameter_expansion_value::num_of_braces != 0}? => .
+				{
+					if(LA(1) == LBRACE && LA(-1) != ESC)
+						++$parameter_expansion_value::num_of_braces;
+					else if(LA(1) == RBRACE && LA(-1) != ESC)
+						--$parameter_expansion_value::num_of_braces;
+				}
+			)+
+	|	-> EMPTY_EXPANSION_VALUE;
 
 parameter_replace_operator
 	:	(SLASH SLASH) => SLASH SLASH -> REPLACE_ALL

diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 0744004..f2b8cbb 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -23,8 +23,8 @@ variable_reference:
 "${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))
+"${asdf='foo'}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET asdf (STRING 'foo')))
+"${asdf:=}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING EMPTY_EXPANSION_VALUE)))
 "${bar:7}" -> (VAR_REF (OFFSET bar 7))
 "${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10)))
 "${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5)))
@@ -41,8 +41,8 @@ variable_reference:
 "${foo##bar}" -> (VAR_REF (REPLACE_AT_START foo (STRING bar)))
 "${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 ;   MATCH_ALL)))
+//"${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)
@@ -60,12 +60,14 @@ variable_reference:
 "${$}" -> (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 - . _)) STRING))
-"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace))))
+"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _)) (STRING EMPTY_EXPANSION_VALUE)))
+"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING $ { 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)))
+"${a/b/\}c}" -> (VAR_REF (REPLACE_FIRST a (STRING b) (STRING \ } c)))
+"${a/b/a\}c}" -> (VAR_REF (REPLACE_FIRST a (STRING b) (STRING a \ } c)))
 
 variable_definition_atom:
 "MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))

diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index 8aca099..36b4c9d 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -57,7 +57,7 @@ echo "$((ARRAY[8]^=3))"
 PARTIAL[8]=5
 echo "$((PARTIAL[8]*=1))"
 echo "$((${#ARRAY[@]}))"
-echo "$((${ARRAY[5]:-10}))"
+#echo "$((${ARRAY[5]:-10}))"
 echo "$((${ARRAY:0}))"
 value=100
 FOO056="value"



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
  To: gentoo-commits

commit:     93de5730f17b88b96974ed4712ca32d815daf3a4
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 08:48:08 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=93de5730

Parser&Walker: support escaped characters in string

---
 bashast/bashast.g              |    2 ++
 bashast/gunit/fname.gunit      |    1 +
 bashast/libbashWalker.g        |    9 ++++++++-
 scripts/command_execution.bash |    1 +
 4 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index 7351a56..d55a392 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -685,6 +685,8 @@ ns_string_part
 	:	num|name|escaped_character
 	|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
 	|TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT
+	// Escaped characters
+	|ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK
 	// The following is for filename expansion
 	|TIMES|QMARK;
 

diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 3d60bc2..9ac0b25 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -48,6 +48,7 @@ string_expr:
 "--preserve=timestamps,mode" -> (STRING - - preserve = timestamps , mode)
 "$'asdf'" -> (STRING (ANSI_C_QUOTING 'asdf'))
 "\"abc#$/\"" -> (STRING (DOUBLE_QUOTED_STRING abc # $ /))
+"\`\(\)\$\>\<" -> (STRING \` \( \) \$ \> \<)
 
 condition_expr:
 // bracket patterns

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 25bfcb2..f4ebaaf 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -422,10 +422,17 @@ double_quoted_string returns[std::string libbash_value]
 	|libbash_string=any_string { $libbash_value = libbash_string; };
 
 any_string returns[std::string libbash_value]
+options {backtrack = true;}
 @declarations {
 	pANTLR3_BASE_TREE any_token;
 }
-	:any_token=. { $libbash_value = get_string(any_token); };
+	:ESC_RPAREN { $libbash_value = ")"; }
+	|ESC_LPAREN { $libbash_value = "("; }
+	|ESC_DOLLAR { $libbash_value = "$"; }
+	|ESC_GT { $libbash_value = ">"; }
+	|ESC_LT { $libbash_value = "<"; }
+	|ESC_TICK { $libbash_value = "`"; }
+	|any_token=. { $libbash_value = get_string(any_token); };
 
 //Allowable variable names in the variable expansion
 var_name returns[std::string libbash_value, unsigned index]

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 017d3af..add4145 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -72,3 +72,4 @@ echo ${array[@]}
 ech\
 o Hello\
  world
+echo \`\(\)\$\>\<\`



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
  To: gentoo-commits

commit:     b162a7bd8490e4224ce42c417ae12ba120d681ad
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 22 12:32:50 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=b162a7bd

Parser&Walker: support nested arithmetic expansion

---
 bashast/bashast.g              |    3 ++-
 bashast/gunit/arith_main.gunit |    1 +
 bashast/libbashWalker.g        |    1 +
 scripts/binary_arithmetic.bash |    1 +
 4 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index dd14f24..9c34478 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -874,7 +874,7 @@ commasep
 	:	brace_expansion_part (COMMA! brace_expansion_part)+;
 
 explicit_arithmetic
-	:	arithmetic_part
+	:	(DOLLAR (LLPAREN|LSQUARE)) => arithmetic_part // (the predicate resolves the conflict with the primary rule)
 	|	arithmetics;
 
 arithmetic_expansion
@@ -921,6 +921,7 @@ primary
 	|	command_substitution
 	|	variable_name_no_digit -> ^(VAR_REF variable_name_no_digit)
 	|	variable_reference
+	|	arithmetic_expansion
 	|	LPAREN! (arithmetics) RPAREN!;
 pre_post_primary
 	:	primary;

diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 7620fd7..7e04dc3 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -130,6 +130,7 @@ arithmetics_test:
 arithmetic_expansion:
 "$((5+4, 3+2, a*b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)))
 "$[1]" -> (ARITHMETIC_EXPRESSION 1)
+"$(($((1))))" -> (ARITHMETIC_EXPRESSION (ARITHMETIC_EXPRESSION 1))
 
 start:
 "echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f4ebaaf..d1bbe93 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -1201,5 +1201,6 @@ arithmetics returns[long value]
 	}
 	| NUMBER { $value = parse_integer($NUMBER);}
 	| DIGIT { $value = parse_integer($DIGIT);}
+	|^(ARITHMETIC_EXPRESSION l=arithmetics) { $value = l; }
 	| ^(VAR_REF libbash_string = var_expansion) { $value = boost::lexical_cast<long>(libbash_string); }
 	;

diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index cac471f..c5f018c 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -69,3 +69,4 @@ echo "$((FOO059||FOO059++))"
 echo "$((0&&FOO059++))"
 echo "$(( 1 == 2))"
 echo "$(( 1 == 1))"
+echo $(($((1))))



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2011-08-04 13:53 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
  To: gentoo-commits

commit:     1edf5ee2f0f778282b3d967d65a5028844fada29
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 28 07:40:00 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=1edf5ee2

Walker: support brace expansion for local and export

---
 bashast/bashast.g                |    4 ++--
 bashast/gunit/pipeline.gunit     |    2 +-
 bashast/gunit/simp_command.gunit |    2 +-
 bashast/libbashWalker.g          |    8 +++++---
 scripts/command_execution.bash   |    1 +
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index cb0a63d..818a598 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -379,9 +379,9 @@ command_atom
 				|	-> ^(VARIABLE_DEFINITIONS variable_definitions)
 			)
 	|	(EXPORT) => EXPORT BLANK builtin_variable_definition_item
-			-> ^(STRING EXPORT) ^(STRING ^(DOUBLE_QUOTED_STRING builtin_variable_definition_item))
+			-> ^(STRING EXPORT) ^(STRING builtin_variable_definition_item)
 	|	(LOCAL) => LOCAL BLANK builtin_variable_definition_item
-			-> ^(STRING LOCAL) ^(STRING ^(DOUBLE_QUOTED_STRING builtin_variable_definition_item))
+			-> ^(STRING LOCAL) ^(STRING builtin_variable_definition_item)
 	|	command_name
 		(
 			(BLANK? parens) => BLANK? parens wspace? compound_command

diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index 8f6dd43..aea66f0 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -20,7 +20,7 @@ gunit java_libbash;
 
 pipeline:
 "cat asdf" -> (COMMAND (STRING cat) (STRING asdf))
-"export VAR=bar LAA=(1 2 3) foo" -> (COMMAND (STRING export) (STRING (DOUBLE_QUOTED_STRING VAR = bar   LAA = ( 1   2   3 )   foo)))
+"export VAR=bar LAA=(1 2 3) foo" -> (COMMAND (STRING export) (STRING VAR = bar   LAA = ( 1   2   3 )   foo))
 "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)))

diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
index 2d98061..e6a8602 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -27,7 +27,7 @@ command_atom:
 "./foobär" -> (STRING . / foob ä r)
 "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" -> (STRING local) (STRING (DOUBLE_QUOTED_STRING a = 123   b = ( 1   2   3 )   c))
+"local a=123 b=(1 2 3) c" -> (STRING local) (STRING a = 123   b = ( 1   2   3 )   c)
 "echo {}{}}{{{}}{{}" -> (STRING echo) (STRING { } { } } { { { } } { { })
 "echo \"ab#af ###\" #abc" -> (STRING echo) (STRING (DOUBLE_QUOTED_STRING ab # af   # # #))
 

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 65fade5..fc05b91 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -576,8 +576,10 @@ command_atom
 simple_command
 @declarations {
 	std::vector<std::string> libbash_args;
+	bool split;
 }
-	:string_expr (argument[libbash_args])* execute_command[$string_expr.libbash_value, libbash_args];
+	:string_expr{ split = ($string_expr.libbash_value != "local" && $string_expr.libbash_value != "export"); }
+	(argument[libbash_args, split])* execute_command[$string_expr.libbash_value, libbash_args];
 
 execute_command[std::string& name, std::vector<std::string>& libbash_args]
 @declarations {
@@ -664,11 +666,11 @@ redirect_destination_input[std::unique_ptr<std::istream>& in]
 		std::cerr << "FILE_DESCRIPTOR_MOVE redirection is not supported yet" << std::endl;
 	};
 
-argument[std::vector<std::string>& args]
+argument[std::vector<std::string>& args, bool split]
 	: string_expr {
 		if(!$string_expr.libbash_value.empty())
 		{
-			if($string_expr.quoted)
+			if($string_expr.quoted || !split)
 				args.push_back($string_expr.libbash_value);
 			else
 				walker->split_word($string_expr.libbash_value, args);

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 1721fa9..a10d229 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -35,6 +35,7 @@ function unset_outer()
 {
     local FOO006=1 FOO007=2
     local gjl_${FOO006}="${FOO007}"
+    local f version install{{site,vendor}{arch,lib},archlib}
     unset_inner
     echo "FOO006=$FOO006 in unset_outer"
     echo "FOO007=$FOO007 in unset_outer"



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2012-06-03  9:08 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2012-06-03  9:08 UTC (permalink / raw
  To: gentoo-commits

commit:     b921511820ee4116b4f1f2746bb90e6b859ae1c8
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 23 03:24:05 2012 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Feb 23 03:27:12 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b9215118

Parser: respect operator precedence in keyword test

---
 bashast/bashast.g             |    5 ++++-
 bashast/gunit/cond_main.gunit |    2 ++
 scripts/test_expr.bash        |    1 +
 3 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index b7e0d32..b383219 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -597,12 +597,15 @@ condition_expr
 	|	{LA(1) == NAME && LA(2) == BLANK && "test".equals(get_string(LT(1)))}? => NAME wspace? builtin_condition-> ^(BUILTIN_TEST builtin_condition);
 #endif
 
+keyword_condition_and
+	:	keyword_condition_primary (BLANK!? LOGICAND^ BLANK!? keyword_condition_primary)?;
 keyword_condition
-	:	((BANG) => keyword_negation_primary|keyword_condition_primary) (BLANK!? (LOGICOR^|LOGICAND^) BLANK!? keyword_condition)?;
+	:	keyword_condition_and (BLANK!? LOGICOR^ BLANK!? keyword_condition_and)?;
 keyword_negation_primary
 	:	BANG BLANK keyword_condition_primary -> ^(NEGATION keyword_condition_primary);
 keyword_condition_primary
 	:	LPAREN! BLANK!? keyword_condition BLANK!? RPAREN!
+	|	(BANG) => keyword_negation_primary
 	|	(unary_operator) => keyword_condition_unary
 	|	keyword_condition_binary;
 keyword_condition_unary

diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index fbf785e..5ecd024 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -37,3 +37,5 @@ condition_expr:
 "[[ 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))))

diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index 66ab24a..ccedb76 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -54,3 +54,4 @@ unset i
 [ abc = bcd -a abc = abc ] || echo true19
 [[ =a <=b ]]
 [[ =a >=b ]]
+[[ a == a || c == b && a == b ]] && echo true



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2012-06-03  9:08 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2012-06-03  9:08 UTC (permalink / raw
  To: gentoo-commits

commit:     f4bdbb24bdbcb12655005202dec2fc6e216f0ed3
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 23 07:58:27 2012 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Feb 23 08:20:16 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f4bdbb24

Parser&Walker: respect precedence in builtin test

Builtin test does not support shortcut capability. Tests are added to
verify that.

---
 bashast/bashast.g             |   28 +++++++++++++++++++++-------
 bashast/gunit/cond_main.gunit |    5 +++--
 bashast/libbashWalker.g       |   13 +++++--------
 scripts/test_expr.bash        |    8 ++++++++
 4 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index b383219..8286a00 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -126,7 +126,8 @@ tokens{
 
 	NOT_EQUALS;
 	EQUALS_TO;
-	BUILTIN_LOGIC;
+	BUILTIN_LOGIC_AND;
+	BUILTIN_LOGIC_OR;
 
 	FUNCTION;
 }
@@ -651,13 +652,16 @@ keyword_binary_string_operator
 	|	BLANK!? LESS_THAN BLANK!?
 	|	BLANK!? GREATER_THAN BLANK!?;
 
+
+builtin_condition_and
+	:	builtin_condition_primary (builtin_logic_and^ BLANK! builtin_condition_primary)?;
 builtin_condition
-	:	((BANG) => builtin_negation_primary|builtin_keyword_condition_primary)
-		(BLANK! builtin_logic_operator^ BLANK! builtin_condition)?;
+	:	builtin_condition_and (builtin_logic_or^ BLANK! builtin_condition_and)?;
 builtin_negation_primary
-	:	BANG BLANK builtin_keyword_condition_primary -> ^(NEGATION builtin_keyword_condition_primary);
-builtin_keyword_condition_primary
+	:	BANG BLANK builtin_condition_primary -> ^(NEGATION builtin_condition_primary);
+builtin_condition_primary
 	:	LPAREN! BLANK!? builtin_condition BLANK!? RPAREN!
+	|	(BANG) => builtin_negation_primary
 	|	(unary_operator) => builtin_condition_unary
 	|	builtin_condition_binary;
 builtin_condition_unary
@@ -671,8 +675,18 @@ builtin_binary_string_operator
 	|	BANG EQUALS -> NOT_EQUALS
 	|	ESC_LT
 	|	ESC_GT;
-builtin_logic_operator
-	:	unary_operator -> ^(BUILTIN_LOGIC unary_operator);
+builtin_logic_and
+#ifdef OUTPUT_C
+	:	{LA(1) == BLANK && LA(2) == MINUS && LA(3) == LETTER && "a" == get_string(LT(3))}?=> BLANK MINUS LETTER -> BUILTIN_LOGIC_AND;
+#else
+	:	{LA(1) == BLANK && LA(2) == MINUS && LA(3) == LETTER && "a".equals(get_string(LT(3)))}?=> BLANK MINUS LETTER -> BUILTIN_LOGIC_AND;
+#endif
+builtin_logic_or
+#ifdef OUTPUT_C
+	:	{LA(1) == BLANK && LA(2) == MINUS && LA(3) == LETTER && "o" == get_string(LT(3))}?=> BLANK MINUS LETTER -> BUILTIN_LOGIC_OR;
+#else
+	:	{LA(1) == BLANK && LA(2) == MINUS && LA(3) == LETTER && "o".equals(get_string(LT(3)))}?=> BLANK MINUS LETTER -> BUILTIN_LOGIC_OR;
+#endif
 
 binary_operator
 	:	MINUS! NAME^;

diff --git a/bashast/gunit/cond_main.gunit b/bashast/gunit/cond_main.gunit
index 5ecd024..bf86d7d 100644
--- a/bashast/gunit/cond_main.gunit
+++ b/bashast/gunit/cond_main.gunit
@@ -31,8 +31,9 @@ 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))))))
+"[ -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))))))
 "[[ \"${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)))

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index e357642..7c7afaf 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -786,14 +786,11 @@ keyword_condition returns[bool status]
 
 builtin_condition returns[bool status]
 	:^(NEGATION l=builtin_condition) { $status = !l; }
-	|^(BUILTIN_LOGIC o=LETTER l=builtin_condition r=builtin_condition) {
-		char op = get_char(o);
-		if(op == 'a')
-			$status = l && r;
-		else if(op == 'o')
-			$status = l || r;
-		else
-			throw libbash::parse_exception(std::string("unrecognized operator in built-in test: ") + op);
+	|^(BUILTIN_LOGIC_AND l=builtin_condition r=builtin_condition) {
+		$status = l && r;
+	}
+	|^(BUILTIN_LOGIC_OR l=builtin_condition r=builtin_condition) {
+		$status = l || r;
 	}
 	|s=builtin_condition_primary { $status = s; };
 

diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index 6ae7246..f8e7c03 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -61,3 +61,11 @@ i=1
 [[ a == b && $((i=1)) ]] || echo $i # i should still be 0
 i=1
 [[ a == a && $((i=0)) ]] && echo $i # i should still be 0
+[ -n "a" -o -n "" -a -n "" ] && echo true
+# builtin test doesn't support shortcut
+i=1
+[ 1 -eq 2 -o $((i=0)) ] && echo $i # i should be 0 now
+[ 1 -eq 1 -o $((i=1)) ] && echo $i # i should still be 1
+[ 1 -eq 2 -a $((i=1)) ] || echo $i # i should still be 1
+i=1
+[ 1 -eq 1 -a $((i=0)) ] && echo $i # i should still be 0



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2012-06-03  9:08 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2012-06-03  9:08 UTC (permalink / raw
  To: gentoo-commits

commit:     62f2e7c112601d5bc7e7f5d042d4fce1e354865e
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar  1 07:51:58 2012 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar  1 07:51:58 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=62f2e7c1

Parser: allow empty replacement pattern

---
 bashast/bashast.g              |    3 ++-
 bashast/gunit/param_main.gunit |    3 +++
 scripts/var_expansion.bash     |    5 +++++
 3 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index 8d627c4..73249ef 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -879,7 +879,8 @@ parameter_value_operator
 	|	QMARK -> DISPLAY_ERROR_WHEN_UNSET
 	|	PLUS -> USE_ALTERNATE_WHEN_UNSET;
 parameter_replace_pattern
-	:	((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
+	:	(SLASH) => -> ^(STRING NAME) // Create an empty string
+	|	((~SLASH) => parameter_pattern_part)+ -> ^(STRING parameter_pattern_part+);
 parameter_delete_pattern
 	:	parameter_pattern_part+ -> ^(STRING parameter_pattern_part+);
 parameter_pattern_part

diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 01ec853..2168d54 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -90,6 +90,9 @@ variable_reference:
 "${!#/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)))
+"${search_paths/%/${root}}" -> (VAR_REF (REPLACE_AT_END search_paths (STRING NAME) (STRING $ { root })))
+"${search_paths/#/${root}}" -> (VAR_REF (REPLACE_AT_START search_paths (STRING NAME) (STRING $ { root })))
+"${search_paths//${root}}" -> (VAR_REF (REPLACE_ALL search_paths (STRING (VAR_REF root))))
 
 variable_definition_atom:
 "MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))

diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 5f0bfca..e78ac8f 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -130,6 +130,11 @@ foo=
 unset bar
 echo ${bar=abc}
 
+search_paths="a%#b"
+root=123
+echo "${search_paths/%/${root}}"
+echo "${search_paths/#/${root}}"
+
 # This regular expression will cause boost::exception_detail::clone_impl<boost::xpressive::regex_error>
 #[[ "${version_components_groups}" =~ ("*".*" "|" *"|^2.*\ (2|\*)|^3.*\ (3|\*)) ]]
 [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2012-06-03  9:08 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2012-06-03  9:08 UTC (permalink / raw
  To: gentoo-commits

commit:     85f4b6d5d9f671ab5d51023f9734ff577d70d9ac
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar  1 06:50:19 2012 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar  1 06:50:19 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=85f4b6d5

Parser: allow ANSI C quoting in expansion values

---
 bashast/bashast.g              |    2 ++
 bashast/gunit/expansions.gunit |    2 +-
 scripts/command_execution.bash |    1 +
 3 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index 98da5e7..700f865 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -746,6 +746,8 @@ expansion_base
 	|	(ESC TICK) => ESC TICK -> TICK
 	|	(ESC DOLLAR) => ESC DOLLAR -> DOLLAR
 	|	(brace_expansion) => brace_expansion
+	|	(DOLLAR SINGLE_QUOTED_STRING_TOKEN) => DOLLAR SINGLE_QUOTED_STRING_TOKEN
+			-> ^(ANSI_C_QUOTING SINGLE_QUOTED_STRING_TOKEN)
 	|	.;
 
 all_expansions

diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit
index 543012e..39acfa9 100644
--- a/bashast/gunit/expansions.gunit
+++ b/bashast/gunit/expansions.gunit
@@ -30,4 +30,4 @@ done" -> (LIST (COMMAND (for each (STRING (COMMAND_SUB `ls |grep output`)) (LIST
 "wc <(cat /usr/share/dict/linux.words)" -> (LIST (COMMAND (STRING wc) (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . words))))))
 
 all_expansions:
-"abc $(ab) ${ab} $((ab)) `ab` \"ab\" 'ab'" -> (STRING abc   (COMMAND_SUB $(ab))   (VAR_REF ab)   (ARITHMETIC_EXPRESSION (ARITHMETIC (VAR_REF ab)))   (COMMAND_SUB `ab`)   (DOUBLE_QUOTED_STRING ab)   'ab')
+"$'abc' abc $(ab) ${ab} $((ab)) `ab` \"ab\" 'ab'" -> (STRING (ANSI_C_QUOTING 'abc')   abc   (COMMAND_SUB $(ab))   (VAR_REF ab)   (ARITHMETIC_EXPRESSION (ARITHMETIC (VAR_REF ab)))   (COMMAND_SUB `ab`)   (DOUBLE_QUOTED_STRING ab)   'ab')

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 06d6676..615b13f 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -84,3 +84,4 @@ variable=a
 echo "${!variable// /_}"
 echo "${!#// /_}"
 echo "${!1// /_}"
+echo "${!variable// /$'\n'}"



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
@ 2012-06-03  9:08 Petteri Räty
  0 siblings, 0 replies; 12+ messages in thread
From: Petteri Räty @ 2012-06-03  9:08 UTC (permalink / raw
  To: gentoo-commits

commit:     c8b13641610f4f6b37b15a91f9f5ff390071545e
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 26 10:14:42 2012 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Mar 26 12:04:43 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c8b13641

Parser&Walker: improve escaped double quote handling

---
 bashast/bashast.g              |    3 ++-
 bashast/gunit/fname.gunit      |    2 +-
 bashast/libbashWalker.g        |    1 +
 scripts/command_execution.bash |    1 +
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index c836047..f7ce358 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -784,7 +784,7 @@ ns_string_part
 	|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON
 	|TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|AT
 	// Escaped characters
-	|ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK
+	|ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK|ESC_DQUOTE
 	// The following is for filename expansion
 	|TIMES|QMARK;
 
@@ -1126,6 +1126,7 @@ AMP_RSHIFT	:	'&>>';
 SEMIC	:	';';
 DOUBLE_SEMIC	:	';;';
 PIPE	:	'|';
+ESC_DQUOTE	:	'\\"';
 DQUOTE	:	'"' { if(LA(-1) != '\\') double_quoted = !double_quoted; };
 SQUOTE	:	{ double_quoted }? => '\'';
 SINGLE_QUOTED_STRING_TOKEN	:	{ !double_quoted }? => '\'' .* '\'';

diff --git a/bashast/gunit/fname.gunit b/bashast/gunit/fname.gunit
index 9ac0b25..65bb614 100644
--- a/bashast/gunit/fname.gunit
+++ b/bashast/gunit/fname.gunit
@@ -77,4 +77,4 @@ condition_expr:
 "[[ x == ab!(gh|i) ]]" -> (KEYWORD_TEST (MATCH_PATTERN (STRING x) (STRING ab (EXTENDED_MATCH_NONE (BRANCH gh) (BRANCH i)))))
 
 double_quoted_string:
-"\"\\\\\"\$\`\"" -> (DOUBLE_QUOTED_STRING \ " \$ \`)
+"\"\\\\\"\$\`\"" -> (DOUBLE_QUOTED_STRING \ \" \$ \`)

diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 5d5b557..fb1ca55 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -446,6 +446,7 @@ options {backtrack = true;}
 	:ESC_RPAREN { $libbash_value = ")"; }
 	|ESC_LPAREN { $libbash_value = "("; }
 	|ESC_DOLLAR { $libbash_value = "$"; }
+	|ESC_DQUOTE { $libbash_value = "\""; }
 	|ESC_GT { $libbash_value = ">"; }
 	|ESC_LT { $libbash_value = "<"; }
 	|ESC_TICK { $libbash_value = "`"; }

diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 89a0ed7..58f1279 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -89,3 +89,4 @@ echo "${!variable// /_}"
 echo "${!#// /_}"
 echo "${!1// /_}"
 echo "${!variable// /$'\n'}"
+eval abc+=\( \"\$@\" \)



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-06-03  9:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-22 21:00 [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/ Petteri Räty
  -- strict thread matches above, loose matches on Subject: below --
2011-06-09  7:27 Petteri Räty
2011-06-09  8:15 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
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
2012-06-03  9:08 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