From 427efeae13912b66e1c030c7645a2b1f322dff4d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 25 May 2017 15:40:06 +0200 Subject: Fix few bugs in C++ lexer and parser --- build2/cc/lexer.cxx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'build2/cc/lexer.cxx') diff --git a/build2/cc/lexer.cxx b/build2/cc/lexer.cxx index 3eb5d5b..05c734c 100644 --- a/build2/cc/lexer.cxx +++ b/build2/cc/lexer.cxx @@ -76,7 +76,7 @@ namespace build2 using type = token_type; void lexer:: - next (token& t, xchar c) + next (token& t, xchar c, bool ignore_pp) { for (;; c = skip_spaces ()) { @@ -101,18 +101,27 @@ namespace build2 // that we assume there cannot be #include directives. // // This may not work for things like #error that can contain - // pretty much anything. + // pretty much anything. Also note that lines that start with + // # can contain # further down. // - for (;;) + if (ignore_pp) { - c = skip_spaces (false); // Stop at newline. + for (;;) + { + c = skip_spaces (false); // Stop at newline. - if (eos (c) || c == '\n') - break; + if (eos (c) || c == '\n') + break; - next (t, c); // Keep using the passed token for buffers. + next (t, c, false); // Keep using the passed token for buffers. + } + break; + } + else + { + t.type = type::punctuation; + return; } - break; } // Single-letter punctuation. // -- cgit v1.1