From 19f82f9686e67da79b9f265f8baf228223d069b4 Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Thu, 1 Mar 2012 16:30:32 +0800 Subject: Parser: Allow EOLs in builtin array definition --- bashast/bashast.g | 13 ++++++++++++- bashast/gunit/array.gunit | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'bashast') diff --git a/bashast/bashast.g b/bashast/bashast.g index 73249ef..92f4f92 100644 --- a/bashast/bashast.g +++ b/bashast/bashast.g @@ -461,7 +461,18 @@ array_atom ); builtin_variable_definition_item - : ((~EOL) => expansion_base)+; +scope { + int parens; +} +@init { + $builtin_variable_definition_item::parens = 0; +} + : ( + (LPAREN) => LPAREN { ++$builtin_variable_definition_item::parens; } + |(RPAREN) => RPAREN { --$builtin_variable_definition_item::parens; } + |(~EOL) => expansion_base + | {LA(1) == EOL && $builtin_variable_definition_item::parens > 0}? => EOL + )+; #ifdef OUTPUT_C builtin_variable_definitions[bool local] diff --git a/bashast/gunit/array.gunit b/bashast/gunit/array.gunit index ddfdfeb..1958836 100644 --- a/bashast/gunit/array.gunit +++ b/bashast/gunit/array.gunit @@ -34,6 +34,18 @@ variable_definition_atom: 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))) (EQUALS ade (STRING (VAR_REF ade))) (= acd (STRING bde))))) +builtin_variable_definition_item: +"local cmakeargs=( + abc + def + ghi +)" -> "local cmakeargs = ( \n abc \n def \n ghi \n )" +"export cmakeargs=( + abc + def + ghi +)" -> "export cmakeargs = ( \n abc \n def \n ghi \n )" + variable_reference: "$asdf" -> (VAR_REF asdf) "${asdf[0]:-default}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL (asdf (ARITHMETIC 0)) (STRING default))) -- cgit v1.2.3-65-gdbad