From 4bf42322fdd5dd7e01a3f61272bccc4a66a5585f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 2 Apr 2016 12:28:56 +0200 Subject: Add attribute syntax infrastructure --- build2/lexer | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'build2/lexer') diff --git a/build2/lexer b/build2/lexer index 001d52c..c856344 100644 --- a/build2/lexer +++ b/build2/lexer @@ -42,32 +42,31 @@ namespace build2 void (*processor) (token&, const lexer&) = nullptr) : char_scanner (is), fail (name), processor_ (processor), sep_ (false) { - mode_.push (lexer_mode::normal); + mode (lexer_mode::normal); } const path& name () const {return fail.name_;} - // Note: sets mode for the next token. If mode is pairs, then - // the second argument specifies the separator character. + // Note: sets mode for the next token. If mode is pairs, then the second + // argument specifies the separator character. // void - mode (lexer_mode m, char pair_separator = '=') + mode (lexer_mode m, char pair_separator = '\0') { - mode_.push (m); - pair_separator_ = pair_separator; + state_.push (state{m, pair_separator}); } // Expire the current mode early. // void - expire_mode () {mode_.pop ();} + expire_mode () {state_.pop ();} lexer_mode - mode () const {return mode_.top ();} + mode () const {return state_.top ().mode;} char - pair_separator () const {return pair_separator_;} + pair_separator () const {return state_.top ().pair_separator;} // Scanner. Note that it is ok to call next() again after getting eos. // @@ -123,8 +122,13 @@ namespace build2 void (*processor_) (token&, const lexer&); - std::stack mode_; - char pair_separator_; + struct state + { + lexer_mode mode; + char pair_separator; + }; + std::stack state_; + bool sep_; // True if we skipped spaces in peek(). }; } -- cgit v1.1