diff options
Diffstat (limited to 'libbuild2/test/script')
-rw-r--r-- | libbuild2/test/script/lexer+variable.test.testscript | 3 | ||||
-rw-r--r-- | libbuild2/test/script/lexer.cxx | 46 |
2 files changed, 22 insertions, 27 deletions
diff --git a/libbuild2/test/script/lexer+variable.test.testscript b/libbuild2/test/script/lexer+variable.test.testscript index ac7d6be..5993c37 100644 --- a/libbuild2/test/script/lexer+variable.test.testscript +++ b/libbuild2/test/script/lexer+variable.test.testscript @@ -64,6 +64,7 @@ test.arguments = variable : multi-digit : $* <"10" 2>>EOE != 0 - <stdin>:1:1: error: multi-digit special variable name + <stdin>:1:2: error: multi-digit special variable name + info: use '($*[NN])' to access elements beyond 9 EOE } 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; } } } |