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:12:06
Message-Id: f3be58e19e78f86ce1006f2ef33875ba4ec14905.betelgeuse@gentoo
1 commit: f3be58e19e78f86ce1006f2ef33875ba4ec14905
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Mon Apr 25 07:53:35 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Wed Apr 27 14:58:44 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f3be58e1
7
8 Walker: implement test expression
9
10 Only a limited set of operation is supported for now: =, ==, !=,
11 \>, \<.
12
13 ---
14 Makefile.am | 2 ++
15 bashast/libbashWalker.g | 18 +++++++++++++++++-
16 scripts/test_expr.bash | 26 ++++++++++++++++++++++++++
17 scripts/test_expr.bash.result | 9 +++++++++
18 4 files changed, 54 insertions(+), 1 deletions(-)
19
20 diff --git a/Makefile.am b/Makefile.am
21 index 0d21393..a21b3ad 100644
22 --- a/Makefile.am
23 +++ b/Makefile.am
24 @@ -53,6 +53,7 @@ BASH_TESTS = scripts/var_def.bash \
25 scripts/function_def.bash \
26 scripts/arithmetic_assignment.bash \
27 scripts/compound_command.bash \
28 + scripts/test_expr.bash \
29 scripts/binary_arithmetic.bash
30 BASH_RESULT = scripts/var_def.bash.result \
31 scripts/var_expansion.bash.result \
32 @@ -60,6 +61,7 @@ BASH_RESULT = scripts/var_def.bash.result \
33 scripts/function_def.bash.result \
34 scripts/arithmetic_assignment.bash.result \
35 scripts/compound_command.bash.result \
36 + scripts/test_expr.bash.result \
37 scripts/binary_arithmetic.bash.result
38
39 TESTS = $(GUNIT_TESTS) $(BASH_TESTS)
40
41 diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
42 index 11b4c19..c616c88 100644
43 --- a/bashast/libbashWalker.g
44 +++ b/bashast/libbashWalker.g
45 @@ -86,7 +86,6 @@ options
46 SEEK(INDEX() + index - 3);
47 CONSUME();
48 }
49 -
50 }
51
52 start: list|EOF;
53 @@ -321,8 +320,25 @@ command_list: ^(LIST logic_command_list+);
54
55 compound_command
56 : ^(CURRENT_SHELL command_list)
57 + | ^(COMPOUND_COND cond_expr)
58 | for_expr;
59
60 +cond_expr
61 + :^(BUILTIN_TEST status=builtin_condition) { walker->set_status(!status); };
62 +
63 +builtin_condition returns[bool status]
64 + :^(NEGATION l=builtin_condition) { $status = !l; }
65 + |s=builtin_condition_primary { $status = s; };
66 +
67 +builtin_condition_primary returns[bool status]
68 + :^(NAME string_expr string_expr) { throw interpreter_exception(walker->get_string($NAME) + "(NAME) is not supported for now");}
69 + |^(EQUALS l=string_expr r=string_expr) { $status = (l.libbash_value == r.libbash_value); }
70 + |^(NOT_EQUALS l=string_expr r=string_expr) { $status = (l.libbash_value != r.libbash_value); }
71 + |^(ESC_LT l=string_expr r=string_expr) { $status = (l.libbash_value < r.libbash_value); }
72 + |^(ESC_GT l=string_expr r=string_expr) { $status = (l.libbash_value > r.libbash_value); }
73 + |^(LETTER l=string_expr) { throw interpreter_exception(walker->get_string($LETTER) + "(LETTER) is not supported for now");}
74 + |string_expr { $status = ($string_expr.libbash_value.size() != 0); };
75 +
76 for_expr
77 @declarations {
78 ANTLR3_MARKER commands_index;
79
80 diff --git a/scripts/test_expr.bash b/scripts/test_expr.bash
81 new file mode 100644
82 index 0000000..95acd36
83 --- /dev/null
84 +++ b/scripts/test_expr.bash
85 @@ -0,0 +1,26 @@
86 +[ a = b ]
87 +echo $? # 1
88 +test a = a
89 +echo $? # 0
90 +#[ ]
91 +#echo $? # 1
92 +[ abc ]
93 +echo $? # 0
94 +[ ! abc ]
95 +echo $? # 1
96 +#[ ! ]
97 +#echo $?
98 +#[ abc -a bcd ]
99 +#echo $?
100 +#[ abc -o bcd ]
101 +#echo $?
102 +test abc == abd
103 +echo $? # 1
104 +[ abc != bcd ]
105 +echo $? # 0
106 +[ abc != abc ]
107 +echo $? # 1
108 +[ abc \> bcd ]
109 +echo $? # 1
110 +[ abc \< bcd ]
111 +echo $? # 0
112
113 diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.result
114 new file mode 100644
115 index 0000000..ff52ae4
116 --- /dev/null
117 +++ b/scripts/test_expr.bash.result
118 @@ -0,0 +1,9 @@
119 +1
120 +0
121 +0
122 +1
123 +1
124 +0
125 +1
126 +1
127 +0