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 1Q7NOc-0003cW-Pb for garchives@archives.gentoo.org; Wed, 06 Apr 2011 07:43:22 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id F262C1C05C; Wed, 6 Apr 2011 07:43:10 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id C27E31C05C for ; Wed, 6 Apr 2011 07:43:10 +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 49FC71B40ED for ; Wed, 6 Apr 2011 07:43:10 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 2D3E880074 for ; Wed, 6 Apr 2011 07:43:09 +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: <9ad65f4f20c373da2517bef333ae4b4c664e1504.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/param_main.gunit X-VCS-Directories: bashast/ bashast/gunit/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 9ad65f4f20c373da2517bef333ae4b4c664e1504 Date: Wed, 6 Apr 2011 07:43:09 +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: e1f963e96e06639aefdc3a83b92a3de1 commit: 9ad65f4f20c373da2517bef333ae4b4c664e1504 Author: Mu Qiao gentoo org> AuthorDate: Tue Apr 5 13:22:39 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed Apr 6 00:53:24 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D9ad65f4f Use arithmetic inside substring expansion Bash manual claims that length and offset are arithmetic expressions. Meanwhile, a negative offset must be separated from the colon by at least one space to avoid being confused with the :- expansion. So a wspace rule is added. Arithmetic expression inside substring expansion with $(()) around is not supported yet. --- bashast/bashast.g | 2 +- bashast/gunit/param_main.gunit | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index 2659ef5..60ad096 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -254,7 +254,7 @@ var_ref | DOLLAR '_' -> ^(VAR_REF '_'); //Variable expansions var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY_ERROR|ASSIGN_DEFAU= LT)^ word - | var_name COLON os=3Dnum (COLON len=3Dnum)? -> ^(OFFSET var_name $os ^= ($len)?) + | var_name COLON wspace* LPAREN? os=3Darithmetic RPAREN? (COLON len=3Da= rithmetic)? -> ^(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) | POUND^ var_name diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gu= nit index 769f19f..a582179 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -23,6 +23,8 @@ var_ref: "${asdf}" -> (VAR_REF asdf) "${asdf:-foo}" -> (VAR_REF (:- asdf (STRING foo))) "${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))) "${foo:5:2}" -> (VAR_REF (OFFSET foo 5 2)) "${!asdf*}" -> (VAR_REF (! asdf *)) "${!asdf@}" -> (VAR_REF (! asdf @))