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 1Q9Ay7-0001Qo-KF for garchives@archives.gentoo.org; Mon, 11 Apr 2011 06:51:33 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 292571C099; Mon, 11 Apr 2011 06:50:40 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id DE3031C099 for ; Mon, 11 Apr 2011 06:50:39 +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 4E7481B40D7 for ; Mon, 11 Apr 2011 06:50:39 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id A277180079 for ; Mon, 11 Apr 2011 06:50:38 +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: <9953ba4f79f12dacc0090c36adda3e7237148e50.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: bashast/, bashast/gunit/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/bashast.g bashast/gunit/assoc_array.gunit bashast/gunit/param_main.gunit X-VCS-Directories: bashast/ bashast/gunit/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 9953ba4f79f12dacc0090c36adda3e7237148e50 Date: Mon, 11 Apr 2011 06:50:38 +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: 310b2a04e1d2392a063473307237623a commit: 9953ba4f79f12dacc0090c36adda3e7237148e50 Author: Petteri R=C3=A4ty petteriraty eu> AuthorDate: Sun Apr 10 17:03:32 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Mon Apr 11 06:45:53 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D9953ba4f Improve explicit arithmetic expression places In array indexes and parameter offset expansion you can use the longer form of arithmetic expansion like foo[$((1))]=3Dbar --- bashast/bashast.g | 9 ++++++--- bashast/gunit/assoc_array.gunit | 1 + bashast/gunit/param_main.gunit | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index 0a42b4e..a9ded45 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -215,7 +215,7 @@ cond_comparison //Variables //Defining a variable var_def - : name LSQUARE BLANK? arithmetics BLANK* RSQUARE EQUALS value -> ^(EQUA= LS ^(name arithmetics) value) + : name LSQUARE BLANK? explicit_arithmetic BLANK* RSQUARE EQUALS value -= > ^(EQUALS ^(name explicit_arithmetic) value) | name EQUALS^ value | LET! name EQUALS^ arithmetic; //Possible values of a variable @@ -226,7 +226,7 @@ value : num //allow the parser to create array variables arr_val : | (ag+=3Dval wspace?)+ -> ^(ARRAY $ag+); -val : LSQUARE! BLANK!* arithmetics BLANK!? RSQUARE! EQUALS^ pos_val +val : LSQUARE! BLANK!* explicit_arithmetic BLANK!? RSQUARE! EQUALS^ pos_= val | pos_val; pos_val : command_sub | var_ref @@ -245,7 +245,7 @@ var_ref | DOLLAR BANG -> ^(VAR_REF BANG); //Variable expansions var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAU= LT)^ word - | var_name COLON wspace* LPAREN? os=3Darithmetic RPAREN? (COLON len=3Da= rithmetic)? -> ^(OFFSET var_name $os ^($len)?) + | var_name COLON wspace* LPAREN? os=3Dexplicit_arithmetic RPAREN? (COLO= N len=3Dexplicit_arithmetic)? -> ^(OFFSET var_name $os ^($len)?) | BANG^ var_name (TIMES|AT) | BANG var_name LSQUARE (op=3DTIMES|op=3DAT) RSQUARE -> ^(LIST_EXPAND v= ar_name $op) | BANG var_name -> ^(VAR_REF var_name) @@ -422,6 +422,9 @@ extended_pattern_match //Arithmetic expansion arithmetic_expansion : DOLLAR LLPAREN BLANK* arithmetics BLANK* RRPAREN -> ^(ARITHMETIC_EXPR= ESSION arithmetics); +//explicit arithmetic in places like array indexes +explicit_arithmetic + : (DOLLAR LLPAREN BLANK*)? arithmetics (BLANK* RRPAREN)? -> arithmetics= ; //The comma operator for arithmetic expansions arithmetics : arithmetic (BLANK!* COMMA! BLANK!* arithmetic)*; diff --git a/bashast/gunit/assoc_array.gunit b/bashast/gunit/assoc_array.= gunit index cdc7b0c..c8043af 100644 --- a/bashast/gunit/assoc_array.gunit +++ b/bashast/gunit/assoc_array.gunit @@ -24,3 +24,4 @@ var_def: "asdf[$idx]=3D${var}" -> (=3D (asdf (VAR_REF idx)) (VAR_REF var)) "asdf[++i]=3D${var}" -> (=3D (asdf (PRE_INCR (VAR_REF i))) (VAR_REF var)= ) "asdf[++i,j]=3D${var}" -> (=3D (asdf (PRE_INCR (VAR_REF i)) (VAR_REF j))= (VAR_REF var)) +"asdf[$((i))]=3D${var}" -> (=3D (asdf (VAR_REF i)) (VAR_REF var)) diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gu= nit index c6194de..4aee6d2 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -26,6 +26,7 @@ var_ref: "${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10))) "${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5))) "${foo:5:2}" -> (VAR_REF (OFFSET foo 5 2)) +"${foo:$((5)):$((2))}" -> (VAR_REF (OFFSET foo 5 2)) "${!asdf*}" -> (VAR_REF (! asdf *)) "${!asdf@}" -> (VAR_REF (! asdf @)) "${!asdf[*]}" -> (VAR_REF (LIST_EXPAND asdf *))