aboutsummaryrefslogtreecommitdiff
path: root/build/lexer.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-08 13:28:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-08 13:43:26 +0200
commitb5940dd5562bfa12d6d76dceb61540b4480a4982 (patch)
tree1e8095300b5413ca510baa10bcb840101b06417c /build/lexer.cxx
parentefd76ff778c0b7b1f8cb9e0485bb9b4b62b149a7 (diff)
Use mode stack in lexer
Diffstat (limited to 'build/lexer.cxx')
-rw-r--r--build/lexer.cxx32
1 files changed, 16 insertions, 16 deletions
diff --git a/build/lexer.cxx b/build/lexer.cxx
index 4151087..f4733be 100644
--- a/build/lexer.cxx
+++ b/build/lexer.cxx
@@ -11,12 +11,6 @@ namespace build
token lexer::
next ()
{
- if (mode_ != next_mode_)
- {
- prev_mode_ = mode_;
- mode_ = next_mode_;
- }
-
bool sep (skip_spaces ());
xchar c (get ());
@@ -25,16 +19,18 @@ namespace build
if (eos (c))
return token (token_type::eos, sep, ln, cn);
+ lexer_mode m (mode_.top ());
+
switch (c)
{
// NOTE: remember to update name() if adding new punctuations.
//
case '\n':
{
- // Restore the normal mode at the end of the line.
+ // Expire value/pairs mode at the end of the line.
//
- if (mode_ == lexer_mode::value || mode_ == lexer_mode::pairs)
- mode_ = next_mode_ = lexer_mode::normal;
+ if (m == lexer_mode::value || m == lexer_mode::pairs)
+ mode_.pop ();
return token (token_type::newline, sep, ln, cn);
}
@@ -62,13 +58,13 @@ namespace build
// Handle pair separator.
//
- if (mode_ == lexer_mode::pairs && c == pair_separator_)
+ if (m == lexer_mode::pairs && c == pair_separator_)
return token (token_type::pair_separator, sep, ln, cn);
// The following characters are not treated as special in the
// value or pairs mode.
//
- if (mode_ != lexer_mode::value && mode_ != lexer_mode::pairs)
+ if (m != lexer_mode::value && m != lexer_mode::pairs)
{
// NOTE: remember to update name() if adding new punctuations.
//
@@ -107,19 +103,21 @@ namespace build
uint64_t ln (c.line), cn (c.column);
string lexeme;
+ lexer_mode m (mode_.top ());
+
for (; !eos (c); c = peek ())
{
bool done (false);
// Handle pair separator.
//
- if (mode_ == lexer_mode::pairs && c == pair_separator_)
+ if (m == lexer_mode::pairs && c == pair_separator_)
break;
// The following characters are not treated as special in the
// value or pairs mode.
//
- if (mode_ != lexer_mode::value && mode_ != lexer_mode::pairs)
+ if (m != lexer_mode::value && m != lexer_mode::pairs)
{
switch (c)
{
@@ -139,7 +137,7 @@ namespace build
// While these extra characters are treated as the name end in
// the variable mode.
//
- if (mode_ == lexer_mode::variable)
+ if (m == lexer_mode::variable)
{
switch (c)
{
@@ -198,8 +196,10 @@ namespace build
//
assert (c.line != ln || c.column != cn);
- if (mode_ == lexer_mode::variable)
- next_mode_ = prev_mode_;
+ // Expire variable mode at the end of the name.
+ //
+ if (m == lexer_mode::variable)
+ mode_.pop ();
return token (lexeme, sep, ln, cn);
}