diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-06-10 10:00:55 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-06-10 10:00:55 +0200 |
commit | d5faeeab1d2115c02a330ac9c95d63ba225faabc (patch) | |
tree | 410f9d2b8c70c30c74d799d4fa7695c6f367cd41 /libbuild2/build/script/lexer.cxx | |
parent | 2ee88b6041557beb517b100c3f608ebfc5eb725d (diff) |
Handle special variable names in base lexer via mode data
Diffstat (limited to 'libbuild2/build/script/lexer.cxx')
-rw-r--r-- | libbuild2/build/script/lexer.cxx | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/libbuild2/build/script/lexer.cxx b/libbuild2/build/script/lexer.cxx index a58f794..d849ac9 100644 --- a/libbuild2/build/script/lexer.cxx +++ b/libbuild2/build/script/lexer.cxx @@ -80,7 +80,15 @@ namespace build2 } default: { - base_lexer::mode (m, ps, esc); + // Recognize special variable names ($>, $<, $~). + // + if (m == lexer_mode::variable) + { + assert (data == 0); + data = reinterpret_cast<uintptr_t> ("><~"); + } + + base_lexer::mode (m, ps, esc, data); return; } } @@ -235,35 +243,6 @@ namespace build2 unget (c); return word (st, sep); } - - token lexer:: - word (state st, bool sep) - { - lexer_mode m (st.mode); - - // Customized implementation that handles special variable names ($>, - // $<, $~). - // - // @@ TODO: $(<), $(>): feels like this will have to somehow be - // handled at the top-level lexer level. Maybe provide a - // string of one-char special variable names as state::data? - // - if (m != lexer_mode::variable) - return base_lexer::word (st, sep); - - xchar c (peek ()); - - if (c != '>' && c != '<' && c != '~') - return base_lexer::word (st, sep); - - get (); - - state_.pop (); // Expire the variable mode. - return token (string (1, c), - sep, - quote_type::unquoted, false, - c.line, c.column); - } } } } |