aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-05-20 23:05:10 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2020-05-27 08:38:57 +0200
commit84cc0fc42c6b86eb09b06c7f59a0beb94397a38a (patch)
treec16c2bcbb6dff26101b700bd3b338eed29512027 /libbuild2/build
parent7765f51c5f6429fcb45a6c195b71929c392b0a31 (diff)
Complete dump(ostream,script::lines)
Diffstat (limited to 'libbuild2/build')
-rw-r--r--libbuild2/build/script/parser+line.test.testscript76
-rw-r--r--libbuild2/build/script/parser.test.cxx98
2 files changed, 127 insertions, 47 deletions
diff --git a/libbuild2/build/script/parser+line.test.testscript b/libbuild2/build/script/parser+line.test.testscript
index fe38249..6401d91 100644
--- a/libbuild2/build/script/parser+line.test.testscript
+++ b/libbuild2/build/script/parser+line.test.testscript
@@ -3,46 +3,70 @@
test.options += -d
-#\
+: command
+:
+$* <<EOF >>EOF
+ foo >| 2>- &a &?b
+ foo >=c 2>~/error:.*/ &!c
+ foo >>:/~%EOS%
+ %.*
+ abc
+ %xyz.*%
+ EOS
+ EOF
+
: if-else
:
-$* <<EOI >|
+$* <<EOF >>EOF
if foo
bar
elif fox
- baz
+ if fix
+ baz
+ end
+ biz
end
if! foo
bar
elif! fox
baz
end
- EOI
-
-: command
-:
-$* <<EOI >|
- foo >| 2>- &a &?b
- foo >=c 2>~/error:.*/ &!c
- foo >>:/~%EOF%
- %.*
- abc
- %xyz.*%
EOF
- EOI
: quoting
:
-$* <<EOI >|
+$* <<EOI >>EOO
foo 'bar' "baz" '' ""
+ "$foo"
+ "foo$"
+ "fo"o
+ "foo"\"
+ "foo\\"
+ "foo\"<"
+ fo\"o
+ fo\\o
+ fo\<o
+ "fo<o"
+ 'fo\"o'
+ f"oo" "ba"r
+ f"oo" 'ba'r
+ "fo"'o'
+ 'foo b"ar baz'
EOI
-#\
-
-#\
- libbuild2/lexer+quoting.test.testscript
-
- : tmp
- :
- $* <'f"oo" "foo$"'
-
-#\
+ foo 'bar' "baz" '' ""
+ "$foo"
+ "foo$"
+ "foo"
+ "foo\""
+ "foo\\"
+ "foo\"<"
+ fo\"o
+ fo\\o
+ fo\<o
+ "fo<o"
+ 'fo\"o'
+ "foo bar"
+ "foo" 'bar'
+ "foo"
+ 'foo b"ar baz'
+ EOO
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index ab9935d..b179884 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -11,6 +11,7 @@
#include <libbuild2/context.hxx>
#include <libbuild2/scheduler.hxx>
+#include <libbuild2/build/script/script.hxx> // line
#include <libbuild2/build/script/parser.hxx>
#include <libbuild2/build/script/runner.hxx>
@@ -71,6 +72,7 @@ namespace build2
//
// argv[0] [-l]
// argv[0] -d
+ // argv[0] -p
//
// In the first form read the script from stdin and trace the script
// execution to stdout using the custom print runner.
@@ -78,44 +80,63 @@ namespace build2
// In the second form read the script from stdin, parse it and dump the
// resulting lines to stdout.
//
+ // In the third form read the script from stdin, parse it and print
+ // line tokens quoting information to stdout.
+ //
// -l
// Print the script line number for each executed expression.
//
// -d
// Dump the parsed script to sdout.
//
+ // -p
+ // Print the parsed script tokens quoting information to sdout. If a
+ // token is quoted follow its representation with its quoting
+ // information in the [<quoting>/<completeness>] form, where:
+ //
+ // <quoting> := 'S' | 'D' | 'M'
+ // <completeness> := 'C' | 'P'
+ //
int
main (int argc, char* argv[])
{
tracer trace ("main");
- // Fake build system driver, default verbosity.
- //
- init_diag (1);
- init (nullptr, argv[0]);
-
- // Serial execution.
- //
- scheduler sched (1);
- global_mutexes mutexes (1);
- context ctx (sched, mutexes);
+ enum class mode
+ {
+ run,
+ dump,
+ print
+ } m (mode::run);
- bool line (false);
- bool dump (false);
+ bool print_line (false);
for (int i (1); i != argc; ++i)
{
string a (argv[i]);
if (a == "-l")
- line = true;
+ print_line = true;
else if (a == "-d")
- dump = true;
+ m = mode::dump;
+ else if (a == "-p")
+ m = mode::print;
else
assert (false);
}
- assert (!dump || !line);
+ assert (m == mode::run || !print_line);
+
+ // Fake build system driver, default verbosity.
+ //
+ init_diag (1);
+ init (nullptr, argv[0]);
+
+ // Serial execution.
+ //
+ scheduler sched (1);
+ global_mutexes mutexes (1);
+ context ctx (sched, mutexes);
try
{
@@ -141,14 +162,49 @@ namespace build2
path_name nm ("buildfile");
script s (p.pre_parse (cin, nm, 11 /* line */));
- if (!dump)
+ switch (m)
{
- environment e (tt);
- print_runner r (line);
- p.execute (s, e, r);
+ case mode::run:
+ {
+ environment e (tt);
+ print_runner r (print_line);
+ p.execute (s, e, r);
+ break;
+ }
+ case mode::dump:
+ {
+ dump (cout, "", s.lines);
+ break;
+ }
+ case mode::print:
+ {
+ for (const line& l: s.lines)
+ {
+ for (const replay_token& rt: l.tokens)
+ {
+ if (&rt != &l.tokens[0])
+ cout << ' ';
+
+ const token& t (rt.token);
+ cout << t;
+
+ char q ('\0');
+ switch (t.qtype)
+ {
+ case quote_type::single: q = 'S'; break;
+ case quote_type::double_: q = 'D'; break;
+ case quote_type::mixed: q = 'M'; break;
+ case quote_type::unquoted: break;
+ }
+
+ if (q != '\0')
+ cout << " [" << q << (t.qcomp ? "/C" : "/P") << ']';
+ }
+ }
+
+ cout << endl;
+ }
}
- else
- build2::script::dump (cout, "", s.lines);
}
catch (const failed&)
{