diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-03-06 09:15:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-03-06 09:15:40 +0200 |
commit | 897a0e4fdf9ca90ee8d236a38e138a8ae6bc3627 (patch) | |
tree | d4c00de32d028823906d342fcd984faee8d977ff /build/lexer | |
parent | 9ef25ab2f9da89ab48ecce3fe1b8cbb0bc5f1e09 (diff) |
Add support for lexing and parsing name pairs
We will need it for the buildspec and also if/when we support map
variable types.
Diffstat (limited to 'build/lexer')
-rw-r--r-- | build/lexer | 30 |
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. }; } |