From a63e1809afd9a837821d6e8376cb14a36e7fc26e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Jan 2017 17:44:39 +0200 Subject: Treat any testscript line that starts with dot as directive Even though we currently only recognize the include directive, we reserve any line that begins with a dot for future. --- build2/test/script/parser.cxx | 56 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'build2/test/script/parser.cxx') diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index 99e4a66..dd5c5c7 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -174,7 +174,7 @@ namespace build2 // for (;;) { - // Start lexing each line recognizing leading ':+-{}'. + // Start lexing each line recognizing leading '.+-{}'. // tt = peek (lexer_mode::first_token); @@ -304,6 +304,31 @@ namespace build2 switch (tt) { + case type::dot: + { + // Directive. + // + next (t, tt); // Skip dot. + next (t, tt); // Get the directive name. + + if (tt != type::word || t.qtype != quote_type::unquoted) + fail (t) << "expected directive name instead of " << t; + + // Make sure we are not inside a test (i.e., after semi). + // + if (ls != nullptr) + fail (ll) << "directive after ';'"; + + const string& n (t.value); + + if (n == "include") + pre_parse_directive (t, tt); + else + fail (t) << "unknown directive '" << n << "'"; + + assert (tt == type::newline); + return false; + } case type::plus: case type::minus: { @@ -331,23 +356,19 @@ namespace build2 } default: { - // Either directive, variable assignment, or test command. + // Either variable assignment or test command. // replay_save (); // Start saving tokens from the current one. next (t, tt); - // Decide whether this is a variable assignment, directive or a - // command. - // - // It is a directive if the first token is an unquoted directive - // name. + // Decide whether this is a variable assignment or a command. // // It is an assignment if the first token is an unquoted name and // the next token is an assign/append/prepend operator. Assignment // to a computed variable name must use the set builtin. // - // Note also that directives/special commands take precedence over - // variable assignments. + // Note also thatspecial commands take precedence over variable + // assignments. // lt = line_type::cmd; // Default. @@ -355,20 +376,7 @@ namespace build2 { const string& n (t.value); - if (n == ".include") - { - replay_stop (); // Stop replay and discard the data. - - // Make sure we are not inside a test (i.e., after semi). - // - if (ls != nullptr) - fail (ll) << "directive after ';'"; - - pre_parse_directive (t, tt); - assert (tt == type::newline); - return false; - } - else if (n == "if") lt = line_type::cmd_if; + if (n == "if") lt = line_type::cmd_if; else if (n == "if!") lt = line_type::cmd_ifn; else if (n == "elif") lt = line_type::cmd_elif; else if (n == "elif!") lt = line_type::cmd_elifn; @@ -941,7 +949,7 @@ namespace build2 if (tt != type::newline) fail (t) << t << " after directive"; - if (d == ".include") + if (d == "include") pre_parse_include_line (move (args), move (l)); else assert (false); // Unhandled directive. -- cgit v1.1