public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
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/, bashast/features_script/
Date: Thu, 14 Apr 2011 04:50:16 +0000 (UTC)	[thread overview]
Message-ID: <edf7a8bd8b991cb27517af0f6b1dcc73620f4158.betelgeuse@gentoo> (raw)

commit:     edf7a8bd8b991cb27517af0f6b1dcc73620f4158
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 13 13:43:23 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Apr 14 01:25:38 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=edf7a8bd

Fix parameter expansion in arithmetic expansion

Parameter expansion happens before arithmetic expansion when it's
used in arithmetic expansion. So the AST is changed to reflect it.

---
 bashast/bashast.g                       |    4 +++-
 bashast/features_script/features.sh.ast |    2 +-
 bashast/gunit/arith_main.gunit          |    8 ++++----
 bashast/gunit/assoc_array.gunit         |    2 +-
 bashast/gunit/expansions.gunit          |    2 +-
 scripts/binary_arithmetic.ebuild        |    2 +-
 scripts/var_expansion.ebuild            |    2 +-
 7 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/bashast/bashast.g b/bashast/bashast.g
index f15bec7..1ef7b1f 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -442,8 +442,10 @@ arithmetic
 	:	arithmetic_condition
 	|	arithmetic_assignment;
 //The base of the arithmetic operator.  Used for order of operations
+arithmetic_var_ref:
+	var_ref -> ^(VAR_REF var_ref);
 primary	:	num
-	|	var_ref
+	|	arithmetic_var_ref
 	|	command_sub
 	|	var_name -> ^(VAR_REF var_name)
 	|	LPAREN! (arithmetics) RPAREN!;

diff --git a/bashast/features_script/features.sh.ast b/bashast/features_script/features.sh.ast
index 070ffdb..cb7fcca 100644
--- a/bashast/features_script/features.sh.ast
+++ b/bashast/features_script/features.sh.ast
@@ -1 +1 @@
-(LIST (function lots_o_echo (CURRSHELL (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The   number   of   tests   that   have   failed :   (VAR_REF failedtests)))) (COMMAND (STRING echo) (STRING (SINGLE_QUOTED_STRING $ failedtests))) (COMMAND (STRING echo) (VAR_REF failedtests))))) (function do_some_arith (CURRSHELL (LIST (COMPOUND_ARITH (* 5 4)) (COMPOUND_ARITH (** 5 4)) (COMPOUND_ARITH (+ (VAR_REF failedtests) (/ 5 4))) (COMPOUND_ARITH (+ (VAR_REF z) (MINUS_SIGN 3)))))) (function arrays (SUBSHELL (LIST (= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d))) (COMMAND (STRING echo) (VAR_REF (asdf 3))) (= foo (ARRAY (STRING (COMMAND_SUB (COMMAND (STRING echo) (STRING 6)))) (STRING b) (STRING c) (STRING d))) (= (arr (VAR_REF foo)) (STRING 3)) (= bar (ARRAY (STRING a) (STRING b) (= 5 (STRING c))))))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING a) (STRING b)))) (COMMAND (STRING echo) (STRING (BRACE_EXP (.. a d)))) (COMMAND (STRING echo) (STRING (BRACE_EXP 
 (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d)))) (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c)))) (COMMAND (STRING (COMMAND_SUB (COMMAND (STRING echo) (STRING foobar))))) (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING gunit) (REDIR >> (STRING filelist)))) (case (COMMAND_SUB (COMMAND (STRING echo) (STRING asdf))) (CASE_PATTERN (STRING gz) (LIST (COMMAND (STRING echo) (STRING yay)))) (CASE_PATTERN (STRING bzip) (LIST (COMMAND (STRING echo) (STRING three)))) (CASE_PATTERN (STRING *) (LIST (COMMAND (STRING echo) (STRING woo))))) (for each (COMMAND_SUB (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING log)))) (LIST (COMMAND (STRING echo) (VAR_REF each)) (COMMAND (STRING cat) (STRING each)))) (for (FOR_INIT (+ 5 3)) (FOR_COND (+ 6 2)) (FOR_MOD (+ 3 1)) (LIST (COMMAND (STRING echo) (STRING yay)))) (select each (COMMAND_SUB (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING output)))) (LIST (COMMAND (STRING echo) (STRING asdf) (STRIN
 G 2) (REDIR > (STRING / dev / null))))) (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COMMAND (STRING echo) (STRING yay)))) (until (LIST (COMPOUND_COND (KEYWORD_TEST (a (STRING this / is . afile))))) (LIST (COMMAND (STRING touch) (STRING this / is . afile)))) (while (LIST (COMPOUND_COND (BUILTIN_TEST (n (STRING foobar))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file   found))))) (if (LIST (COMPOUND_COND (BUILTIN_TEST (eq 5 6)))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING something ' s   wrong))))) (COMMAND (STRING echo) (STRING this) (STRING command) (STRING has) (STRING multiple) (STRING arguments)) (COMMAND (STRING wc) (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . words))))) (|| (&& (&& (&& (COMMAND (STRING cd) (STRING build)) (COMMAND (STRING . / configure))) (COMMAND (STRING make))) (COMMAND (STRING make_install))) (COMMAND (STRING echo) (STRING fail))) (COMMAND (STRING cd) (STRING
  / usr / bin)) (| (COMMAND (STRING ls) (STRING - al)) (COMMAND (STRING grep) (STRING more))) (= asdf (STRING parameters)) (COMMAND (STRING (VAR_REF (:- asdf (STRING foo))))) (COMMAND (STRING (VAR_REF (OFFSET asdf 8)))) (COMMAND (STRING (VAR_REF (! asdf *)))) (COMMAND (STRING (VAR_REF (! asdf @)))) (COMMAND (STRING (VAR_REF (# foo)))) (COMMAND (STRING (VAR_REF (REPLACE_FIRST replaice (STRING with) (STRING pattern))))) (COMMAND (STRING (VAR_REF (# asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (## asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (% asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (% asdf (STRING bar))))) (COMMAND (STRING (VAR_REF 1)) (VAR_REF @) (VAR_REF *)) (COMMAND (STRING (VAR_REF ?))) (COMMAND (STRING (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar))))) (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING aster
 isk -))))) (| (COMMAND (STRING cat) (STRING asdf)) (COMMAND (STRING grep) (STRING three) (STRING 2) (REDIR >& 1) (REDIR > (STRING / dev / null)))) (COMMAND (STRING echo) (STRING asdf) (REDIR >> (STRING APPEND))) (COMMAND (STRING echo) (STRING cat) (<<< (STRING word))))
