From d42ed27cc2672f2bdb5eeeb1cbc5668e21741bfe Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Thu, 9 Feb 2023 23:24:10 +0100 Subject: [PATCH] more coverage, fix range error in q"str --- src/dparse/lexer.d | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dparse/lexer.d b/src/dparse/lexer.d index ae9217f1..30ed88c9 100644 --- a/src/dparse/lexer.d +++ b/src/dparse/lexer.d @@ -1401,7 +1401,7 @@ private pure nothrow @safe: { Token ident; lexIdentifier(ident); - if (isNewline()) + if (!(range.index >= range.bytes.length) && isNewline()) popFrontWhitespaceAware(); else error("Newline expected"); @@ -1426,14 +1426,15 @@ private pure nothrow @safe: range.popFront(); } } + IdType type; if (!(range.index >= range.bytes.length) && range.bytes[range.index] == '"') { + type = tok!"stringLiteral"; + lexStringSuffix(type); range.popFront(); } else error("`\"` expected"); - IdType type = tok!"stringLiteral"; - lexStringSuffix(type); token = Token(type, cache.intern(range.slice(mark)), line, column, index); } @@ -2504,6 +2505,9 @@ void main() { checkInvalidTrailingString(getTokensForParser(`x = "foo`, cf, &ca)); checkInvalidTrailingString(getTokensForParser(`x = r"foo`, cf, &ca)); + checkInvalidTrailingString(getTokensForParser(`x = x"00`, cf, &ca)); checkInvalidTrailingString(getTokensForParser("x = `foo", cf, &ca)); checkInvalidTrailingString(getTokensForParser("x = q{foo", cf, &ca)); + checkInvalidTrailingString(getTokensForParser(`x = q"foo`, cf, &ca)); + checkInvalidTrailingString(getTokensForParser("x = '", cf, &ca)); }