summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-06-19 14:26:41 -0700
committerGitHub <noreply@github.com>2017-06-19 14:26:41 -0700
commit01cdb43ecfd945f8374969a7293a5e1ac6762d1e (patch)
tree2693987d8cbac64369b30857f6a6b8e6d78cd903 /source
parent838e8331da24744948539c12d2a8edcd9c594ee5 (diff)
parente65d2ad1e776610427b85dd20e861d3ad5e0ea71 (diff)
Merge pull request #31 from tfoleyNV/escaped-newlines
Bug fix for newline escaping.
Diffstat (limited to 'source')
-rw-r--r--source/slang/lexer.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp
index cb718b538..f81ead87c 100644
--- a/source/slang/lexer.cpp
+++ b/source/slang/lexer.cpp
@@ -1052,8 +1052,39 @@ namespace Slang
// Note(tfoley): `StringBuilder::Append()` seems to crash when appending zero bytes
if(textEnd != textBegin)
{
+ // HACK(tfoley): "scrubbing" token value here to remove escaped newlines...
+ //
+ // TODO: Only perform this work if we encountered an escaped newline
+ // while lexing this token (e.g., keep a flag on the lexer), or
+ // do it on-demand when the actual value of the token is needed.
+
StringBuilder valueBuilder;
- valueBuilder.Append(textBegin, int(textEnd - textBegin));
+ auto tt = textBegin;
+ while(tt != textEnd)
+ {
+ char c = *tt++;
+ if(c == '\\')
+ {
+ char d = *tt;
+ switch(d)
+ {
+ case '\r': case '\n':
+ {
+ tt++;
+ char e = *tt;
+ if((d ^ e) == ('\r' ^ '\n'))
+ {
+ tt++;
+ }
+ }
+ continue;
+
+ default:
+ break;
+ }
+ }
+ valueBuilder.Append(c);
+ }
token.Content = valueBuilder.ProduceString();
}