* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-03 10:16 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-03 10:16 UTC (permalink / raw
To: gentoo-commits
commit: 6e93cd4a457e08e0900f5bba8a5f4ffa83318e4d
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 3 06:28:56 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 3 06:28:56 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=6e93cd4a
Support empty double quoted string literal
---
bashast/libbashWalker.g | 2 +-
scripts/var_def.ebuild | 2 +-
scripts/var_def.ebuild.result | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 95c2ff3..c0c8395 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -62,7 +62,7 @@ var_def:
string_expr returns[std::string libbash_value]:
^(STRING libbash_string=string_expr) { $libbash_value = libbash_string; }
- |^(DOUBLE_QUOTED_STRING (dq_str_part { libbash_string += $dq_str_part.libbash_value; })+) {
+ |^(DOUBLE_QUOTED_STRING (dq_str_part { libbash_string += $dq_str_part.libbash_value; })*) {
$libbash_value = libbash_string;
};
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index 7100b84..b5f9a14 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -6,5 +6,5 @@ SRC_URI="http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
LICENSE="LGPL-2.1 CDDL"
SLOT="0"
KEYWORDS="~amd64 ~x86"
-IUSE="abc"
+IUSE=""
RDEPEND="dev-db/sqlite:3"
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 6a3a0b8..750f11b 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,7 +1,7 @@
DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
EAPI=1
HOMEPAGE=http://sunpinyin.googlecode.com
-IUSE=abc
+IUSE=
KEYWORDS=~amd64 ~x86
LICENSE=LGPL-2.1 CDDL
RDEPEND=dev-db/sqlite:3
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-03 13:09 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-03 13:09 UTC (permalink / raw
To: gentoo-commits
commit: 0dfd3c9fc0901c078f064f7f738f6974dcabc4c1
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 3 10:49:47 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Apr 3 10:49:47 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=0dfd3c9f
Implement variable reference
Double quoted string can use variable reference now.
---
bashast/libbashWalker.g | 12 +++++++++---
scripts/var_def.ebuild | 2 ++
scripts/var_def.ebuild.result | 2 ++
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index c0c8395..fd736c8 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -62,9 +62,7 @@ var_def:
string_expr returns[std::string libbash_value]:
^(STRING libbash_string=string_expr) { $libbash_value = libbash_string; }
- |^(DOUBLE_QUOTED_STRING (dq_str_part { libbash_string += $dq_str_part.libbash_value; })*) {
- $libbash_value = libbash_string;
- };
+ |^(DOUBLE_QUOTED_STRING (libbash_string=dqstr { $libbash_value += libbash_string; })*);
//A rule for filenames/strings
res_word_str returns[std::string libbash_value]
@@ -105,6 +103,14 @@ dq_str_part returns[std::string libbash_value]
}:
BLANK|EOL|AMP|LOGICAND|LOGICOR|LESS_THAN|GREATER_THAN|PIPE|SQUOTE|SEMIC|COMMA|LPAREN|RPAREN|LLPAREN|RRPAREN|DOUBLE_SEMIC|LBRACE|RBRACE|TICK|LEQ|GEQ|str_part_with_pound;
+//double quoted string rule, allows expansions
+dqstr returns[std::string libbash_value]:
+ dq_str_part { $libbash_value = $dq_str_part.libbash_value; }
+ | libbash_string=var_ref { $libbash_value = libbash_string; };
+
+//variable reference
+var_ref returns[std::string libbash_value]:
+ ^(VAR_REF libbash_name=name) { $libbash_value=walker->resolve<std::string>(libbash_name); };
// shell arithmetic
arithmetics returns[int value]
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index b5f9a14..73f94b1 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -8,3 +8,5 @@ SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""
RDEPEND="dev-db/sqlite:3"
+DEPEND="${RDEPEND}
+ dev-util/pkgconfig"
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 750f11b..671ae4c 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,3 +1,5 @@
+DEPEND=dev-db/sqlite:3
+ dev-util/pkgconfig
DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
EAPI=1
HOMEPAGE=http://sunpinyin.googlecode.com
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-04 16:09 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-04 16:09 UTC (permalink / raw
To: gentoo-commits
commit: 1406a7f53e34f78f29b14a0af85872a37d37b341
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 4 13:29:45 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 4 16:01:00 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=1406a7f5
Support non-quoted string and expansions in variable definition
Non-quoted variable reference, number, string and arithmetic
expansion are allowed in variable definition.
---
bashast/libbashWalker.g | 3 ++-
scripts/var_expansion.ebuild | 3 +++
scripts/var_expansion.ebuild.result | 3 +++
3 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index ac8a040..a25c58c 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -56,13 +56,14 @@ options{ k=1; }:
|NUMBER { $libbash_value = walker->get_string($NUMBER); };
var_def:
- ^(EQUALS libbash_name=name libbash_value=string_expr){
+ ^(EQUALS libbash_name=name libbash_value=word){
walker->define(libbash_name, libbash_value);
};
string_expr returns[std::string libbash_value]:
^(STRING(
(DOUBLE_QUOTED_STRING) => ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string { $libbash_value += libbash_string; })*)
+ |(ARITHMETIC_EXPRESSION) => ^(ARITHMETIC_EXPRESSION value=arithmetics { $libbash_value = boost::lexical_cast<std::string>(value); })
|libbash_string=any_string { $libbash_value = libbash_string; }
));
diff --git a/scripts/var_expansion.ebuild b/scripts/var_expansion.ebuild
index 62e95c3..533e7a7 100644
--- a/scripts/var_expansion.ebuild
+++ b/scripts/var_expansion.ebuild
@@ -2,3 +2,6 @@ EAPI="3"
EAPI4="$(($EAPI+1))"
FOO="${EAPI:-hello}"
FOO2="${EAPI3:-hello}"
+FOO3=123
+FOO4=$EAPI
+FOO5=$(( 1+1 ))
diff --git a/scripts/var_expansion.ebuild.result b/scripts/var_expansion.ebuild.result
index f92abe4..bad2cf3 100644
--- a/scripts/var_expansion.ebuild.result
+++ b/scripts/var_expansion.ebuild.result
@@ -2,3 +2,6 @@ EAPI=3
EAPI4=4
FOO=3
FOO2=hello
+FOO3=123
+FOO4=3
+FOO5=2
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-12 18:29 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-12 18:29 UTC (permalink / raw
To: gentoo-commits
commit: 6db1d40390c7b90925085df91e4888b2b5d5f91e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 12 02:05:28 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 07:22:49 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=6db1d403
Support multiple unquoted string tokens
for AST like (STRING ldflags . patch), ". patch" was lost. Now the
AST can be handled correctly.
---
bashast/libbashWalker.g | 2 +-
scripts/var_def.ebuild | 1 +
scripts/var_def.ebuild.result | 1 +
3 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 825987a..06ff2f8 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -64,7 +64,7 @@ string_expr returns[std::string libbash_value]:
^(STRING(
(DOUBLE_QUOTED_STRING) => ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string { $libbash_value += libbash_string; })*)
|(ARITHMETIC_EXPRESSION) => ^(ARITHMETIC_EXPRESSION value=arithmetics { $libbash_value = boost::lexical_cast<std::string>(value); })
- |libbash_string=any_string { $libbash_value = libbash_string; }
+ |(libbash_string=any_string { $libbash_value += libbash_string; })+
));
//double quoted string rule, allows expansions
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index 73f94b1..acb132b 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -10,3 +10,4 @@ IUSE=""
RDEPEND="dev-db/sqlite:3"
DEPEND="${RDEPEND}
dev-util/pkgconfig"
+MY_PATCH=ldflags.patch
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 671ae4c..71872a4 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -6,6 +6,7 @@ HOMEPAGE=http://sunpinyin.googlecode.com
IUSE=
KEYWORDS=~amd64 ~x86
LICENSE=LGPL-2.1 CDDL
+MY_PATCH=ldflags.patch
RDEPEND=dev-db/sqlite:3
SLOT=0
SRC_URI=http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-12 18:29 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-12 18:29 UTC (permalink / raw
To: gentoo-commits
commit: 5b7cec85d9adeaee707cb3e74122c70aa96c6518
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 12 07:19:42 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 12:08:11 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=5b7cec85
Implement array element reference for string
Now we can refer an array element as a string value.
---
bashast/libbashWalker.g | 96 ++++++++++++++++++++++++-----------------
scripts/var_def.ebuild | 3 +-
scripts/var_def.ebuild.result | 3 +-
3 files changed, 60 insertions(+), 42 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 33c18a6..1061c3f 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -45,11 +45,23 @@ start: list|EOF;
list: ^(LIST var_def+);
-name returns[std::string libbash_value]:
+name_base returns[std::string libbash_value]:
NAME {$libbash_value = walker->get_string($NAME);}
| LETTER {$libbash_value = walker->get_string($LETTER);}
| '_' {$libbash_value="_";};
+name returns[std::string libbash_value, unsigned index]
+@init {
+ $index = 0;
+}:
+ ^(libbash_name=name_base value=arithmetics){
+ $index = value;
+ $libbash_value = libbash_name;
+ }
+ |libbash_name=name_base{
+ $libbash_value = libbash_name;
+ };
+
num returns[std::string libbash_value]
options{ k=1; }:
DIGIT { $libbash_value = walker->get_string($DIGIT); }
@@ -60,14 +72,14 @@ var_def
std::map<int, std::string> values;
int index = 0;
}:
- ^(EQUALS libbash_name=name libbash_value=word){
+ ^(EQUALS libbash_name=name_base libbash_value=word){
walker->define(libbash_name, libbash_value);
}
- |^(EQUALS libbash_name=name ^(ARRAY (
- (libbash_string=string_expr
- |^(EQUALS value=arithmetics { index = value; } libbash_string=string_expr))
- { values[index++] = libbash_string; })*
- )){
+ |^(EQUALS libbash_name=name_base ^(ARRAY (
+ (libbash_string=string_expr
+ |^(EQUALS value=arithmetics { index = value; } libbash_string=string_expr))
+ { values[index++] = libbash_string; })*
+ )){
walker->define(libbash_name, values);
};
@@ -91,11 +103,15 @@ any_string returns[std::string libbash_value]
any_token=. { $libbash_value = walker->get_string(any_token); };
//Allowable variable names in the variable expansion
-var_name returns[std::string libbash_value]
-@after {
- $libbash_value = walker->get_string($var_name.start);
+var_name returns[std::string libbash_value, unsigned index]
+@init {
+ $var_name.index = 0;
}:
- num|name;
+ libbash_string=num { $libbash_value = libbash_string; }
+ |name {
+ $libbash_value = $name.libbash_value;
+ $index = $name.index;
+ };
var_expansion returns[std::string libbash_value]:
^(USE_DEFAULT var_name libbash_word=word) {
@@ -127,7 +143,7 @@ word returns[std::string libbash_value]:
//variable reference
var_ref returns[std::string libbash_value]:
- ^(VAR_REF libbash_name=name) { $libbash_value = walker->resolve<std::string>(libbash_name); }
+ ^(VAR_REF name) { $libbash_value = walker->resolve<std::string>($name.libbash_value, $name.index); }
|^(VAR_REF libbash_string=var_expansion) { $libbash_value = libbash_string; };
// shell arithmetic
@@ -157,45 +173,45 @@ arithmetics returns[int value]
|^(ARITHMETIC_CONDITION cnd=arithmetics l=arithmetics r=arithmetics){
$value = walker->arithmetic_condition(cnd, l, r);
}
- |^(VAR_REF libbash_name=name) {
- $value = walker->resolve<int>(libbash_name);
+ |^(VAR_REF name) {
+ $value = walker->resolve<int>($name.libbash_value);
}
- |^(PRE_INCR ^(VAR_REF libbash_name=name)){ $value = walker->pre_incr(libbash_name); }
- |^(PRE_DECR ^(VAR_REF libbash_name=name)){ $value = walker->pre_decr(libbash_name); }
- |^(POST_INCR ^(VAR_REF libbash_name=name)){ $value = walker->post_incr(libbash_name); }
- |^(POST_DECR ^(VAR_REF libbash_name=name)){ $value = walker->post_decr(libbash_name); }
- |^(EQUALS libbash_name=name l=arithmetics) {
- $value = walker->set_value(libbash_name, l);
+ |^(PRE_INCR ^(VAR_REF name)){ $value = walker->pre_incr($name.libbash_value); }
+ |^(PRE_DECR ^(VAR_REF name)){ $value = walker->pre_decr($name.libbash_value); }
+ |^(POST_INCR ^(VAR_REF name)){ $value = walker->post_incr($name.libbash_value); }
+ |^(POST_DECR ^(VAR_REF name)){ $value = walker->post_decr($name.libbash_value); }
+ |^(EQUALS name l=arithmetics) {
+ $value = walker->set_value($name.libbash_value, l);
}
- |^(MUL_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::multiply, libbash_name, l);
+ |^(MUL_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::multiply, $name.libbash_value, l);
}
- |^(DIVIDE_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::divide, libbash_name, l);
+ |^(DIVIDE_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::divide, $name.libbash_value, l);
}
- |^(MOD_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::mod, libbash_name, l);
+ |^(MOD_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::mod, $name.libbash_value, l);
}
- |^(PLUS_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::plus, libbash_name, l);
+ |^(PLUS_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::plus, $name.libbash_value, l);
}
- |^(MINUS_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::minus, libbash_name, l);
+ |^(MINUS_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::minus, $name.libbash_value, l);
}
- |^(LSHIFT_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::left_shift, libbash_name, l);
+ |^(LSHIFT_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::left_shift, $name.libbash_value, l);
}
- |^(RSHIFT_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::right_shift, libbash_name, l);
+ |^(RSHIFT_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::right_shift, $name.libbash_value, l);
}
- |^(AND_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::bitwiseand, libbash_name, l);
+ |^(AND_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::bitwiseand, $name.libbash_value, l);
}
- |^(XOR_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::bitwisexor, libbash_name, l);
+ |^(XOR_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::bitwisexor, $name.libbash_value, l);
}
- |^(OR_ASSIGN libbash_name=name l=arithmetics) {
- $value = walker->assign(&interpreter::bitwiseor, libbash_name, l);
+ |^(OR_ASSIGN name l=arithmetics) {
+ $value = walker->assign(&interpreter::bitwiseor, $name.libbash_value, l);
}
| NUMBER { $value = walker->parse_int($NUMBER);}
| DIGIT { $value = walker->parse_int($DIGIT);}
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index 3dfeb80..a621409 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -12,4 +12,5 @@ DEPEND="${RDEPEND}
dev-util/pkgconfig"
MY_PATCH=ldflags.patch
PATCH=("1.patch" 2.patch)
-ARRAY=(1 2 3 [5]=4)
+ARRAY=(1 2 3 [5]=4 5)
+ARRAY_LAST=${ARRAY[6]}
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 3e19cdb..b563a56 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,4 +1,5 @@
-ARRAY=1 2 3 4
+ARRAY=1 2 3 4 5
+ARRAY_LAST=5
DEPEND=dev-db/sqlite:3
dev-util/pkgconfig
DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-14 4:50 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-14 4:50 UTC (permalink / raw
To: gentoo-commits
commit: 9da31d2c884ef0b5af54fc71ab4be1d399ae0d1a
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 13 02:09:24 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 13 08:25:07 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9da31d2c
Implement array element assignment
---
bashast/libbashWalker.g | 4 ++--
scripts/var_def.ebuild | 4 ++++
scripts/var_def.ebuild.result | 2 ++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index ddeffa0..f4fff5d 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -72,8 +72,8 @@ var_def
std::map<int, std::string> values;
int index = 0;
}:
- ^(EQUALS libbash_name=name_base libbash_value=string_expr){
- walker->define(libbash_name, libbash_value);
+ ^(EQUALS name libbash_string=string_expr){
+ walker->set_value($name.libbash_value, libbash_string, $name.index);
}
|^(EQUALS libbash_name=name_base ^(ARRAY (
(libbash_string=string_expr
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index a621409..5d336ee 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -13,4 +13,8 @@ DEPEND="${RDEPEND}
MY_PATCH=ldflags.patch
PATCH=("1.patch" 2.patch)
ARRAY=(1 2 3 [5]=4 5)
+ARRAY2=(1 2 3)
+ARRAY2[2]=4
+ARRAY2[3]=5
ARRAY_LAST=${ARRAY[6]}
+PARTIAL[5]=5
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index b563a56..f288519 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -1,4 +1,5 @@
ARRAY=1 2 3 4 5
+ARRAY2=1 2 4 5
ARRAY_LAST=5
DEPEND=dev-db/sqlite:3
dev-util/pkgconfig
@@ -9,6 +10,7 @@ IUSE=
KEYWORDS=~amd64 ~x86
LICENSE=LGPL-2.1 CDDL
MY_PATCH=ldflags.patch
+PARTIAL=5
PATCH=1.patch 2.patch
RDEPEND=dev-db/sqlite:3
SLOT=0
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-20 14:04 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-20 14:04 UTC (permalink / raw
To: gentoo-commits
commit: a46ef6a3de34ee796cd3274079e6e5b91fd99cfc
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 19 09:14:22 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 20 13:44:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a46ef6a3
Walker: support multiple atoms of string_expr
Expression like "${PN}-${PV}" will be parsed as var_ref, '-',
var_ref. Multiple atoms could not be handled by previous walker
grammar but now it's fixed.
---
bashast/libbashWalker.g | 17 +++++++++--------
scripts/var_def.ebuild | 3 +++
scripts/var_def.ebuild.result | 3 +++
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 182f6c3..b6c9a7f 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -132,18 +132,19 @@ var_def
};
string_expr returns[std::string libbash_value, bool quoted]
- :^(STRING(
+@init {
+ $quoted = true;
+}
+ :^(STRING (
(DOUBLE_QUOTED_STRING) =>
- ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string { $libbash_value += libbash_string; })*) {
- $quoted = true;
- }
+ ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string { $libbash_value += libbash_string; })*)
|(ARITHMETIC_EXPRESSION) =>
^(ARITHMETIC_EXPRESSION value=arithmetics {
- $libbash_value = boost::lexical_cast<std::string>(value); $quoted = false;
+ $libbash_value += boost::lexical_cast<std::string>(value); $quoted = false;
})
- |(var_ref[false]) => libbash_string=var_ref[false] { $libbash_value = libbash_string; $quoted = false; }
- |(libbash_string=any_string { $libbash_value += libbash_string; $quoted = false; })+
- ));
+ |(var_ref[false]) => libbash_string=var_ref[false] { $libbash_value += libbash_string; $quoted = false; }
+ |(libbash_string=any_string { $libbash_value += libbash_string; $quoted = false; })
+ )+);
//double quoted string rule, allows expansions
double_quoted_string returns[std::string libbash_value]
diff --git a/scripts/var_def.ebuild b/scripts/var_def.ebuild
index c93a6de..56f8f8d 100644
--- a/scripts/var_def.ebuild
+++ b/scripts/var_def.ebuild
@@ -32,3 +32,6 @@ ARRAY08="${ARRAY05[@]}"
ARRAY09="${ARRAY05[*]}"
IFS=";,:"
ARRAY10="${ARRAY05[*]}"
+FOO001="networkmanager"
+FOO002="0.8.2"
+FOO003=${FOO001}-${FOO002}
diff --git a/scripts/var_def.ebuild.result b/scripts/var_def.ebuild.result
index 058bd98..292b9c7 100644
--- a/scripts/var_def.ebuild.result
+++ b/scripts/var_def.ebuild.result
@@ -15,6 +15,9 @@ DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
EAPI=1
EMPTY=
EMPTY_ARRAY=
+FOO001=networkmanager
+FOO002=0.8.2
+FOO003=networkmanager-0.8.2
HOMEPAGE=http://sunpinyin.googlecode.com
IUSE=
KEYWORDS=~amd64 ~x86
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-27 15:11 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-27 15:11 UTC (permalink / raw
To: gentoo-commits
commit: cf1db9bbcdd15525359fa96084d04c0e876dea54
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 26 07:05:52 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 27 14:58:45 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=cf1db9bb
Walker: support while loop
---
bashast/libbashWalker.g | 27 ++++++++++++++++++++++++++-
scripts/compound_command.bash | 12 ++++++++++++
scripts/compound_command.bash.result | 6 +++++-
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index c616c88..01c080e 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -321,7 +321,8 @@ command_list: ^(LIST logic_command_list+);
compound_command
: ^(CURRENT_SHELL command_list)
| ^(COMPOUND_COND cond_expr)
- | for_expr;
+ | for_expr
+ | while_expr;
cond_expr
:^(BUILTIN_TEST status=builtin_condition) { walker->set_status(!status); };
@@ -402,6 +403,30 @@ for_condition returns[int libbash_value]
for_modification
:^(FOR_MOD arithmetics);
+while_expr
+@declarations {
+ ANTLR3_MARKER command_index;
+}
+ :^(WHILE {
+ // omit the first DOWN token
+ SEEK(INDEX() + 1);
+
+ command_index = INDEX();
+ while(true)
+ {
+ command_list(ctx);
+ if(walker->get_status())
+ break;
+ command_list(ctx);
+ SEEK(command_index);
+ }
+ // Skip the body and get out
+ seek_to_next_tree(ctx);
+
+ // omit the last UP token
+ SEEK(INDEX() + 1);
+ });
+
command_substitution returns[std::string libbash_value]
@declarations {
std::stringstream out;
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index ad3e4f4..9da53b8 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -22,3 +22,15 @@ for ((;i<0;))
do
echo "Shouldn't print this"
done
+
+i=0;
+while [ $i != 4 ]
+do
+ i=$(( i + 1 ))
+ echo $i
+done
+
+while [ $i \< 0 ]
+do
+ echo "Shouldn't print this"
+done
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index c865c15..b2d305a 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -11,6 +11,10 @@ ghi
8
9
10
+1
+2
+3
+4
file= foo bar
foo=ghi
-i=10
+i=4
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-04-27 15:11 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-04-27 15:11 UTC (permalink / raw
To: gentoo-commits
commit: 67ae08a05b489c31f9df7453eea3ed8446d4f5ae
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 26 10:47:40 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Apr 27 14:58:45 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=67ae08a0
Walker: support until loop
---
bashast/libbashWalker.g | 5 +++--
scripts/compound_command.bash | 12 ++++++++++++
scripts/compound_command.bash.result | 4 ++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 01c080e..8dc0b41 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -406,8 +406,9 @@ for_modification
while_expr
@declarations {
ANTLR3_MARKER command_index;
+ bool negate;
}
- :^(WHILE {
+ :^((WHILE { negate = false; } | UNTIL { negate = true; }) {
// omit the first DOWN token
SEEK(INDEX() + 1);
@@ -415,7 +416,7 @@ while_expr
while(true)
{
command_list(ctx);
- if(walker->get_status())
+ if(walker->get_status() == (negate? 0 : 1))
break;
command_list(ctx);
SEEK(command_index);
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 9da53b8..ad00e63 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -34,3 +34,15 @@ while [ $i \< 0 ]
do
echo "Shouldn't print this"
done
+
+i=0;
+until [ $i == 4 ]
+do
+ i=$(( i + 1 ))
+ echo $i
+done
+
+until [ $i \> 0 ]
+do
+ echo "Shouldn't print this"
+done
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index b2d305a..3e2e9f4 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -15,6 +15,10 @@ ghi
2
3
4
+1
+2
+3
+4
file= foo bar
foo=ghi
i=4
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-06 10:29 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-06 10:29 UTC (permalink / raw
To: gentoo-commits
commit: ea40bc721b3926876dcde99289865c5f023ee0e2
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri May 6 06:50:49 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri May 6 06:54:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ea40bc72
Walker: support logical command list
&& and || operators are supported for command list.
---
bashast/libbashWalker.g | 11 +++++++++--
scripts/command_execution.bash | 5 +++++
scripts/command_execution.bash.result | 3 +++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 203cd28..064556a 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -310,9 +310,16 @@ argument[std::vector<std::string>& args]
};
logic_command_list
+@declarations {
+ bool logic_and;
+}
:command
- |^(LOGICAND command command)
- |^(LOGICOR command command);
+ |^((LOGICAND { logic_and = true; } | LOGICOR { logic_and = false; }) command {
+ if(logic_and ? !walker->get_status() : walker->get_status())
+ command(ctx);
+ else
+ seek_to_next_tree(ctx);
+ });
command_list: ^(LIST logic_command_list+);
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 0f7cd03..3664356 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -8,3 +8,8 @@ true
false
FOO001=$(echo hello)
FOO002=$(hi)
+true && echo "right"
+false && echo "wrong"
+false || echo "right"
+true || echo "wrong"
+echo "end"
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index 4330a65..d9f3021 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -1,4 +1,7 @@
Hello World
hello world
+right
+right
+end
FOO001=hello
FOO002=Hello World
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 3dbf3ca1f5e0884b41844e3dd1fa8538f5c28e5c
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun May 8 11:24:11 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 11 06:45:02 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3dbf3ca1
Walker: first support for basic pattern matching
---
bashast/libbashWalker.g | 93 +++++++++++++++++++++++++++++-----------
scripts/compound_command.bash | 6 +-
2 files changed, 70 insertions(+), 29 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index fb3add0..e328c21 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -27,9 +27,12 @@ options
@includes{
+ #include <memory>
#include <string>
#include <vector>
+ #include <boost/xpressive/xpressive.hpp>
+
class interpreter;
void set_interpreter(interpreter* w);
@@ -86,6 +89,29 @@ options
SEEK(INDEX() + index - 3);
CONSUME();
}
+
+ // The method is used to append a pattern with another one. Because it's not allowed to append an empty pattern,
+ // we need the argument 'do_append' to indicate whether the pattern is empty. 'do_append' will be set to true after
+ // the first assignment.
+ inline void append(boost::xpressive::sregex& pattern, const boost::xpressive::sregex& new_pattern, bool& do_append)
+ {
+ using namespace boost::xpressive;
+ if(do_append)
+ {
+ pattern = sregex(pattern >> new_pattern);
+ }
+ else
+ {
+ pattern = new_pattern;
+ do_append = true;
+ }
+ }
+
+ bool match(const std::string& target,
+ const boost::xpressive::sregex& pattern)
+ {
+ return boost::xpressive::regex_match(target, pattern);
+ }
}
start: list|EOF;
@@ -160,6 +186,27 @@ string_expr returns[std::string libbash_value, bool quoted]
|(libbash_string=any_string { $libbash_value += libbash_string; $quoted = false; })
)+);
+bash_pattern[boost::xpressive::sregex& pattern]
+@declarations {
+ using namespace boost::xpressive;
+ bool do_append = false;
+}
+ :^(STRING (
+ (DOUBLE_QUOTED_STRING) =>
+ ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string {
+ append($pattern, as_xpr(libbash_string), do_append);
+ })*)
+ |(MATCH_ALL) => MATCH_ALL {
+ append($pattern, *_, do_append);
+ }
+ |(MATCH_ONE) => MATCH_ONE {
+ append($pattern, _, do_append);
+ }
+ |(libbash_string=any_string {
+ append($pattern, as_xpr(libbash_string), do_append);
+ })
+ )+);
+
//double quoted string rule, allows expansions
double_quoted_string returns[std::string libbash_value]
:(var_ref[true]) => libbash_string=var_ref[true] { $libbash_value = libbash_string; }
@@ -209,50 +256,50 @@ var_expansion returns[std::string libbash_value]
libbash_value = boost::lexical_cast<std::string>(walker->get_array_length(libbash_name));
}
))
- |^(REPLACE_ALL var_name pattern=string_expr (replacement=string_expr)?) {
+ |^(REPLACE_ALL var_name replace_pattern=string_expr (replacement=string_expr)?) {
libbash_value = walker->do_replace_expansion($var_name.libbash_value,
std::bind(&interpreter::replace_all,
std::placeholders::_1,
- pattern.libbash_value,
+ replace_pattern.libbash_value,
replacement.libbash_value),
$var_name.index);
}
- |^(REPLACE_AT_END var_name pattern=string_expr (replacement=string_expr)?) {
+ |^(REPLACE_AT_END var_name replace_pattern=string_expr (replacement=string_expr)?) {
libbash_value = walker->do_replace_expansion($var_name.libbash_value,
std::bind(&interpreter::replace_at_end,
std::placeholders::_1,
- pattern.libbash_value,
+ replace_pattern.libbash_value,
replacement.libbash_value),
$var_name.index);
}
- |^(REPLACE_AT_START var_name pattern=string_expr (replacement=string_expr)?) {
+ |^(REPLACE_AT_START var_name replace_pattern=string_expr (replacement=string_expr)?) {
libbash_value = walker->do_replace_expansion($var_name.libbash_value,
std::bind(&interpreter::replace_at_start,
std::placeholders::_1,
- pattern.libbash_value,
+ replace_pattern.libbash_value,
replacement.libbash_value),
$var_name.index);
}
- |^(REPLACE_FIRST var_name pattern=string_expr (replacement=string_expr)?) {
+ |^(REPLACE_FIRST var_name replace_pattern=string_expr (replacement=string_expr)?) {
libbash_value = walker->do_replace_expansion($var_name.libbash_value,
std::bind(&interpreter::replace_first,
std::placeholders::_1,
- pattern.libbash_value,
+ replace_pattern.libbash_value,
replacement.libbash_value),
$var_name.index);
}
- |^(LAZY_REMOVE_AT_START var_name pattern=string_expr) {
+ |^(LAZY_REMOVE_AT_START var_name replace_pattern=string_expr) {
libbash_value = walker->do_replace_expansion($var_name.libbash_value,
std::bind(&interpreter::lazy_remove_at_start,
std::placeholders::_1,
- pattern.libbash_value),
+ replace_pattern.libbash_value),
$var_name.index);
}
- |^(LAZY_REMOVE_AT_END var_name pattern=string_expr) {
+ |^(LAZY_REMOVE_AT_END var_name replace_pattern=string_expr) {
libbash_value = walker->do_replace_expansion($var_name.libbash_value,
std::bind(&interpreter::lazy_remove_at_end,
std::placeholders::_1,
- pattern.libbash_value),
+ replace_pattern.libbash_value),
$var_name.index);
};
@@ -524,35 +571,29 @@ case_expr
case_clause[const std::string& target] returns[bool matched]
@declarations {
- std::vector<std::string> patterns;
+ std::vector<boost::xpressive::sregex> patterns;
}
- :^(CASE_PATTERN (libbash_string=case_pattern { patterns.push_back(libbash_string); })+ {
+ :^(CASE_PATTERN ( { patterns.push_back(boost::xpressive::sregex()); } bash_pattern[patterns.back()])+ {
if(LA(1) == CASE_COMMAND)
{
// omit CASE_COMMAND
SEEK(INDEX() + 1);
- matched = false;
+ $matched = false;
+
for(auto iter = patterns.begin(); iter != patterns.end(); ++iter)
{
- // pattern matching should happen here in future
- if(*iter == "*" || *iter == target)
+ if(match(target, *iter))
{
command_list(ctx);
$matched = true;
- }
- else
- {
- seek_to_next_tree(ctx);
+ break;
}
}
+ if(!$matched)
+ seek_to_next_tree(ctx);
}
});
-case_pattern returns[std::string libbash_value]
- :libbash_string=command_substitution { $libbash_value = libbash_string; }
- |(^(STRING MATCH_ALL)) => ^(STRING MATCH_ALL) { $libbash_value = "*"; }
- |string_expr { $libbash_value = $string_expr.libbash_value; };
-
command_substitution returns[std::string libbash_value]
@declarations {
std::stringstream out;
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 6365fbe..b521b77 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -85,13 +85,13 @@ fi
target=123
case $target in
- bcd)
+ 1.3)
echo "Shouldn't print this"
;;
- abc)
+ \d+)
echo "Shouldn't print this"
;;
- 123)
+ 456|1?*|789)
echo yep
;;
123)
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: b7ca45122d791c6a76edf9104f49aea3737ee516
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 9 13:24:15 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 11 06:45:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b7ca4512
Walker: fix a bug in word rule
Inside the word rule, we used arithmetic rule to do variable
reference. But that requires the variable to be integer. Now it's
fixed by adding a variable reference alternative.
---
bashast/libbashWalker.g | 1 +
scripts/compound_command.bash | 1 +
scripts/compound_command.bash.result | 2 +-
3 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index e328c21..16e4624 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -306,6 +306,7 @@ var_expansion returns[std::string libbash_value]
word returns[std::string libbash_value]
:(num) => libbash_string=num { $libbash_value = libbash_string; }
|string_expr { $libbash_value = $string_expr.libbash_value; }
+ |(VAR_REF) => libbash_string=var_ref[false] { $libbash_value = libbash_string; }
|value=arithmetics { $libbash_value = boost::lexical_cast<std::string>(value); };
//variable reference
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index b521b77..1bd7943 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -98,6 +98,7 @@ case $target in
echo "Shouldn't print this"
;;
esac
+target=xyz
case $target in
bcd)
echo "Shouldn't print this"
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 69d693d..08ddf31 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -31,4 +31,4 @@ b=2
file= foo bar
foo=ghi
i=4
-target=123
+target=xyz
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 63ee3c1c1242562685bf78b58a662204bf5e6c42
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 9 10:38:10 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 11 06:46:28 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=63ee3c1c
Walker: support ranged pattern
Patterns like [a-z] and [!0-9] are supported.
---
bashast/libbashWalker.g | 36 +++++++++++++++++++++++++++++----
scripts/compound_command.bash | 25 +++++++++++++++++++++++
scripts/compound_command.bash.result | 5 +++-
3 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 38cd459..c3ef8ac 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -209,6 +209,7 @@ bash_pattern[boost::xpressive::sregex& pattern]
using namespace boost::xpressive;
bool do_append = false;
bool negation;
+ std::string pattern_str;
}
:^(STRING (
(DOUBLE_QUOTED_STRING) =>
@@ -222,13 +223,38 @@ bash_pattern[boost::xpressive::sregex& pattern]
append($pattern, _, do_append);
}
|(MATCH_ANY_EXCEPT|MATCH_PATTERN) =>
- ^((MATCH_ANY_EXCEPT { negation = true; } | MATCH_PATTERN { negation = false;}) s=string_part) {
- if(s.libbash_value.empty())
+ ^((MATCH_ANY_EXCEPT { negation = true; } | MATCH_PATTERN { negation = false; })
+ (s=string_part { pattern_str += s.libbash_value; })+) {
+ if(pattern_str.empty())
return;
- auto char_set = set = as_xpr(s.libbash_value[0]);
- for(auto iter = s.libbash_value.begin() + 1; iter != s.libbash_value.end(); ++iter)
- char_set = (char_set | *iter);
+ // deal with the first character specially
+ int index = 0;
+ auto char_set = set = as_xpr(pattern_str[0]);
+ if( index + 1 < pattern_str.size() && pattern_str[index + 1] == '-')
+ {
+ char_set = set[range(pattern_str[index], pattern_str[index + 2])];
+ index += 3;
+ }
+ else
+ {
+ ++index;
+ }
+
+ // handle all characters in the pattern
+ while(index < pattern_str.size())
+ {
+ if( index + 1 < pattern_str.size() && pattern_str[index + 1] == '-')
+ {
+ char_set |= range(pattern_str[index], pattern_str[index + 2]);
+ index += 3;
+ }
+ else
+ {
+ char_set |= pattern_str[index];
+ ++index;
+ }
+ }
if(negation)
append($pattern, ~char_set, do_append);
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 3a3c5d8..a75898f 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -135,4 +135,29 @@ case $target in
echo yep
;;
esac
+case $target in
+ [d-z])
+ echo "Shouldn't print this"
+ ;;
+ [a-c])
+ echo yep
+ ;;
+esac
+case $target in
+ [!a-c])
+ echo "Shouldn't print this"
+ ;;
+ [!d-z])
+ echo yep
+ ;;
+esac
+target=bar
+case $target in
+ a[a-cx-z]r)
+ echo "Shouldn't print this"
+ ;;
+ b[!d-fx-z]r)
+ echo yep
+ ;;
+esac
echo "case end"
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 1ee0f91..255c8eb 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -28,10 +28,13 @@ default
yep
yep
yep
+yep
+yep
+yep
case end
a=1
b=2
file= foo bar
foo=ghi
i=4
-target=a
+target=bar
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-11 7:19 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-11 7:19 UTC (permalink / raw
To: gentoo-commits
commit: 99716ee225f60d40dfb1a49be840c0abe3557c00
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 9 08:10:54 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 11 06:45:15 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=99716ee2
Walker: support MATCH_ANY_EXCEPT and MATCH_PATTERN
Patterns like [abc] and [!abc] are supported now.
---
bashast/libbashWalker.g | 51 ++++++++++++++++++++++++++++------
scripts/compound_command.bash | 25 ++++++++++++++++
scripts/compound_command.bash.result | 5 ++-
3 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 16e4624..38cd459 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -175,21 +175,40 @@ string_expr returns[std::string libbash_value, bool quoted]
$quoted = true;
}
:^(STRING (
- (DOUBLE_QUOTED_STRING) =>
- ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string { $libbash_value += libbash_string; })*)
- |(ARITHMETIC_EXPRESSION) =>
- ^(ARITHMETIC_EXPRESSION value=arithmetics {
- $libbash_value += boost::lexical_cast<std::string>(value); $quoted = false;
- })
- |(var_ref[false]) => libbash_string=var_ref[false] { $libbash_value += libbash_string; $quoted = false; }
- |libbash_string=command_substitution { $libbash_value += libbash_string; $quoted = false; }
- |(libbash_string=any_string { $libbash_value += libbash_string; $quoted = false; })
+ string_part {
+ $libbash_value += $string_part.libbash_value;
+ $quoted = $string_part.quoted;
+ }
)+);
+string_part returns[std::string libbash_value, bool quoted]
+@init {
+ $quoted = false;
+}
+ :(DOUBLE_QUOTED_STRING) =>
+ ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string {
+ $libbash_value += libbash_string;
+ $quoted = true;
+ })*)
+ |(ARITHMETIC_EXPRESSION) =>
+ ^(ARITHMETIC_EXPRESSION value=arithmetics {
+ $libbash_value = boost::lexical_cast<std::string>(value);
+ })
+ |(var_ref[false]) => libbash_string=var_ref[false] {
+ $libbash_value = libbash_string;
+ }
+ |libbash_string=command_substitution {
+ $libbash_value = libbash_string;
+ }
+ |(libbash_string=any_string {
+ $libbash_value = libbash_string;
+ });
+
bash_pattern[boost::xpressive::sregex& pattern]
@declarations {
using namespace boost::xpressive;
bool do_append = false;
+ bool negation;
}
:^(STRING (
(DOUBLE_QUOTED_STRING) =>
@@ -202,6 +221,20 @@ bash_pattern[boost::xpressive::sregex& pattern]
|(MATCH_ONE) => MATCH_ONE {
append($pattern, _, do_append);
}
+ |(MATCH_ANY_EXCEPT|MATCH_PATTERN) =>
+ ^((MATCH_ANY_EXCEPT { negation = true; } | MATCH_PATTERN { negation = false;}) s=string_part) {
+ if(s.libbash_value.empty())
+ return;
+
+ auto char_set = set = as_xpr(s.libbash_value[0]);
+ for(auto iter = s.libbash_value.begin() + 1; iter != s.libbash_value.end(); ++iter)
+ char_set = (char_set | *iter);
+
+ if(negation)
+ append($pattern, ~char_set, do_append);
+ else
+ append($pattern, char_set, do_append);
+ }
|(libbash_string=any_string {
append($pattern, as_xpr(libbash_string), do_append);
})
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 1bd7943..3a3c5d8 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -110,4 +110,29 @@ case $target in
echo "default"
;;
esac
+target=a
+case $target in
+ [def])
+ echo "Shouldn't print this"
+ ;;
+ [abc])
+ echo yep
+ ;;
+esac
+case $target in
+ [def])
+ echo "Shouldn't print this"
+ ;;
+ [a])
+ echo yep
+ ;;
+esac
+case $target in
+ [!abc])
+ echo "Shouldn't print this"
+ ;;
+ [!def])
+ echo yep
+ ;;
+esac
echo "case end"
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 08ddf31..1ee0f91 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -25,10 +25,13 @@ ghi
1
yep
default
+yep
+yep
+yep
case end
a=1
b=2
file= foo bar
foo=ghi
i=4
-target=xyz
+target=a
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-12 14:06 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-12 14:06 UTC (permalink / raw
To: gentoo-commits
commit: a546d315659f98c4942488e305f799e747f28337
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu May 12 10:24:44 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu May 12 14:28:23 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a546d315
Walker: first support for extended pattern matching
?(pattern-list), *(pattern-list), +(pattern-list), @(pattern-list)
are supported now.
---
bashast/libbashWalker.g | 115 +++++++++++++++++++++++++++----------
scripts/var_expansion.bash | 12 ++++
scripts/var_expansion.bash.result | 12 ++++
3 files changed, 108 insertions(+), 31 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 407c8b6..5b22e7a 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -208,47 +208,100 @@ bash_pattern[boost::xpressive::sregex& pattern, bool greedy]
@declarations {
using namespace boost::xpressive;
bool do_append = false;
- bool negation;
- std::string pattern_str;
+ sregex pattern_list;
}
:^(STRING (
- (DOUBLE_QUOTED_STRING) =>
- ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string {
- append($pattern, as_xpr(libbash_string), do_append);
- })*)
- |(MATCH_ALL) => MATCH_ALL {
+ (EXTENDED_MATCH_AT_MOST_ONE) => ^(EXTENDED_MATCH_AT_MOST_ONE composite_pattern[pattern_list, $greedy]) {
if($greedy)
- append($pattern, *_, do_append);
+ append($pattern, !sregex(pattern_list), do_append);
else
- append($pattern, -*_, do_append);
+ append($pattern, -!sregex(pattern_list), do_append);
}
- |(MATCH_ONE) => MATCH_ONE {
- append($pattern, _, do_append);
+ |(EXTENDED_MATCH_ANY) => ^(EXTENDED_MATCH_ANY composite_pattern[pattern_list, $greedy]) {
+ if($greedy)
+ append($pattern, *sregex(pattern_list), do_append);
+ else
+ append($pattern, -*sregex(pattern_list), do_append);
}
- |(MATCH_ANY_EXCEPT|MATCH_ANY) =>
- ^((MATCH_ANY_EXCEPT { negation = true; } | MATCH_ANY { negation = false; })
- ((CHARACTER_CLASS) => ^(CHARACTER_CLASS n=NAME) {
- std::string class_name = walker->get_string(n);
- if(class_name == "word")
- pattern_str += "A-Za-z0-9_";
- else if(class_name == "ascii")
- pattern_str += "\\x00-\\x7F";
- else
- pattern_str += "[:" + class_name + ":]";
- }
- |s=string_part { pattern_str += s.libbash_value; })+) {
+ |(EXTENDED_MATCH_AT_LEAST_ONE) => ^(EXTENDED_MATCH_AT_LEAST_ONE composite_pattern[pattern_list, $greedy]) {
+ if($greedy)
+ append($pattern, +sregex(pattern_list), do_append);
+ else
+ append($pattern, -+sregex(pattern_list), do_append);
+ }
+ // We don't have to do anything for the following rule
+ |(EXTENDED_MATCH_EXACTLY_ONE) => ^(EXTENDED_MATCH_EXACTLY_ONE composite_pattern[pattern_list, $greedy]) {
+ append($pattern, pattern_list, do_append);
+ }
+ |(EXTENDED_MATCH_NONE) => ^(EXTENDED_MATCH_NONE composite_pattern[pattern_list, $greedy]) {
+ throw interpreter_exception("!(blah) is not supported for now");
+ }
+ |basic_pattern[$pattern, $greedy, do_append])+);
- if(negation)
- pattern_str = "[^" + pattern_str + "]";
+composite_pattern[boost::xpressive::sregex& pattern_list, bool greedy]
+@declarations {
+ using namespace boost::xpressive;
+ bool do_append = false;
+ bool do_sub_append = false;
+ sregex sub_pattern;
+}
+ :(^(STRING
+ (basic_pattern[sub_pattern, $greedy, do_sub_append]{
+ if(do_append)
+ {
+ $pattern_list = sregex($pattern_list | sub_pattern);
+ }
else
- pattern_str = "[" + pattern_str + "]";
+ {
+ $pattern_list = sub_pattern;
+ do_append = true;
+ }
+ do_sub_append = false;
+ })+
+ ))+;
- append($pattern, sregex::compile(pattern_str), do_append);
- }
- |(libbash_string=any_string {
+basic_pattern[boost::xpressive::sregex& pattern, bool greedy, bool& do_append]
+@declarations {
+ using namespace boost::xpressive;
+ bool negation;
+ std::string pattern_str;
+}
+ :(DOUBLE_QUOTED_STRING) =>
+ ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string {
append($pattern, as_xpr(libbash_string), do_append);
- })
- )+);
+ })*)
+ |(MATCH_ALL) => MATCH_ALL {
+ if($greedy)
+ append($pattern, *_, do_append);
+ else
+ append($pattern, -*_, do_append);
+ }
+ |(MATCH_ONE) => MATCH_ONE {
+ append($pattern, _, do_append);
+ }
+ |(MATCH_ANY_EXCEPT|MATCH_ANY) =>
+ ^((MATCH_ANY_EXCEPT { negation = true; } | MATCH_ANY { negation = false; })
+ ((CHARACTER_CLASS) => ^(CHARACTER_CLASS n=NAME) {
+ std::string class_name = walker->get_string(n);
+ if(class_name == "word")
+ pattern_str += "A-Za-z0-9_";
+ else if(class_name == "ascii")
+ pattern_str += "\\x00-\\x7F";
+ else
+ pattern_str += "[:" + class_name + ":]";
+ }
+ |s=string_part { pattern_str += s.libbash_value; })+) {
+
+ if(negation)
+ pattern_str = "[^" + pattern_str + "]";
+ else
+ pattern_str = "[" + pattern_str + "]";
+
+ append($pattern, sregex::compile(pattern_str), do_append);
+ }
+ |(libbash_string=any_string {
+ append($pattern, as_xpr(libbash_string), do_append);
+ });
//double quoted string rule, allows expansions
double_quoted_string returns[std::string libbash_value]
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 7a371b3..8db702d 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -70,3 +70,15 @@ FOO068=${FOO039/#He/he}
FOO069=${FOO039/#ello/i}
FOO070=${FOO039/%ld/d}
FOO071=${FOO039/%rl/r}
+FOO072=${FOO039/+(l)}
+FOO073=${FOO039/+(l|e)}
+FOO074=${FOO039/*(l)}
+FOO075=${FOO039//*(l)}
+FOO076=${FOO039//*(l|e)}
+FOO077=${FOO039/?(l)}
+FOO078=${FOO039//?(l)}
+FOO079=${FOO039//?(l|e|o)}
+FOO080=${FOO039/@([a-c]|[k-m])}
+FOO081=${FOO039//@([a-c]|[k-m])}
+target="abc123abc"
+FOO082="${target##+(ab[c])*([[:digit:]])}"
diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
index a1fe905..c01e769 100644
--- a/scripts/var_expansion.bash.result
+++ b/scripts/var_expansion.bash.result
@@ -72,3 +72,15 @@ FOO068=hello World
FOO069=Hello World
FOO070=Hello Word
FOO071=Hello World
+FOO072=Heo World
+FOO073=Ho World
+FOO074=Hello World
+FOO075=Heo Word
+FOO076=Ho Word
+FOO077=Hello World
+FOO078=Heo Word
+FOO079=H Wrd
+FOO080=Helo World
+FOO081=Heo Word
+FOO082=abc
+target=abc123abc
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-12 14:06 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-12 14:06 UTC (permalink / raw
To: gentoo-commits
commit: 82268e958be9caee5d9e71d14d27d0d25fd36ee6
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed May 11 13:46:14 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 11 13:48:05 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=82268e95
Walker: support character class in patterns
---
bashast/libbashWalker.g | 11 ++++++++++-
scripts/compound_command.bash | 18 ++++++++++++++++++
scripts/compound_command.bash.result | 5 ++++-
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 6c9e0c1..407c8b6 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -227,7 +227,16 @@ bash_pattern[boost::xpressive::sregex& pattern, bool greedy]
}
|(MATCH_ANY_EXCEPT|MATCH_ANY) =>
^((MATCH_ANY_EXCEPT { negation = true; } | MATCH_ANY { negation = false; })
- (s=string_part { pattern_str += s.libbash_value; })+) {
+ ((CHARACTER_CLASS) => ^(CHARACTER_CLASS n=NAME) {
+ std::string class_name = walker->get_string(n);
+ if(class_name == "word")
+ pattern_str += "A-Za-z0-9_";
+ else if(class_name == "ascii")
+ pattern_str += "\\x00-\\x7F";
+ else
+ pattern_str += "[:" + class_name + ":]";
+ }
+ |s=string_part { pattern_str += s.libbash_value; })+) {
if(negation)
pattern_str = "[^" + pattern_str + "]";
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index a75898f..daeef24 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -160,4 +160,22 @@ case $target in
echo yep
;;
esac
+target="a"
+case $target in
+ [[:alnum:][:alpha:][:ascii:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:word:][:xdigit:]])
+ echo yep
+ ;;
+esac
+target="a"
+case $target in
+ [[:ascii:]])
+ echo yep
+ ;;
+esac
+target="_"
+case $target in
+ [[:word:]])
+ echo yep
+ ;;
+esac
echo "case end"
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 255c8eb..2a23d0c 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -31,10 +31,13 @@ yep
yep
yep
yep
+yep
+yep
+yep
case end
a=1
b=2
file= foo bar
foo=ghi
i=4
-target=bar
+target=_
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-22 21:00 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-22 21:00 UTC (permalink / raw
To: gentoo-commits
commit: 31ee5e693a535e3c16d7e7bfca9d57fc3bca2d53
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 16 12:54:07 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 22 16:16:28 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=31ee5e69
Walker: first support for keyword test
Keyword test that doesn't involve "-x" operators are supported now.
Pattern matching inside the keyword test is not supported for now.
---
bashast/libbashWalker.g | 38 +++++++++++++++++++++++++++++++-------
scripts/test_expr.bash | 11 +++++++++++
scripts/test_expr.bash.result | 9 +++++++++
3 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index bd87ee8..a341109 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -503,20 +503,44 @@ compound_command
| case_expr;
cond_expr
- :^(BUILTIN_TEST status=builtin_condition) { walker->set_status(!status); };
+ :^(BUILTIN_TEST status=builtin_condition) { walker->set_status(!status); }
+ |^(KEYWORD_TEST status=keyword_condition) { walker->set_status(!status); };
+
+common_condition returns[bool status]
+ // -eq, -ne, -lt, -le, -gt, or -ge for arithmetic. -nt -ot -ef for files
+ :^(NAME left_str=string_expr right_str=string_expr)
+ // -o for shell option, -z -n for string, -abcdefghkprstuwxOGLSN for files
+ |^(LETTER string_expr)
+ // We do not trigger pattern matching for now
+ |^((EQUALS|MATCH_PATTERN) left_str=string_expr right_str=string_expr) {
+ $status = left_str.libbash_value == right_str.libbash_value;
+ }
+ // We do not trigger pattern matching for now
+ |^((NOT_EQUALS|NOT_MATCH_PATTERN) left_str=string_expr right_str=string_expr) {
+ $status = left_str.libbash_value != right_str.libbash_value;
+ }
+ |^(LESS_THAN left_str=string_expr right_str=string_expr) {
+ $status = left_str.libbash_value < right_str.libbash_value;
+ }
+ |^(GREATER_THAN left_str=string_expr right_str=string_expr) {
+ $status = left_str.libbash_value > right_str.libbash_value;
+ }
+ |string_expr { $status = (!$string_expr.libbash_value.empty()); };
+
+keyword_condition returns[bool status]
+ :^(LOGICOR l=keyword_condition r=keyword_condition) { $status= l || r; }
+ |^(LOGICAND l=keyword_condition r=keyword_condition) { $status= l && r; }
+ |^(NEGATION l=keyword_condition) { $status = !l; }
+ |s=common_condition { $status = s; };
builtin_condition returns[bool status]
:^(NEGATION l=builtin_condition) { $status = !l; }
|s=builtin_condition_primary { $status = s; };
builtin_condition_primary returns[bool status]
- :^(NAME string_expr string_expr) { throw interpreter_exception(walker->get_string($NAME) + "(NAME) is not supported for now");}
- |^(EQUALS l=string_expr r=string_expr) { $status = (l.libbash_value == r.libbash_value); }
- |^(NOT_EQUALS l=string_expr r=string_expr) { $status = (l.libbash_value != r.libbash_value); }
- |^(ESC_LT l=string_expr r=string_expr) { $status = (l.libbash_value < r.libbash_value); }
+ :^(ESC_LT l=string_expr r=string_expr) { $status = (l.libbash_value < r.libbash_value); }
|^(ESC_GT l=string_expr r=string_expr) { $status = (l.libbash_value > r.libbash_value); }
- |^(LETTER l=string_expr) { throw interpreter_exception(walker->get_string($LETTER) + "(LETTER) is not supported for now");}
- |string_expr { $status = ($string_expr.libbash_value.size() != 0); };
+ |s=common_condition { $status = s; };
for_expr
@declarations {
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index 95acd36..1c63998 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -24,3 +24,14 @@ echo $? # 1
echo $? # 1
[ abc \< bcd ]
echo $? # 0
+[[ abc ]] && echo true1
+[[ abc < bcd ]] && echo true2
+[[ abc > bcd ]] || echo true3
+[[ abc != bcd ]] && echo true4
+[[ abc = bcd ]] || echo true5
+[[ abc == abc ]] && echo true6
+[[ ! abc = bcd ]] && echo true7
+[[ abc = bcd || abc == abc ]] && echo true8
+[[ abc = bcd && abc == abc ]] || echo true9
+# abc=bcd is treated as a simple string
+[[ abc=bcd && abc == abc ]] || echo wrong
diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.result
index ff52ae4..63aaa92 100644
--- a/scripts/test_expr.bash.result
+++ b/scripts/test_expr.bash.result
@@ -7,3 +7,12 @@
1
1
0
+true1
+true2
+true3
+true4
+true5
+true6
+true7
+true8
+true9
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-23 14:39 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-23 14:39 UTC (permalink / raw
To: gentoo-commits
commit: ee81417cdac313a5e44d6064be3152301951acd2
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon May 23 13:54:03 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 14:34:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ee81417c
Parser: support variable appending
Array appending is not supported for now.
---
bashast/bashast.g | 3 ++-
scripts/var_def.bash | 2 ++
scripts/var_def.bash.result | 1 +
3 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 693ee96..b5b133e 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -241,7 +241,8 @@ cond_comparison
//It's not legal to do FOO[1]=(a b c)
var_def
: name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS fname? -> ^(EQUALS ^(name explicit_arithmetic) fname?)
- | name EQUALS^ value?;
+ | name EQUALS^ 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!;
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index 9b27dc3..f832a96 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -41,3 +41,5 @@ FOO004=$#
FOO004=$?
FOO004=$-
FOO004=$!
+FOO005=abc
+FOO005+=def
diff --git a/scripts/var_def.bash.result b/scripts/var_def.bash.result
index ba1a44e..121c267 100644
--- a/scripts/var_def.bash.result
+++ b/scripts/var_def.bash.result
@@ -23,6 +23,7 @@ FOO001=networkmanager
FOO002=0.8.2
FOO003=networkmanager-0.8.2
FOO004=
+FOO005=abcdef
HOMEPAGE=http://sunpinyin.googlecode.com
IUSE=
KEYWORDS=~amd64 ~x86
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-24 14:50 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-24 14:50 UTC (permalink / raw
To: gentoo-commits
commit: 48e0205899383f4b3b1cea6b7fc367cef8341caf
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun May 22 13:52:33 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 15:16:51 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=48e02058
Walker: accept some bash redirection syntax
Some bash redirection syntax is allowed now. No actual logic is
implemented for them.
---
bashast/libbashWalker.g | 18 +++++++++++++++++-
scripts/command_execution.bash | 1 +
scripts/command_execution.bash.result | 1 +
3 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 0663d1e..baabdfe 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -446,7 +446,7 @@ execute_command[const std::string& name, std::vector<std::string>& libbash_args]
@declarations {
interpreter::local_scope current_scope(*walker);
}
- :var_def[true]* {
+ :var_def[true]* redirect* {
if(walker->has_function(name))
{
ANTLR3_MARKER command_index = INDEX();
@@ -474,6 +474,22 @@ execute_command[const std::string& name, std::vector<std::string>& libbash_args]
}
(BANG { walker->set_status(!walker->get_status()); })?;
+redirect
+ :^(REDIR redirect_operator redirect_destination) {
+ std::cerr << "Redirection is not supported yet" << std::endl;
+ };
+
+redirect_destination
+ :DIGIT MINUS?
+ |string_expr //path to a file
+ |FILE_DESCRIPTOR
+ |FILE_DESCRIPTOR_MOVE;
+
+redirect_operator
+ :LESS_THAN
+ |GREATER_THAN
+ |DIGIT redirect_operator;
+
argument[std::vector<std::string>& args]
: string_expr {
if($string_expr.quoted)
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 37cce6e..344618e 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -16,3 +16,4 @@ true || echo "wrong"
echo "end"
: ${DEFAULTED:="yes"}
FOO="abc" echo "command environment"
+true > /dev/null
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index 7ee093d..bd09a8b 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -4,6 +4,7 @@ right
right
end
command environment
+Redirection is not supported yet
DEFAULTED=yes
FOO001=hello
FOO002=Hello World
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-24 14:50 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-24 14:50 UTC (permalink / raw
To: gentoo-commits
commit: 8062053b59ad806fa327bb9dcb06f69acdadc6b7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun May 22 13:42:35 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 22 13:42:35 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=8062053b
Walker: support negation in command execution
Syntax like "! true" is supported now.
---
bashast/libbashWalker.g | 3 ++-
scripts/command_execution.bash | 1 +
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index bd87ee8..b760f74 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -470,7 +470,8 @@ execute_command[const std::string& name, std::vector<std::string>& libbash_args]
std::cerr << name << " is not supported yet" << std::endl;
walker->set_status(1);
}
- };
+ }
+ (BANG { walker->set_status(!walker->get_status()); })?;
argument[std::vector<std::string>& args]
: string_expr {
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 9e1901c..37cce6e 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -10,6 +10,7 @@ FOO001=$(echo hello)
FOO002=$(hi)
true && echo "right"
false && echo "wrong"
+! true && echo "wrong"
false || echo "right"
true || echo "wrong"
echo "end"
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-24 14:50 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-24 14:50 UTC (permalink / raw
To: gentoo-commits
commit: 4f707ab4ec05da9c311b28fb4aeb07a345f8ef28
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun May 22 13:48:02 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 15:16:50 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4f707ab4
Walker: support function def in compound statement
Now we can declare functions inside compound statement. The rule
is renamed for better consistency.
---
bashast/libbashWalker.g | 5 +++--
scripts/function_def.bash | 12 ++++++++++++
scripts/function_def.bash.result | 1 +
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index b760f74..0663d1e 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -116,7 +116,7 @@ options
start: list|EOF;
-list: ^(LIST (function_def|logic_command_list)+);
+list: ^(LIST (logic_command_list)+);
variable_definitions
@declarations {
@@ -432,6 +432,7 @@ var_ref [bool double_quoted] returns[std::string libbash_value]
command
:variable_definitions
+ |function_definition
|simple_command
|compound_command;
@@ -710,7 +711,7 @@ command_substitution returns[std::string libbash_value]
walker->trim_trailing_eols($libbash_value);
};
-function_def returns[int placeholder]
+function_definition returns[int placeholder]
:^(FUNCTION ^(STRING name) {
// Define the function with current index
walker->define_function($name.libbash_value, INDEX());
diff --git a/scripts/function_def.bash b/scripts/function_def.bash
index bcf5a4b..101e732 100644
--- a/scripts/function_def.bash
+++ b/scripts/function_def.bash
@@ -52,3 +52,15 @@ func_nested2() {
func_nested1
}
func_nested2
+
+if true; then
+ function_in_compound_statement() {
+ echo "function_in_compound_statement"
+ }
+fi
+if false; then
+ function_in_compound_statement() {
+ echo "I should not get called"
+ }
+fi
+function_in_compound_statement
diff --git a/scripts/function_def.bash.result b/scripts/function_def.bash.result
index 2c5783c..a1c9b91 100644
--- a/scripts/function_def.bash.result
+++ b/scripts/function_def.bash.result
@@ -1,4 +1,5 @@
hi 1
+function_in_compound_statement
ARG1=100
ARG2=2
ARG3=3
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-28 13:11 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-28 13:11 UTC (permalink / raw
To: gentoo-commits
commit: a316f3d632b98ade273420121947c9cc51d6be98
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat May 28 07:57:25 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat May 28 08:27:16 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a316f3d6
Walker: support single quoted string
Single quoted string is supported in string expression and basic
pattern matching.
---
bashast/libbashWalker.g | 17 +++++++++--------
scripts/command_execution.bash | 1 +
scripts/command_execution.bash.result | 1 +
scripts/var_expansion.bash | 4 ++++
scripts/var_expansion.bash.result | 5 ++++-
5 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 378d5e5..67886a0 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -191,6 +191,11 @@ string_part returns[std::string libbash_value, bool quoted]
$libbash_value += libbash_string;
$quoted = true;
})*)
+ |(SINGLE_QUOTED_STRING) =>
+ ^(SINGLE_QUOTED_STRING (libbash_string=any_string {
+ $libbash_value += libbash_string;
+ $quoted = true;
+ })*)
|(ARITHMETIC_EXPRESSION) =>
^(ARITHMETIC_EXPRESSION value=arithmetics {
$libbash_value = boost::lexical_cast<std::string>(value);
@@ -276,11 +281,7 @@ basic_pattern[boost::xpressive::sregex& pattern, bool greedy, bool& do_append]
bool negation;
std::string pattern_str;
}
- :(DOUBLE_QUOTED_STRING) =>
- ^(DOUBLE_QUOTED_STRING (libbash_string=double_quoted_string {
- append($pattern, as_xpr(libbash_string), do_append);
- })*)
- |(MATCH_ALL) => MATCH_ALL {
+ :(MATCH_ALL) => MATCH_ALL {
if($greedy)
append($pattern, *_, do_append);
else
@@ -309,9 +310,9 @@ basic_pattern[boost::xpressive::sregex& pattern, bool greedy, bool& do_append]
append($pattern, sregex::compile(pattern_str), do_append);
}
- |(libbash_string=any_string {
- append($pattern, as_xpr(libbash_string), do_append);
- });
+ |string_part {
+ append($pattern, as_xpr($string_part.libbash_value), do_append);
+ };
//double quoted string rule, allows expansions
double_quoted_string returns[std::string libbash_value]
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index b1670f2..b9b1c82 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -43,3 +43,4 @@ echo "FOO006=$FOO006 in global"
declare -F unset_outer
unset -f unset_outer
declare -F unset_outer
+echo '$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...'
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index d941a6d..d7642f5 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -13,6 +13,7 @@ FOO006= in global
FOO006=0 in global
FOO006= in global
unset_outer
+$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...
DEFAULTED=yes
FOO001=hello
FOO002=Hello World
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 0a84737..1419686 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -92,3 +92,7 @@ function positional_parameter_test(){
FOO088=${*:0}
}
positional_parameter_test 1 2 3 4 5
+target="abc*abc"
+echo ${target/*}
+echo ${target/'*'}
+echo ${target/"*"}
diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
index 5ec7c65..dac4d8e 100644
--- a/scripts/var_expansion.bash.result
+++ b/scripts/var_expansion.bash.result
@@ -1,3 +1,6 @@
+
+abcabc
+abcabc
ARRAY=hi hello 1 2 3
ARRAY2=hello
EAPI=3
@@ -89,4 +92,4 @@ FOO085=1 2
FOO086=5
FOO087=4 5
FOO088=filename 1 2 3 4 5
-target=abc123abc
+target=abc*abc
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-28 13:11 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-28 13:11 UTC (permalink / raw
To: gentoo-commits
commit: 1434467973035473d51ad3f8c0955e363fc0df17
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat May 28 08:19:29 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat May 28 12:10:25 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=14344679
Walker: support command substitution in double quoted string
---
bashast/libbashWalker.g | 3 +++
scripts/command_execution.bash | 2 ++
scripts/command_execution.bash.result | 2 ++
3 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 67886a0..d5522fc 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -320,6 +320,9 @@ double_quoted_string returns[std::string libbash_value]
|(ARITHMETIC_EXPRESSION) => ^(ARITHMETIC_EXPRESSION value=arithmetics) {
$libbash_value = boost::lexical_cast<std::string>(value);
}
+ |libbash_string=command_substitution {
+ $libbash_value = libbash_string;
+ }
|libbash_string=any_string { $libbash_value = libbash_string; };
any_string returns[std::string libbash_value]
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index b9b1c82..95401b4 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -44,3 +44,5 @@ declare -F unset_outer
unset -f unset_outer
declare -F unset_outer
echo '$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...'
+echo "abc $(echo def) ghi"
+FOO008="abc $(echo def) ghi"
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index d7642f5..d47650d 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -14,9 +14,11 @@ FOO006=0 in global
FOO006= in global
unset_outer
$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...
+abc def ghi
DEFAULTED=yes
FOO001=hello
FOO002=Hello World
FOO003=1
FOO004=abc
FOO005=1 2 3
+FOO008=abc def ghi
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-29 11:20 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-29 11:20 UTC (permalink / raw
To: gentoo-commits
commit: 4fbd4e219d4c36de28036e02ba616d7faa43e066
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri May 27 13:44:07 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 29 11:44:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4fbd4e21
Walker: support continue in for loop
A bug in seek_to_next_tree is fixed. This bug can only be reproduced
by c-style for loop. It prevents the c-style for loop from working
properly when a modification statement is specified.
---
bashast/libbashWalker.g | 53 ++++++++++++++++++++++++++++------
scripts/compound_command.bash | 19 ++++++++++++
scripts/compound_command.bash.result | 8 ++++-
3 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index d5522fc..39b84c5 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -71,12 +71,13 @@ options
// seek to LT(2) and consume
static void seek_to_next_tree(plibbashWalker ctx)
{
- // We start from LA(1)
- int index = 1;
// Current depth of the tree we are traversing
int depth = 1;
- for(index = 1; depth != 0; ++index)
+ // The beginning should always be ROOT DOWN ANY_TOKEN
+ // So we start from LA(4)
+ int index = 4;
+ for(; depth != 0; ++index)
{
// Go one level done if we encounter DOWN
if(LA(index) == DOWN)
@@ -87,7 +88,7 @@ options
}
// Seek to the correct offset and consume.
- SEEK(INDEX() + index - 3);
+ SEEK(INDEX() + index - 2);
CONSUME();
}
@@ -614,7 +615,15 @@ for_expr
{
SEEK(commands_index);
walker->set_value(libbash_string, *iter);
- command_list(ctx);
+ try
+ {
+ command_list(ctx);
+ }
+ catch(continue_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+ continue;
+ }
}
})
|^(CFOR {
@@ -625,11 +634,37 @@ for_expr
for_initilization(ctx);
condition_index = INDEX();
- bool has_condition = (LA(1) != FOR_COND);
- while(has_condition || for_condition(ctx))
+ bool has_condition = (LA(1) == FOR_COND);
+
+ if(has_condition)
+ seek_to_next_tree(ctx);
+ // before the body
+ seek_to_next_tree(ctx);
+ bool has_modification = (LA(1) == FOR_MOD);
+ ANTLR3_MARKER modification_index = INDEX();
+
+ SEEK(condition_index);
+
+ while(!has_condition || for_condition(ctx))
{
- command_list(ctx);
- if(LA(1) == FOR_MOD)
+ try
+ {
+ command_list(ctx);
+ }
+ catch(continue_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+
+ if(has_modification)
+ {
+ SEEK(modification_index);
+ for_modification(ctx);
+ }
+
+ SEEK(condition_index);
+ continue;
+ }
+ if(has_modification)
for_modification(ctx);
SEEK(condition_index);
}
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index daeef24..bb7961c 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -23,6 +23,25 @@ do
echo "Shouldn't print this"
done
+for file in foo bar
+do
+ if [[ $file == "foo" ]]; then
+ continue
+ fi
+ echo $file
+done
+
+for outer in 1 2 3
+do
+ for file in foo bar
+ do
+ if [[ $file == "foo" && $outer == 1 ]]; then
+ continue 2
+ fi
+ echo "$outer $file"
+ done
+done
+
i=0;
while [ $i != 4 ]
do
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 2a23d0c..6014421 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -11,6 +11,11 @@ ghi
8
9
10
+bar
+2 foo
+2 bar
+3 foo
+3 bar
1
2
3
@@ -37,7 +42,8 @@ yep
case end
a=1
b=2
-file= foo bar
+file=bar
foo=ghi
i=4
+outer=3
target=_
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-29 11:20 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-29 11:20 UTC (permalink / raw
To: gentoo-commits
commit: c3356056896f2fab67e11cf4b4165487b6832211
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat May 28 15:59:20 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 29 11:44:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c3356056
Walker: use any_string for function name
The name rule doesn't cover all the possible characters in function
names. As we've already validated the function name in parser grammar,
the any_string rule is sufficient to match the function name.
---
bashast/libbashWalker.g | 8 ++++++--
scripts/function_def.bash | 8 ++++----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 5c8c371..e61d7b6 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -826,9 +826,13 @@ command_substitution returns[std::string libbash_value]
};
function_definition returns[int placeholder]
- :^(FUNCTION ^(STRING name) {
+@declarations {
+ std::string function_name;
+}
+ // We've already validated the function name in parser grammar so here we just use any_string to match the name.
+ :^(FUNCTION ^(STRING (libbash_string=any_string { function_name += libbash_string; })+) {
// Define the function with current index
- walker->define_function($name.libbash_value, INDEX());
+ walker->define_function(function_name, INDEX());
// Skip the AST for function body
seek_to_next_tree(ctx);
});
diff --git a/scripts/function_def.bash b/scripts/function_def.bash
index 54030e7..53e5ec8 100644
--- a/scripts/function_def.bash
+++ b/scripts/function_def.bash
@@ -27,20 +27,20 @@ ARRAY=(1 2 3)
func_with_args ${ARRAY[@]} $FOO001
func_with_args 100 $ARG2 $ARG3 $ARG4
-func_with_return()
+func-with-return()
{
return 1
NOT_EXIST=1
}
-func_with_return
+func-with-return
RETURN_STATUS=$?
-func_with_return2()
+func_with-return2()
{
true
return
NOT_EXIST=1
}
-func_with_return2
+func_with-return2
RETURN_STATUS2=$?
func_nested1() {
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-05-29 11:20 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-05-29 11:20 UTC (permalink / raw
To: gentoo-commits
commit: 4f4eff53b4ad98e386010f7d9717c3192954a0dc
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri May 27 14:22:01 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun May 29 11:44:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4f4eff53
Walker: support continue in while and until loop
---
bashast/libbashWalker.g | 11 ++++++-
scripts/compound_command.bash | 52 ++++++++++++++++++++++++++++++++++
scripts/compound_command.bash.result | 9 ++++++
3 files changed, 71 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f2fba4a..5c8c371 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -703,7 +703,16 @@ while_expr
command_list(ctx);
if(walker->get_status() == (negate? 0 : 1))
break;
- command_list(ctx);
+ try
+ {
+ command_list(ctx);
+ }
+ catch(continue_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+ SEEK(condition_index);
+ continue;
+ }
SEEK(condition_index);
}
// Skip the body and get out
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index bb7961c..a81e395 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -54,6 +54,32 @@ do
echo "Shouldn't print this"
done
+i=0
+while [ $i != 4 ]
+do
+ i=$(( i + 1 ))
+ if [[ $i == 1 ]]; then
+ continue
+ fi
+ echo $i
+done
+
+i=0
+j=1
+while [ $i != 4 ]
+do
+ i=$(( i + 1 ))
+
+ while [ $j == 1 ]
+ do
+ if [[ $i == 1 ]]; then
+ continue 2
+ fi
+ echo $i
+ let ++j
+ done
+done
+
i=0;
until [ $i == 4 ]
do
@@ -66,6 +92,32 @@ do
echo "Shouldn't print this"
done
+i=0
+until [ $i == 4 ]
+do
+ i=$(( i + 1 ))
+ if [[ $i == 1 ]]; then
+ continue
+ fi
+ echo $i
+done
+
+i=0
+j=1
+until [ $i == 4 ]
+do
+ i=$(( i + 1 ))
+
+ while [ $j == 1 ]
+ do
+ if [[ $i == 1 ]]; then
+ continue 2
+ fi
+ echo $i
+ let ++j
+ done
+done
+
a=1
b=2
if [ $a == $b ]
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 6014421..0450c8f 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -20,10 +20,18 @@ bar
2
3
4
+2
+3
+4
+2
1
2
3
4
+2
+3
+4
+2
1
2
1
@@ -45,5 +53,6 @@ b=2
file=bar
foo=ghi
i=4
+j=2
outer=3
target=_
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-01 12:19 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-01 12:19 UTC (permalink / raw
To: gentoo-commits
commit: 135a631da5c8f2a51539caa366d6d4ebb1582d34
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue May 31 08:22:31 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 12:15:21 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=135a631d
Walker: fix variable definition handling
As we ignore the exported variables that are not declared with values,
the variable definition rule has to handle empty variable definitions.
---
bashast/libbashWalker.g | 2 +-
scripts/command_execution.bash | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f53a2be..af19dcd 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -124,7 +124,7 @@ variable_definitions
@declarations {
bool local = false;
}
- :^(VARIABLE_DEFINITIONS (LOCAL { local = true; })? var_def[local]+);
+ :^(VARIABLE_DEFINITIONS (LOCAL { local = true; })? var_def[local]*);
name_base returns[std::string libbash_value]
:NAME { $libbash_value = walker->get_string($NAME); }
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 95401b4..8005a23 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -17,6 +17,7 @@ echo "end"
: ${DEFAULTED:="yes"}
FOO="abc" echo "command environment"
export FOO003=1 FOO004=abc FOO005=(1 2 3) FOO002
+export foo
abc=1 export foo
true > /dev/null
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-03 12:43 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-03 12:43 UTC (permalink / raw
To: gentoo-commits
commit: 752ef90a75d20aa62b34bd4efa04db5a75c581cf
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue May 31 12:02:07 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 1 06:12:50 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=752ef90a
Walker: support pattern matching in keyword test
---
bashast/libbashWalker.g | 17 +++++++++++++----
scripts/test_expr.bash | 6 ++++++
scripts/test_expr.bash.result | 3 +++
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f53a2be..a55e0b2 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -551,6 +551,9 @@ cond_expr
|^(KEYWORD_TEST status=keyword_condition) { walker->set_status(!status); };
common_condition returns[bool status]
+@declarations {
+ boost::xpressive::sregex pattern;
+}
// -eq, -ne, -lt, -le, -gt, or -ge for arithmetic. -nt -ot -ef for files
:^(NAME left_str=string_expr right_str=string_expr) {
$status = internal::test_binary(walker->get_string($NAME), left_str.libbash_value, right_str.libbash_value);
@@ -560,14 +563,20 @@ common_condition returns[bool status]
$status = internal::test_unary(*reinterpret_cast<const char *>(op->getToken(op)->start),
$string_expr.libbash_value);
}
- // We do not trigger pattern matching for now
- |^((EQUALS|MATCH_PATTERN) left_str=string_expr right_str=string_expr) {
+ |^(EQUALS left_str=string_expr right_str=string_expr) {
$status = left_str.libbash_value == right_str.libbash_value;
}
- // We do not trigger pattern matching for now
- |^((NOT_EQUALS|NOT_MATCH_PATTERN) left_str=string_expr right_str=string_expr) {
+ // Greedy is meaningless as we need to match the whole string
+ |^(MATCH_PATTERN left_str=string_expr bash_pattern[pattern, false]) {
+ $status = match(left_str.libbash_value, pattern);
+ }
+ |^(NOT_EQUALS left_str=string_expr right_str=string_expr) {
$status = left_str.libbash_value != right_str.libbash_value;
}
+ // Greedy is meaningless as we need to match the whole string
+ |^(NOT_MATCH_PATTERN left_str=string_expr bash_pattern[pattern, false]) {
+ $status = !match(left_str.libbash_value, pattern);
+ }
|^(LESS_THAN left_str=string_expr right_str=string_expr) {
$status = left_str.libbash_value < right_str.libbash_value;
}
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index f89287b..79398dd 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -38,3 +38,9 @@ echo $? # 0
[[ -a "/" ]] && echo "true10"
[[ . -ef . ]] && echo "true11"
[[ 2 -ge 2 ]] && echo "true12"
+[[ "abc def xyz" == *"def"* ]] && echo "true13"
+[[ "abc def xyz" == *"defg"* ]] && echo "wrong"
+[[ "abc def xyz" != *"def"* ]] && echo "wrong"
+[[ "abc def xyz" != *"defg"* ]] && echo "true14"
+shopt -s extglob
+[[ "123" == *([[:digit:]]) ]] && echo "true15"
diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.result
index d045597..653200b 100644
--- a/scripts/test_expr.bash.result
+++ b/scripts/test_expr.bash.result
@@ -19,3 +19,6 @@ true9
true10
true11
true12
+true13
+true14
+true15
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-09 7:27 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-09 7:27 UTC (permalink / raw
To: gentoo-commits
commit: a4825412c8b69296d4c817df139ca7841936efa4
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 8 14:56:43 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 07:23:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=a4825412
Walker: fix case command with empty body
---
bashast/libbashWalker.g | 22 +++++++++++-----------
scripts/compound_command.bash | 7 +++++++
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 39b0a16..8263b15 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -834,24 +834,24 @@ case_clause[const std::string& target] returns[bool matched]
std::vector<boost::xpressive::sregex> patterns;
}
:^(CASE_PATTERN ( { patterns.push_back(boost::xpressive::sregex()); } bash_pattern[patterns.back(), true])+ {
- if(LA(1) == CASE_COMMAND)
- {
- // omit CASE_COMMAND
- SEEK(INDEX() + 1);
- $matched = false;
+ $matched = false;
- for(auto iter = patterns.begin(); iter != patterns.end(); ++iter)
+ for(auto iter = patterns.begin(); iter != patterns.end(); ++iter)
+ {
+ if(match(target, *iter))
{
- if(match(target, *iter))
+ if(LA(1) == CASE_COMMAND)
{
+ // omit CASE_COMMAND
+ SEEK(INDEX() + 1);
command_list(ctx);
- $matched = true;
- break;
}
+ $matched = true;
+ break;
}
- if(!$matched)
- seek_to_next_tree(ctx);
}
+ if(!$matched)
+ seek_to_next_tree(ctx);
});
command_substitution returns[std::string libbash_value]
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index a81e395..7a4e526 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -181,6 +181,13 @@ case $target in
echo "default"
;;
esac
+case $target in
+ abc|bcd|xyz)
+ ;;
+ *)
+ echo "Shouldn't print this"
+ ;;
+esac
target=a
case $target in
[def])
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-09 8:15 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-09 8:15 UTC (permalink / raw
To: gentoo-commits
commit: 9454cb4dcc3d1501ba486bd2414e2736680f354c
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 4 09:16:57 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 08:21:46 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9454cb4d
Parser: support line break in command list
---
bashast/bashast.g | 2 +-
scripts/command_execution.bash | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index d63bc09..d75ef35 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -111,7 +111,7 @@ flcomment
clist
: list_level_2 -> ^(LIST list_level_2);
list_level_1
- : pipeline (BLANK!*(LOGICAND^|LOGICOR^)BLANK!* pipeline)*;
+ : pipeline (BLANK!*(LOGICAND^|LOGICOR^)(BLANK!|EOL!)* pipeline)*;
// ';' '&' and EOL have lower operator precedence than '&&' and '||' so we need level2 here
list_level_2
: list_level_1 (BLANK!? command_separator (BLANK!? EOL!)* BLANK!? list_level_1)*;
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 6060df3..ee2b85f 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -8,11 +8,13 @@ true
false
FOO001=$(echo hello)
FOO002=$(hi)
-true && echo "right"
+true &&
+ echo "right"
false && echo "wrong"
! true && echo "wrong"
false || echo "right"
-true || echo "wrong"
+true ||
+ echo "wrong"
echo "end"
: ${DEFAULTED:="yes"}
FOO="abc" echo "command environment"
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-09 11:46 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-09 11:46 UTC (permalink / raw
To: gentoo-commits
commit: 8d058790d54382de2979b06f0268c9bf8a425438
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 7 10:59:30 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 11:41:23 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=8d058790
Walker: fix for-loop for no items
In for loop, if there are no items in the expansion of words, no
commands are executed, and the return status is zero.
---
bashast/libbashWalker.g | 31 ++++++++++++++++++++-----------
scripts/compound_command.bash | 7 +++++++
scripts/compound_command.bash.result | 1 +
3 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index e793f56..ddbf669 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -649,19 +649,28 @@ for_expr
}
)+
{
- commands_index = INDEX();
- for(auto iter = splitted_values.begin(); iter != splitted_values.end(); ++iter)
+ if(splitted_values.empty())
{
- SEEK(commands_index);
- walker->set_value(libbash_string, *iter);
- try
- {
- command_list(ctx);
- }
- catch(continue_exception& e)
+ //skip the body
+ seek_to_next_tree(ctx);
+ walker->set_status(0);
+ }
+ else
+ {
+ commands_index = INDEX();
+ for(auto iter = splitted_values.begin(); iter != splitted_values.end(); ++iter)
{
- e.rethrow_unless_correct_frame();
- continue;
+ SEEK(commands_index);
+ walker->set_value(libbash_string, *iter);
+ try
+ {
+ command_list(ctx);
+ }
+ catch(continue_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+ continue;
+ }
}
}
})
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 7a4e526..5a04beb 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -8,6 +8,13 @@ do
echo $foo
done
+bar=
+# We behave differently from bash with "for foo in ''"
+for foo in $bar
+do
+ echo "Shouldn't print this"
+done
+
for (( i=1; i<4; ++i ))
do
echo $i
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 0450c8f..aeef870 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -50,6 +50,7 @@ yep
case end
a=1
b=2
+bar=
file=bar
foo=ghi
i=4
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-11 8:52 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-11 8:52 UTC (permalink / raw
To: gentoo-commits
commit: 5cc91900c887df1209b59f0357718c78d2d5ca4e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 6 10:21:58 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Jun 11 08:49:51 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=5cc91900
Walker: simplify variable reference
$* and $@ are treated equally now. This will simplify the grammar and
we won't differentiate them until this causes any problem. $@ is
supported in walker grammar with this change.
---
bashast/libbashWalker.g | 24 ++++--------------------
scripts/var_def.bash | 2 --
scripts/var_def.bash.result | 1 -
scripts/var_expansion.bash | 20 ++++++++++++++------
scripts/var_expansion.bash.result | 17 ++++++++++++-----
5 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 9cb578f..44df1a9 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -348,7 +348,7 @@ 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
|TIMES { $libbash_value = "*"; }
- |AT { $libbash_value = "@"; };
+ |AT { $libbash_value = "*"; };
var_expansion returns[std::string libbash_value]
@declarations {
@@ -437,26 +437,10 @@ word returns[std::string libbash_value]
//variable reference
var_ref [bool double_quoted] returns[std::string libbash_value]
- :^(VAR_REF name) {
- $libbash_value = walker->resolve<std::string>($name.libbash_value, $name.index);
+ :^(VAR_REF var_name) {
+ $libbash_value = walker->resolve<std::string>($var_name.libbash_value, $var_name.index);
}
- |^(VAR_REF libbash_string=num) {
- $libbash_value = walker->resolve<std::string>(libbash_string);
- }
- |^(VAR_REF ^(ARRAY libbash_string=name_base AT)) { walker->get_all_elements(libbash_string, $libbash_value); }
- |^(VAR_REF ^(ARRAY libbash_string=name_base TIMES)) {
- if(double_quoted)
- walker->get_all_elements_IFS_joined(libbash_string, $libbash_value);
- else
- walker->get_all_elements(libbash_string, $libbash_value);
- }
- |^(VAR_REF TIMES) {
- if(double_quoted)
- walker->get_all_elements_IFS_joined("*", $libbash_value);
- else
- walker->get_all_elements("*", $libbash_value);
- }
- |^(VAR_REF AT) { std::cerr << "$@ has not been implemented yet" << std::endl; }
+ |^(VAR_REF libbash_string=array_name) { walker->get_all_elements_IFS_joined(libbash_string, $libbash_value); }
|^(VAR_REF POUND) { std::cerr << "$# has not been implemented yet" << std::endl; }
|^(VAR_REF QMARK) { $libbash_value = walker->get_status<std::string>(); }
|^(VAR_REF MINUS) { std::cerr << "$- has not been implemented yet" << std::endl; }
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index f832a96..1980681 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -35,8 +35,6 @@ ARRAY10="${ARRAY05[*]}"
FOO001="networkmanager"
FOO002="0.8.2"
FOO003=${FOO001}-${FOO002}
-FOO004=$*
-FOO004=$@
FOO004=$#
FOO004=$?
FOO004=$-
diff --git a/scripts/var_def.bash.result b/scripts/var_def.bash.result
index 121c267..5ab9882 100644
--- a/scripts/var_def.bash.result
+++ b/scripts/var_def.bash.result
@@ -1,4 +1,3 @@
-$@ has not been implemented yet
$# has not been implemented yet
$- has not been implemented yet
$! has not been implemented yet
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index c3f41d3..1ac22b4 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -84,12 +84,20 @@ FOO081=${FOO039//@([a-c]|[k-m])}
target="abc123abc"
FOO082="${target##+(ab[c])*([[:digit:]])}"
function positional_parameter_test(){
- FOO083=${*}
- FOO084=${*:1}
- FOO085=${*:1:2}
- FOO086=${*: -1}
- FOO087=${*: -2:5}
- FOO088=${*:0}
+ FOO083=$*
+ FOO084=${*}
+ FOO085=${*:1}
+ FOO086=${*:1:2}
+ FOO087=${*: -1}
+ FOO088=${*: -2:5}
+ FOO089=${*:0}
+ FOO090=$@
+ FOO091=${@}
+ FOO092=${@:1}
+ FOO093=${@:1:2}
+ FOO094=${@: -1}
+ FOO095=${@: -2:5}
+ FOO096=${@:0}
}
positional_parameter_test 1 2 3 4 5
target="abc*abc"
diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
index 299d975..31cca8d 100644
--- a/scripts/var_expansion.bash.result
+++ b/scripts/var_expansion.bash.result
@@ -90,9 +90,16 @@ FOO081=Heo Word
FOO082=abc
FOO083=1 2 3 4 5
FOO084=1 2 3 4 5
-FOO085=1 2
-FOO086=5
-FOO087=4 5
-FOO088=@srcdir@/scripts/var_expansion.bash 1 2 3 4 5
-FOO089=
+FOO085=1 2 3 4 5
+FOO086=1 2
+FOO087=5
+FOO088=4 5
+FOO089=@srcdir@/scripts/var_expansion.bash 1 2 3 4 5
+FOO090=1 2 3 4 5
+FOO091=1 2 3 4 5
+FOO092=1 2 3 4 5
+FOO093=1 2
+FOO094=5
+FOO095=4 5
+FOO096=@srcdir@/scripts/var_expansion.bash 1 2 3 4 5
target=abc*abc
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-11 8:52 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-11 8:52 UTC (permalink / raw
To: gentoo-commits
commit: 9f31ac2104a97e7f12cdc10f27037996041f20c6
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 9 15:21:30 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Jun 11 08:51:16 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9f31ac21
Walker: support $#
---
bashast/libbashWalker.g | 2 +-
scripts/var_def.bash | 1 -
scripts/var_def.bash.result | 1 -
scripts/var_expansion.bash | 2 ++
scripts/var_expansion.bash.result | 2 ++
5 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 2648ecb..6cd1ef2 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -444,7 +444,7 @@ var_ref [bool double_quoted] returns[std::string libbash_value]
$libbash_value = walker->resolve<std::string>($var_name.libbash_value, $var_name.index);
}
|^(VAR_REF libbash_string=array_name) { walker->get_all_elements_IFS_joined(libbash_string, $libbash_value); }
- |^(VAR_REF POUND) { std::cerr << "$# has not been implemented yet" << std::endl; }
+ |^(VAR_REF POUND) { $libbash_value = boost::lexical_cast<std::string>(walker->get_array_length("*")); }
|^(VAR_REF QMARK) { $libbash_value = walker->get_status<std::string>(); }
|^(VAR_REF MINUS) { std::cerr << "$- has not been implemented yet" << std::endl; }
|^(VAR_REF BANG) { std::cerr << "$! has not been implemented yet" << std::endl; }
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index 1980681..0989f9a 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -35,7 +35,6 @@ ARRAY10="${ARRAY05[*]}"
FOO001="networkmanager"
FOO002="0.8.2"
FOO003=${FOO001}-${FOO002}
-FOO004=$#
FOO004=$?
FOO004=$-
FOO004=$!
diff --git a/scripts/var_def.bash.result b/scripts/var_def.bash.result
index 5ab9882..b9b415e 100644
--- a/scripts/var_def.bash.result
+++ b/scripts/var_def.bash.result
@@ -1,4 +1,3 @@
-$# has not been implemented yet
$- has not been implemented yet
$! has not been implemented yet
ARRAY01=1 2 3 4 5
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 1ac22b4..9f42f19 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -98,6 +98,7 @@ function positional_parameter_test(){
FOO094=${@: -1}
FOO095=${@: -2:5}
FOO096=${@:0}
+ echo $#
}
positional_parameter_test 1 2 3 4 5
target="abc*abc"
@@ -108,3 +109,4 @@ echo ${target/"*"}
ARRAY=(1 2 3 4 5)
echo ${ARRAY[@]:1}
echo ${ARRAY[@]:1:3}
+echo $#
diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
index 31cca8d..bd83c62 100644
--- a/scripts/var_expansion.bash.result
+++ b/scripts/var_expansion.bash.result
@@ -1,8 +1,10 @@
+5
abcabc
abcabc
2 3 4 5
2 3 4
+0
ARRAY=1 2 3 4 5
ARRAY2=hello
EAPI=3
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-16 16:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-16 16:53 UTC (permalink / raw
To: gentoo-commits
commit: 4006e69739fa88f24ab9e79797217e5648413b3e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 16 10:05:18 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 16 10:05:18 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4006e697
Walker: support regular expression in keyword test
---
bashast/libbashWalker.g | 4 ++++
scripts/test_expr.bash | 2 ++
scripts/test_expr.bash.result | 1 +
3 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 5469f84..9d297d2 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -649,6 +649,10 @@ keyword_condition returns[bool status]
:^(LOGICOR l=keyword_condition r=keyword_condition) { $status= l || r; }
|^(LOGICAND l=keyword_condition r=keyword_condition) { $status= l && r; }
|^(NEGATION l=keyword_condition) { $status = !l; }
+ |^(MATCH_REGULAR_EXPRESSION left_str=string_expr right_str=string_expr) {
+ boost::xpressive::sregex re = boost::xpressive::sregex::compile(right_str.libbash_value);
+ $status = boost::xpressive::regex_match(left_str.libbash_value, re);
+ }
|s=common_condition { $status = s; };
builtin_condition returns[bool status]
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index 1fa00b4..f1f3093 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -48,3 +48,5 @@ i=2
[[ i++ -gt 2 ]] && echo wrong
[[ i++ -gt 2 ]] && echo true16
unset i
+[[ "setup.py" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]] && echo true17
+[[ "setup.py" =~ ^(setup\.p|nosetests|py\.test|trial(\ .*)?)$ ]] && echo false
diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.result
index e883295..2082757 100644
--- a/scripts/test_expr.bash.result
+++ b/scripts/test_expr.bash.result
@@ -23,3 +23,4 @@ true13
true14
true15
true16
+true17
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-16 16:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-16 16:53 UTC (permalink / raw
To: gentoo-commits
commit: e014fed890948d80e754b34b4096ec1e911d52e4
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 13 15:03:03 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Jun 13 15:03:03 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=e014fed8
Walker: support $-
---
bashast/libbashWalker.g | 4 +++-
scripts/var_def.bash | 2 +-
scripts/var_def.bash.result | 2 +-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index c9a83e6..458dcd8 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -374,6 +374,9 @@ var_name returns[std::string libbash_value, unsigned index]
|name {
$libbash_value = $name.libbash_value;
$index = $name.index;
+ }
+ |MINUS {
+ $libbash_value = "-";
};
array_name returns[std::string libbash_value]
@@ -475,7 +478,6 @@ var_ref [bool double_quoted] returns[std::string libbash_value]
|^(VAR_REF libbash_string=array_name) { walker->get_all_elements_IFS_joined(libbash_string, $libbash_value); }
|^(VAR_REF POUND) { $libbash_value = boost::lexical_cast<std::string>(walker->get_array_length("*")); }
|^(VAR_REF QMARK) { $libbash_value = walker->get_status<std::string>(); }
- |^(VAR_REF MINUS) { std::cerr << "$- has not been implemented yet" << std::endl; }
|^(VAR_REF BANG) { std::cerr << "$! has not been implemented yet" << std::endl; }
|^(VAR_REF libbash_string=var_expansion) { $libbash_value = libbash_string; };
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index 0989f9a..fa07952 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -36,7 +36,7 @@ FOO001="networkmanager"
FOO002="0.8.2"
FOO003=${FOO001}-${FOO002}
FOO004=$?
-FOO004=$-
FOO004=$!
FOO005=abc
FOO005+=def
+echo $-
diff --git a/scripts/var_def.bash.result b/scripts/var_def.bash.result
index b9b415e..667c3e0 100644
--- a/scripts/var_def.bash.result
+++ b/scripts/var_def.bash.result
@@ -1,5 +1,5 @@
-$- has not been implemented yet
$! has not been implemented yet
+Bh
ARRAY01=1 2 3 4 5
ARRAY02=1 2 4 5
ARRAY03= 2 3
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-18 9:55 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-18 9:55 UTC (permalink / raw
To: gentoo-commits
commit: 846f4e61709a56bd7509272cb8b8500d1084c934
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 15 09:38:12 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Jun 18 09:50:49 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=846f4e61
Walker: Fix variable indirection in arithmetic
---
bashast/libbashWalker.g | 3 ++-
scripts/arithmetic_assignment.bash | 8 ++++++++
scripts/arithmetic_assignment.bash.result | 7 +++++++
3 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f74f64e..f78259f 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -969,7 +969,8 @@ arithmetics returns[int value]
$value = (cnd ? l : r);
}
|primary {
- $value = walker->resolve<int>($primary.libbash_value, $primary.index);
+ std::string primary_value(walker->resolve<std::string>($primary.libbash_value, $primary.index));
+ $value = (primary_value.empty() ? 0 : walker->eval_arithmetic(primary_value));
}
|^(PRE_INCR primary) {
$value = walker->set_value($primary.libbash_value,
diff --git a/scripts/arithmetic_assignment.bash b/scripts/arithmetic_assignment.bash
index c53758c..d8b1fe4 100644
--- a/scripts/arithmetic_assignment.bash
+++ b/scripts/arithmetic_assignment.bash
@@ -14,3 +14,11 @@ FOO012="$((${FOO011[0]}=10))"
FOO013="$((3!=5))"
value=100
let "value=${value}"
+a=c
+b=d
+c=1
+d=2
+e="1+2"
+echo $(($a + $b))
+echo $(($a + $e))
+
diff --git a/scripts/arithmetic_assignment.bash.result b/scripts/arithmetic_assignment.bash.result
index d5e6ea4..dd8a219 100644
--- a/scripts/arithmetic_assignment.bash.result
+++ b/scripts/arithmetic_assignment.bash.result
@@ -1,3 +1,5 @@
+3
+4
CREATED=10
FOO001=1000
FOO002=100
@@ -12,4 +14,9 @@ FOO010=15
FOO011=CREATED 2
FOO012=10
FOO013=1
+a=c
+b=d
+c=1
+d=2
+e=1+2
value=100
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-19 19:15 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-19 19:15 UTC (permalink / raw
To: gentoo-commits
commit: ae0cabbc1a5a36ac35b05710fb51f1098cf301e3
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 14 08:21:34 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Jun 19 19:13:39 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ae0cabbc
Walker: support -a and -o in built-in test
---
bashast/libbashWalker.g | 16 +++++++++++++++-
scripts/test_expr.bash | 2 ++
scripts/test_expr.bash.result | 2 ++
3 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f78259f..fda4ef6 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -143,6 +143,11 @@ options
return std::string(reinterpret_cast<const char *>(token->start),
boost::numeric_cast<unsigned>(token->stop - token->start + 1));
}
+
+ char get_char(pANTLR3_BASE_TREE node)
+ {
+ return *reinterpret_cast<const char *>(node->getToken(node)->start);
+ }
}
}
@@ -622,7 +627,7 @@ common_condition returns[bool status]
}
// -o for shell option, -z -n for string, -abcdefghkprstuwxOGLSN for files
|^(op=LETTER string_expr) {
- $status = internal::test_unary(*reinterpret_cast<const char *>(op->getToken(op)->start),
+ $status = internal::test_unary(get_char(op),
$string_expr.libbash_value);
}
|^(EQUALS left_str=string_expr right_str=string_expr) {
@@ -659,6 +664,15 @@ 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::interpreter_exception(std::string("unrecognized operator in built-in test: ") + op);
+ }
|s=builtin_condition_primary { $status = s; };
builtin_condition_primary returns[bool status]
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index f1f3093..04b5a62 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -50,3 +50,5 @@ i=2
unset i
[[ "setup.py" =~ ^(setup\.py|nosetests|py\.test|trial(\ .*)?)$ ]] && echo true17
[[ "setup.py" =~ ^(setup\.p|nosetests|py\.test|trial(\ .*)?)$ ]] && echo false
+[ abc = bcd -o abc = abc ] && echo true18
+[ abc = bcd -a abc = abc ] || echo true19
diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.result
index 2082757..fb147eb 100644
--- a/scripts/test_expr.bash.result
+++ b/scripts/test_expr.bash.result
@@ -24,3 +24,5 @@ true14
true15
true16
true17
+true18
+true19
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-25 10:05 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-25 10:05 UTC (permalink / raw
To: gentoo-commits
commit: 95430b008ae1d3ed9526726a84088f2943d28be4
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 14:39:05 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 23 03:24:42 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=95430b00
Walker: fix a bug in for each loop
The index of input stream would be wrong if continue is called and there
are no elements left. Now this is fixed.
---
bashast/libbashWalker.g | 4 ++--
scripts/compound_command.bash | 8 ++++++++
scripts/compound_command.bash.result | 1 +
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index fda4ef6..02e2f33 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -710,7 +710,6 @@ for_expr
commands_index = INDEX();
for(auto iter = splitted_values.begin(); iter != splitted_values.end(); ++iter)
{
- SEEK(commands_index);
walker->set_value(libbash_string, *iter);
try
{
@@ -719,9 +718,10 @@ for_expr
catch(continue_exception& e)
{
e.rethrow_unless_correct_frame();
- continue;
}
+ SEEK(commands_index);
}
+ seek_to_next_tree(ctx);
}
})
|^(CFOR {
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 5a04beb..06b4f9e 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -38,6 +38,14 @@ do
echo $file
done
+for file in foo bar
+do
+ if [[ $file == "bar" ]]; then
+ continue
+ fi
+ echo $file
+done
+
for outer in 1 2 3
do
for file in foo bar
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index aeef870..4662025 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -12,6 +12,7 @@ ghi
9
10
bar
+foo
2 foo
2 bar
3 foo
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-25 10:05 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-25 10:05 UTC (permalink / raw
To: gentoo-commits
commit: 4a6aa796319c9dbc9ac1b50c846c6f4b009c196f
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 14:48:22 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 23 03:24:43 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4a6aa796
Walker: support break built-in
---
bashast/libbashWalker.g | 24 ++++++++++-
scripts/compound_command.bash | 79 ++++++++++++++++++++++++++++++++++
scripts/compound_command.bash.result | 9 ++--
3 files changed, 107 insertions(+), 5 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 02e2f33..2bd446d 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -719,6 +719,12 @@ for_expr
{
e.rethrow_unless_correct_frame();
}
+ catch(break_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+ SEEK(commands_index);
+ break;
+ }
SEEK(commands_index);
}
seek_to_next_tree(ctx);
@@ -743,8 +749,10 @@ for_expr
SEEK(condition_index);
+ ANTLR3_MARKER command_index;
while(!has_condition || for_condition(ctx))
{
+ command_index = INDEX();
try
{
command_list(ctx);
@@ -758,10 +766,15 @@ for_expr
SEEK(modification_index);
for_modification(ctx);
}
-
SEEK(condition_index);
continue;
}
+ catch(break_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+ SEEK(command_index);
+ break;
+ }
if(has_modification)
for_modification(ctx);
SEEK(condition_index);
@@ -789,6 +802,7 @@ for_modification
while_expr
@declarations {
ANTLR3_MARKER condition_index;
+ ANTLR3_MARKER command_index;
bool negate;
}
:^((WHILE { negate = false; } | UNTIL { negate = true; }) {
@@ -801,6 +815,8 @@ while_expr
command_list(ctx);
if(walker->get_status() == (negate? 0 : 1))
break;
+
+ command_index = INDEX();
try
{
command_list(ctx);
@@ -811,6 +827,12 @@ while_expr
SEEK(condition_index);
continue;
}
+ catch(break_exception& e)
+ {
+ e.rethrow_unless_correct_frame();
+ SEEK(command_index);
+ break;
+ }
SEEK(condition_index);
}
// Skip the body and get out
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 06b4f9e..ece5504 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -46,6 +46,22 @@ do
echo $file
done
+for file in foo bar
+do
+ if [[ $file == "foo" ]]; then
+ break
+ fi
+ echo $file
+done
+
+for file in foo bar
+do
+ if [[ $file == "bar" ]]; then
+ break
+ fi
+ echo $file
+done
+
for outer in 1 2 3
do
for file in foo bar
@@ -57,6 +73,17 @@ do
done
done
+for outer in 1 2 3
+do
+ for file in foo bar
+ do
+ if [[ $file == "foo" && $outer == 1 ]]; then
+ break 2
+ fi
+ echo "$outer $file"
+ done
+done
+
i=0;
while [ $i != 4 ]
do
@@ -80,6 +107,16 @@ do
done
i=0
+while [ $i != 4 ]
+do
+ i=$(( i + 1 ))
+ if [[ $i == 1 ]]; then
+ break
+ fi
+ echo $i
+done
+
+i=0
j=1
while [ $i != 4 ]
do
@@ -95,6 +132,22 @@ do
done
done
+i=0
+j=1
+while [ $i != 4 ]
+do
+ i=$(( i + 1 ))
+
+ while [ $j == 1 ]
+ do
+ if [[ $i == 1 ]]; then
+ break 2
+ fi
+ echo $i
+ let ++j
+ done
+done
+
i=0;
until [ $i == 4 ]
do
@@ -118,6 +171,16 @@ do
done
i=0
+until [ $i == 4 ]
+do
+ i=$(( i + 1 ))
+ if [[ $i == 1 ]]; then
+ break
+ fi
+ echo $i
+done
+
+i=0
j=1
until [ $i == 4 ]
do
@@ -133,6 +196,22 @@ do
done
done
+i=0
+j=1
+until [ $i == 4 ]
+do
+ i=$(( i + 1 ))
+
+ while [ $j == 1 ]
+ do
+ if [[ $i == 1 ]]; then
+ break 2
+ fi
+ echo $i
+ let ++j
+ done
+done
+
a=1
b=2
if [ $a == $b ]
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
index 4662025..c083e6a 100644
--- a/scripts/compound_command.bash.result
+++ b/scripts/compound_command.bash.result
@@ -13,6 +13,7 @@ ghi
10
bar
foo
+foo
2 foo
2 bar
3 foo
@@ -52,9 +53,9 @@ case end
a=1
b=2
bar=
-file=bar
+file=foo
foo=ghi
-i=4
-j=2
-outer=3
+i=1
+j=1
+outer=1
target=_
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-25 10:30 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-25 10:30 UTC (permalink / raw
To: gentoo-commits
commit: ba6972dbe97c47614f4aeef8187ae15e08b57ee2
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 09:55:48 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 22 11:53:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=ba6972db
Walker: support shortcut capability for logic or
---
bashast/libbashWalker.g | 22 ++++++++++++++++++++--
scripts/binary_arithmetic.bash | 1 +
scripts/binary_arithmetic.bash.result | 1 +
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index fda4ef6..99d7f53 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -71,7 +71,7 @@ options
index = value;
}
- // seek to LT(2) and consume
+ // skip to next tree
void seek_to_next_tree(plibbashWalker ctx)
{
// Current depth of the tree we are traversing
@@ -95,6 +95,14 @@ options
CONSUME();
}
+ void skip_next_token_or_tree(plibbashWalker ctx)
+ {
+ if(LA(2) != DOWN)
+ SEEK(INDEX() + 1);
+ else
+ seek_to_next_tree(ctx);
+ }
+
// The method is used to append a pattern with another one. Because it's not allowed to append an empty pattern,
// we need the argument 'do_append' to indicate whether the pattern is empty. 'do_append' will be set to true after
// the first assignment.
@@ -953,7 +961,17 @@ primary returns[std::string libbash_value, unsigned index]
// shell arithmetic
arithmetics returns[int value]
- :^(LOGICOR l=arithmetics r=arithmetics) { $value = l || r; }
+ :^(LOGICOR l=arithmetics {
+ if(l)
+ {
+ skip_next_token_or_tree(ctx);
+ $value = 1;
+ }
+ else
+ {
+ $value = (arithmetics(ctx) != 0);
+ }
+ })
|^(LOGICAND l=arithmetics r=arithmetics) { $value = l && r; }
|^(PIPE l=arithmetics r=arithmetics) { $value = l | r; }
|^(CARET l=arithmetics r=arithmetics) { $value = l ^ r; }
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index 330d07b..114655a 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -63,3 +63,4 @@ FOO057="$((${FOO056}++))"
FOO058="$((${FOO056}+=10))"
ARRAY=(1 2 3 4 5)
FOO059="$((100**0))"
+FOO060="$((FOO059||FOO059++))"
diff --git a/scripts/binary_arithmetic.bash.result b/scripts/binary_arithmetic.bash.result
index de065d6..740548d 100644
--- a/scripts/binary_arithmetic.bash.result
+++ b/scripts/binary_arithmetic.bash.result
@@ -58,5 +58,6 @@ FOO056=value
FOO057=100
FOO058=111
FOO059=1
+FOO060=1
PARTIAL=5
value=111
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-25 10:30 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-25 10:30 UTC (permalink / raw
To: gentoo-commits
commit: d346fde50e1ef43c00ae2a76449b3f9dc0207ccb
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 09:59:39 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 22 11:53:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d346fde5
Walker: support shortcut capability for logic and
---
bashast/libbashWalker.g | 12 +++++++++++-
scripts/binary_arithmetic.bash | 1 +
scripts/binary_arithmetic.bash.result | 1 +
3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 99d7f53..d6a6dca 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -972,7 +972,17 @@ arithmetics returns[int value]
$value = (arithmetics(ctx) != 0);
}
})
- |^(LOGICAND l=arithmetics r=arithmetics) { $value = l && r; }
+ |^(LOGICAND l=arithmetics {
+ if(!l)
+ {
+ skip_next_token_or_tree(ctx);
+ $value = 0;
+ }
+ else
+ {
+ $value = (arithmetics(ctx) != 0);
+ }
+ })
|^(PIPE l=arithmetics r=arithmetics) { $value = l | r; }
|^(CARET l=arithmetics r=arithmetics) { $value = l ^ r; }
|^(AMP l=arithmetics r=arithmetics) { $value = l & r; }
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index 114655a..577ddbc 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -64,3 +64,4 @@ FOO058="$((${FOO056}+=10))"
ARRAY=(1 2 3 4 5)
FOO059="$((100**0))"
FOO060="$((FOO059||FOO059++))"
+FOO061="$((0&&FOO059++))"
diff --git a/scripts/binary_arithmetic.bash.result b/scripts/binary_arithmetic.bash.result
index 740548d..926b23a 100644
--- a/scripts/binary_arithmetic.bash.result
+++ b/scripts/binary_arithmetic.bash.result
@@ -59,5 +59,6 @@ FOO057=100
FOO058=111
FOO059=1
FOO060=1
+FOO061=0
PARTIAL=5
value=111
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-06-25 10:30 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-06-25 10:30 UTC (permalink / raw
To: gentoo-commits
commit: 24c5d0ac08d27131f0c38c41c6c1ae8e65999c1a
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 11:04:00 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 22 11:56:04 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=24c5d0ac
Walker: support arithmetic expression
---
bashast/libbashWalker.g | 1 +
scripts/command_execution.bash | 1 +
scripts/command_execution.bash.result | 1 +
3 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index d6a6dca..879443d 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -616,6 +616,7 @@ command_list: ^(LIST logic_command_list+);
compound_command
: ^(CURRENT_SHELL command_list)
| ^(COMPOUND_COND cond_expr)
+ | ^(ARITHMETIC_EXPRESSION arithmetics)
| for_expr
| while_expr
| if_expr
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 2df1b0d..d485d57 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -55,3 +55,4 @@ shopt -s extglob
shopt -p
printf "%s %s\n" abc def
printf "%s %s\n" $FOO001, def
+((FOO010=1))
diff --git a/scripts/command_execution.bash.result b/scripts/command_execution.bash.result
index 3165843..280798b 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/command_execution.bash.result
@@ -63,3 +63,4 @@ FOO004=abc
FOO005=1 2 3
FOO008=abc def ghi
FOO009=10
+FOO010=1
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-07-20 13:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-07-20 13:08 UTC (permalink / raw
To: gentoo-commits
commit: 53f52fea7c45a92771094af3a7dbaa637ecd397a
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 20 08:22:33 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jul 20 08:22:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=53f52fea
Parser: fix a bug in escaped double quote handling
The internal lexer state for handling double quotes should be changed if
the double quote is escaped. Now this is fixed.
---
bashast/bashast.g | 7 ++++++-
scripts/command_execution.bash | 1 +
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 9681cb1..c69edea 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -120,6 +120,11 @@ tokens{
bool double_quoted = false;
#else
boolean double_quoted = false;
+
+ int LA(int index)
+ {
+ return input.LA(index);
+ }
#endif
}
@@ -723,7 +728,7 @@ SEMIC : ';';
DOUBLE_SEMIC
: ';;';
PIPE : '|';
-DQUOTE : '"' { double_quoted = !double_quoted; };
+DQUOTE : '"' { if(LA(-1) != '\\') double_quoted = !double_quoted; };
SQUOTE : { double_quoted }? => '\'';
SINGLE_QUOTED_STRING_TOKEN : { !double_quoted }? => '\'' .* '\'';
COMMA : ',';
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 33200bd..3d138fd 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -64,3 +64,4 @@ echo $FOO010
echo "abc #av### ##" # for comment
echo $'abc\tdef\nxyz'
echo -e "\'\"\t\n"
+echo 'quotes should be handled correctly'
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 1dbbb7aa1833505a692f8c506fcd5ee0b54314d1
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 09:23:37 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=1dbbb7aa
Walker: support == in arithmetic comparison
---
bashast/libbashWalker.g | 1 +
scripts/binary_arithmetic.bash | 2 ++
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index c8962fd..2ee887c 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -1084,6 +1084,7 @@ arithmetics returns[long value]
|^(LESS_THAN l=arithmetics r=arithmetics) { $value = l < r; }
|^(GREATER_THAN l=arithmetics r=arithmetics) { $value = l > r; }
|^(NOT_EQUALS l=arithmetics r=arithmetics) { $value = l != r; }
+ |^(EQUALS_TO l=arithmetics r=arithmetics) { $value = l == r; }
|^(LSHIFT l=arithmetics r=arithmetics) { $value = l << r; }
|^(RSHIFT l=arithmetics r=arithmetics) { $value = l >> r; }
|^(PLUS l=arithmetics r=arithmetics) { $value = l + r; }
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index 36b4c9d..cac471f 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -67,3 +67,5 @@ ARRAY=(1 2 3 4 5)
FOO059="$((100**0))"
echo "$((FOO059||FOO059++))"
echo "$((0&&FOO059++))"
+echo "$(( 1 == 2))"
+echo "$(( 1 == 1))"
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 52b5991a8814319c36677d37440a93470b2fa16c
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 09:48:34 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=52b5991a
Parser: support -a and -i option for local
---
bashast/bashast.g | 11 ++++++++++-
scripts/var_def.bash | 7 +++++++
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index fee25b6..6566a5b 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -136,6 +136,8 @@ tokens{
C_INCLUDE #include <string>
C_INCLUDE #include <boost/numeric/conversion/cast.hpp>
+
+ C_INCLUDE #include "core/exceptions.h"
}
@members
{
@@ -393,7 +395,14 @@ array_atom
local_item
: variable_definition_atom
- | name -> ^(EQUALS name);
+ | name -> ^(EQUALS name)
+ | MINUS op=LETTER {
+#ifdef OUTPUT_C
+ std::string option = get_string(op);
+ if(option != "i" && option != "a")
+ throw libbash::unsupported_exception("We do not support -" + option + " for local");
+#endif
+ } ->;
export_item
: variable_definition_atom
| name ->;
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index fe2441d..6dc83dd 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -75,3 +75,10 @@ FOO005=abc
echo $FOO005
FOO005+=def
echo $FOO005
+function foo() {
+ local -i foo=1
+ local -a bar=(1 2 3)
+ echo $foo
+ echo ${bar[@]}
+}
+foo
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 81e8d87cad6f45db77cc8f0be9a382e6c44489a2
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 21 10:07:57 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=81e8d87c
Parser: support '@' in non-quoted string
---
bashast/bashast.g | 2 +-
scripts/var_def.bash | 2 ++
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 6566a5b..b380379 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -660,7 +660,7 @@ ns_string_part
|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON|TEST_EXPR
|TILDE|MUL_ASSIGN|DIVIDE_ASSIGN|MOD_ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN
|LSHIFT_ASSIGN|RSHIFT_ASSIGN|AND_ASSIGN|XOR_ASSIGN|LSQUARE|RSQUARE
- |OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT|LOCAL;
+ |OR_ASSIGN|CARET|POUND|POUNDPOUND|COMMA|EXPORT|LOCAL|AT;
escaped_character
: ESC
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index 6dc83dd..09c07c6 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -82,3 +82,5 @@ function foo() {
echo ${bar[@]}
}
foo
+bar=@
+echo $bar
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 5752979a8a8320c3bf3606055aa69e0fc202969e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 27 06:27:47 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=5752979a
Parser: improve exported variable handling
The double quotes were not reserved when calling export. So when the
walker called back to parser, the white spaces inside double quotes
would be problematic. Now this is fixed.
---
bashast/bashast.g | 13 +++++++------
scripts/command_execution.bash | 1 +
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2a0b23a..55a499d 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -445,7 +445,7 @@ local_item
#endif
} ->;
export_item
- : ((~EOL) => (string_expr_part|BLANK|LPAREN|RPAREN))+;
+ : ((~EOL) => expansion_base)+;
builtin_variable_definitions
: (builtin_variable_definition_atom) (BLANK builtin_variable_definition_atom)*
@@ -681,22 +681,23 @@ quoted_string
| SINGLE_QUOTED_STRING_TOKEN -> ^(SINGLE_QUOTED_STRING SINGLE_QUOTED_STRING_TOKEN);
double_quoted_string
- : DQUOTE double_quoted_string_part* DQUOTE -> ^(DOUBLE_QUOTED_STRING double_quoted_string_part*);
-double_quoted_string_part
+ : DQUOTE ((~DQUOTE) => expansion_base)* DQUOTE -> ^(DOUBLE_QUOTED_STRING expansion_base*);
+
+// Perform all kinds of expansions
+expansion_base
: (DOLLAR (LBRACE|name|num|TIMES|AT|POUND|QMARK|MINUS|DOLLAR|BANG)) => variable_reference
| (command_substitution) => command_substitution
| (DOLLAR (LLPAREN|LSQUARE)) => arithmetic_expansion
| (ESC DQUOTE) => ESC DQUOTE -> DQUOTE
| (ESC TICK) => ESC TICK -> TICK
| (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;
+ | expansion_base;
string_part
: ns_string_part
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index add4145..05e2177 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -73,3 +73,4 @@ ech\
o Hello\
world
echo \`\(\)\$\>\<\`
+export SRC_URI="${SRC_URI} http://www.oracle.com/technology/products/berkeley-db/db/update/${MY_PV}/patch.${MY_PV}.${i}"
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: b04f9d064a8aec90812df91be179f6bddb7f8174
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 28 09:04:34 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=b04f9d06
Parser: split token compositions
'<=' will generate one token so that some expressions cannot be fully
parsed. Now '>=' and '<=' are split to parse these expressions.
---
bashast/bashast.g | 8 ++++----
scripts/test_expr.bash | 2 ++
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 8486619..7dc9ad5 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -121,6 +121,8 @@ tokens{
AND_ASSIGN;
XOR_ASSIGN;
OR_ASSIGN;
+ LEQ;
+ GEQ;
NOT_EQUALS;
EQUALS_TO;
@@ -991,8 +993,8 @@ shifts
compare
: shifts (compare_operator^ BLANK!? shifts)?;
compare_operator
- : LEQ
- | GEQ
+ : LESS_THAN EQUALS -> LEQ
+ | GREATER_THAN EQUALS -> GEQ
| LESS_THAN
| GREATER_THAN
| EQUALS EQUALS -> EQUALS_TO
@@ -1048,8 +1050,6 @@ MINUS : '-';
PLUS : '+';
EXP : '**';
AMP : '&';
-LEQ : '<=';
-GEQ : '>=';
CARET : '^';
LESS_THAN : '<';
GREATER_THAN : '>';
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index 04b5a62..66ab24a 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -52,3 +52,5 @@ unset i
[[ "setup.py" =~ ^(setup\.p|nosetests|py\.test|trial(\ .*)?)$ ]] && echo false
[ abc = bcd -o abc = abc ] && echo true18
[ abc = bcd -a abc = abc ] || echo true19
+[[ =a <=b ]]
+[[ =a >=b ]]
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2011-08-04 13:53 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2011-08-04 13:53 UTC (permalink / raw
To: gentoo-commits
commit: 1e51015b4e2e76a912e077faf772e6470090b130
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 29 12:54:12 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=1e51015b
Parser: improve the rule for regular expression
---
bashast/bashast.g | 14 +++++++++++---
scripts/var_expansion.bash | 7 +++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index ea8185f..5549439 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -620,19 +620,27 @@ keyword_condition_binary
-> ^(MATCH_PATTERN condition_part ^(STRING extended_pattern_match+))
| -> condition_part
);
-//TODO improve this rule
bash_pattern_part
scope {
int parens;
+#ifdef OUTPUT_C
+ bool quoted;
+#else
+ boolean quoted;
+#endif
}
@init {
$bash_pattern_part::parens = 0;
+ $bash_pattern_part::quoted = false;
}
:(
- (ESC BLANK) => ESC BLANK
+ DQUOTE! { $bash_pattern_part::quoted = !$bash_pattern_part::quoted; }
+ | {$bash_pattern_part::quoted}? => ~DQUOTE
+ | (ESC BLANK) => ESC BLANK
| LPAREN { if(LA(-2) != ESC) $bash_pattern_part::parens++; }
+ | LLPAREN { if(LA(-2) != ESC) $bash_pattern_part::parens += 2; }
| {$bash_pattern_part::parens != 0}? => RPAREN { if(LA(-2) != ESC) $bash_pattern_part::parens--; }
- | ~(BLANK|EOL|LOGICAND|LOGICOR|LPAREN|RPAREN)
+ | ~(BLANK|EOL|LOGICAND|LOGICOR|LPAREN|RPAREN|DQUOTE|LLPAREN)
)+;
keyword_binary_string_operator
: BLANK! binary_operator BLANK!
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 2d9a28e..9f442b1 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -127,3 +127,10 @@ echo ${bar+abc}
foo=
unset bar
echo ${bar=abc}
+
+# 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)" " ]]
+[[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]
+[[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]]
+[[ "$(echo "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]]
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 49facd905dadf5bae1b33362686d1d02be80a5fe
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 23 03:26:29 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Feb 23 03:27:18 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=49facd90
Walker: support shortcut in keyword test
---
bashast/libbashWalker.g | 16 ++++++++++++++--
scripts/test_expr.bash | 6 ++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index bfcb73b..e357642 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -763,8 +763,20 @@ common_condition returns[bool status]
|string_expr { $status = (!$string_expr.libbash_value.empty()); };
keyword_condition returns[bool status]
- :^(LOGICOR l=keyword_condition r=keyword_condition) { $status= l || r; }
- |^(LOGICAND l=keyword_condition r=keyword_condition) { $status= l && r; }
+ :^(LOGICOR l=keyword_condition {
+ if(l){
+ seek_to_next_tree(ctx);
+ SEEK(INDEX() + 1);
+ return true;
+ }
+ } r=keyword_condition) { $status= l || r; }
+ |^(LOGICAND l=keyword_condition {
+ if(!l){
+ seek_to_next_tree(ctx);
+ SEEK(INDEX() + 1);
+ return false;
+ }
+ } r=keyword_condition) { $status= l && r; }
|^(NEGATION l=keyword_condition) { $status = !l; }
|^(MATCH_REGULAR_EXPRESSION left_str=string_expr right_str=string_expr) {
boost::xpressive::sregex re = boost::xpressive::sregex::compile(right_str.libbash_value);
diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
index ccedb76..6ae7246 100644
--- a/scripts/test_expr.bash
+++ b/scripts/test_expr.bash
@@ -55,3 +55,9 @@ unset i
[[ =a <=b ]]
[[ =a >=b ]]
[[ a == a || c == b && a == b ]] && echo true
+i=1
+[[ a == b || $((i=0)) ]] && echo $i # i should be 0 now
+[[ a == a || $((i=1)) ]] && echo $i # i should still be 0
+[[ a == b && $((i=1)) ]] || echo $i # i should still be 0
+i=1
+[[ a == a && $((i=0)) ]] && echo $i # i should still be 0
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 66be73c1d8a0c253d34ee76206982e3cf12954b7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 1 03:32:58 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar 1 03:32:58 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=66be73c1
Walker: support indirect ref in runtime
---
bashast/bashast.g | 2 +-
scripts/command_execution.bash | 5 +++++
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 0be9b46..98da5e7 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -860,7 +860,6 @@ parameter_expansion
TIMES -> ^(BANG variable_name_for_bang TIMES)
| AT -> ^(BANG variable_name_for_bang AT)
| LSQUARE (op=TIMES|op=AT) RSQUARE -> ^(LIST_EXPAND variable_name_for_bang $op)
- | -> ^(VAR_REF variable_name_for_bang)
)
| {LA(1) == POUND && LA(2) != RBRACE }? => variable_size_ref;
parameter_delete_operator
@@ -915,6 +914,7 @@ variable_name
: num
| name LSQUARE AT RSQUARE -> ^(ARRAY name AT)
| name LSQUARE TIMES RSQUARE -> ^(ARRAY name TIMES)
+ | BANG variable_name_for_bang -> ^(VAR_REF variable_name_for_bang)
| variable_name_no_digit
| DOLLAR
| TIMES
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index e400409..06d6676 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -79,3 +79,8 @@ echo \`\(\)\$\>\<\`
export SRC_URI="${SRC_URI} http://www.oracle.com/technology/products/berkeley-db/db/update/${MY_PV}/patch.${MY_PV}.${i}"
> /dev/null
(( i=1, j=2)) && echo $i $j
+a="ab cd ef"
+variable=a
+echo "${!variable// /_}"
+echo "${!#// /_}"
+echo "${!1// /_}"
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: d418891be2a8428a4b1edc82a7b964b0c6b34d6e
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 29 08:08:04 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Feb 29 08:08:04 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d418891b
Parser: allow double quotes in arithmetic expression
---
bashast/bashast.g | 2 +-
scripts/binary_arithmetic.bash | 6 ++++++
scripts/compound_command.bash | 5 +++++
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index ded2fab..0be9b46 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -1005,7 +1005,7 @@ primary
| arithmetic_expansion
| LPAREN! (arithmetics) RPAREN!;
pre_post_primary
- : primary;
+ : DQUOTE!? primary DQUOTE!?;
post_inc_dec
: pre_post_primary ((BLANK) => BLANK)?
(
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index c5f018c..db7dcb7 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -70,3 +70,9 @@ echo "$((0&&FOO059++))"
echo "$(( 1 == 2))"
echo "$(( 1 == 1))"
echo $(($((1))))
+(( a= "1+ 1"*2))
+echo $a
+FOO="3 * 2"
+echo $(( $FOO + 1 ))
+FOO="3, b = 2"
+echo $(( $FOO + 1 ))
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 0db8ff8..0d3321e 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -356,3 +356,8 @@ for((i=1,j=2;i!=2&&j!=4;++i))
do
echo $i $j
done
+python_versions=(2.6 2.7 3.0 3.1)
+for ((i = "${#python_versions[@]}"; i >= 0; i--))
+do
+ echo $i
+done
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 6b1bcb401a25727bea39066cfe7d16fe3536e981
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 2 08:25:49 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Mar 2 08:25:49 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=6b1bcb40
Walker: allow empty case command
---
bashast/libbashWalker.g | 3 ++-
scripts/compound_command.bash | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index f57f403..95f8a90 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -1068,7 +1068,8 @@ case_clause[const std::string& target] returns[bool matched]
else
{
$matched = false;
- seek_to_next_tree(ctx);
+ if(LA(1) == CASE_COMMAND)
+ seek_to_next_tree(ctx);
}
})
|CASE_PATTERN;
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 0d3321e..36161fe 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -361,3 +361,15 @@ for ((i = "${#python_versions[@]}"; i >= 0; i--))
do
echo $i
done
+EAPI="4"
+case ${EAPI} in
+ 0|1)
+ echo "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
+ 2|3);;
+ 4)
+ # S is no longer automatically assigned when it doesn't exist.
+ S="${WORKDIR}"
+ ;;
+ *)
+ echo "Unknown EAPI=${EAPI} for ruby-ng.eclass"
+esac
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 7442b34889d4bfc6feca9cdc6d4bc5c881488053
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 26 08:09:47 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=7442b348
Walker: fix single quoted argument handling
---
bashast/libbashWalker.g | 1 +
scripts/command_execution.bash | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 95f8a90..5e3fd6e 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -282,6 +282,7 @@ string_part returns[std::string libbash_value, bool quoted, bool is_raw_string]
})*)
|(SINGLE_QUOTED_STRING) => ^(SINGLE_QUOTED_STRING node=SINGLE_QUOTED_STRING_TOKEN) {
$libbash_value = get_single_quoted_string(node);
+ $quoted = true;
}
|(ARITHMETIC_EXPRESSION) =>
^(ARITHMETIC_EXPRESSION value=arithmetics {
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 0927642..89a0ed7 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -64,6 +64,7 @@ printf "%s %s\n" abc def
printf "%s %s\n" $FOO001, def
printf "123-%s" 456 789
printf "\n"
+printf 'debug-%s ' dvc kbd nla
printf "123-%s"
((FOO010=1))
echo $FOO010
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 156c4064b36c833ee8080d0b3aa7da1316914c1c
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 2 02:19:33 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Mar 2 02:19:33 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=156c4064
Walker: allow bash expansions in regular expressions
---
bashast/libbashWalker.g | 4 +++-
scripts/var_expansion.bash | 5 +++++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 67a39fc..d45d9c3 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -797,7 +797,9 @@ keyword_condition returns[bool status]
} r=keyword_condition) { $status= l && r; }
|^(NEGATION l=keyword_condition) { $status = !l; }
|^(MATCH_REGULAR_EXPRESSION left_str=string_expr right_str=string_expr) {
- boost::xpressive::sregex re = boost::xpressive::sregex::compile(right_str.libbash_value);
+ bash_ast ast(std::stringstream(right_str.libbash_value), &bash_ast::parser_all_expansions);
+ std::string pattern = ast.interpret_with(*walker, &bash_ast::walker_string_expr);
+ boost::xpressive::sregex re = boost::xpressive::sregex::compile(pattern);
$status = boost::xpressive::regex_match(left_str.libbash_value, re);
}
|s=common_condition { $status = s; };
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index e78ac8f..4bdcb3e 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -141,3 +141,8 @@ echo "${search_paths/#/${root}}"
[[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]
[[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]]
[[ "$(echo "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]]
+
+PYTHON_DEPEND="2:2.6"
+version_components_group_regex="(2|3|\*)(:([[:digit:]]+\.[[:digit:]]+)?(:([[:digit:]]+\.[[:digit:]]+)?)?)?"
+version_components_groups="${PYTHON_DEPEND}"
+[[ "${version_components_groups}" =~ ^((\!)?[[:alnum:]_-]+\?\ )?${version_components_group_regex}(\ ${version_components_group_regex})?$ ]] && echo true
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-07-08 9:31 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-07-08 9:31 UTC (permalink / raw
To: gentoo-commits
commit: d23dab871c34b69444bab8ef0f30ca45314600f8
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Tue May 29 18:26:04 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Jul 8 09:22:30 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d23dab87
Walker: Improve command list to support "command && command && command"
---
bashast/libbashWalker.g | 7 ++++---
scripts/command_execution.bash | 3 +++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 9157574..0c21ccd 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -736,18 +736,19 @@ argument[std::vector<std::string>& args, bool split]
}
};
-logic_command_list
+logic_command
@declarations {
bool logic_and;
}
- :command
- |^((LOGICAND { logic_and = true; } | LOGICOR { logic_and = false; }) command {
+ : ^((LOGICAND { logic_and = true; } | LOGICOR { logic_and = false; }) logic_command_list {
if(logic_and ? !walker->get_status() : walker->get_status())
command(ctx);
else
seek_to_next_tree(ctx);
});
+logic_command_list: command | logic_command;
+
command_list: ^(LIST logic_command_list+);
compound_command
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 58f1279..4c04908 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -17,6 +17,9 @@ false && echo "wrong"
false || echo "right"
true ||
echo "wrong"
+echo right1 && echo right2 && false && echo wrong
+false || echo right3 || echo wrong
+true && false || echo right4 && echo right5
echo "end"
: ${DEFAULTED:="yes"}
FOO="abc" echo "command environment"
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-07-08 9:44 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-07-08 9:44 UTC (permalink / raw
To: gentoo-commits
commit: 3d70950f61980d0268356124b9cc4753dfd6265e
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Mon Jul 2 23:20:05 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Jul 8 09:38:47 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3d70950f
Parser&Walker: Support for loop without list
---
bashast/bashast.g | 8 ++++----
bashast/libbashWalker.g | 10 +++++++---
scripts/compound_command.bash | 12 ++++++++++++
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index f7ce358..e2702d0 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -530,11 +530,11 @@ semiel
for_expr
: FOR BLANK?
(
- name wspace
+ name
(
- IN for_each_value* BLANK? (SEMIC|EOL) wspace?
- |SEMIC wspace?
- |
+ wspace IN for_each_value* BLANK? (SEMIC|EOL) wspace?
+ | wspace? SEMIC wspace?
+ | wspace
) DO wspace command_list semiel DONE -> ^(FOR name for_each_value* command_list)
| LLPAREN EOL?
// initilization
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 0c21ccd..648dd53 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -842,11 +842,11 @@ for_expr
@declarations {
ANTLR3_MARKER commands_index;
std::vector<std::string> splitted_values;
+ bool in_array = false;
ANTLR3_MARKER condition_index;
}
:^(FOR libbash_string=name_base
- // Empty value as $@ is not supported currently
(string_expr
{
// Word splitting happens here
@@ -854,10 +854,11 @@ for_expr
splitted_values.push_back($string_expr.libbash_value);
else
walker->split_word($string_expr.libbash_value, splitted_values);
+ in_array = true;
}
- )+
+ )*
{
- if(splitted_values.empty())
+ if(splitted_values.empty() && in_array)
{
//skip the body
seek_to_next_tree(ctx);
@@ -865,6 +866,9 @@ for_expr
}
else
{
+ if(!in_array)
+ walker->resolve_array<std::string>("*", splitted_values);
+
commands_index = INDEX();
for(auto iter = splitted_values.begin(); iter != splitted_values.end(); ++iter)
{
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index 36161fe..fe3eac4 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -84,6 +84,18 @@ do
done
done
+function positional_for()
+{
+ for arg; do
+ echo $arg
+ done
+
+ for arg do
+ echo $arg
+ done
+}
+positional_for foo bar
+
i=0;
while [ $i != 4 ]
do
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-07-29 12:45 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-07-29 12:45 UTC (permalink / raw
To: gentoo-commits
commit: 4e7532418091e60ba632350eb865698dd208e968
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Thu Jul 5 02:00:22 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jul 20 01:20:22 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4e753241
Parser: Support line continuation inside keyword test
---
bashast/bashast.g | 4 ++--
scripts/compound_command.bash | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 2d425ce..0fb8212 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -614,9 +614,9 @@ condition_expr
#endif
keyword_condition_and
- : keyword_condition_primary (BLANK!? LOGICAND^ BLANK!? keyword_condition_primary)*;
+ : keyword_condition_primary ( wspace!? LOGICAND^ wspace!? keyword_condition_primary)*;
keyword_condition
- : keyword_condition_and (BLANK!? LOGICOR^ BLANK!? keyword_condition_and)*;
+ : keyword_condition_and ( wspace!? LOGICOR^ wspace!? keyword_condition_and)*;
keyword_negation_primary
: BANG BLANK keyword_condition_primary -> ^(NEGATION keyword_condition_primary);
keyword_condition_primary
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
index fe3eac4..f328f85 100644
--- a/scripts/compound_command.bash
+++ b/scripts/compound_command.bash
@@ -385,3 +385,25 @@ case ${EAPI} in
*)
echo "Unknown EAPI=${EAPI} for ruby-ng.eclass"
esac
+
+if [[ 1 == 0 ||
+ 1 == 0
+|| 1 == 0
+ || 1 == 0 || # Extra space here
+ 1 == 1 ]]; then
+ echo or
+fi
+
+if [[ 1 == 1 # Extra space here
+ && 1 == 1 && 1 == 1 &&
+ 1 == 1&&
+ 1 == 1 ]]; then
+ echo and
+fi
+
+if [[ 1 == 1 &&
+ 1 == 0 || 1 == 1
+ && 1 == 1 ||
+ 1 == 1 && 1 == 1 ]]; then
+ echo and or
+fi
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-07-29 12:46 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-07-29 12:46 UTC (permalink / raw
To: gentoo-commits
commit: 1c01ffc3d49a910445c86b76999cd62531ab3e91
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Mon Jul 16 20:38:28 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jul 20 01:20:22 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=1c01ffc3
Walker: Support local declaration inside eval
---
bashast/libbashWalker.g | 2 +-
scripts/var_def.bash | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 42a8917..44cb4c2 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -650,7 +650,7 @@ execute_command[std::string& name, std::vector<std::string>& libbash_args]
bool redirection = false;
}
@init {
- if(name != "local" && name != "set" && name != "declare")
+ if(name != "local" && name != "set" && name != "declare" && name != "eval")
current_scope.reset(new interpreter::local_scope(*walker));
}
:var_def[true]* (redirect[out, err, in]{ redirection = true; })* {
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index b0224f1..fb6550d 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -85,12 +85,15 @@ echo $FOO005
function foo() {
local -i foo=1
local -a bar=(1 2 3)
+ eval local foobar=23
echo $foo
echo ${bar[@]}
+ echo foobar
}
foo
bar=@
echo $bar
+echo $foobar
ARRAY11=(1 2 3 [10]=15)
ARRAY11+=(1 [15]=20)
echo ${ARRAY11[@]}
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-07 2:38 Mu Qiao
0 siblings, 0 replies; 66+ messages in thread
From: Mu Qiao @ 2012-08-07 2:38 UTC (permalink / raw
To: gentoo-commits
commit: d8876bc0f19842c9773284af2cee3c61a7dfdc39
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Thu Jul 19 22:35:40 2012 +0000
Commit: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
CommitDate: Fri Aug 3 00:03:41 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d8876bc0
Walker: Fix appending to an array of size 1
---
bashast/libbashWalker.g | 2 +-
scripts/var_def.bash | 4 ++++
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 34a7660..460ed0c 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -242,7 +242,7 @@ var_def[bool local]
}
|^(PLUS_ASSIGN libbash_name=name_base {
index = walker->get_max_index(libbash_name) + 1;
- if(index == 1) // The variable is not defined
+ if(index == 1 && walker->is_unset_or_null(libbash_name, 0))
index = 0;
} array_def_helper[libbash_name, values, index]){
if(local)
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index fb6550d..dc47b6c 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -102,6 +102,10 @@ echo ${ARRAY12[@]}
ARRAY13=()
ARRAY13+=(4 5 6)
echo ${ARRAY13[@]}
+ARRAY14=(1)
+ARRAY14+=(3)
+ARRAY14+=(4 5)
+echo ${ARRAY14[@]}
declare num=42
echo $num
unset num
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-07 2:38 Mu Qiao
0 siblings, 0 replies; 66+ messages in thread
From: Mu Qiao @ 2012-08-07 2:38 UTC (permalink / raw
To: gentoo-commits
commit: 6404756744b9230da6d755b456c6922c1693301a
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Thu Jul 12 21:30:48 2012 +0000
Commit: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
CommitDate: Fri Aug 3 00:03:41 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=64047567
Parser&Walker: Escape '[' and ']'
---
bashast/bashast.g | 4 +++-
bashast/libbashWalker.g | 2 ++
scripts/command_execution.bash | 1 +
3 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 3ce2c8e..61c7e57 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -786,7 +786,7 @@ ns_string_part
|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON
|TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|DECLARE|AT
// Escaped characters
- |ESC_RPAREN|ESC_LPAREN|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK|ESC_DQUOTE
+ |ESC_RPAREN|ESC_LPAREN|ESC_RSQUARE|ESC_LSQUARE|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK|ESC_DQUOTE
// The following is for filename expansion
|TIMES|QMARK;
@@ -1160,6 +1160,8 @@ LOGICOR : '||';
CONTINUE_LINE : (ESC EOL)+{$channel=HIDDEN;};
ESC_RPAREN : ESC RPAREN;
ESC_LPAREN : ESC LPAREN;
+ESC_RSQUARE : ESC RSQUARE;
+ESC_LSQUARE : ESC LSQUARE;
ESC_DOLLAR : ESC DOLLAR;
ESC_TICK : ESC TICK;
COMMAND_SUBSTITUTION_PAREN
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 27377de..9c85f9d 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -462,6 +462,8 @@ options {backtrack = true;}
}
:ESC_RPAREN { $libbash_value = ")"; }
|ESC_LPAREN { $libbash_value = "("; }
+ |ESC_RSQUARE { $libbash_value = "]"; }
+ |ESC_LSQUARE { $libbash_value = "["; }
|ESC_DOLLAR { $libbash_value = "$"; }
|ESC_DQUOTE { $libbash_value = "\""; }
|ESC_GT { $libbash_value = ">"; }
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 3b275ca..1cc837b 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -96,6 +96,7 @@ eval abc+=\( \"\$@\" \)
declare MOZILLA_FIVE_HOME="/usr/share/${PN}"
declare foo=23 empty bar=42
echo $MOZILLA_FIVE_HOME $foo $lol $bar
+echo \(\)\[\]\$\"\>
FILE=scripts/input_output_test
echo foo > $FILE
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-07 2:38 Mu Qiao
0 siblings, 0 replies; 66+ messages in thread
From: Mu Qiao @ 2012-08-07 2:38 UTC (permalink / raw
To: gentoo-commits
commit: 14db07b33b4a2df8ede5b8f7b7cda89004009d8d
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Fri Jul 20 02:25:32 2012 +0000
Commit: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
CommitDate: Fri Aug 3 00:03:41 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=14db07b3
Parser&Walker: Escape '
---
bashast/bashast.g | 3 ++-
bashast/libbashWalker.g | 1 +
scripts/command_execution.bash | 2 +-
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 61c7e57..4438b8c 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -786,7 +786,7 @@ ns_string_part
|OTHER|EQUALS|PCT|PCTPCT|PLUS|MINUS|DOT|DOTDOT|COLON
|TILDE|LSQUARE|RSQUARE|CARET|POUND|COMMA|EXPORT|LOCAL|DECLARE|AT
// Escaped characters
- |ESC_RPAREN|ESC_LPAREN|ESC_RSQUARE|ESC_LSQUARE|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK|ESC_DQUOTE
+ |ESC_RPAREN|ESC_LPAREN|ESC_RSQUARE|ESC_LSQUARE|ESC_DOLLAR|ESC_GT|ESC_LT|ESC_TICK|ESC_DQUOTE|ESC_SQUOTE
// The following is for filename expansion
|TIMES|QMARK;
@@ -1129,6 +1129,7 @@ SEMIC : ';';
DOUBLE_SEMIC : ';;';
PIPE : '|';
ESC_DQUOTE : '\\"';
+ESC_SQUOTE : { !double_quoted }? => '\\\'';
DQUOTE : '"' { if(LA(-1) != '\\') double_quoted = !double_quoted; };
SQUOTE : { double_quoted }? => '\'';
SINGLE_QUOTED_STRING_TOKEN : { !double_quoted }? => '\'' .* '\'';
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 9c85f9d..34a7660 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -466,6 +466,7 @@ options {backtrack = true;}
|ESC_LSQUARE { $libbash_value = "["; }
|ESC_DOLLAR { $libbash_value = "$"; }
|ESC_DQUOTE { $libbash_value = "\""; }
+ |ESC_SQUOTE { $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 1cc837b..c526d75 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -96,7 +96,7 @@ eval abc+=\( \"\$@\" \)
declare MOZILLA_FIVE_HOME="/usr/share/${PN}"
declare foo=23 empty bar=42
echo $MOZILLA_FIVE_HOME $foo $lol $bar
-echo \(\)\[\]\$\"\>
+echo \(\)\[\]\$\"\>\'
FILE=scripts/input_output_test
echo foo > $FILE
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-19 14:29 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-08-19 14:29 UTC (permalink / raw
To: gentoo-commits
commit: 249c86b76e37e6057d27956337d5e84d61563498
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Tue Aug 7 14:53:36 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Aug 9 02:44:42 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=249c86b7
Parser: Support appending strings with special characters
---
bashast/bashast.g | 4 ++--
scripts/var_def.bash | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 4438b8c..9fd3fdb 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -431,8 +431,8 @@ variable_definition_atom
-> ^(EQUALS ^(name explicit_arithmetic) string_expr?)
| name EQUALS value? -> ^(EQUALS name value?)
| 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?));
+ | name PLUS EQUALS string_expr_part*
+ -> ^(EQUALS name ^(STRING ^(VAR_REF name) string_expr_part*));
value
: string_expr
| array_value;
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index dc47b6c..b3ffca7 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -82,6 +82,8 @@ FOO005=abc
echo $FOO005
FOO005+=def
echo $FOO005
+FOO005+=-foo-bar
+echo $FOO005
function foo() {
local -i foo=1
local -a bar=(1 2 3)
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-19 14:54 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-08-19 14:54 UTC (permalink / raw
To: gentoo-commits
commit: 4b0cb9bdc2981094bb94e210a3bf080c303da832
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Fri Aug 3 03:03:28 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Aug 3 03:07:32 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=4b0cb9bd
Parser: Accept semicolons inside builtin variable definitions
---
bashast/bashast.g | 1 +
scripts/command_execution.bash | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 0d59e8c..55c469a 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -481,6 +481,7 @@ scope {
|(RPAREN) => RPAREN { --$builtin_variable_definition_item::parens; }
|(DQUOTE) => DQUOTE { $builtin_variable_definition_item::dquotes = ! $builtin_variable_definition_item::dquotes; }
|(~(EOL|SEMIC)) => expansion_base
+ | {LA(1) == SEMIC && $builtin_variable_definition_item::dquotes}? => SEMIC
| {LA(1) == EOL && $builtin_variable_definition_item::parens > 0 || $builtin_variable_definition_item::dquotes}? => EOL
)+;
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index ca8a4e5..df6275b 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -109,6 +109,7 @@ echo "${!variable// /$'\n'}"
eval abc+=\( \"\$@\" \)
declare MOZILLA_FIVE_HOME="/usr/share/${PN}"
declare foo=23 empty bar=42
+declare var=";; ; foobar"; echo yay
echo $MOZILLA_FIVE_HOME $foo $lol $bar
echo \(\)\[\]\$\"\>\'
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-19 14:54 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-08-19 14:54 UTC (permalink / raw
To: gentoo-commits
commit: 5a31b0886ca36364c34ed04011bcdac211bb5bd7
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Fri Jul 27 03:02:20 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Aug 3 03:07:25 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=5a31b088
Parser: Multiline string declaration
Support quoted strings line breaks in builtin variable definitions
---
bashast/bashast.g | 9 ++++++++-
scripts/command_execution.bash | 14 ++++++++++++++
2 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 4438b8c..0d59e8c 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -466,15 +466,22 @@ array_atom
builtin_variable_definition_item
scope {
int parens;
+#ifdef OUTPUT_C
+ bool dquotes;
+#else
+ boolean dquotes;
+#endif
}
@init {
$builtin_variable_definition_item::parens = 0;
+ $builtin_variable_definition_item::dquotes = false;
}
: (
(LPAREN) => LPAREN { ++$builtin_variable_definition_item::parens; }
|(RPAREN) => RPAREN { --$builtin_variable_definition_item::parens; }
+ |(DQUOTE) => DQUOTE { $builtin_variable_definition_item::dquotes = ! $builtin_variable_definition_item::dquotes; }
|(~(EOL|SEMIC)) => expansion_base
- | {LA(1) == EOL && $builtin_variable_definition_item::parens > 0}? => EOL
+ | {LA(1) == EOL && $builtin_variable_definition_item::parens > 0 || $builtin_variable_definition_item::dquotes}? => EOL
)+;
#ifdef OUTPUT_C
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index c526d75..ca8a4e5 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -82,6 +82,20 @@ echo ${array[@]}
ech\
o Hello\
world
+function multiline()
+{
+ declare var1="foo
+bar"
+ export var2="one
+ two
+three"
+ local var3="foo
+bar"
+ echo $var1
+ echo $var2
+ echo $var3
+}
+multiline
echo \`\(\)\$\>\<\`
export SRC_URI="${SRC_URI} http://www.oracle.com/technology/products/berkeley-db/db/update/${MY_PV}/patch.${MY_PV}.${i}"
> /dev/null
^ permalink raw reply related [flat|nested] 66+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
@ 2012-08-19 15:23 Petteri Räty
0 siblings, 0 replies; 66+ messages in thread
From: Petteri Räty @ 2012-08-19 15:23 UTC (permalink / raw
To: gentoo-commits
commit: 527b3e33399dc4075339463f2b1f0478bb61ca6b
Author: André Aparício <aparicio99 <AT> gmail <DOT> com>
AuthorDate: Sat Aug 11 01:17:05 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Aug 19 15:13:55 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=527b3e33
Parser&Walker: Support nested command substitution
---
bashast/bashast.g | 2 +-
bashast/libbashWalker.g | 15 ++++++++++++---
scripts/command_execution.bash | 4 ++++
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 799b1cf..2226839 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -1197,7 +1197,7 @@ COMMAND_SUBSTITUTION_PAREN
| .
)+
));
-COMMAND_SUBSTITUTION_TICK : TICK (~(TICK))+ TICK;
+COMMAND_SUBSTITUTION_TICK : TICK .+ (~ESC) TICK;
ESC_LT : ESC'<';
ESC_GT : ESC'>';
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 768129f..f50b32c 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -1132,13 +1132,22 @@ command_substitution returns[std::string libbash_value]
@declarations {
std::string subscript;
std::stringstream out;
+ current_streams streams(walker->get_output_stream(), walker->get_error_stream(), walker->get_input_stream());
}
:^(COMMAND_SUB { walker->set_output_stream(&out); } (libbash_string=any_string { subscript += libbash_string; })+) {
- if(subscript[0] == '`')
- bash_ast(std::stringstream(subscript.substr(1, subscript.size() - 2))).interpret_with(*walker);
+ if(subscript[0] == '`') {
+ std::string sub = subscript.substr(1, subscript.size() - 2);
+ // Escape \ and ' for nested command substitution
+ size_t pos = 0;
+ while((pos = sub.find("\\\\", pos)) != std::string::npos)
+ sub.erase(pos++, 1);
+ pos = 0;
+ while((pos = sub.find("\\`", pos)) != std::string::npos)
+ sub.erase(pos++, 1);
+ bash_ast(std::stringstream(sub)).interpret_with(*walker);
+ }
else
bash_ast(std::stringstream(subscript.substr(2, subscript.size() - 3))).interpret_with(*walker);
- walker->restore_output_stream();
$libbash_value = out.str();
walker->trim_trailing_eols($libbash_value);
};
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index df6275b..248de63 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -79,6 +79,10 @@ echo "$(echo 'hi')"
echo "`echo 'hi'`"
array=(`echo 1` `echo 2` 3)
echo ${array[@]}
+echo `echo 1`
+echo `echo 1 \`echo 2\` 3`
+echo `echo 1 \`echo 2 \\\`echo 3\\\` 4\` 5`
+echo $(echo 1 `echo 2 $(echo 3) 4` 5)
ech\
o Hello\
world
^ permalink raw reply related [flat|nested] 66+ messages in thread
end of thread, other threads:[~2012-08-19 15:24 UTC | newest]
Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-09 7:27 [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/ Petteri Räty
-- strict thread matches above, loose matches on Subject: below --
2012-08-19 15:23 Petteri Räty
2012-08-19 14:54 Petteri Räty
2012-08-19 14:54 Petteri Räty
2012-08-19 14:29 Petteri Räty
2012-08-07 2:38 Mu Qiao
2012-08-07 2:38 Mu Qiao
2012-08-07 2:38 Mu Qiao
2012-07-29 12:46 Petteri Räty
2012-07-29 12:45 Petteri Räty
2012-07-08 9:44 Petteri Räty
2012-07-08 9:31 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
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-07-20 13:08 Petteri Räty
2011-06-25 10:30 Petteri Räty
2011-06-25 10:30 Petteri Räty
2011-06-25 10:30 Petteri Räty
2011-06-25 10:05 Petteri Räty
2011-06-25 10:05 Petteri Räty
2011-06-19 19:15 Petteri Räty
2011-06-18 9:55 Petteri Räty
2011-06-16 16:53 Petteri Räty
2011-06-16 16:53 Petteri Räty
2011-06-11 8:52 Petteri Räty
2011-06-11 8:52 Petteri Räty
2011-06-09 11:46 Petteri Räty
2011-06-09 8:15 Petteri Räty
2011-06-03 12:43 Petteri Räty
2011-06-01 12:19 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-28 13:11 Petteri Räty
2011-05-28 13:11 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-23 14:39 Petteri Räty
2011-05-22 21:00 Petteri Räty
2011-05-12 14:06 Petteri Räty
2011-05-12 14:06 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-11 7:19 Petteri Räty
2011-05-06 10:29 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-20 14:04 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-04 16:09 Petteri Räty
2011-04-03 13:09 Petteri Räty
2011-04-03 10:16 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