diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-05-01 17:09:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-05-01 17:12:04 +0200 |
commit | 630b498533f5a9a1e9d40893f4806ef855f1e03b (patch) | |
tree | 18657642a3d0deffc1ed14ad449bd6f3ac4b1e64 /libbuild2/parser.cxx | |
parent | c7e9f97fc7684c01c692916be1ac2cfc92024a0c (diff) |
Fix outstanding issue with directive vs assignment differentiation
Specifically, now the following does the right thing:
print +foo
Diffstat (limited to 'libbuild2/parser.cxx')
-rw-r--r-- | libbuild2/parser.cxx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 1432d4b..f0eac97 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -5747,7 +5747,7 @@ namespace build2 // // - it is not quoted [so a keyword can always be escaped] and // - next token is '\n' (or eos) or '(' [so if(...) will work] or - // - next token is separated and is not '=', '=+', or '+=' [which + // - next token is separated and is not '=', '=+', '+=', or '?=' [which // means a "directive trailer" can never start with one of them]. // // See tests/keyword. @@ -5757,15 +5757,23 @@ namespace build2 // We cannot peek at the whole token here since it might have to be // lexed in a different mode. So peek at its first character. // - pair<char, bool> p (lexer_->peek_char ()); - char c (p.first); + pair<pair<char, char>, bool> p (lexer_->peek_chars ()); + char c0 (p.first.first); + char c1 (p.first.second); - // @@ Just checking for leading '+' is not sufficient, for example: + // Note that just checking for leading '+'/'?' is not sufficient, for + // example: // // print +foo // - return c == '\n' || c == '\0' || c == '(' || - (p.second && c != '=' && c != '+'); + // So wepeek at one more character since what we expect next ('=') can't + // be whitespace-separated. + // + return c0 == '\n' || c0 == '\0' || c0 == '(' || + (p.second && + c0 != '=' && + (c0 != '+' || c1 != '=') && + (c0 != '?' || c1 != '=')); } return false; |