aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/build/script/parser+line.test.testscript9
-rw-r--r--libbuild2/build/script/parser.test.cxx12
-rw-r--r--libbuild2/script/script.cxx29
3 files changed, 43 insertions, 7 deletions
diff --git a/libbuild2/build/script/parser+line.test.testscript b/libbuild2/build/script/parser+line.test.testscript
index df4e77b..fe38249 100644
--- a/libbuild2/build/script/parser+line.test.testscript
+++ b/libbuild2/build/script/parser+line.test.testscript
@@ -37,3 +37,12 @@ $* <<EOI >|
foo 'bar' "baz" '' ""
EOI
#\
+
+#\
+ libbuild2/lexer+quoting.test.testscript
+
+ : tmp
+ :
+ $* <'f"oo" "foo$"'
+
+#\
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index b5afd47..ab9935d 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -72,6 +72,18 @@ namespace build2
// argv[0] [-l]
// argv[0] -d
//
+ // In the first form read the script from stdin and trace the script
+ // execution to stdout using the custom print runner.
+ //
+ // In the second form read the script from stdin, parse it and dump the
+ // resulting lines to stdout.
+ //
+ // -l
+ // Print the script line number for each executed expression.
+ //
+ // -d
+ // Dump the parsed script to sdout.
+ //
int
main (int argc, char* argv[])
{
diff --git a/libbuild2/script/script.cxx b/libbuild2/script/script.cxx
index 349b05e..04727a5 100644
--- a/libbuild2/script/script.cxx
+++ b/libbuild2/script/script.cxx
@@ -46,7 +46,7 @@ namespace build2
// information is lost and we won't be able to restore the token
// original representation.
//
-// char qseq ('\0'); // Can be used as bool.
+ char qseq ('\0'); // Can be used as bool.
for (const replay_token& rt: l.tokens)
{
@@ -57,18 +57,18 @@ namespace build2
char lq ('\0');
char rq ('\0');
- /*
if (t.qtype != quote_type::unquoted)
{
auto quote = [&t] ()
{
return t.qtype == quote_type::single ? '\'' : '"';
- }
+ };
if (t.qcomp) // Complete quoting.
{
// If we are inside quoted token sequence then we do noting.
- // Otherwise we just quote the token not starting a sequence.
+ // Otherwise we just quote the current token not starting a
+ // sequence.
//
if (!qseq)
{
@@ -78,12 +78,27 @@ namespace build2
}
else // Partial quoting.
{
+ // Note that we can not always reproduce the original tokens
+ // representation for partial quoting. For example, the
+ // following two tokens are lexed into the identical token
+ // objects:
+ //
+ // "foo
+ // f"oo"
+ //
if (!qseq)
- lq =
-
+ {
+ lq = quote ();
+ qseq = lq;
+ }
+ else
+ {
+ rq = quote ();
+ qseq = '\0';
+ }
}
}
- */
+
// @@ Add 2 spaces indentation for if block contents.
if (t.separated &&