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 1QoyPf-0006c3-UK for garchives@archives.gentoo.org; Thu, 04 Aug 2011 13:56:40 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E9DB621C1E7; Thu, 4 Aug 2011 13:53:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id AE55321C1E6 for ; Thu, 4 Aug 2011 13:53:42 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4E1E81B4032 for ; Thu, 4 Aug 2011 13:53:42 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id AA2FC80048 for ; Thu, 4 Aug 2011 13:53:41 +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: <4241b112b64937a27b4ff04917fe6f497e98c123.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: 4241b112b64937a27b4ff04917fe6f497e98c123 Date: Thu, 4 Aug 2011 13:53:41 +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: d4bd731905b9d8c9e13d280fda4625ed commit: 4241b112b64937a27b4ff04917fe6f497e98c123 Author: Mu Qiao gentoo org> AuthorDate: Fri Jul 22 07:48:16 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Tue Aug 2 07:46:29 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D4241b112 Parser: fix the rule for expansion pattern --- bashast/bashast.g | 60 +++++++++++++++++++++++-----------= ----- bashast/gunit/param_main.gunit | 3 ++ 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/bashast/bashast.g b/bashast/bashast.g index 610b495..fae2137 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -141,8 +141,10 @@ tokens{ =20 C_INCLUDE #include "core/exceptions.h" } +#endif @members { +#ifdef OUTPUT_C static std::string get_string(pANTLR3_COMMON_TOKEN token) { if(!token || !token->start) @@ -166,10 +168,7 @@ tokens{ { (&(scope->here_document_word))->std::string::~string(); } -} #else -@members -{ boolean is_here_end(String here_document_word, int number_of_tokens) { String word =3D ""; for(int i =3D 1; i <=3D number_of_tokens; ++i) @@ -188,8 +187,37 @@ tokens{ int LA(int index) { return input.LA(index); } -} #endif +#ifdef OUTPUT_C + bool is_special_token(int token) +#else + boolean is_special_token(int token) +#endif + { + return token =3D=3D AMP + ||token =3D=3D BLANK + // for bash redirection + ||token =3D=3D LESS_THAN + ||token =3D=3D GREATER_THAN + ||token =3D=3D RSHIFT + // for end of command + ||token =3D=3D SEMIC + ||token =3D=3D EOL + // for sub shell + ||token =3D=3D LPAREN + ||token =3D=3D RPAREN + // for case statement + ||token =3D=3D DOUBLE_SEMIC + // for logical operator + ||token =3D=3D LOGICAND + ||token =3D=3D LOGICOR + // for pipeline + ||token =3D=3D PIPE + // for document and here string + ||token =3D=3D HERE_STRING_OP + ||token =3D=3D LSHIFT; + } +} =20 start : ((POUND) =3D>first_line_comment)? EOL* BLANK? command_list BLANK? (SE= MIC|AMP|EOL)? EOF -> command_list; @@ -326,28 +354,10 @@ command_atom | ( {LA(1) =3D=3D BLANK && ( - LA(2) !=3D AMP - // Resolve conflicts with bash redirection - &&LA(2) !=3D LESS_THAN - &&LA(2) !=3D GREATER_THAN - &&LA(2) !=3D RSHIFT + !is_special_token(LA(2)) + // redirection &&(LA(2) !=3D DIGIT || (LA(3) !=3D AMP && LA(3) !=3D LESS_THAN && LA(3) !=3D GREATER_THAN && LA(3) !=3D RSHIFT)) - // Resolve conflicts with end of command - &&LA(2) !=3D SEMIC - &&LA(2) !=3D EOL - // Resolve conflict with sub shell - &&LA(2) !=3D RPAREN - // Resolve conflict with case statement - &&LA(2) !=3D DOUBLE_SEMIC - // Resolve conflicts with logical operator - &&LA(2) !=3D LOGICAND - &&LA(2) !=3D LOGICOR - // Resolve conflict with pipeline - &&LA(2) !=3D PIPE - // Resolve conflicts with here document and here string - &&LA(2) !=3D HERE_STRING_OP - &&LA(2) !=3D LSHIFT )}? =3D> BLANK bash_command_arguments )* -> string_expr_no_reserved_word bash_command_arguments* ); @@ -784,7 +794,7 @@ parameter_replace_pattern parameter_delete_pattern : parameter_pattern_part+ -> ^(STRING parameter_pattern_part+); parameter_pattern_part - : extended_pattern_match|BLANK|SEMIC; + : extended_pattern_match|{is_special_token(LA(1))}? =3D> .; =20 // TODO fix this rule parameter_expansion_value diff --git a/bashast/gunit/param_main.gunit b/bashast/gunit/param_main.gu= nit index 0a56a57..c83ccc2 100644 --- a/bashast/gunit/param_main.gunit +++ b/bashast/gunit/param_main.gunit @@ -47,6 +47,9 @@ variable_reference: "${foo%%bar}" -> (VAR_REF (REPLACE_AT_END foo (STRING bar))) "${foo%; *}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING ; MATCH_ALL))= ) "${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /))) +"${1%& <><<; +();&&|<<<<<()*}" -> (VAR_REF (LAZY_REMOVE_AT_END 1 (STRING & < > << ;=20 + ( ) ; && | <<< << ( ) MATCH_ALL))) "${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING p= attern))) //Test positional/special parameters "$1" -> (VAR_REF 1)