aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/parser.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-02-11 14:12:34 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-02-11 14:12:34 +0300
commit61aa8e2b4bd7849838c04dc1f421c4760d88319f (patch)
treeb188706eb629cb8604bf07ecbcd0a2bba5b155f6 /build2/test/script/parser.cxx
parent4a416fd328d685b0946e5e6f40e5ea18e9c1adf0 (diff)
Fix testscript parser not to strip leading blanks in here-doc
Diffstat (limited to 'build2/test/script/parser.cxx')
-rw-r--r--build2/test/script/parser.cxx23
1 files changed, 16 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);
}
//