+(LIST (function lots_o_echo (CURRSHELL (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The   number   of   tests   that   have   failed :   (VAR_REF failedtests)))) (COMMAND (STRING echo) (STRING (SINGLE_QUOTED_STRING $ failedtests))) (COMMAND (STRING echo) (VAR_REF failedtests))))) (function do_some_arith (CURRSHELL (LIST (COMPOUND_ARITH (* 5 4)) (COMPOUND_ARITH (** 5 4)) (COMPOUND_ARITH (+ (VAR_REF (VAR_REF failedtests)) (/ 5 4))) (COMPOUND_ARITH (+ (VAR_REF (VAR_REF z)) (MINUS_SIGN 3)))))) (function arrays (SUBSHELL (LIST (= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d))) (COMMAND (STRING echo) (VAR_REF (asdf 3))) (= foo (ARRAY (STRING (COMMAND_SUB (COMMAND (STRING echo) (STRING 6)))) (STRING b) (STRING c) (STRING d))) (= (arr (VAR_REF foo)) (STRING 3)) (= bar (ARRAY (STRING a) (STRING b) (= 5 (STRING c))))))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING a) (STRING b)))) (COMMAND (STRING echo) (STRING (BRACE_EXP (.. a d)))) (COMMAND (STRING echo)
  (STRING (BRACE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d)))) (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c)))) (COMMAND (STRING (COMMAND_SUB (COMMAND (STRING echo) (STRING foobar))))) (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING gunit) (REDIR >> (STRING filelist)))) (case (COMMAND_SUB (COMMAND (STRING echo) (STRING asdf))) (CASE_PATTERN (STRING gz) (LIST (COMMAND (STRING echo) (STRING yay)))) (CASE_PATTERN (STRING bzip) (LIST (COMMAND (STRING echo) (STRING three)))) (CASE_PATTERN (STRING *) (LIST (COMMAND (STRING echo) (STRING woo))))) (for each (COMMAND_SUB (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING log)))) (LIST (COMMAND (STRING echo) (VAR_REF each)) (COMMAND (STRING cat) (STRING each)))) (for (FOR_INIT (+ 5 3)) (FOR_COND (+ 6 2)) (FOR_MOD (+ 3 1)) (LIST (COMMAND (STRING echo) (STRING yay)))) (select each (COMMAND_SUB (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING output)))) (LIST (COMMAND (STRING echo) 
 (STRING asdf) (STRING 2) (REDIR > (STRING / dev / null))))) (if (LIST (COMMAND (STRING echo) (STRING yay2))) (LIST (COMMAND (STRING echo) (STRING yay)))) (until (LIST (COMPOUND_COND (KEYWORD_TEST (a (STRING this / is . afile))))) (LIST (COMMAND (STRING touch) (STRING this / is . afile)))) (while (LIST (COMPOUND_COND (BUILTIN_TEST (n (STRING foobar))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING file   found))))) (if (LIST (COMPOUND_COND (BUILTIN_TEST (eq 5 6)))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING something ' s   wrong))))) (COMMAND (STRING echo) (STRING this) (STRING command) (STRING has) (STRING multiple) (STRING arguments)) (COMMAND (STRING wc) (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . words))))) (|| (&& (&& (&& (COMMAND (STRING cd) (STRING build)) (COMMAND (STRING . / configure))) (COMMAND (STRING make))) (COMMAND (STRING make_install))) (COMMAND (STRING echo) (STRING fail))) (COMMAND
  (STRING cd) (STRING / usr / bin)) (| (COMMAND (STRING ls) (STRING - al)) (COMMAND (STRING grep) (STRING more))) (= asdf (STRING parameters)) (COMMAND (STRING (VAR_REF (:- asdf (STRING foo))))) (COMMAND (STRING (VAR_REF (OFFSET asdf 8)))) (COMMAND (STRING (VAR_REF (! asdf *)))) (COMMAND (STRING (VAR_REF (! asdf @)))) (COMMAND (STRING (VAR_REF (# foo)))) (COMMAND (STRING (VAR_REF (REPLACE_FIRST replaice (STRING with) (STRING pattern))))) (COMMAND (STRING (VAR_REF (# asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (## asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (% asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (% asdf (STRING bar))))) (COMMAND (STRING (VAR_REF 1)) (VAR_REF @) (VAR_REF *)) (COMMAND (STRING (VAR_REF ?))) (COMMAND (STRING (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar))))) (= MY_PN (STRING (VAR_REF (REPLACE_FI
 RST PN (STRING asterisk -))))) (| (COMMAND (STRING cat) (STRING asdf)) (COMMAND (STRING grep) (STRING three) (STRING 2) (REDIR >& 1) (REDIR > (STRING / dev / null)))) (COMMAND (STRING echo) (STRING asdf) (REDIR >> (STRING APPEND))) (COMMAND (STRING echo) (STRING cat) (<<< (STRING word))))

diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit
index 219cc30..8ead7ef 100644
--- a/bashast/gunit/arith_main.gunit
+++ b/bashast/gunit/arith_main.gunit
@@ -44,9 +44,9 @@ unary:
 "!8" -> (! 8)
 "!!8" -> (! (! 8))
 "--8" -> (PRE_DECR 8)
-"+++${a}" -> (PLUS_SIGN (PRE_INCR (VAR_REF a)))
-"++++${a}" -> (PLUS_SIGN (PLUS_SIGN (PRE_INCR (VAR_REF a))))
-"+-++${a}" -> (PLUS_SIGN (MINUS_SIGN (PRE_INCR (VAR_REF a))))
+"+++${a}" -> (PLUS_SIGN (PRE_INCR (VAR_REF (VAR_REF a))))
+"++++${a}" -> (PLUS_SIGN (PLUS_SIGN (PRE_INCR (VAR_REF (VAR_REF a)))))
+"+-++${a}" -> (PLUS_SIGN (MINUS_SIGN (PRE_INCR (VAR_REF (VAR_REF a)))))
 
 exponential:
 "8" -> "8"
@@ -121,7 +121,7 @@ arithmetic_condition:
 "(4-3)?0:1"->(ARITHMETIC_CONDITION (- 4 3) 0 1)
 
 arithmetic_expansion:
