aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-07-28 15:40:00 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-08-02 15:52:18 +0800
commit1edf5ee2f0f778282b3d967d65a5028844fada29 (patch)
tree0e77d2356b817d72ddd776c9b2dea5ec5ecd1421
parentBuiltin: reimplement the local built-in (diff)
downloadlibbash-1edf5ee2f0f778282b3d967d65a5028844fada29.tar.gz
libbash-1edf5ee2f0f778282b3d967d65a5028844fada29.tar.bz2
libbash-1edf5ee2f0f778282b3d967d65a5028844fada29.zip
Walker: support brace expansion for local and export
-rw-r--r--bashast/bashast.g4
-rw-r--r--bashast/gunit/pipeline.gunit2
-rw-r--r--bashast/gunit/simp_command.gunit2
-rw-r--r--bashast/libbashWalker.g8
-rw-r--r--scripts/command_execution.bash1
5 files changed, 10 insertions, 7 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g
index cb0a63d..818a598 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -379,9 +379,9 @@ command_atom
| -> ^(VARIABLE_DEFINITIONS variable_definitions)
)
| (EXPORT) => EXPORT BLANK builtin_variable_definition_item
- -> ^(STRING EXPORT) ^(STRING ^(DOUBLE_QUOTED_STRING builtin_variable_definition_item))
+ -> ^(STRING EXPORT) ^(STRING builtin_variable_definition_item)
| (LOCAL) => LOCAL BLANK builtin_variable_definition_item
- -> ^(STRING LOCAL) ^(STRING ^(DOUBLE_QUOTED_STRING builtin_variable_definition_item))
+ -> ^(STRING LOCAL) ^(STRING builtin_variable_definition_item)
| command_name
(
(BLANK? parens) => BLANK? parens wspace? compound_command
diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit
index 8f6dd43..aea66f0 100644
--- a/bashast/gunit/pipeline.gunit
+++ b/bashast/gunit/pipeline.gunit
@@ -20,7 +20,7 @@ gunit java_libbash;
pipeline:
"cat asdf" -> (COMMAND (STRING cat) (STRING asdf))
-"export VAR=bar LAA=(1 2 3) foo" -> (COMMAND (STRING export) (STRING (DOUBLE_QUOTED_STRING VAR = bar LAA = ( 1 2 3 ) foo)))
+"export VAR=bar LAA=(1 2 3) foo" -> (COMMAND (STRING export) (STRING VAR = bar LAA = ( 1 2 3 ) foo))
"LOCAL1=a LOCAL2=b export GLOBAL1=2 GLOBAL2 GLOBAL3" -> (COMMAND (STRING export) (STRING GLOBAL1 = 2) (STRING GLOBAL2) (STRING GLOBAL3) (= LOCAL1 (STRING a)) (= LOCAL2 (STRING b)))
"time -p cat file" -> (COMMAND (STRING cat) (STRING file) (time p))
"time cat file | grep search" -> (| (COMMAND (STRING cat) (STRING file) time) (COMMAND (STRING grep) (STRING search)))
diff --git a/bashast/gunit/simp_command.gunit b/bashast/gunit/simp_command.gunit
index 2d98061..e6a8602 100644
--- a/bashast/gunit/simp_command.gunit
+++ b/bashast/gunit/simp_command.gunit
@@ -27,7 +27,7 @@ command_atom:
"./foobär" -> (STRING . / foob ä r)
"cat ~/Documents/todo.txt" -> (STRING cat) (STRING ~ / Documents / todo . txt)
"dodir ${foo}/${bar}" -> (STRING dodir) (STRING (VAR_REF foo) / (VAR_REF bar))
-"local a=123 b=(1 2 3) c" -> (STRING local) (STRING (DOUBLE_QUOTED_STRING a = 123 b = ( 1 2 3 ) c))
+"local a=123 b=(1 2 3) c" -> (STRING local) (STRING a = 123 b = ( 1 2 3 ) c)
"echo {}{}}{{{}}{{}" -> (STRING echo) (STRING { } { } } { { { } } { { })
"echo \"ab#af ###\" #abc" -> (STRING echo) (STRING (DOUBLE_QUOTED_STRING ab # af # # #))
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index 65fade5..fc05b91 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -576,8 +576,10 @@ command_atom
simple_command
@declarations {
std::vector<std::string> libbash_args;
+ bool split;
}
- :string_expr (argument[libbash_args])* execute_command[$string_expr.libbash_value, libbash_args];
+ :string_expr{ split = ($string_expr.libbash_value != "local" && $string_expr.libbash_value != "export"); }
+ (argument[libbash_args, split])* execute_command[$string_expr.libbash_value, libbash_args];
execute_command[std::string& name, std::vector<std::string>& libbash_args]
@declarations {
@@ -664,11 +666,11 @@ redirect_destination_input[std::unique_ptr<std::istream>& in]
std::cerr << "FILE_DESCRIPTOR_MOVE redirection is not supported yet" << std::endl;
};
-argument[std::vector<std::string>& args]
+argument[std::vector<std::string>& args, bool split]
: string_expr {
if(!$string_expr.libbash_value.empty())
{
- if($string_expr.quoted)
+ if($string_expr.quoted || !split)
args.push_back($string_expr.libbash_value);
else
walker->split_word($string_expr.libbash_value, args);
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index 1721fa9..a10d229 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -35,6 +35,7 @@ function unset_outer()
{
local FOO006=1 FOO007=2
local gjl_${FOO006}="${FOO007}"
+ local f version install{{site,vendor}{arch,lib},archlib}
unset_inner
echo "FOO006=$FOO006 in unset_outer"
echo "FOO007=$FOO007 in unset_outer"