From b37e6b7db8578aaba3af5a6c536527b397a38660 Mon Sep 17 00:00:00 2001 From: Rerumu Date: Sun, 7 Nov 2021 21:09:41 -0500 Subject: [PATCH] Move shebang skip to readFile --- Ast/src/Parser.cpp | 3 --- CLI/FileUtils.cpp | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index 47a910d2..ee84542d 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -160,9 +160,6 @@ ParseResult Parser::parse(const char* buffer, size_t bufferSize, AstNameTable& n { std::vector hotcomments; - if (p.lexer.current().type == '#' && p.lexer.lookahead().type == '!') - p.lexer.nextline(); - while (isComment(p.lexer.current()) || (FFlag::LuauCaptureBrokenCommentSpans && p.lexer.current().type == Lexeme::BrokenComment)) { const char* text = p.lexer.current().data; diff --git a/CLI/FileUtils.cpp b/CLI/FileUtils.cpp index 0702b74f..ae326f3e 100644 --- a/CLI/FileUtils.cpp +++ b/CLI/FileUtils.cpp @@ -67,6 +67,17 @@ std::optional readFile(const std::string& name) if (read != size_t(length)) return std::nullopt; + // Skip first line if it's a comment + if (length != 0 && result[0] == '#') + { + auto newLine = result.find('\n'); + + if (newLine != std::string::npos) + result.erase(0, newLine); + else + result.clear(); + } + return result; }