1 |
commit: 330481c3c8d60d0e2456e5155b857738fc3ffa02 |
2 |
Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu> |
3 |
AuthorDate: Sat Jun 11 12:15:19 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jun 14 07:23:14 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=330481c3 |
7 |
|
8 |
Parser: fix brace expansion inside bracket pattern |
9 |
|
10 |
We now support expressions like [{a,b}-c]*. As a side benefit code |
11 |
complexity is reduced. |
12 |
|
13 |
--- |
14 |
bashast/bashast.g | 19 ++++++++----------- |
15 |
bashast/gunit/brace.gunit | 1 + |
16 |
2 files changed, 9 insertions(+), 11 deletions(-) |
17 |
|
18 |
diff --git a/bashast/bashast.g b/bashast/bashast.g |
19 |
index 2db45de..10e5556 100644 |
20 |
--- a/bashast/bashast.g |
21 |
+++ b/bashast/bashast.g |
22 |
@@ -455,21 +455,18 @@ pattern_match_trigger |
23 |
| AT; |
24 |
//Pattern matching using brackets |
25 |
bracket_pattern_match |
26 |
- : LSQUARE RSQUARE (BANG|CARET) pattern_match* RSQUARE -> ^(MATCH_ANY_EXCEPT RSQUARE pattern_match*) |
27 |
- | LSQUARE RSQUARE pattern_match* RSQUARE -> ^(MATCH_ANY RSQUARE pattern_match*) |
28 |
- | LSQUARE (BANG|CARET) pattern_match+ RSQUARE -> ^(MATCH_ANY_EXCEPT pattern_match+) |
29 |
- | LSQUARE pattern_match+ RSQUARE -> ^(MATCH_ANY pattern_match+) |
30 |
+ : LSQUARE RSQUARE (BANG|CARET) pattern_match RSQUARE -> ^(MATCH_ANY_EXCEPT RSQUARE pattern_match) |
31 |
+ | LSQUARE RSQUARE pattern_match RSQUARE -> ^(MATCH_ANY RSQUARE pattern_match) |
32 |
+ | LSQUARE (BANG|CARET) pattern_match RSQUARE -> ^(MATCH_ANY_EXCEPT pattern_match) |
33 |
+ | LSQUARE pattern_match RSQUARE -> ^(MATCH_ANY pattern_match) |
34 |
| TIMES -> MATCH_ALL |
35 |
| QMARK -> MATCH_ONE; |
36 |
-//allowable patterns with bracket pattern matching |
37 |
pattern_match |
38 |
+ : pattern_match_atom+; |
39 |
+//allowable patterns with bracket pattern matching |
40 |
+pattern_match_atom |
41 |
: pattern_class_match |
42 |
- | pattern_string_part+; |
43 |
-pattern_string_part |
44 |
- : var_ref |
45 |
- | command_sub |
46 |
- | arithmetic_expansion |
47 |
- | ns_str_part; |
48 |
+ | (~RSQUARE) => fname_part; |
49 |
|
50 |
//special class patterns to match: [:alpha:] etc |
51 |
pattern_class_match |
52 |
|
53 |
diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit |
54 |
index 1930560..4d5d6a5 100644 |
55 |
--- a/bashast/gunit/brace.gunit |
56 |
+++ b/bashast/gunit/brace.gunit |
57 |
@@ -31,3 +31,4 @@ fname: |
58 |
"a{b,c}" -> (STRING a (BRACE_EXP (STRING b) (STRING c))) |
59 |
"{c..d}f" -> (STRING (BRACE_EXP (.. c d)) f) |
60 |
"a{a,b}b{c,d}" -> (STRING a (BRACE_EXP (STRING a) (STRING b)) b (BRACE_EXP (STRING c) (STRING d))) |
61 |
+"[{a,b}-c]*" -> (STRING (MATCH_ANY (BRACE_EXP (STRING a) (STRING b)) - c) MATCH_ALL) |