aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-06-10 10:00:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-06-10 10:00:55 +0200
commitd5faeeab1d2115c02a330ac9c95d63ba225faabc (patch)
tree410f9d2b8c70c30c74d799d4fa7695c6f367cd41 /libbuild2/test
parent2ee88b6041557beb517b100c3f608ebfc5eb725d (diff)
Handle special variable names in base lexer via mode data
Diffstat (limited to 'libbuild2/test')
-rw-r--r--libbuild2/test/script/lexer+variable.test.testscript3
-rw-r--r--libbuild2/test/script/lexer.cxx46
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;
}
}
}