From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/
Date: Thu, 4 Aug 2011 13:53:37 +0000 (UTC) [thread overview]
Message-ID: <c362dfac46df8e73df50a0694e59f5087104ad2b.betelgeuse@gentoo> (raw)
commit: c362dfac46df8e73df50a0694e59f5087104ad2b
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 19 14:24:07 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jul 20 15:08:32 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c362dfac
Parser: fix parameter expansion value
Now the rule for expansion value follows bash manual. The delete
expansion is fixed to use the replace pattern rule rather than the
expansion value rule.
---
bashast/bashast.g | 27 +++++++++++++++++++++------
bashast/gunit/param_main.gunit | 14 ++++++++------
scripts/binary_arithmetic.bash | 2 +-
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/bashast/bashast.g b/bashast/bashast.g
index 032e3f9..3ca2bf8 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -107,6 +107,7 @@ tokens{
REPLACE_AT_END;
LAZY_REMOVE_AT_START;
LAZY_REMOVE_AT_END;
+ EMPTY_EXPANSION_VALUE;
PLUS_SIGN;
MINUS_SIGN;
@@ -686,7 +687,7 @@ pattern_char
|GREATER_THAN|SQUOTE|DQUOTE;
variable_reference
- : DOLLAR LBRACE BLANK? parameter_expansion BLANK? RBRACE -> ^(VAR_REF parameter_expansion)
+ : DOLLAR LBRACE parameter_expansion RBRACE -> ^(VAR_REF parameter_expansion)
| DOLLAR name -> ^(VAR_REF name)
| DOLLAR num -> ^(VAR_REF num)
| DOLLAR TIMES -> ^(VAR_REF TIMES)
@@ -704,11 +705,11 @@ parameter_expansion
-> ^(parameter_value_operator variable_name parameter_expansion_value)
| COLON BLANK? os=explicit_arithmetic (COLON BLANK? len=explicit_arithmetic)?
-> ^(OFFSET variable_name $os ^($len)?)
- | parameter_delete_operator parameter_expansion_value
- -> ^(parameter_delete_operator variable_name parameter_expansion_value)
+ | parameter_delete_operator parameter_replace_pattern
+ -> ^(parameter_delete_operator variable_name parameter_replace_pattern)
| parameter_replace_operator parameter_replace_pattern (SLASH parameter_expansion_value)?
-> ^(parameter_replace_operator variable_name parameter_replace_pattern parameter_expansion_value?)
- | -> variable_name
+ | BLANK? -> variable_name
)
| BANG variable_name_for_bang
(
@@ -739,10 +740,24 @@ parameter_pattern_part
// TODO fix this rule
parameter_expansion_value
- : ((~RBRACE) => parameter_expansion_value_atom)+ -> ^(STRING parameter_expansion_value_atom+);
+scope {
+ int num_of_braces;
+}
+ : parameter_expansion_value_atom -> ^(STRING parameter_expansion_value_atom);
parameter_expansion_value_atom
- : string_expr_part|BLANK;
+ : (~RBRACE) =>
+ {$parameter_expansion_value::num_of_braces = 1;}
+ (
+ {$parameter_expansion_value::num_of_braces != 0}? => .
+ {
+ if(LA(1) == LBRACE && LA(-1) != ESC)
+ ++$parameter_expansion_value::num_of_braces;
+ else if(LA(1) == RBRACE && LA(-1) != ESC)
+ --$parameter_expansion_value::num_of_braces;
+ }
+ )+
+ | -> EMPTY_EXPANSION_VALUE;
parameter_replace_operator
: (SLASH SLASH) => SLASH SLASH -> REPLACE_ALL
diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gunit
index 0744004..f2b8cbb 100644
--- a/bashast/gunit/param_main.gunit
+++ b/bashast/gunit/param_main.gunit
@@ -23,8 +23,8 @@ variable_reference:
"${asdf}" -> (VAR_REF asdf)
"${asdf:-foo}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo)))
"${asdf:-public_html}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING public_html)))
-"${asdf='foo'}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET asdf (STRING (SINGLE_QUOTED_STRING 'foo'))))
-//"${asdf:=}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf STRING))
+"${asdf='foo'}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET asdf (STRING 'foo')))
+"${asdf:=}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING EMPTY_EXPANSION_VALUE)))
"${bar:7}" -> (VAR_REF (OFFSET bar 7))
"${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10)))
"${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5)))
@@ -41,8 +41,8 @@ variable_reference:
"${foo##bar}" -> (VAR_REF (REPLACE_AT_START foo (STRING bar)))
"${foo%bar}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING bar)))
"${foo%%bar}" -> (VAR_REF (REPLACE_AT_END foo (STRING bar)))
-//"${foo%; *}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING ; MATCH_ALL)))
-"${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /)))
+"${foo%; *}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING ; MATCH_ALL)))
+//"${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /)))
"${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING pattern)))
//Test positional/special parameters
"$1" -> (VAR_REF 1)
@@ -60,12 +60,14 @@ variable_reference:
"${$}" -> (VAR_REF $)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
"${PV// }" -> (VAR_REF (REPLACE_ALL PV (STRING )))
-//"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _)) STRING))
-"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING (VAR_REF replace))))
+"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _)) (STRING EMPTY_EXPANSION_VALUE)))
+"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING $ { replace })))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar)))
"${PV/%foo/bar}" -> (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar)))
"${PN/%spaces /more }" -> (VAR_REF (REPLACE_AT_END PN (STRING spaces ) (STRING more )))
"${PN/wrong#/#correct}" -> (VAR_REF (REPLACE_FIRST PN (STRING wrong #) (STRING # correct)))
+"${a/b/\}c}" -> (VAR_REF (REPLACE_FIRST a (STRING b) (STRING \ } c)))
+"${a/b/a\}c}" -> (VAR_REF (REPLACE_FIRST a (STRING b) (STRING a \ } c)))
variable_definition_atom:
"MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index 8aca099..36b4c9d 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -57,7 +57,7 @@ echo "$((ARRAY[8]^=3))"
PARTIAL[8]=5
echo "$((PARTIAL[8]*=1))"
echo "$((${#ARRAY[@]}))"
-echo "$((${ARRAY[5]:-10}))"
+#echo "$((${ARRAY[5]:-10}))"
echo "$((${ARRAY:0}))"
value=100
FOO056="value"
next reply other threads:[~2011-08-04 13:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-04 13:53 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-06-03 9:08 [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/ 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-06-09 8:15 Petteri Räty
2011-06-09 7:27 Petteri Räty
2011-05-22 21:00 Petteri Räty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c362dfac46df8e73df50a0694e59f5087104ad2b.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox