diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-22 17:12:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-04 09:26:35 +0200 |
commit | 8bc5612e8ccddf38b0ebf6e89af2074ffde33c5f (patch) | |
tree | 7cf647aae4713331f8ead86efbf6642df352a18d | |
parent | 132c1f2bb19c92722274c69a190c2f71b801b602 (diff) |
Add support for multi-line comments
Now we can do:
line 1
line 2
Or even:
foo #\
line1
line2 #\
bar
-rw-r--r-- | build2/lexer.cxx | 46 |
1 files changed, 41 insertions, 5 deletions
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 '\\': |