1 |
commit: c3356056896f2fab67e11cf4b4165487b6832211 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 28 15:59:20 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun May 29 11:44:52 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=c3356056 |
7 |
|
8 |
Walker: use any_string for function name |
9 |
|
10 |
The name rule doesn't cover all the possible characters in function |
11 |
names. As we've already validated the function name in parser grammar, |
12 |
the any_string rule is sufficient to match the function name. |
13 |
|
14 |
--- |
15 |
bashast/libbashWalker.g | 8 ++++++-- |
16 |
scripts/function_def.bash | 8 ++++---- |
17 |
2 files changed, 10 insertions(+), 6 deletions(-) |
18 |
|
19 |
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g |
20 |
index 5c8c371..e61d7b6 100644 |
21 |
--- a/bashast/libbashWalker.g |
22 |
+++ b/bashast/libbashWalker.g |
23 |
@@ -826,9 +826,13 @@ command_substitution returns[std::string libbash_value] |
24 |
}; |
25 |
|
26 |
function_definition returns[int placeholder] |
27 |
- :^(FUNCTION ^(STRING name) { |
28 |
+@declarations { |
29 |
+ std::string function_name; |
30 |
+} |
31 |
+ // We've already validated the function name in parser grammar so here we just use any_string to match the name. |
32 |
+ :^(FUNCTION ^(STRING (libbash_string=any_string { function_name += libbash_string; })+) { |
33 |
// Define the function with current index |
34 |
- walker->define_function($name.libbash_value, INDEX()); |
35 |
+ walker->define_function(function_name, INDEX()); |
36 |
// Skip the AST for function body |
37 |
seek_to_next_tree(ctx); |
38 |
}); |
39 |
|
40 |
diff --git a/scripts/function_def.bash b/scripts/function_def.bash |
41 |
index 54030e7..53e5ec8 100644 |
42 |
--- a/scripts/function_def.bash |
43 |
+++ b/scripts/function_def.bash |
44 |
@@ -27,20 +27,20 @@ ARRAY=(1 2 3) |
45 |
func_with_args ${ARRAY[@]} $FOO001 |
46 |
func_with_args 100 $ARG2 $ARG3 $ARG4 |
47 |
|
48 |
-func_with_return() |
49 |
+func-with-return() |
50 |
{ |
51 |
return 1 |
52 |
NOT_EXIST=1 |
53 |
} |
54 |
-func_with_return |
55 |
+func-with-return |
56 |
RETURN_STATUS=$? |
57 |
-func_with_return2() |
58 |
+func_with-return2() |
59 |
{ |
60 |
true |
61 |
return |
62 |
NOT_EXIST=1 |
63 |
} |
64 |
-func_with_return2 |
65 |
+func_with-return2 |
66 |
RETURN_STATUS2=$? |
67 |
|
68 |
func_nested1() { |