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/test/script/lexer.cxx | |
parent | 2ee88b6041557beb517b100c3f608ebfc5eb725d (diff) |
Handle special variable names in base lexer via mode data
Diffstat (limited to 'libbuild2/test/script/lexer.cxx')
-rw-r--r-- | libbuild2/test/script/lexer.cxx | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/libbuild2/test/script/lexer.cxx b/libbuild2/test/script/lexer.cxx index e895d4a..c23dea4 100644 --- a/libbuild2/test/script/lexer.cxx +++ b/libbuild2/test/script/lexer.cxx @@ -92,16 +92,16 @@ namespace build2 } default: { - // Make sure pair separators are only enabled where we expect - // them. + // Recognize special variable names ($*, $N, $~, $@). See also an + // extra check in word() below. // - // @@ Should we disable pair separators in the eval mode? - // - assert (ps == '\0' || - m == lexer_mode::eval || - m == lexer_mode::attribute_value); + if (m == lexer_mode::variable) + { + assert (data == 0); + data = reinterpret_cast<uintptr_t> ("*~@0123456789"); + } - base_lexer::mode (m, ps, esc); + base_lexer::mode (m, ps, esc, data); return; } } @@ -335,27 +335,21 @@ namespace build2 { lexer_mode m (st.mode); - // Customized implementation that handles special variable names ($*, - // $N, $~, $@). - // - if (m != lexer_mode::variable) - return base_lexer::word (st, sep); - - xchar c (peek ()); - - if (c != '*' && c != '~' && c != '@' && !digit (c)) - return base_lexer::word (st, sep); + token r (base_lexer::word (st, sep)); - get (); + if (m == lexer_mode::variable) + { + if (r.value.size () == 1 && digit (r.value[0])) // $N + { + xchar c (peek ()); - if (digit (c) && digit (peek ())) - fail (c) << "multi-digit special variable name"; + if (digit (c)) // $NN + fail (c) << "multi-digit special variable name" << + info << "use '($*[NN])' to access elements beyond 9"; + } + } - state_.pop (); // Expire the variable mode. - return token (string (1, c), - sep, - quote_type::unquoted, false, - c.line, c.column); + return r; } } } |