From 8bc5612e8ccddf38b0ebf6e89af2074ffde33c5f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 22 Oct 2016 17:12:26 +0200 Subject: Add support for multi-line comments Now we can do: line 1 line 2 Or even: foo #\ line1 line2 #\ bar --- build2/lexer.cxx | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'build2/lexer.cxx') diff --git a/build2/lexer.cxx b/build2/lexer.cxx index f2426e7..38d33ae 100644 --- a/build2/lexer.cxx +++ b/build2/lexer.cxx @@ -479,7 +479,7 @@ namespace build2 bool r (sep_); sep_ = false; - // In some modes we don't skip spaces. + // In some special modes we don't skip spaces. // if (!state_.top ().sep_space) return r; @@ -511,14 +511,50 @@ namespace build2 } case '#': { + r = true; get (); - // Read until newline or eos. + // See if this is a multi-line comment in the form: // - for (c = peek (); !eos (c) && c != '\n'; c = peek ()) - get (); + /* + #\ + ... + #\ + */ + auto ml = [&c, this] () -> bool + { + if ((c = peek ()) == '\\') + { + get (); + if ((c = peek ()) == '\n') + return true; + } + + return false; + }; + + if (ml ()) + { + // Scan until we see the closing one. + // + for (; !eos (c); c = peek ()) + { + get (); + if (c == '#' && ml ()) + break; + } + + if (eos (c)) + fail (c) << "unterminated multi-line comment"; + } + else + { + // Read until newline or eos. + // + for (; !eos (c) && c != '\n'; c = peek ()) + get (); + } - r = true; continue; } case '\\': -- cgit v1.1