From 89e836d42822e69dcaa4eb0a366d8c66e5aaa7e4 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 19 Jul 2024 00:29:43 +0800 Subject: Correctly parse multiple escaped newlines (#4672) closes https://github.com/shader-slang/slang/issues/4667 --- source/compiler-core/slang-lexer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/compiler-core/slang-lexer.cpp b/source/compiler-core/slang-lexer.cpp index 10c5aa1ae..7d84ed938 100644 --- a/source/compiler-core/slang-lexer.cpp +++ b/source/compiler-core/slang-lexer.cpp @@ -185,7 +185,7 @@ namespace Slang c = lexer->m_cursor[pos++]; - if (c == '\\') + while (c == '\\') { // We might have a backslash-escaped newline. // Look at the next byte (if any) to see. @@ -198,18 +198,21 @@ namespace Slang case '\r': case '\n': { // The newline was escaped, so return the code point after *that* - int e = lexer->m_cursor[pos++]; if ((d ^ e) == ('\r' ^ '\n')) c = lexer->m_cursor[pos++]; else c = e; - break; + continue; } default: break; } + + // Only continue this while loop in the case where we consumed + // some newlines + break; } // TODO: handle UTF-8 encoding for non-ASCII code points here -- cgit v1.2.3