From 84cc0fc42c6b86eb09b06c7f59a0beb94397a38a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 20 May 2020 23:05:10 +0300 Subject: Complete dump(ostream,script::lines) --- libbuild2/build/script/parser.test.cxx | 98 ++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 21 deletions(-) (limited to 'libbuild2/build/script/parser.test.cxx') 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 #include +#include // line #include #include @@ -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 [/] form, where: + // + // := 'S' | 'D' | 'M' + // := '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&) { -- cgit v1.1