diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-12 15:16:32 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-13 12:25:29 -0700 |
| commit | a14f3c50ef2cf7d3e34e729dfe10ce1cec880955 (patch) | |
| tree | 14e9c3ea339de274e11864d2bae3a5c3da83da4f /source/slang | |
| parent | 7fc4c40b17f340800d6616e0bae111606cef18cc (diff) | |
Fixups for newline-escaping behavior.
This is really messy and I'm not entirely happy with the result, but at least we handle a couple more corner cases.
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/lexer.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp index 5127c876c..87b3eaf63 100644 --- a/source/slang/lexer.cpp +++ b/source/slang/lexer.cpp @@ -135,9 +135,8 @@ namespace Slang // // We always look for the longest match possible. // - static void handleNewLine(Lexer* lexer) + static void handleNewLineInner(Lexer* lexer, int c) { - int c = advanceRaw(lexer); assert(c == '\n' || c == '\r'); int d = peekRaw(lexer); @@ -168,8 +167,14 @@ namespace Slang switch (d) { case '\r': case '\n': - // The newline was escaped, so return the character after *that* - return lexer->cursor[2]; + { + // The newline was escaped, so return the code point after *that* + + int e = lexer->cursor[2]; + if ((d ^ e) == ('\r' ^ '\n')) + return lexer->cursor[3]; + return e; + } default: break; @@ -207,7 +212,8 @@ namespace Slang { case '\r': case '\n': // handle the end-of-line for our source location tracking - handleNewLine(lexer); + lexer->cursor++; + handleNewLineInner(lexer, d); // Now try again, looking at the character after the // escaped nmewline. @@ -230,6 +236,11 @@ namespace Slang } } + static void handleNewLine(Lexer* lexer) + { + int c = advance(lexer); + handleNewLineInner(lexer, c); + } static void lexLineComment(Lexer* lexer) { |
