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: bashast/, bashast/gunit/
Date: Sun, 17 Apr 2011 10:59:14
Message-Id: 32ea83a17790cfc700bce50cd91b8aa2129a6014.betelgeuse@gentoo
1 commit: 32ea83a17790cfc700bce50cd91b8aa2129a6014
2 Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
3 AuthorDate: Sat Apr 16 12:43:32 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Sun Apr 17 10:57:03 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=32ea83a1
7
8 Parser: empty atoms in brace expansion
9
10 With expressions like README{.txt,} you can expand to the word with and
11 without the extension. We now parse these expressions and mark the
12 result in the AST with a virtual token.
13
14 ---
15 bashast/bashast.g | 4 +++-
16 bashast/gunit/brace.gunit | 1 +
17 2 files changed, 4 insertions(+), 1 deletions(-)
18
19 diff --git a/bashast/bashast.g b/bashast/bashast.g
20 index 468a460..b318f3c 100644
21 --- a/bashast/bashast.g
22 +++ b/bashast/bashast.g
23 @@ -29,6 +29,7 @@ tokens{
24 ARRAY;
25 ARRAY_SIZE;
26 BRACE_EXP;
27 + EMPTY_BRACE_EXPANSION_ATOM;
28 COMMAND_SUB;
29 CASE_PATTERN;
30 SUBSHELL;
31 @@ -162,7 +163,8 @@ brace_expansion_part
32 : brace_expansion
33 | ((~COMMA) => fname_part)+ -> ^(STRING fname_part+)
34 | var_ref
35 - | command_sub;
36 + | command_sub
37 + | -> EMPTY_BRACE_EXPANSION_ATOM;
38 commasep: brace_expansion_part(COMMA! brace_expansion_part)+;
39 command_sub
40 : DOLLAR LPAREN BLANK* pipeline BLANK? RPAREN -> ^(COMMAND_SUB pipeline)
41
42 diff --git a/bashast/gunit/brace.gunit b/bashast/gunit/brace.gunit
43 index 2030d58..c9a7ba9 100644
44 --- a/bashast/gunit/brace.gunit
45 +++ b/bashast/gunit/brace.gunit
46 @@ -23,6 +23,7 @@ brace_expansion:
47 "{a,b,c}" -> (BRACE_EXP (STRING a) (STRING b) (STRING c))
48 "{a..d}" -> (BRACE_EXP (.. a d))
49 "{{a,b},c,d}" -> (BRACE_EXP (BRACE_EXP (STRING a) (STRING b)) (STRING c) (STRING d))
50 +"{.txt,,}" -> (BRACE_EXP (STRING . txt) EMPTY_BRACE_EXPANSION_ATOM EMPTY_BRACE_EXPANSION_ATOM)
51
52 fname:
53 "a{b,c}" -> (STRING a (BRACE_EXP (STRING b) (STRING c)))