aboutsummaryrefslogtreecommitdiff
path: root/build/lexer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'build/lexer.cxx')
-rw-r--r--build/lexer.cxx54
1 files changed, 33 insertions, 21 deletions
diff --git a/build/lexer.cxx b/build/lexer.cxx
index 77e803c..0835704 100644
--- a/build/lexer.cxx
+++ b/build/lexer.cxx
@@ -8,6 +8,8 @@ using namespace std;
namespace build
{
+ typedef token_type type;
+
token lexer::
next ()
{
@@ -47,7 +49,7 @@ namespace build
uint64_t ln (c.line), cn (c.column);
if (eos (c))
- return token (token_type::eos, sep, ln, cn);
+ return token (type::eos, sep, ln, cn);
switch (c)
{
@@ -61,19 +63,19 @@ namespace build
if (m == lexer_mode::value || m == lexer_mode::pairs)
mode_.pop ();
- return token (token_type::newline, sep, ln, cn);
+ return token (type::newline, sep, ln, cn);
}
- case '{': return token (token_type::lcbrace, sep, ln, cn);
- case '}': return token (token_type::rcbrace, sep, ln, cn);
- case '$': return token (token_type::dollar, sep, ln, cn);
- case '(': return token (token_type::lparen, sep, ln, cn);
- case ')': return token (token_type::rparen, sep, ln, cn);
+ case '{': return token (type::lcbrace, sep, ln, cn);
+ case '}': return token (type::rcbrace, sep, ln, cn);
+ case '$': return token (type::dollar, sep, ln, cn);
+ case '(': return token (type::lparen, sep, ln, cn);
+ case ')': return token (type::rparen, sep, ln, cn);
}
// Handle pair separator.
//
if (m == lexer_mode::pairs && c == pair_separator_)
- return token (token_type::pair_separator, sep, ln, cn);
+ return token (type::pair_separator, sep, ln, cn);
// The following characters are not treated as special in the
// value or pairs mode.
@@ -85,14 +87,24 @@ namespace build
// NOTE: remember to update name(), next_eval() if adding new
// special characters.
//
- case ':': return token (token_type::colon, sep, ln, cn);
- case '=': return token (token_type::equal, sep, ln, cn);
+ case ':': return token (type::colon, sep, ln, cn);
+ case '=':
+ {
+ if (peek () == '+')
+ {
+ get ();
+ return token (type::equal_plus, sep, ln, cn);
+ }
+ else
+ return token (type::equal, sep, ln, cn);
+ }
case '+':
{
- if (get () != '=')
- fail (c) << "expected = after +";
-
- return token (token_type::plus_equal, sep, ln, cn);
+ if (peek () == '=')
+ {
+ get ();
+ return token (type::plus_equal, sep, ln, cn);
+ }
}
}
}
@@ -122,14 +134,14 @@ namespace build
// NOTE: remember to update name() if adding new special characters.
//
case '\n': fail (c) << "newline in evaluation context";
- case '{': return token (token_type::lcbrace, sep, ln, cn);
- case '}': return token (token_type::rcbrace, sep, ln, cn);
- case '$': return token (token_type::dollar, sep, ln, cn);
- case '(': return token (token_type::lparen, sep, ln, cn);
+ case '{': return token (type::lcbrace, sep, ln, cn);
+ case '}': return token (type::rcbrace, sep, ln, cn);
+ case '$': return token (type::dollar, sep, ln, cn);
+ case '(': return token (type::lparen, sep, ln, cn);
case ')':
{
mode_.pop (); // Expire eval mode.
- return token (token_type::rparen, sep, ln, cn);
+ return token (type::rparen, sep, ln, cn);
}
}
@@ -151,8 +163,8 @@ namespace build
switch (c)
{
- case '$': return token (token_type::dollar, false, ln, cn);
- case '(': return token (token_type::lparen, false, ln, cn);
+ case '$': return token (type::dollar, false, ln, cn);
+ case '(': return token (type::lparen, false, ln, cn);
}
// Otherwise it is a name.