1 |
commit: 41079afae26d6203928c8647de87c63e28aeb6c3 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 5 12:40:59 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 7 07:01:28 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=41079afa |
7 |
|
8 |
Parser: support defining local variables |
9 |
|
10 |
--- |
11 |
bashast/bashast.g | 5 +++-- |
12 |
bashast/gunit/simp_command.gunit | 1 + |
13 |
2 files changed, 4 insertions(+), 2 deletions(-) |
14 |
|
15 |
diff --git a/bashast/bashast.g b/bashast/bashast.g |
16 |
index 3a84d29..51fe9a9 100644 |
17 |
--- a/bashast/bashast.g |
18 |
+++ b/bashast/bashast.g |
19 |
@@ -130,7 +130,7 @@ simple_command |
20 |
| variable_definitions -> ^(VARIABLE_DEFINITIONS variable_definitions) |
21 |
| bash_command^ redirect*; |
22 |
variable_definitions |
23 |
- : var_def (BLANK!+ var_def)*; |
24 |
+ : (LOCAL BLANK!+)? var_def (BLANK!+ var_def)*; |
25 |
bash_command |
26 |
: fname_no_res_word (BLANK+ fname)* -> ^(COMMAND fname_no_res_word fname*); |
27 |
redirect: BLANK!* here_string_op^ BLANK!* fname |
28 |
@@ -388,7 +388,7 @@ options{k=1;backtrack=false;} |
29 |
: DIGIT|NUMBER; |
30 |
//A rule for filenames/strings |
31 |
res_word_str |
32 |
- : CASE|DO|DONE|ELIF|ELSE|ESAC|FI|FOR|FUNCTION|IF|IN|SELECT|THEN|UNTIL|WHILE|TIME; |
33 |
+ : CASE|DO|DONE|ELIF|ELSE|ESAC|FI|FOR|FUNCTION|IF|IN|SELECT|THEN|UNTIL|WHILE|TIME|LOCAL; |
34 |
//Any allowable part of a string, including slashes, no pounds |
35 |
str_part |
36 |
: ns_str_part |
37 |
@@ -653,6 +653,7 @@ COLON : ':'; |
38 |
QMARK : '?'; |
39 |
//Operators for conditional statements |
40 |
TEST_EXPR : 'test'; |
41 |
+LOCAL : 'local'; |
42 |
LOGICAND : '&&'; |
43 |
LOGICOR : '||'; |
44 |
//Tokens for strings |
45 |
|
46 |
diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit |
47 |
index b2dc74a..0ec100f 100644 |
48 |
--- a/bashast/gunit/simp_command.gunit |
49 |
+++ b/bashast/gunit/simp_command.gunit |
50 |
@@ -29,3 +29,4 @@ simple_command: |
51 |
"./foobär" -> (COMMAND (STRING . / foob ä r)) |
52 |
"cat ~/Documents/todo.txt" -> (COMMAND (STRING cat) (STRING ~ / Documents / todo . txt)) |
53 |
"dodir ${foo}/${bar}" -> (COMMAND (STRING dodir) (STRING (VAR_REF foo) / (VAR_REF bar))) |
54 |
+"local a=123 b=(1 2 3)" -> (VARIABLE_DEFINITIONS local (= a (STRING 123)) (= b (ARRAY (STRING 1) (STRING 2) (STRING 3)))) |