From a6ae456de2d2bb88de07c80560424e8fb644dfce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 25 Oct 2016 07:22:40 +0200 Subject: Diagnose semicolon after testscript setup/teardown commands --- build2/test/script/parser | 2 +- build2/test/script/parser.cxx | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'build2') diff --git a/build2/test/script/parser b/build2/test/script/parser index 2e8a9b1..5538b62 100644 --- a/build2/test/script/parser +++ b/build2/test/script/parser @@ -64,7 +64,7 @@ namespace build2 parse_variable_line (token&, token_type&); bool - parse_command_line (token&, token_type&, size_t); + parse_command_line (token&, token_type&, line_type, size_t); command_exit parse_command_exit (token&, token_type&); diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index 1231759..424029f 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -294,7 +294,7 @@ namespace build2 if (lt != line_type::test) next (t, tt); - return make_pair (lt, parse_command_line (t, tt, 0)); + return make_pair (lt, parse_command_line (t, tt, lt, 0)); } void parser:: @@ -306,7 +306,7 @@ namespace build2 case line_type::setup: case line_type::tdown: next (t, tt); // Skip plus/minus fallthrough. - case line_type::test: parse_command_line (t, tt, li); break; + case line_type::test: parse_command_line (t, tt, lt, li); break; } } @@ -397,7 +397,7 @@ namespace build2 } bool parser:: - parse_command_line (token& t, type& tt, size_t li) + parse_command_line (token& t, type& tt, line_type lt, size_t li) { command c; @@ -616,8 +616,8 @@ namespace build2 const location ll (get_location (t)); // Line location. - // Keep parsing chunks of the command line until we see the newline or - // the exit status comparison. + // Keep parsing chunks of the command line until we see one of the + // "terminators" (newline, semicolon, exit status comparison, etc). // location l (ll); names ns; // Reuse to reduce allocations. @@ -888,7 +888,11 @@ namespace build2 if (tt == type::equal || tt == type::not_equal) c.exit = parse_command_exit (t, tt); - bool semi (tt == type::semi); + // Semicolon is only valid in test command lines. Note that we still + // recognize it lexically, it's just not a valid token per the + // grammar. + // + bool semi (tt == type::semi && lt == line_type::test); if (semi) next (t, tt); // Get newline. -- cgit v1.1