From 323e774380995c04ae705e29ae0e51d62246333d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Nov 2017 17:06:35 +0200 Subject: Add support for for-loop The semantics is similar to the C++11 range-based for: list = 1 2 3 for i: $list print $i Note that there is no scoping of any kind for the loop variable ('i' in the above example). See tests/loop/for.test for some examples/ideas. In the future the plan is to also support more general while-loop as well as break and continue. --- build2/lexer.hxx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'build2/lexer.hxx') diff --git a/build2/lexer.hxx b/build2/lexer.hxx index d88d5ba..a4eda1e 100644 --- a/build2/lexer.hxx +++ b/build2/lexer.hxx @@ -66,15 +66,18 @@ namespace build2 lexer_mode (base_type v): base_type (v) {} }; - class lexer: protected butl::char_scanner + class lexer: public butl::char_scanner { public: // If escape is not NULL then only escape sequences with characters from // this string are considered "effective escapes" with all others passed // through as is. Note that the escape string is not copied. // - lexer (istream& is, const path& name, const char* escapes = nullptr) - : lexer (is, name, escapes, true) {} + lexer (istream& is, + const path& name, + uint64_t line = 1, // Start line in the stream. + const char* escapes = nullptr) + : lexer (is, name, line, escapes, true /* set_mode */) {} const path& name () const {return name_;} @@ -164,11 +167,18 @@ namespace build2 // Lexer state. // protected: - lexer (istream& is, const path& n, const char* e, bool sm) - : char_scanner (is), fail ("error", &name_), name_ (n), sep_ (false) + lexer (istream& is, + const path& name, + uint64_t line, + const char* escapes, + bool set_mode) + : char_scanner (is, true /* crlf */, line), + fail ("error", &name_), + name_ (name), + sep_ (false) { - if (sm) - mode (lexer_mode::normal, '@', e); + if (set_mode) + mode (lexer_mode::normal, '@', escapes); } const path name_; -- cgit v1.1