aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/lexer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'build2/test/script/lexer.cxx')
-rw-r--r--build2/test/script/lexer.cxx38
1 files changed, 23 insertions, 15 deletions
diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx
index cdf726b..74aa02e 100644
--- a/build2/test/script/lexer.cxx
+++ b/build2/test/script/lexer.cxx
@@ -17,13 +17,19 @@ namespace build2
using type = token_type;
void lexer::
- mode (base_mode m, char ps, const char* esc)
+ mode (base_mode m, char ps, optional<const char*> esc)
{
const char* s1 (nullptr);
const char* s2 (nullptr);
bool s (true);
bool q (true);
+ if (!esc)
+ {
+ assert (!state_.empty ());
+ esc = state_.top ().escapes;
+ }
+
switch (m)
{
case lexer_mode::script_line:
@@ -129,7 +135,7 @@ namespace build2
}
assert (ps == '\0');
- state_.push (state {m, ps, s, q, esc, s1, s2});
+ state_.push (state {m, ps, s, q, *esc, s1, s2});
}
token lexer::
@@ -170,16 +176,24 @@ namespace build2
xchar c (get ());
uint64_t ln (c.line), cn (c.column);
- auto make_token = [&sep, ln, cn] (type t)
+ if (eos (c))
+ return token (type::eos, sep, ln, cn, token_printer);
+
+ state st (state_.top ()); // Make copy (see first/second_token).
+ lexer_mode m (st.mode);
+
+ auto make_token = [&sep, &m, ln, cn] (type t, string v = string ())
{
- return token (t, sep, ln, cn, token_printer);
- };
+ bool q (m == lexer_mode::here_line_double);
- if (eos (c))
- return make_token (type::eos);
+ return token (t, move (v), sep,
+ (q ? quote_type::double_ : quote_type::unquoted), q,
+ ln, cn,
+ token_printer);
+ };
auto make_token_with_modifiers =
- [&sep, ln, cn, this] (type t, const char* mods, bool exc = false)
+ [&make_token, this] (type t, const char* mods, bool exc = false)
{
string v;
if (mods != nullptr)
@@ -199,15 +213,9 @@ namespace build2
}
}
- return token (t, move (v), sep,
- quote_type::unquoted, false,
- ln, cn,
- token_printer);
+ return make_token (t, move (v));
};
- state st (state_.top ()); // Make copy (see first/second_token).
- lexer_mode m (st.mode);
-
// Expire certain modes at the end of the token. Do it early in case
// we push any new mode (e.g., double quote).
//