summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-07-19 00:29:43 +0800
committerGitHub <noreply@github.com>2024-07-19 00:29:43 +0800
commit89e836d42822e69dcaa4eb0a366d8c66e5aaa7e4 (patch)
treecc45e206cddfe8526a61a3d7536d49b2670cfff1 /source
parent3750a4dcb284d4695f5188c497c5a9dcff98388e (diff)
Correctly parse multiple escaped newlines (#4672)
closes https://github.com/shader-slang/slang/issues/4667
Diffstat (limited to 'source')
-rw-r--r--source/compiler-core/slang-lexer.cpp9
1 files changed, 6 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