diff options
-rw-r--r-- | libbuild2/build/script/parser+command-re-parse.test.testscript | 14 | ||||
-rw-r--r-- | libbuild2/build/script/parser+expansion.test.testscript | 23 | ||||
-rw-r--r-- | libbuild2/build/script/parser.hxx | 2 | ||||
-rw-r--r-- | libbuild2/script/parser.cxx | 21 | ||||
-rw-r--r-- | libbuild2/script/parser.hxx | 3 | ||||
-rw-r--r-- | libbuild2/test/script/parser.hxx | 2 |
6 files changed, 53 insertions, 12 deletions
diff --git a/libbuild2/build/script/parser+command-re-parse.test.testscript b/libbuild2/build/script/parser+command-re-parse.test.testscript index a59b49c..56e05b5 100644 --- a/libbuild2/build/script/parser+command-re-parse.test.testscript +++ b/libbuild2/build/script/parser+command-re-parse.test.testscript @@ -1,11 +1,23 @@ # file : libbuild2/build/script/parser+command-re-parse.test.testscript # license : MIT; see accompanying LICENSE file +# @@ TMP +# +#\ : double-quote : $* <<EOI >>EOO -x = cmd \">-\" "'<-'" +x = [cmd_line] cmd \">-\" "'<-'" $x EOI cmd '>-' '<-' EOO +#\ + +: literal-re-parse +: +$* <<EOI >>EOO +cmd >foo +EOI +cmd >foo +EOO diff --git a/libbuild2/build/script/parser+expansion.test.testscript b/libbuild2/build/script/parser+expansion.test.testscript index 9f1e774..086ec8f 100644 --- a/libbuild2/build/script/parser+expansion.test.testscript +++ b/libbuild2/build/script/parser+expansion.test.testscript @@ -24,12 +24,33 @@ EOI buildfile:12:5: info: while parsing string 'xy'a bc' EOE +# @@ TMP +# +#\ : invalid-redirect : $* <<EOI 2>>EOE != 0 -x = "1>&a" +x = [cmd_line] "1>&a" cmd $x EOI <string>:1:4: error: stdout merge redirect file descriptor must be 2 buildfile:12:5: info: while parsing string '1>&a' EOE +#\ + +: expansion-re-parse +: +$* <<EOI >>EOO +x = <foo> <bar> +cmd $x + +x = foo +cmd >$x + +x = [string] foo +cmd >$x +EOI +cmd '<foo>' '<bar>' +cmd >foo +cmd >foo +EOO diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx index 09a349f..b737a13 100644 --- a/libbuild2/build/script/parser.hxx +++ b/libbuild2/build/script/parser.hxx @@ -29,7 +29,7 @@ namespace build2 // Pre-parse. Issue diagnostics and throw failed in case of an error. // public: - parser (context& c): build2::script::parser (c) {} + parser (context& c): build2::script::parser (c, false /* relex */) {} // Note that the returned script object references the passed path // name. diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx index b0431a9..fffe7bb 100644 --- a/libbuild2/script/parser.cxx +++ b/libbuild2/script/parser.cxx @@ -1084,17 +1084,24 @@ namespace build2 "command line", nullptr); - // Nothing else to do if we are pre-parsing. + // Nothing else to do if we are pre-parsing (or if parse_program() + // took care of this chunk). // - if (pre_parse_) + if (pre_parse_ || ns.empty ()) break; - // Process what we got. Determine whether anything inside was - // quoted (note that the current token is "next" and is not part - // of this). + // Process what we got. + // + // First see if this is a value that should not be re-lexed. The + // long term plan is to only re-lex values of a special type + // representing a canned command line. + // + // Otherwise, determine whether anything inside was quoted (note + // that the current token is "next" and is not part of this). // - bool q ((quoted () - - (t.qtype != quote_type::unquoted ? 1 : 0)) != 0); + bool q ( + (pr.value && !relex_) || + (quoted () - (t.qtype != quote_type::unquoted ? 1 : 0)) != 0); for (name& n: ns) { diff --git a/libbuild2/script/parser.hxx b/libbuild2/script/parser.hxx index 077cb22..6e24d37 100644 --- a/libbuild2/script/parser.hxx +++ b/libbuild2/script/parser.hxx @@ -25,7 +25,7 @@ namespace build2 class parser: protected build2::parser { public: - parser (context& c): build2::parser (c) {} + parser (context& c, bool relex): build2::parser (c), relex_ (relex) {} // Helpers. // @@ -229,6 +229,7 @@ namespace build2 size_t replay_quoted_; protected: + bool relex_; lexer* lexer_ = nullptr; }; } diff --git a/libbuild2/test/script/parser.hxx b/libbuild2/test/script/parser.hxx index 3b008aa..c63bce6 100644 --- a/libbuild2/test/script/parser.hxx +++ b/libbuild2/test/script/parser.hxx @@ -30,7 +30,7 @@ namespace build2 // Pre-parse. Issue diagnostics and throw failed in case of an error. // public: - parser (context& c): build2::script::parser (c) {} + parser (context& c): build2::script::parser (c, true /* relex */) {} void pre_parse (script&); |