diff options
author | 2011-07-21 23:41:08 +0800 | |
---|---|---|
committer | 2011-08-02 15:46:29 +0800 | |
commit | 2a7c39aed496a03d4e0fe184bafbc34d50c87bd5 (patch) | |
tree | 20768a3eaacc1b2bbe53bf1c016ef5a7a9a71f26 /bashast | |
parent | Parser: allow filename expansion characters (diff) | |
download | libbash-2a7c39aed496a03d4e0fe184bafbc34d50c87bd5.tar.gz libbash-2a7c39aed496a03d4e0fe184bafbc34d50c87bd5.tar.bz2 libbash-2a7c39aed496a03d4e0fe184bafbc34d50c87bd5.zip |
Parser&Walker: reimplement export built-in
Now export built-in will call back to parser grammar in order to support
array definition.
Diffstat (limited to 'bashast')
-rw-r--r-- | bashast/bashast.g | 11 | ||||
-rw-r--r-- | bashast/gunit/array.gunit | 3 | ||||
-rw-r--r-- | bashast/gunit/pipeline.gunit | 2 | ||||
-rw-r--r-- | bashast/libbashWalker.g | 5 |
4 files changed, 13 insertions, 8 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g index 2709fc5..3b9b5bd 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -313,11 +313,12 @@ command_atom : (FOR|SELECT|IF|WHILE|UNTIL|CASE|LPAREN|LBRACE|LLPAREN|LSQUARE|TEST_EXPR) => compound_command | FUNCTION BLANK string_expr_no_reserved_word ((BLANK? parens wspace?)|wspace) compound_command -> ^(FUNCTION string_expr_no_reserved_word compound_command) - | (name (LSQUARE|EQUALS|PLUS EQUALS)|LOCAL|EXPORT) => variable_definitions + | (name (LSQUARE|EQUALS|PLUS EQUALS)|LOCAL) => variable_definitions ( (BLANK bash_command) => BLANK bash_command -> bash_command variable_definitions | -> ^(VARIABLE_DEFINITIONS variable_definitions) ) + | (EXPORT) => EXPORT BLANK export_item -> ^(STRING EXPORT) ^(STRING ^(DOUBLE_QUOTED_STRING export_item)) | string_expr_no_reserved_word ( (BLANK? parens) => BLANK? parens wspace? compound_command @@ -355,7 +356,6 @@ variable_definitions : ( variable_definition_atom ((BLANK name (LSQUARE|EQUALS|PLUS EQUALS)) => BLANK! variable_definition_atom)* | (LOCAL) => LOCAL BLANK! local_item ((BLANK name) => BLANK! local_item)* - | (EXPORT) => EXPORT! ((BLANK name) => BLANK! export_item)+ ); variable_definition_atom @@ -406,6 +406,13 @@ local_item #endif } ->; export_item + : ((~EOL) => (string_expr_part|BLANK|LPAREN|RPAREN))+; + +builtin_variable_definitions + : (builtin_variable_definition_atom) (BLANK builtin_variable_definition_atom)* + -> ^(LIST ^(COMMAND ^(VARIABLE_DEFINITIONS builtin_variable_definition_atom +))); + +builtin_variable_definition_atom : variable_definition_atom | name ->; diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit index c304e7c..734343f 100644 --- a/bashast/gunit/array.gunit +++ b/bashast/gunit/array.gunit @@ -31,6 +31,9 @@ variable_definition_atom: "asdf+=()" -> (PLUS_ASSIGN asdf ARRAY) "asdf+=(a)" -> (PLUS_ASSIGN asdf (ARRAY (STRING a))) +builtin_variable_definitions: +"asdf=(a b c d) ade acd=bde" -> (LIST (COMMAND (VARIABLE_DEFINITIONS (= asdf (ARRAY (STRING a) (STRING b) (STRING c) (STRING d))) (= acd (STRING bde))))) + variable_reference: "$asdf" -> (VAR_REF asdf) "${asdf[0]:-default}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL (asdf 0) (STRING default))) diff --git a/bashast/gunit/pipeline.gunit b/bashast/gunit/pipeline.gunit index ec6deda..8f6dd43 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=laa foo" -> (COMMAND (VARIABLE_DEFINITIONS (= VAR (STRING bar)) (= LAA (STRING laa)))) +"export VAR=bar LAA=(1 2 3) foo" -> (COMMAND (STRING export) (STRING (DOUBLE_QUOTED_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/libbashWalker.g b/bashast/libbashWalker.g index 2ee887c..25bfcb2 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -602,11 +602,6 @@ execute_command[const std::string& name, std::vector<std::string>& libbash_args] { walker->set_status(walker->execute_builtin(name, libbash_args, out.get(), err.get(), in.get())); } - else if(name == "export") - { - std::cerr << "We do not support command env before the export builtin." << std::endl; - walker->set_status(1); - } else { walker->set_status(1); |