1 |
commit: 2f23c0e62045a498a9d10c1ba0352527407f4a14 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Apr 3 11:44:24 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Apr 3 11:44:24 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2f23c0e6 |
7 |
|
8 |
Support arithmetic expansion in double quoted string |
9 |
|
10 |
A virtual token is added to avoid ambiguity. |
11 |
|
12 |
--- |
13 |
Makefile.am | 3 ++- |
14 |
bashast/bashast.g | 3 ++- |
15 |
bashast/gunit/arith_main.gunit | 6 +++--- |
16 |
bashast/libbashWalker.g | 3 ++- |
17 |
scripts/var_expansion.ebuild | 2 ++ |
18 |
scripts/var_expansion.ebuild.result | 2 ++ |
19 |
6 files changed, 13 insertions(+), 6 deletions(-) |
20 |
|
21 |
diff --git a/Makefile.am b/Makefile.am |
22 |
index 0ef756a..44cdcba 100644 |
23 |
--- a/Makefile.am |
24 |
+++ b/Makefile.am |
25 |
@@ -47,7 +47,8 @@ GUNIT_TESTS = bashast/gunit/arith_main.gunit \ |
26 |
bashast/gunit/simp_prog.gunit |
27 |
|
28 |
EBUILD_LOG_COMPILER = $(srcdir)/test/script_compiler.sh |
29 |
-EBUILD_TESTS = scripts/var_def.ebuild |
30 |
+EBUILD_TESTS = scripts/var_def.ebuild \ |
31 |
+ scripts/var_expansion.ebuild |
32 |
EBUILD_RESULT = scripts/var_def.ebuild.result |
33 |
|
34 |
TESTS = $(GUNIT_TESTS) $(EBUILD_TESTS) |
35 |
|
36 |
diff --git a/bashast/bashast.g b/bashast/bashast.g |
37 |
index 948b839..d83b616 100644 |
38 |
--- a/bashast/bashast.g |
39 |
+++ b/bashast/bashast.g |
40 |
@@ -60,6 +60,7 @@ tokens{ |
41 |
FILE_DESCRIPTOR_MOVE; |
42 |
REDIR; |
43 |
ARITHMETIC_CONDITION; |
44 |
+ ARITHMETIC_EXPRESSION; |
45 |
KEYWORD_TEST; |
46 |
BUILTIN_TEST; |
47 |
MATCH_ANY_EXCEPT; |
48 |
@@ -446,7 +447,7 @@ extended_pattern_match |
49 |
| BANG LPAREN fname (PIPE fname)* RPAREN -> ^(MATCH_NONE fname+); |
50 |
//Arithmetic expansion |
51 |
arithmetic_expansion |
52 |
- : DOLLAR! LLPAREN! BLANK!* arithmetic_part BLANK!* RRPAREN!; |
53 |
+ : DOLLAR LLPAREN BLANK* arithmetic_part BLANK* RRPAREN -> ^(ARITHMETIC_EXPRESSION arithmetic_part); |
54 |
arithmetic_part |
55 |
: arithmetics |
56 |
| arithmetic; |
57 |
|
58 |
diff --git a/bashast/gunit/arith_main.gunit b/bashast/gunit/arith_main.gunit |
59 |
index ff7f678..1444203 100644 |
60 |
--- a/bashast/gunit/arith_main.gunit |
61 |
+++ b/bashast/gunit/arith_main.gunit |
62 |
@@ -119,6 +119,6 @@ arithmetics: |
63 |
"5+4, 3+2, $a*$b" -> (+ 5 4) (+ 3 2) (* (VAR_REF a) (VAR_REF b)) |
64 |
|
65 |
start: |
66 |
-"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (+ 3 2)))) |
67 |
-"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (PRE_INCR i)))) |
68 |
-"echo \"The solution is: $(( 3+2 ))\""-> (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The solution is : (+ 3 2))))) |
69 |
+"echo $(( 3 + 2 ))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (+ 3 2))))) |
70 |
+"echo $((++i))" -> (LIST (COMMAND (STRING echo) (STRING (ARITHMETIC_EXPRESSION (PRE_INCR i))))) |
71 |
+"echo \"The solution is: $(( 3+2 ))\""-> (LIST (COMMAND (STRING echo) (STRING (DOUBLE_QUOTED_STRING The solution is : (ARITHMETIC_EXPRESSION (+ 3 2)))))) |
72 |
|
73 |
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g |
74 |
index fd736c8..ddfef7a 100644 |
75 |
--- a/bashast/libbashWalker.g |
76 |
+++ b/bashast/libbashWalker.g |
77 |
@@ -106,7 +106,8 @@ dq_str_part returns[std::string libbash_value] |
78 |
//double quoted string rule, allows expansions |
79 |
dqstr returns[std::string libbash_value]: |
80 |
dq_str_part { $libbash_value = $dq_str_part.libbash_value; } |
81 |
- | libbash_string=var_ref { $libbash_value = libbash_string; }; |
82 |
+ | libbash_string=var_ref { $libbash_value = libbash_string; } |
83 |
+ | ^(ARITHMETIC_EXPRESSION value=arithmetics) { $libbash_value = boost::lexical_cast<std::string>(value); }; |
84 |
|
85 |
//variable reference |
86 |
var_ref returns[std::string libbash_value]: |
87 |
|
88 |
diff --git a/scripts/var_expansion.ebuild b/scripts/var_expansion.ebuild |
89 |
new file mode 100644 |
90 |
index 0000000..a5cadb6 |
91 |
--- /dev/null |
92 |
+++ b/scripts/var_expansion.ebuild |
93 |
@@ -0,0 +1,2 @@ |
94 |
+EAPI="3" |
95 |
+EAPI4="$(($EAPI+1))" |
96 |
|
97 |
diff --git a/scripts/var_expansion.ebuild.result b/scripts/var_expansion.ebuild.result |
98 |
new file mode 100644 |
99 |
index 0000000..cec88e4 |
100 |
--- /dev/null |
101 |
+++ b/scripts/var_expansion.ebuild.result |
102 |
@@ -0,0 +1,2 @@ |
103 |
+EAPI=3 |
104 |
+EAPI4=4 |