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 1QQe2Z-0004X9-0U for garchives@archives.gentoo.org; Sun, 29 May 2011 11:20:15 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EC1731C00A; Sun, 29 May 2011 11:20:06 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id A87711C00A for ; Sun, 29 May 2011 11:20:06 +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 43D821B4041 for ; Sun, 29 May 2011 11:20:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 9936E8050A for ; Sun, 29 May 2011 11:20:05 +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: <4fbd4e219d4c36de28036e02ba616d7faa43e066.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g scripts/compound_command.bash scripts/compound_command.bash.result X-VCS-Directories: scripts/ bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 4fbd4e219d4c36de28036e02ba616d7faa43e066 Date: Sun, 29 May 2011 11:20:05 +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: 7c8904f08959ee8d27b5b8b6f8797740 commit: 4fbd4e219d4c36de28036e02ba616d7faa43e066 Author: Mu Qiao gentoo org> AuthorDate: Fri May 27 13:44:07 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Sun May 29 11:44:52 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D4fbd4e21 Walker: support continue in for loop A bug in seek_to_next_tree is fixed. This bug can only be reproduced by c-style for loop. It prevents the c-style for loop from working properly when a modification statement is specified. --- bashast/libbashWalker.g | 53 ++++++++++++++++++++++++++++= ------ scripts/compound_command.bash | 19 ++++++++++++ scripts/compound_command.bash.result | 8 ++++- 3 files changed, 70 insertions(+), 10 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index d5522fc..39b84c5 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -71,12 +71,13 @@ options // seek to LT(2) and consume static void seek_to_next_tree(plibbashWalker ctx) { - // We start from LA(1) - int index =3D 1; // Current depth of the tree we are traversing int depth =3D 1; =20 - for(index =3D 1; depth !=3D 0; ++index) + // The beginning should always be ROOT DOWN ANY_TOKEN + // So we start from LA(4) + int index =3D 4; + for(; depth !=3D 0; ++index) { // Go one level done if we encounter DOWN if(LA(index) =3D=3D DOWN) @@ -87,7 +88,7 @@ options } =20 // Seek to the correct offset and consume. - SEEK(INDEX() + index - 3); + SEEK(INDEX() + index - 2); CONSUME(); } =20 @@ -614,7 +615,15 @@ for_expr { SEEK(commands_index); walker->set_value(libbash_string, *iter); - command_list(ctx); + try + { + command_list(ctx); + } + catch(continue_exception& e) + { + e.rethrow_unless_correct_frame(); + continue; + } } }) |^(CFOR { @@ -625,11 +634,37 @@ for_expr for_initilization(ctx); =20 condition_index =3D INDEX(); - bool has_condition =3D (LA(1) !=3D FOR_COND); - while(has_condition || for_condition(ctx)) + bool has_condition =3D (LA(1) =3D=3D FOR_COND); + + if(has_condition) + seek_to_next_tree(ctx); + // before the body + seek_to_next_tree(ctx); + bool has_modification =3D (LA(1) =3D=3D FOR_MOD); + ANTLR3_MARKER modification_index =3D INDEX(); + + SEEK(condition_index); + + while(!has_condition || for_condition(ctx)) { - command_list(ctx); - if(LA(1) =3D=3D FOR_MOD) + try + { + command_list(ctx); + } + catch(continue_exception& e) + { + e.rethrow_unless_correct_frame(); + + if(has_modification) + { + SEEK(modification_index); + for_modification(ctx); + } + + SEEK(condition_index); + continue; + } + if(has_modification) for_modification(ctx); SEEK(condition_index); } diff --git a/scripts/compound_command.bash b/scripts/compound_command.bas= h index daeef24..bb7961c 100644 --- a/scripts/compound_command.bash +++ b/scripts/compound_command.bash @@ -23,6 +23,25 @@ do echo "Shouldn't print this" done =20 +for file in foo bar +do + if [[ $file =3D=3D "foo" ]]; then + continue + fi + echo $file +done + +for outer in 1 2 3 +do + for file in foo bar + do + if [[ $file =3D=3D "foo" && $outer =3D=3D 1 ]]; then + continue 2 + fi + echo "$outer $file" + done +done + i=3D0; while [ $i !=3D 4 ] do diff --git a/scripts/compound_command.bash.result b/scripts/compound_comm= and.bash.result index 2a23d0c..6014421 100644 --- a/scripts/compound_command.bash.result +++ b/scripts/compound_command.bash.result @@ -11,6 +11,11 @@ ghi 8 9 10 +bar +2 foo +2 bar +3 foo +3 bar 1 2 3 @@ -37,7 +42,8 @@ yep case end a=3D1 b=3D2 -file=3D foo bar=20 +file=3Dbar foo=3Dghi i=3D4 +outer=3D3 target=3D_