From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QOWE2-0005QK-VL for garchives@archives.gentoo.org; Mon, 23 May 2011 14:35:19 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A038E1C052; Mon, 23 May 2011 14:34:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 413D11C047 for ; Mon, 23 May 2011 14:34:21 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AAFAE1B4029 for ; Mon, 23 May 2011 14:34:20 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 1A33580505 for ; Mon, 23 May 2011 14:34:20 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <2ccdd59f81e372c51daa099528dd18a0e5ddb6b1.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/, bashast/features_script/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/bashast.g bashast/features_script/features.sh.ast bashast/libbashWalker.g scripts/arithmetic_assignment.bash scripts/binary_arithmetic.bash scripts/binary_arithmetic.bash.result X-VCS-Directories: scripts/ bashast/ bashast/features_script/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 2ccdd59f81e372c51daa099528dd18a0e5ddb6b1 Date: Mon, 23 May 2011 14:34:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 54bf7345af5c0a1f7198d333e4ab0073 commit: 2ccdd59f81e372c51daa099528dd18a0e5ddb6b1 Author: Mu Qiao gentoo org> AuthorDate: Thu May 19 11:03:58 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Mon May 23 15:04:44 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D2ccdd59f Parser: fix var_ref in arithmetic expansion All variable references in arithmetic expansion were treated as indirect references. This is fixed now. With this modification variable expansion in arithmetics is supported now. --- bashast/bashast.g | 11 ++++++----- bashast/features_script/features.sh.ast | 2 +- bashast/libbashWalker.g | 1 + scripts/arithmetic_assignment.bash | 3 ++- scripts/binary_arithmetic.bash | 1 - scripts/binary_arithmetic.bash.result | 6 +++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index e391a35..dd1c92d 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -492,16 +492,17 @@ extended_pattern_match arithmetic_var_ref: var_ref -> ^(VAR_REF var_ref); primary : num - | arithmetic_var_ref + | var_ref | command_sub | var_name_no_digit -> ^(VAR_REF var_name_no_digit) | LPAREN! (arithmetics) RPAREN!; +pre_post_primary: arithmetic_var_ref | primary; post_inc_dec - : primary BLANK? PLUS PLUS -> ^(POST_INCR primary) - | primary BLANK? MINUS MINUS -> ^(POST_DECR primary); + : pre_post_primary BLANK? PLUS PLUS -> ^(POST_INCR pre_post_primary) + | pre_post_primary BLANK? MINUS MINUS -> ^(POST_DECR pre_post_primary); pre_inc_dec - : PLUS PLUS BLANK? primary -> ^(PRE_INCR primary) - | MINUS MINUS BLANK? primary -> ^(PRE_DECR primary); + : PLUS PLUS BLANK? pre_post_primary -> ^(PRE_INCR pre_post_primary) + | MINUS MINUS BLANK? pre_post_primary -> ^(PRE_DECR pre_post_primary); unary : post_inc_dec | pre_inc_dec | primary BLANK!* diff --git a/bashast/features_script/features.sh.ast b/bashast/features_s= cript/features.sh.ast index 920a23a..1a53b15 100644 --- a/bashast/features_script/features.sh.ast +++ b/bashast/features_script/features.sh.ast @@ -1 +1 @@ -(LIST (function (STRING lots_o_echo) (CURRENT_SHELL (LIST (COMMAND (STRI= NG echo) (STRING (DOUBLE_QUOTED_STRING The number of tests that = have failed : (VAR_REF failedtests)))) (COMMAND (STRING echo) (STRIN= G (SINGLE_QUOTED_STRING $ failedtests))) (COMMAND (STRING echo) (STRING (= VAR_REF failedtests)))))) (function (STRING do_some_arith) (CURRENT_SHELL= (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 (STRING arrays) (SUBSHELL (LI= ST (VARIABLE_DEFINITIONS (=3D asdf (ARRAY (STRING a) (STRING b) (STRING c= ) (STRING d)))) (COMMAND (STRING echo) (STRING (VAR_REF (asdf 3)))) (VARI= ABLE_DEFINITIONS (=3D foo (ARRAY (STRING (COMMAND_SUB (LIST (COMMAND (STR= ING echo) (STRING 6))))) (STRING b) (STRING c) (STRING d)))) (VARIABLE_DE= FINITIONS (=3D (arr (VAR_REF foo)) (STRING 3))) (VARIABLE_DEFINITIONS (=3D= bar (ARRAY (STRING a) (STRING b) (=3D 5 (STRING c )))))))) (COMMAND (STRING echo) (STRING (BRACE_EXP (STRING a) (STRING b)= ))) (COMMAND (STRING echo) (STRING (BRACE_EXP (.. a d)))) (COMMAND (STRIN= G echo) (STRING (BRACE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (= STRING d)))) (COMMAND (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRI= NG c)))) (COMMAND (STRING (COMMAND_SUB (LIST (COMMAND (STRING echo) (STRI= NG foobar)))))) (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING g= unit) (REDIR >> (STRING filelist)))) (case (COMMAND_SUB (LIST (COMMAND (S= TRING echo) (STRING asdf)))) (CASE_PATTERN (STRING gz) CASE_COMMAND (LIST= (COMMAND (STRING echo) (STRING yay)))) (CASE_PATTERN (STRING bzip) CASE_= COMMAND (LIST (COMMAND (STRING echo) (STRING three)))) (CASE_PATTERN (STR= ING MATCH_ALL) CASE_COMMAND (LIST (COMMAND (STRING echo) (STRING woo)))))= (for each (STRING (COMMAND_SUB (LIST (| (COMMAND (STRING ls)) (COMMAND (= STRING grep) (STRING log)))))) (LIST (COMMAND (STRING echo) (STRING (VAR_= REF each))) (COMMAND (STRING cat) (STRING each)))) (CFOR (FOR_INIT (+ 5 3)) (FOR_COND (+ 6 2)) (LIST (COMMAND (ST= RING echo) (STRING yay))) (FOR_MOD (+ 3 1))) (select each (COMMAND_SUB (L= IST (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING output))))) (= LIST (COMMAND (STRING echo) (STRING asdf) (STRING 2) (REDIR > (STRING / d= ev / null))))) (IF_STATEMENT (if (LIST (COMMAND (STRING echo) (STRING yay= 2))) (LIST (COMMAND (STRING echo) (STRING yay))))) (until (LIST (COMPOUND= _COND (KEYWORD_TEST (a (STRING this / is . afile))))) (LIST (COMMAND (STR= ING touch) (STRING this / is . afile)))) (while (LIST (COMPOUND_COND (BUI= LTIN_TEST (n (STRING foobar))))) (LIST (COMMAND (STRING echo) (STRING (DO= UBLE_QUOTED_STRING file found))))) (IF_STATEMENT (if (LIST (COMPOUND_CO= ND (BUILTIN_TEST (eq (STRING 5) (STRING 6))))) (LIST (COMMAND (STRING ech= o) (STRING (DOUBLE_QUOTED_STRING something ' s wrong)))))) (COMMAND (ST= RING echo) (STRING this) (STRING command) (STRING has) (STRING multiple) = (STRING arguments)) (COMMAND (STRING wc)=20 (PROCESS_SUBSTITUTION < (LIST (COMMAND (STRING cat) (STRING / usr / shar= e / dict / linux . words))))) (|| (&& (&& (&& (COMMAND (STRING cd) (STRIN= G build)) (COMMAND (STRING . / configure))) (COMMAND (STRING make))) (COM= MAND (STRING make_install))) (COMMAND (STRING echo) (STRING fail))) (COMM= AND (STRING cd) (STRING / usr / bin)) (| (COMMAND (STRING ls) (STRING - a= l)) (COMMAND (STRING grep) (STRING more))) (VARIABLE_DEFINITIONS (=3D asd= f (STRING parameters))) (COMMAND (STRING (VAR_REF (USE_DEFAULT_WHEN_UNSET= _OR_NULL asdf (STRING foo))))) (COMMAND (STRING (VAR_REF (OFFSET asdf 8))= )) (COMMAND (STRING (VAR_REF (! asdf *)))) (COMMAND (STRING (VAR_REF (! a= sdf @)))) (COMMAND (STRING (VAR_REF (# foo)))) (COMMAND (STRING (VAR_REF = (REPLACE_FIRST replaice (STRING with) (STRING pattern))))) (COMMAND (STRI= NG (VAR_REF (LAZY_REMOVE_AT_START asdf (STRING bar))))) (COMMAND (STRING = (VAR_REF (REPLACE_AT_START asdf (STRING bar))))) (COMMAND (STRING (VAR_RE= F (LAZY_REMOVE_AT_END asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_END asdf (STRING bar))))) (CO= MMAND (STRING (VAR_REF 1)) (STRING (VAR_REF @)) (STRING (VAR_REF *))) (CO= MMAND (STRING (VAR_REF ?))) (COMMAND (STRING (VAR_REF (REPLACE_ALL PV (ST= RING .) (STRING _))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_START PV (ST= RING foo) (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_END PV (= STRING foo) (STRING bar))))) (VARIABLE_DEFINITIONS (=3D MY_PN (STRING (VA= R_REF (REPLACE_FIRST 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 asd= f) (REDIR >> (STRING APPEND))) (COMMAND (STRING echo) (STRING cat) (<<< (= STRING word)))) +(LIST (function (STRING lots_o_echo) (CURRENT_SHELL (LIST (COMMAND (STRI= NG echo) (STRING (DOUBLE_QUOTED_STRING The number of tests that = have failed : (VAR_REF failedtests)))) (COMMAND (STRING echo) (STRIN= G (SINGLE_QUOTED_STRING $ failedtests))) (COMMAND (STRING echo) (STRING (= VAR_REF failedtests)))))) (function (STRING do_some_arith) (CURRENT_SHELL= (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 (STRING arrays) (SUBSHELL (LIST (VARIABLE_DEFINIT= IONS (=3D asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d)))) (COM= MAND (STRING echo) (STRING (VAR_REF (asdf 3)))) (VARIABLE_DEFINITIONS (=3D= foo (ARRAY (STRING (COMMAND_SUB (LIST (COMMAND (STRING echo) (STRING 6))= ))) (STRING b) (STRING c) (STRING d)))) (VARIABLE_DEFINITIONS (=3D (arr (= VAR_REF foo)) (STRING 3))) (VARIABLE_DEFINITIONS (=3D bar (ARRAY (STRING = a) (STRING b) (=3D 5 (STRING c)))))))) (COMMAND (S TRING echo) (STRING (BRACE_EXP (STRING a) (STRING b)))) (COMMAND (STRING= echo) (STRING (BRACE_EXP (.. a d)))) (COMMAND (STRING echo) (STRING (BRA= CE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d)))) (COMMAN= D (STRING echo) (STRING a (BRACE_EXP (STRING b) (STRING c)))) (COMMAND (S= TRING (COMMAND_SUB (LIST (COMMAND (STRING echo) (STRING foobar)))))) (| (= COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING gunit) (REDIR >> (STR= ING filelist)))) (case (COMMAND_SUB (LIST (COMMAND (STRING echo) (STRING = asdf)))) (CASE_PATTERN (STRING gz) CASE_COMMAND (LIST (COMMAND (STRING ec= ho) (STRING yay)))) (CASE_PATTERN (STRING bzip) CASE_COMMAND (LIST (COMMA= ND (STRING echo) (STRING three)))) (CASE_PATTERN (STRING MATCH_ALL) CASE_= COMMAND (LIST (COMMAND (STRING echo) (STRING woo))))) (for each (STRING (= COMMAND_SUB (LIST (| (COMMAND (STRING ls)) (COMMAND (STRING grep) (STRING= log)))))) (LIST (COMMAND (STRING echo) (STRING (VAR_REF each))) (COMMAND= (STRING cat) (STRING each)))) (CFOR (FOR _INIT (+ 5 3)) (FOR_COND (+ 6 2)) (LIST (COMMAND (STRING echo) (STRING y= ay))) (FOR_MOD (+ 3 1))) (select each (COMMAND_SUB (LIST (| (COMMAND (STR= ING ls)) (COMMAND (STRING grep) (STRING output))))) (LIST (COMMAND (STRIN= G echo) (STRING asdf) (STRING 2) (REDIR > (STRING / dev / null))))) (IF_S= TATEMENT (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 t= his / is . afile)))) (while (LIST (COMPOUND_COND (BUILTIN_TEST (n (STRING= foobar))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING f= ile found))))) (IF_STATEMENT (if (LIST (COMPOUND_COND (BUILTIN_TEST (eq= (STRING 5) (STRING 6))))) (LIST (COMMAND (STRING echo) (STRING (DOUBLE_Q= UOTED_STRING something ' s wrong)))))) (COMMAND (STRING echo) (STRING t= his) (STRING command) (STRING has) (STRING multiple) (STRING arguments)) = (COMMAND (STRING wc) (PROCESS_SUBSTITUTIO N < (LIST (COMMAND (STRING cat) (STRING / usr / share / dict / linux . w= ords))))) (|| (&& (&& (&& (COMMAND (STRING cd) (STRING build)) (COMMAND (= STRING . / configure))) (COMMAND (STRING make))) (COMMAND (STRING make_in= stall))) (COMMAND (STRING echo) (STRING fail))) (COMMAND (STRING cd) (STR= ING / usr / bin)) (| (COMMAND (STRING ls) (STRING - al)) (COMMAND (STRING= grep) (STRING more))) (VARIABLE_DEFINITIONS (=3D asdf (STRING parameters= ))) (COMMAND (STRING (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRIN= G 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 repla= ice (STRING with) (STRING pattern))))) (COMMAND (STRING (VAR_REF (LAZY_RE= MOVE_AT_START asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (REPLACE_AT= _START asdf (STRING bar))))) (COMMAND (STRING (VAR_REF (LAZY_REMOVE_AT_EN= D asdf (STRING bar))))) (COMMAND (STRING (V AR_REF (LAZY_REMOVE_AT_END asdf (STRING bar))))) (COMMAND (STRING (VAR_R= EF 1)) (STRING (VAR_REF @)) (STRING (VAR_REF *))) (COMMAND (STRING (VAR_R= EF ?))) (COMMAND (STRING (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))= )) (COMMAND (STRING (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING ba= r))))) (COMMAND (STRING (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING = bar))))) (VARIABLE_DEFINITIONS (=3D MY_PN (STRING (VAR_REF (REPLACE_FIRST= PN (STRING asterisk -)))))) (| (COMMAND (STRING cat) (STRING asdf)) (COM= MAND (STRING grep) (STRING three) (STRING 2) (REDIR >& 1) (REDIR > (STRIN= G / dev / null)))) (COMMAND (STRING echo) (STRING asdf) (REDIR >> (STRING= APPEND))) (COMMAND (STRING echo) (STRING cat) (<<< (STRING word)))) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index d781a03..955c316 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -836,4 +836,5 @@ arithmetics returns[int value] } | NUMBER { $value =3D walker->parse_int($NUMBER);} | DIGIT { $value =3D walker->parse_int($DIGIT);} + | ^(VAR_REF libbash_string=3Dvar_expansion) { $value =3D boost::lexical= _cast(libbash_string); } ; diff --git a/scripts/arithmetic_assignment.bash b/scripts/arithmetic_assi= gnment.bash index 7f77ec7..f1f40f6 100644 --- a/scripts/arithmetic_assignment.bash +++ b/scripts/arithmetic_assignment.bash @@ -11,4 +11,5 @@ FOO009=3D"$((value^=3D5))" FOO010=3D"$((value|=3D10))" FOO011=3D("CREATED" 2) FOO012=3D"$((${FOO011[0]}=3D10))" -let "value=3D100" +value=3D100 +let "value=3D${value}" diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.b= ash index bdc3d94..8089d87 100644 --- a/scripts/binary_arithmetic.bash +++ b/scripts/binary_arithmetic.bash @@ -54,7 +54,6 @@ FOO050=3D"$((ARRAY[8]|=3D10))" FOO051=3D"$((ARRAY[8]^=3D3))" PARTIAL[8]=3D5 FOO052=3D"$((PARTIAL[8]*=3D1))" -# The following 3 just expand to non-exist variables FOO053=3D"$((${#ARRAY[@]}))" FOO054=3D"$((${ARRAY[5]:-10}))" FOO055=3D"$((${ARRAY:0}))" diff --git a/scripts/binary_arithmetic.bash.result b/scripts/binary_arith= metic.bash.result index 63cfa28..938e18c 100644 --- a/scripts/binary_arithmetic.bash.result +++ b/scripts/binary_arithmetic.bash.result @@ -51,9 +51,9 @@ FOO049=3D1 FOO050=3D11 FOO051=3D8 FOO052=3D5 -FOO053=3D0 -FOO054=3D0 -FOO055=3D0 +FOO053=3D6 +FOO054=3D10 +FOO055=3D1 FOO056=3Dvalue FOO057=3D100 FOO058=3D111