aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/lexer.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-28 10:10:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:36 +0200
commitcd40097447ff2400cb420ec973c16dadd26e6cda (patch)
treebcd1c902d487e7a60ffffd5b02b7c608829fbc57 /build2/test/script/lexer.cxx
parente61874e76052d3600d6f10807248f92935f3dd61 (diff)
Implement description support in testscript
Diffstat (limited to 'build2/test/script/lexer.cxx')
-rw-r--r--build2/test/script/lexer.cxx60
1 files changed, 52 insertions, 8 deletions
diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx
index 003e4ac..aa7b098 100644
--- a/build2/test/script/lexer.cxx
+++ b/build2/test/script/lexer.cxx
@@ -26,8 +26,8 @@ namespace build2
{
case lexer_mode::script_line:
{
- s1 = ";=!|&<> $(#\t\n";
- s2 = " == ";
+ s1 = ":;=!|&<> $(#\t\n";
+ s2 = " == ";
break;
}
case lexer_mode::first_token:
@@ -39,8 +39,8 @@ namespace build2
// Note that to recognize only leading '+-{}' we shouldn't add
// them to the separator strings.
//
- s1 = ";=+!|&<> $(#\t\n";
- s2 = " == ";
+ s1 = ":;=+!|&<> $(#\t\n";
+ s2 = " == ";
break;
}
case lexer_mode::second_token:
@@ -52,8 +52,8 @@ namespace build2
// add them to the separator strings (so this is identical to
// script_line).
//
- s1 = ";=!|&<> $(#\t\n";
- s2 = " == ";
+ s1 = ":;=!|&<> $(#\t\n";
+ s2 = " == ";
break;
}
case lexer_mode::variable_line:
@@ -85,6 +85,13 @@ namespace build2
q = false;
break;
}
+ case lexer_mode::description_line:
+ {
+ // This one is like a single-quoted string and has an ad hoc
+ // implementation.
+ //
+ break;
+ }
default:
{
// Disable pair separator except for attributes.
@@ -109,8 +116,15 @@ namespace build2
case lexer_mode::second_token:
case lexer_mode::variable_line:
case lexer_mode::command_line:
- case lexer_mode::here_line: r = next_line (); break;
- default: r = base_lexer::next_impl (); break;
+ case lexer_mode::here_line:
+ r = next_line ();
+ break;
+ case lexer_mode::description_line:
+ r = next_description ();
+ break;
+ default:
+ r = base_lexer::next_impl ();
+ break;
}
if (r.quoted)
@@ -191,6 +205,16 @@ namespace build2
}
}
+ if (m == lexer_mode::script_line ||
+ m == lexer_mode::first_token ||
+ m == lexer_mode::second_token)
+ {
+ switch (c)
+ {
+ case ':': return make_token (type::colon);
+ }
+ }
+
// Command line operator/separators.
//
if (m == lexer_mode::script_line ||
@@ -379,6 +403,26 @@ namespace build2
}
token lexer::
+ next_description ()
+ {
+ xchar c (get ());
+
+ uint64_t ln (c.line), cn (c.column);
+ string lexeme;
+
+ // For now no line continutions though we could support them.
+ //
+ for (; !eos (c) && c != '\n'; c = get ())
+ lexeme += c;
+
+ if (eos (c))
+ fail (c) << "expected newline at the end of description line";
+
+ state_.pop (); // Expire the description mode.
+ return token (move (lexeme), false, false, ln, cn);
+ }
+
+ token lexer::
word (state st, bool sep)
{
lexer_mode m (st.mode);