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 1Q9XtA-0002FD-U2 for garchives@archives.gentoo.org; Tue, 12 Apr 2011 07:19:53 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2B2A41C040; Tue, 12 Apr 2011 07:19:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id EE5CB1C040 for ; Tue, 12 Apr 2011 07:19:15 +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 67AFB1BC0D3 for ; Tue, 12 Apr 2011 07:19:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 8F21F80074 for ; Tue, 12 Apr 2011 07:19:14 +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: <12e31160ac9ea5d797a1637f1cae20d1284010da.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/array.gunit X-VCS-Directories: bashast/ bashast/gunit/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 12e31160ac9ea5d797a1637f1cae20d1284010da Date: Tue, 12 Apr 2011 07:19:14 +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: d5e42a9bcdb9c3244982f17974dcdf5f commit: 12e31160ac9ea5d797a1637f1cae20d1284010da Author: Petteri R=C3=A4ty petteriraty eu> AuthorDate: Mon Apr 11 14:37:16 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Tue Apr 12 06:23:20 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D12e31160 Support parsing array member sizes The parser now supports the syntax to the length of array members and the array itself. For example ${#arr[@]} is for the size of the array. --- bashast/bashast.g | 10 ++++++++-- bashast/gunit/array.gunit | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index b0b809d..9e1d012 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -27,6 +27,7 @@ options tokens{ ARG; ARRAY; + ARRAY_SIZE; BRACE_EXP; COMMAND_SUB; CASE_PATTERN; @@ -241,7 +242,6 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY= _ERROR|ASSIGN_DEFAULT)^ wor | 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) - | POUND^ var_name | var_name (POUND^|POUNDPOUND^) fname | var_name (PCT^|PCTPCT^) fname | var_name SLASH POUND ns_str SLASH fname -> ^(REPLACE_FIRST var_name n= s_str fname) @@ -253,6 +253,7 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLAY= _ERROR|ASSIGN_DEFAULT)^ wor | var_name SLASH PCT ns_str SLASH? -> ^(REPLACE_LAST var_name ns_str) | var_name SLASH ns_str SLASH? -> ^(REPLACE_FIRST var_name ns_str) | arr_var_ref + | var_size_ref | var_name | TIMES | AT; @@ -260,7 +261,12 @@ var_exp : var_name (USE_DEFAULT|USE_ALTERNATE|DISPLA= Y_ERROR|ASSIGN_DEFAULT)^ wor var_name: num|name|POUND; //Referencing an array variable arr_var_ref - : name^ LSQUARE! DIGIT+ RSQUARE!; + : name^ LSQUARE! (DIGIT+|AT|TIMES) RSQUARE!; +var_size_ref + : POUND^ name (LSQUARE! array_size_index RSQUARE!)?; +array_size_index + : DIGIT+ + | (AT|TIMES) -> ARRAY_SIZE; //Conditional Expressions cond_expr : LSQUARE LSQUARE wspace keyword_cond wspace RSQUARE RSQUARE -> ^(KEYWO= RD_TEST keyword_cond) diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit index 5fd47db..fd7b5d4 100644 --- a/bashast/gunit/array.gunit +++ b/bashast/gunit/array.gunit @@ -28,3 +28,8 @@ var_ref: "${asdf[3]}" -> (VAR_REF (asdf 3)) "${asdf[4] }" -> (VAR_REF (asdf 4)) "${asdf}" -> (VAR_REF asdf) +"${#asdf[0]}" -> (VAR_REF (# asdf 0)) +"${asdf[@]}" -> (VAR_REF (asdf @)) +"${asdf[*]}" -> (VAR_REF (asdf *)) +"${#asdf[@]}" -> (VAR_REF (# asdf ARRAY_SIZE)) +"${#asdf[*]}" -> (VAR_REF (# asdf ARRAY_SIZE))