Skip to content

Commit 7207858

Browse files
committed
lexer: Handle \r correctly
1 parent cdb0f2c commit 7207858

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/source/pl/core/lexer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace pl::core {
146146
m_cursor++; // Skip space
147147
auto location = this->location();
148148

149-
while (m_sourceCode[m_cursor] != '\n' && m_sourceCode[m_cursor] != '\0') {
149+
while (m_sourceCode[m_cursor] != '\n' && m_sourceCode[m_cursor] != '\r' && m_sourceCode[m_cursor] != '\0') {
150150

151151
auto character = parseCharacter();
152152
if (!character.has_value()) {
@@ -170,7 +170,7 @@ namespace pl::core {
170170

171171
while (m_sourceCode[m_cursor] != '\"') {
172172
char c = peek(0);
173-
if (c == '\n') {
173+
if (c == '\n' || c == '\r') {
174174
m_errorLength = 1;
175175
error("Unexpected newline in string literal");
176176
m_line++;
@@ -311,7 +311,7 @@ namespace pl::core {
311311
m_cursor += 2;
312312

313313
std::string result;
314-
while(m_sourceCode[m_cursor] != '\n' && m_sourceCode[m_cursor] != '\0') {
314+
while(m_sourceCode[m_cursor] != '\n' && m_sourceCode[m_cursor] != '\r' && m_sourceCode[m_cursor] != '\0') {
315315
result += m_sourceCode[m_cursor];
316316
m_cursor++;
317317
}
@@ -329,7 +329,7 @@ namespace pl::core {
329329
m_cursor += 3;
330330

331331
std::string result;
332-
while(m_sourceCode[m_cursor] != '\n' && m_sourceCode[m_cursor] != '\0') {
332+
while(m_sourceCode[m_cursor] != '\n' && m_sourceCode[m_cursor] != '\r' && m_sourceCode[m_cursor] != '\0') {
333333
result += m_sourceCode[m_cursor];
334334
m_cursor++;
335335
}

0 commit comments

Comments
 (0)