-"$((5+4, 3+2, $a*$b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)))
+"$((5+4, 3+2, a*b))" -> (ARITHMETIC_EXPRESSION (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)))
 
 start:
 "echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2)))))

diff --git a/bashast/gunit/assoc_array.gunit b/bashast/gunit/assoc_array.gunit
index 4bb4e05..a3d1508 100644
--- a/bashast/gunit/assoc_array.gunit
+++ b/bashast/gunit/assoc_array.gunit
@@ -21,7 +21,7 @@ gunit bashast;
 var_def:
 "arr[foo]=\"asdf\"" -> (= (arr (VAR_REF foo)) (STRING (DOUBLE_QUOTED_STRING asdf)))
 "arr=(a b [4]=c)" -> (= arr (ARRAY (STRING a) (STRING b) (= 4 (STRING c))))
-"asdf[$idx]=${var}" -> (= (asdf (VAR_REF idx)) (STRING (VAR_REF var)))
+"asdf[idx]=${var}" -> (= (asdf (VAR_REF idx)) (STRING (VAR_REF var)))
 "asdf[++i]=${var}" -> (= (asdf (PRE_INCR (VAR_REF i))) (STRING (VAR_REF var)))
 "asdf[++i,j]=${var}" -> (= (asdf (PRE_INCR (VAR_REF i)) (VAR_REF j)) (STRING (VAR_REF var)))
 "asdf[$((i))]=${var}" -> (= (asdf (VAR_REF i)) (STRING (VAR_REF var)))

diff --git a/bashast/gunit/expansions.gunit b/bashast/gunit/expansions.gunit
index 252c6bf..406d583 100644
--- a/bashast/gunit/expansions.gunit
+++ b/bashast/gunit/expansions.gunit
@@ -21,7 +21,7 @@ gunit bashast;
 list:
 "echo a{b,c,d}" -> (LIST (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c) (STRING d)))))
 "((5+5))" -> (LIST (COMPOUND_ARITH (+ 5 5)))
-"(( 4 + $asdf ))" -> (LIST (COMPOUND_ARITH (+ 4 (VAR_REF asdf))))
+"(( 4 + asdf ))" -> (LIST (COMPOUND_ARITH (+ 4 (VAR_REF asdf))))
 "[[ while=while ]] && echo true" -> (LIST (&& (COMPOUND_COND (KEYWORD_TEST (= (STRING while) (STRING while)))) (COMMAND (STRING echo) (STRING true))))
 "for each in `ls |grep output`; do
 echo $each

diff --git a/scripts/binary_arithmetic.ebuild b/scripts/binary_arithmetic.ebuild
index 01ca17a..a674f5c 100644
--- a/scripts/binary_arithmetic.ebuild
+++ b/scripts/binary_arithmetic.ebuild
@@ -34,6 +34,6 @@ value="$((100))"
 FOO032="$((value+++value++))"
 FOO033="$((++value+value++))"
 FOO034="$((10*(2+5)<<3%2**5))"
-FOO035="$((10*${value}<<3%2**5))"
+FOO035="$((10*value<<3%2**5))"
 FOO036="$(( (20&5|3||1*100-20&5*10)+~(2*5) ))"
 value="$((100))"

diff --git a/scripts/var_expansion.ebuild b/scripts/var_expansion.ebuild
index 96b6bf2..c45ad1e 100644
--- a/scripts/var_expansion.ebuild
+++ b/scripts/var_expansion.ebuild
@@ -1,6 +1,6 @@
 ARRAY=(hi hello 1 2 3)
 EAPI="3"
-EAPI4="$(($EAPI+1))"
+EAPI4="$((EAPI+1))"
 FOO001="${EAPI:-hello}"
 FOO002="${EAPI3:-hello}"
 FOO003=123



             reply	other threads:[~2011-04-14  4:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-14  4:50 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-04-27 15:11 [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/gunit/, bashast/features_script/ Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2012-06-03  9:08 Petteri Räty

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=edf7a8bd8b991cb27517af0f6b1dcc73620f4158.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