aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/test/script/parser2
-rw-r--r--build2/test/script/parser.cxx16
-rw-r--r--unit-tests/test/script/parser/buildfile2
-rw-r--r--unit-tests/test/script/parser/setup-teardown.test7
4 files changed, 19 insertions, 8 deletions
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.
diff --git a/unit-tests/test/script/parser/buildfile b/unit-tests/test/script/parser/buildfile
index a6be1f6..18acd20 100644
--- a/unit-tests/test/script/parser/buildfile
+++ b/unit-tests/test/script/parser/buildfile
@@ -11,6 +11,6 @@ filesystem config/{utility init operation} dump types-parsers \
test/{target script/{token lexer parser script}}
exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs \
-test{pre-parse expansion here-document command-re-parse scope}
+test{pre-parse expansion here-document command-re-parse scope setup-teardown}
include ../../../../build2/
diff --git a/unit-tests/test/script/parser/setup-teardown.test b/unit-tests/test/script/parser/setup-teardown.test
new file mode 100644
index 0000000..fa940fd
--- /dev/null
+++ b/unit-tests/test/script/parser/setup-teardown.test
@@ -0,0 +1,7 @@
+$* <"+cmd;" 2>>EOE != 0 # semi-after-setup
+testscript:1:5: error: expected newline instead of ';'
+EOE
+
+$* <"-cmd;" 2>>EOE != 0 # semi-after-tdown
+testscript:1:5: error: expected newline instead of ';'
+EOE