Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, bashast/
Date: Wed, 27 Apr 2011 15:11:43
Message-Id: cf1db9bbcdd15525359fa96084d04c0e876dea54.betelgeuse@gentoo
1 commit: cf1db9bbcdd15525359fa96084d04c0e876dea54
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Tue Apr 26 07:05:52 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Wed Apr 27 14:58:45 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=cf1db9bb
7
8 Walker: support while loop
9
10 ---
11 bashast/libbashWalker.g | 27 ++++++++++++++++++++++++++-
12 scripts/compound_command.bash | 12 ++++++++++++
13 scripts/compound_command.bash.result | 6 +++++-
14 3 files changed, 43 insertions(+), 2 deletions(-)
15
16 diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
17 index c616c88..01c080e 100644
18 --- a/bashast/libbashWalker.g
19 +++ b/bashast/libbashWalker.g
20 @@ -321,7 +321,8 @@ command_list: ^(LIST logic_command_list+);
21 compound_command
22 : ^(CURRENT_SHELL command_list)
23 | ^(COMPOUND_COND cond_expr)
24 - | for_expr;
25 + | for_expr
26 + | while_expr;
27
28 cond_expr
29 :^(BUILTIN_TEST status=builtin_condition) { walker->set_status(!status); };
30 @@ -402,6 +403,30 @@ for_condition returns[int libbash_value]
31 for_modification
32 :^(FOR_MOD arithmetics);
33
34 +while_expr
35 +@declarations {
36 + ANTLR3_MARKER command_index;
37 +}
38 + :^(WHILE {
39 + // omit the first DOWN token
40 + SEEK(INDEX() + 1);
41 +
42 + command_index = INDEX();
43 + while(true)
44 + {
45 + command_list(ctx);
46 + if(walker->get_status())
47 + break;
48 + command_list(ctx);
49 + SEEK(command_index);
50 + }
51 + // Skip the body and get out
52 + seek_to_next_tree(ctx);
53 +
54 + // omit the last UP token
55 + SEEK(INDEX() + 1);
56 + });
57 +
58 command_substitution returns[std::string libbash_value]
59 @declarations {
60 std::stringstream out;
61
62 diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash
63 index ad3e4f4..9da53b8 100644
64 --- a/scripts/compound_command.bash
65 +++ b/scripts/compound_command.bash
66 @@ -22,3 +22,15 @@ for ((;i<0;))
67 do
68 echo "Shouldn't print this"
69 done
70 +
71 +i=0;
72 +while [ $i != 4 ]
73 +do
74 + i=$(( i + 1 ))
75 + echo $i
76 +done
77 +
78 +while [ $i \< 0 ]
79 +do
80 + echo "Shouldn't print this"
81 +done
82
83 diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
84 index c865c15..b2d305a 100644
85 --- a/scripts/compound_command.bash.result
86 +++ b/scripts/compound_command.bash.result
87 @@ -11,6 +11,10 @@ ghi
88 8
89 9
90 10
91 +1
92 +2
93 +3
94 +4
95 file= foo bar
96 foo=ghi
97 -i=10
98 +i=4