diff --git a/src/Parser/Lexer/Lexer.hpp b/src/Parser/Lexer/Lexer.hpp index b243b5d..ced8bbe 100644 --- a/src/Parser/Lexer/Lexer.hpp +++ b/src/Parser/Lexer/Lexer.hpp @@ -9,8 +9,6 @@ namespace MalachScript::Parser { class Lexer { public: - Lexer(const char* scriptName, const char* script, Diagnostics::Diagnostics* diag) - : Lexer(reinterpret_cast(scriptName), reinterpret_cast(script), diag) {} Lexer(const char8_t* scriptName, const char8_t* script, Diagnostics::Diagnostics* diag) : Lexer(std::u8string_view(scriptName), std::u8string_view(script), diag) {} Lexer(std::u8string_view scriptName, std::u8string_view script, Diagnostics::Diagnostics* diag) diff --git a/src/Parser/Parser.hpp b/src/Parser/Parser.hpp index 455d3c5..c879853 100644 --- a/src/Parser/Parser.hpp +++ b/src/Parser/Parser.hpp @@ -7,10 +7,6 @@ namespace MalachScript::Parser { class Parser { public: - Parser(const char* scriptName, const LexToken* firstToken, Diagnostics::Diagnostics* diagnostics) - : _scriptName(reinterpret_cast(scriptName)), _diagnostics(diagnostics), - _currentToken(firstToken) {} - Parser(std::u8string_view scriptName, const LexToken* firstToken, Diagnostics::Diagnostics* diagnostics) : _scriptName(scriptName), _diagnostics(diagnostics), _currentToken(firstToken) {} ParsedScriptStatement* Parse(); diff --git a/tests/LexerTests/IdentifierLexTests.cpp b/tests/LexerTests/IdentifierLexTests.cpp index e083d02..bf534bf 100644 --- a/tests/LexerTests/IdentifierLexTests.cpp +++ b/tests/LexerTests/IdentifierLexTests.cpp @@ -6,7 +6,7 @@ using namespace MalachScript::Parser; #define KEYWORD_TEST(script, symbol) \ TEST_CASE("Lex " script) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(script, script, &diag); \ + auto lexer = Lexer(u8##script, u8##script, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ CHECK(token->GetKind() == LexTokenKind::symbol); \ @@ -93,7 +93,7 @@ namespace doctest { #define IDENTIFIER_TEST(identifier) \ TEST_CASE("Lex identifier " identifier) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(identifier, identifier, &diag); \ + auto lexer = Lexer(u8##identifier, u8##identifier, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ REQUIRE(token->GetKind() == LexTokenKind::Identifier); \ diff --git a/tests/LexerTests/LexerIntegrationTests.cpp b/tests/LexerTests/LexerIntegrationTests.cpp index 347037f..747fa4e 100644 --- a/tests/LexerTests/LexerIntegrationTests.cpp +++ b/tests/LexerTests/LexerIntegrationTests.cpp @@ -6,7 +6,7 @@ using namespace MalachScript::Parser; #define LEX_TEST(script, ...) \ TEST_CASE("Lex: " script) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(script, script, &diag); \ + auto lexer = Lexer(u8##script, u8##script, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ std::vector vec = {__VA_ARGS__, LexTokenKind::EndOfFile}; \ diff --git a/tests/LexerTests/NumericalLexTests.cpp b/tests/LexerTests/NumericalLexTests.cpp index ad6025e..f2d2e62 100644 --- a/tests/LexerTests/NumericalLexTests.cpp +++ b/tests/LexerTests/NumericalLexTests.cpp @@ -6,7 +6,7 @@ using namespace MalachScript::Parser; #define INTEGER_TEST(script, expected) \ TEST_CASE("Lex " script) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(script, script, &diag); \ + auto lexer = Lexer(u8##script, u8##script, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ REQUIRE(token->GetKind() == LexTokenKind::IntegerLiteral); \ @@ -18,7 +18,7 @@ using namespace MalachScript::Parser; #define FLOAT_TEST(script, expected) \ TEST_CASE("Lex " script) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(script, script, &diag); \ + auto lexer = Lexer(u8##script, u8##script, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ REQUIRE(token->GetKind() == LexTokenKind::FloatLiteral); \ @@ -73,7 +73,7 @@ INTEGER_TEST("0B110011", 51); TEST_CASE("Lex invalid numerical base") { MalachScript::Diagnostics::Diagnostics diag; - auto lexer = Lexer("bad base", "0f553", &diag); + auto lexer = Lexer(u8"bad base", u8"0f553", &diag); lexer.Lex(); const auto& messages = diag.GetMessages(); REQUIRE(messages.size() == 1); diff --git a/tests/LexerTests/StringLexTests.cpp b/tests/LexerTests/StringLexTests.cpp index 15b0b94..84c1ef1 100644 --- a/tests/LexerTests/StringLexTests.cpp +++ b/tests/LexerTests/StringLexTests.cpp @@ -6,7 +6,7 @@ using namespace MalachScript::Parser; #define STRING_TEST(str, constraint) \ TEST_CASE("Lex string " constraint str constraint) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(str, constraint str constraint, &diag); \ + auto lexer = Lexer(u8##str, u8##constraint str constraint, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ REQUIRE(token->GetKind() == LexTokenKind::StringLiteral); \ @@ -23,7 +23,7 @@ STRING_TEST("\"\"foo bar\"\"", "\"\"\""); TEST_CASE("Lex multiline string") { MalachScript::Diagnostics::Diagnostics diag; - auto lexer = Lexer("multiline", R"("""foo + auto lexer = Lexer(u8"multiline", u8R"("""foo bar""")", &diag); const auto* token = lexer.Lex(); diff --git a/tests/LexerTests/SymbolLexTests.cpp b/tests/LexerTests/SymbolLexTests.cpp index 38770a3..2adfd3d 100644 --- a/tests/LexerTests/SymbolLexTests.cpp +++ b/tests/LexerTests/SymbolLexTests.cpp @@ -7,7 +7,7 @@ using namespace MalachScript::Parser; #define SYMBOL_TEST(script, symbol) \ TEST_CASE("Lex " script) { \ MalachScript::Diagnostics::Diagnostics diag; \ - auto lexer = Lexer(script, script, &diag); \ + auto lexer = Lexer(u8##script, u8##script, &diag); \ const auto* token = lexer.Lex(); \ CHECK(diag.GetMessages().empty()); \ CHECK(token->GetKind() == LexTokenKind::symbol); \ @@ -71,10 +71,10 @@ SYMBOL_TEST(" ", Whitespace) #undef SYMBOL_TEST TEST_CASE("Lex whitespace") { - auto whitespace = {" ", "\t", "\n", "\r", "\xef\xbb\xbf"}; + auto whitespace = {u8" ", u8"\t", u8"\n", u8"\r", u8"\xef\xbb\xbf"}; for (const auto* v : whitespace) { MalachScript::Diagnostics::Diagnostics diag; - auto lexer = Lexer("whitespace", v, &diag); + auto lexer = Lexer(u8"whitespace", v, &diag); const auto* token = lexer.Lex(); CHECK(diag.GetMessages().empty()); CHECK(token->GetKind() == LexTokenKind::Whitespace); diff --git a/tests/ParserTests/ParserIntegrationTests.cpp b/tests/ParserTests/ParserIntegrationTests.cpp index 22b6f12..4664364 100644 --- a/tests/ParserTests/ParserIntegrationTests.cpp +++ b/tests/ParserTests/ParserIntegrationTests.cpp @@ -7,9 +7,9 @@ using namespace MalachScript; #define PARSE_TEST(name, scriptText, asserts) \ TEST_CASE(name) { \ Diagnostics::Diagnostics diags; \ - auto lexer = Parser::Lexer(name, scriptText, &diags); \ + auto lexer = Parser::Lexer(u8##name, u8##scriptText, &diags); \ auto token = lexer.Lex(); \ - auto parser = Parser::Parser(name, token, &diags); \ + auto parser = Parser::Parser(u8##name, token, &diags); \ auto script = parser.Parse(); \ asserts; \ }