diff options
-rw-r--r-- | build2/test/script/parser.cxx | 23 | ||||
-rw-r--r-- | unit-tests/test/script/parser/here-document.test | 2 |
2 files changed, 18 insertions, 7 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index 5822d9e..d4e318b 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -2499,7 +2499,11 @@ namespace build2 // enter: first token on first line // leave: newline (after end marker) - string rs; // String literal. + // String literal. Note that when decide if to terminate the previously + // added line with a newline, we need to distinguish a yet empty result + // and the one that has a single blank line added. + // + optional<string> rs; regex_lines rre; @@ -2604,10 +2608,13 @@ namespace build2 { // Add newline after previous line. // - if (!rs.empty ()) - rs += '\n'; - - rs += s; + if (rs) + { + *rs += '\n'; + *rs += s; + } + else + rs = move (s); } else { @@ -2753,8 +2760,10 @@ namespace build2 // expect any diagnostics to refer this line. // rre.lines.emplace_back (l.line, l.column, string (), false); + else if (rs) + *rs += '\n'; else - rs += '\n'; + rs = "\n"; } // Finalize regex lines. @@ -2772,7 +2781,7 @@ namespace build2 return re ? parsed_doc (move (rre), l.line, l.column) - : parsed_doc (move (rs), l.line, l.column); + : parsed_doc (rs ? move (*rs) : string (), l.line, l.column); } // diff --git a/unit-tests/test/script/parser/here-document.test b/unit-tests/test/script/parser/here-document.test index 1e4f93b..b32961c 100644 --- a/unit-tests/test/script/parser/here-document.test +++ b/unit-tests/test/script/parser/here-document.test @@ -176,6 +176,7 @@ : $* <<EOI >>EOO cmd <<EOF + foo bar @@ -183,6 +184,7 @@ bar EOF EOI cmd <<EOF + foo bar |