diff options
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; } } } |