diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-07-19 00:29:43 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-19 00:29:43 +0800 |
| commit | 89e836d42822e69dcaa4eb0a366d8c66e5aaa7e4 (patch) | |
| tree | cc45e206cddfe8526a61a3d7536d49b2670cfff1 | |
| parent | 3750a4dcb284d4695f5188c497c5a9dcff98388e (diff) | |
Correctly parse multiple escaped newlines (#4672)
closes https://github.com/shader-slang/slang/issues/4667
| -rw-r--r-- | source/compiler-core/slang-lexer.cpp | 9 | ||||
| -rw-r--r-- | tests/bugs/gh-4667.slang | 4 |
2 files changed, 10 insertions, 3 deletions
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 diff --git a/tests/bugs/gh-4667.slang b/tests/bugs/gh-4667.slang new file mode 100644 index 000000000..4b9078387 --- /dev/null +++ b/tests/bugs/gh-4667.slang @@ -0,0 +1,4 @@ +//TEST:SIMPLE: +\ +\ +int x; |
