From fd3618bd6e741c2bfdd4f65f4ace6f651cdff323 Mon Sep 17 00:00:00 2001 From: Justus Garbe Date: Sat, 4 Nov 2023 22:11:48 +0100 Subject: [PATCH] pipeline: small fixes --- lib/source/pl/core/lexer.cpp | 5 +++++ lib/source/pl/core/preprocessor.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/source/pl/core/lexer.cpp b/lib/source/pl/core/lexer.cpp index ad0a624d..34acd5b1 100644 --- a/lib/source/pl/core/lexer.cpp +++ b/lib/source/pl/core/lexer.cpp @@ -100,6 +100,11 @@ std::optional Lexer::parseStringLiteral() { m_cursor++; while(m_sourceCode[m_cursor] != '\"') { + if(peek() == '\n') { + error("Unexpected newline in string literal"); + return std::nullopt; + } + auto character = parseCharacter(); if(character.has_value()) { diff --git a/lib/source/pl/core/preprocessor.cpp b/lib/source/pl/core/preprocessor.cpp index 46c58302..5b4b31da 100644 --- a/lib/source/pl/core/preprocessor.cpp +++ b/lib/source/pl/core/preprocessor.cpp @@ -100,7 +100,7 @@ namespace pl::core { Location start = location(); u32 depth = 1; while(peek() != 0 && depth > 0) { - if(m_code.substr(m_offset, 6) == "#endif") { + if(m_code.substr(m_offset, 6) == "#endif" && !m_inString && m_startOfLine) { m_offset += 6; depth--; } @@ -356,7 +356,7 @@ namespace pl::core { if (this->m_pragmaHandlers.contains(type)) { if (!this->m_pragmaHandlers[type](runtimeRef, value)) - error_at(Location { m_source, 0, line }, + error_at(Location { m_source, line, 0 }, "Value '{}' cannot be used with the '{}' pragma directive.", value, type); } } @@ -388,7 +388,8 @@ namespace pl::core { } Location Preprocessor::location() { - return { m_source, m_lineNumber, (u32) (m_offset - m_lineBeginOffset) }; + u32 column = (u32) (m_offset - m_lineBeginOffset); + return { m_source, m_lineNumber, column }; } void Preprocessor::registerDirectiveHandler(const std::string& name, auto memberFunction) {