aboutsummaryrefslogtreecommitdiff
path: root/build/lexer
diff options
context:
space:
mode:
Diffstat (limited to 'build/lexer')
-rw-r--r--build/lexer30
1 files changed, 21 insertions, 9 deletions
diff --git a/build/lexer b/build/lexer
index d6817f2..787ba72 100644
--- a/build/lexer
+++ b/build/lexer
@@ -15,11 +15,29 @@
namespace build
{
+ // Context-dependent lexing mode. In the value mode we don't treat
+ // certain characters (e.g., +, =) as special so that we can use
+ // them in the variable values, e.g., 'foo = g++'. In contrast,
+ // in the variable mode, we restrict certain character (e.g., /)
+ // from appearing in the name. The pairs mode is just like value
+ // except that we split names separated by '='. The pairs mode must
+ // be set manually.
+ //
+ enum class lexer_mode {normal, value, variable, pairs};
+
class lexer
{
public:
lexer (std::istream& is, const std::string& name): is_ (is), fail (name) {}
+ // Note: sets mode for the next token.
+ //
+ void
+ mode (lexer_mode m) {next_mode_ = m;}
+
+ lexer_mode
+ mode () const {return mode_;}
+
// Scanner.
//
token
@@ -108,15 +126,9 @@ namespace build
xchar buf_ {0, 0, 0};
bool eos_ {false};
-
- // Context-dependent lexing mode. In the value mode we don't treat
- // certain characters (e.g., +, =) as special so that we can use
- // them in the variable values, e.g., 'foo = g++'. In contrast,
- // in the variable mode, we restrict certain character (e.g., /)
- // from appearing in the name.
- //
- enum class mode {normal, value, variable};
- mode mode_ {mode::normal};
+ lexer_mode mode_ {lexer_mode::normal};
+ lexer_mode next_mode_; // Mode to switch to for the next token.
+ lexer_mode prev_mode_; // Mode to return to after this mode expires.
};
}