Remove const char* constructors, only take u8 chars now.
This commit is contained in:
parent
2036f1ce43
commit
e99b1af78d
|
@ -9,8 +9,6 @@
|
||||||
namespace MalachScript::Parser {
|
namespace MalachScript::Parser {
|
||||||
class Lexer {
|
class Lexer {
|
||||||
public:
|
public:
|
||||||
Lexer(const char* scriptName, const char* script, Diagnostics::Diagnostics* diag)
|
|
||||||
: Lexer(reinterpret_cast<const char8_t*>(scriptName), reinterpret_cast<const char8_t*>(script), diag) {}
|
|
||||||
Lexer(const char8_t* scriptName, const char8_t* script, Diagnostics::Diagnostics* 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), diag) {}
|
||||||
Lexer(std::u8string_view scriptName, std::u8string_view script, Diagnostics::Diagnostics* diag)
|
Lexer(std::u8string_view scriptName, std::u8string_view script, Diagnostics::Diagnostics* diag)
|
||||||
|
|
|
@ -7,10 +7,6 @@
|
||||||
namespace MalachScript::Parser {
|
namespace MalachScript::Parser {
|
||||||
class Parser {
|
class Parser {
|
||||||
public:
|
public:
|
||||||
Parser(const char* scriptName, const LexToken* firstToken, Diagnostics::Diagnostics* diagnostics)
|
|
||||||
: _scriptName(reinterpret_cast<const char8_t*>(scriptName)), _diagnostics(diagnostics),
|
|
||||||
_currentToken(firstToken) {}
|
|
||||||
|
|
||||||
Parser(std::u8string_view scriptName, const LexToken* firstToken, Diagnostics::Diagnostics* diagnostics)
|
Parser(std::u8string_view scriptName, const LexToken* firstToken, Diagnostics::Diagnostics* diagnostics)
|
||||||
: _scriptName(scriptName), _diagnostics(diagnostics), _currentToken(firstToken) {}
|
: _scriptName(scriptName), _diagnostics(diagnostics), _currentToken(firstToken) {}
|
||||||
ParsedScriptStatement* Parse();
|
ParsedScriptStatement* Parse();
|
||||||
|
|
|
@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||||
#define KEYWORD_TEST(script, symbol) \
|
#define KEYWORD_TEST(script, symbol) \
|
||||||
TEST_CASE("Lex " script) { \
|
TEST_CASE("Lex " script) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
MalachScript::Diagnostics::Diagnostics diag; \
|
||||||
auto lexer = Lexer(script, script, &diag); \
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||||
const auto* token = lexer.Lex(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
||||||
|
@ -93,7 +93,7 @@ namespace doctest {
|
||||||
#define IDENTIFIER_TEST(identifier) \
|
#define IDENTIFIER_TEST(identifier) \
|
||||||
TEST_CASE("Lex identifier " identifier) { \
|
TEST_CASE("Lex identifier " identifier) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
MalachScript::Diagnostics::Diagnostics diag; \
|
||||||
auto lexer = Lexer(identifier, identifier, &diag); \
|
auto lexer = Lexer(u8##identifier, u8##identifier, &diag); \
|
||||||
const auto* token = lexer.Lex(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
REQUIRE(token->GetKind() == LexTokenKind::Identifier); \
|
REQUIRE(token->GetKind() == LexTokenKind::Identifier); \
|
||||||
|
|
|
@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||||
#define LEX_TEST(script, ...) \
|
#define LEX_TEST(script, ...) \
|
||||||
TEST_CASE("Lex: " script) { \
|
TEST_CASE("Lex: " script) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
MalachScript::Diagnostics::Diagnostics diag; \
|
||||||
auto lexer = Lexer(script, script, &diag); \
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||||
const auto* token = lexer.Lex(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
std::vector<LexTokenKind> vec = {__VA_ARGS__, LexTokenKind::EndOfFile}; \
|
std::vector<LexTokenKind> vec = {__VA_ARGS__, LexTokenKind::EndOfFile}; \
|
||||||
|
|
|
@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||||
#define INTEGER_TEST(script, expected) \
|
#define INTEGER_TEST(script, expected) \
|
||||||
TEST_CASE("Lex " script) { \
|
TEST_CASE("Lex " script) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
MalachScript::Diagnostics::Diagnostics diag; \
|
||||||
auto lexer = Lexer(script, script, &diag); \
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||||
const auto* token = lexer.Lex(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
REQUIRE(token->GetKind() == LexTokenKind::IntegerLiteral); \
|
REQUIRE(token->GetKind() == LexTokenKind::IntegerLiteral); \
|
||||||
|
@ -18,7 +18,7 @@ using namespace MalachScript::Parser;
|
||||||
#define FLOAT_TEST(script, expected) \
|
#define FLOAT_TEST(script, expected) \
|
||||||
TEST_CASE("Lex " script) { \
|
TEST_CASE("Lex " script) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
MalachScript::Diagnostics::Diagnostics diag; \
|
||||||
auto lexer = Lexer(script, script, &diag); \
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||||
const auto* token = lexer.Lex(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
REQUIRE(token->GetKind() == LexTokenKind::FloatLiteral); \
|
REQUIRE(token->GetKind() == LexTokenKind::FloatLiteral); \
|
||||||
|
@ -73,7 +73,7 @@ INTEGER_TEST("0B110011", 51);
|
||||||
|
|
||||||
TEST_CASE("Lex invalid numerical base") {
|
TEST_CASE("Lex invalid numerical base") {
|
||||||
MalachScript::Diagnostics::Diagnostics diag;
|
MalachScript::Diagnostics::Diagnostics diag;
|
||||||
auto lexer = Lexer("bad base", "0f553", &diag);
|
auto lexer = Lexer(u8"bad base", u8"0f553", &diag);
|
||||||
lexer.Lex();
|
lexer.Lex();
|
||||||
const auto& messages = diag.GetMessages();
|
const auto& messages = diag.GetMessages();
|
||||||
REQUIRE(messages.size() == 1);
|
REQUIRE(messages.size() == 1);
|
||||||
|
|
|
@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||||
#define STRING_TEST(str, constraint) \
|
#define STRING_TEST(str, constraint) \
|
||||||
TEST_CASE("Lex string " constraint str constraint) { \
|
TEST_CASE("Lex string " constraint str constraint) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
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(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
REQUIRE(token->GetKind() == LexTokenKind::StringLiteral); \
|
REQUIRE(token->GetKind() == LexTokenKind::StringLiteral); \
|
||||||
|
@ -23,7 +23,7 @@ STRING_TEST("\"\"foo bar\"\"", "\"\"\"");
|
||||||
|
|
||||||
TEST_CASE("Lex multiline string") {
|
TEST_CASE("Lex multiline string") {
|
||||||
MalachScript::Diagnostics::Diagnostics diag;
|
MalachScript::Diagnostics::Diagnostics diag;
|
||||||
auto lexer = Lexer("multiline", R"("""foo
|
auto lexer = Lexer(u8"multiline", u8R"("""foo
|
||||||
bar""")",
|
bar""")",
|
||||||
&diag);
|
&diag);
|
||||||
const auto* token = lexer.Lex();
|
const auto* token = lexer.Lex();
|
||||||
|
|
|
@ -7,7 +7,7 @@ using namespace MalachScript::Parser;
|
||||||
#define SYMBOL_TEST(script, symbol) \
|
#define SYMBOL_TEST(script, symbol) \
|
||||||
TEST_CASE("Lex " script) { \
|
TEST_CASE("Lex " script) { \
|
||||||
MalachScript::Diagnostics::Diagnostics diag; \
|
MalachScript::Diagnostics::Diagnostics diag; \
|
||||||
auto lexer = Lexer(script, script, &diag); \
|
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||||
const auto* token = lexer.Lex(); \
|
const auto* token = lexer.Lex(); \
|
||||||
CHECK(diag.GetMessages().empty()); \
|
CHECK(diag.GetMessages().empty()); \
|
||||||
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
||||||
|
@ -71,10 +71,10 @@ SYMBOL_TEST(" ", Whitespace)
|
||||||
#undef SYMBOL_TEST
|
#undef SYMBOL_TEST
|
||||||
|
|
||||||
TEST_CASE("Lex whitespace") {
|
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) {
|
for (const auto* v : whitespace) {
|
||||||
MalachScript::Diagnostics::Diagnostics diag;
|
MalachScript::Diagnostics::Diagnostics diag;
|
||||||
auto lexer = Lexer("whitespace", v, &diag);
|
auto lexer = Lexer(u8"whitespace", v, &diag);
|
||||||
const auto* token = lexer.Lex();
|
const auto* token = lexer.Lex();
|
||||||
CHECK(diag.GetMessages().empty());
|
CHECK(diag.GetMessages().empty());
|
||||||
CHECK(token->GetKind() == LexTokenKind::Whitespace);
|
CHECK(token->GetKind() == LexTokenKind::Whitespace);
|
||||||
|
|
|
@ -7,9 +7,9 @@ using namespace MalachScript;
|
||||||
#define PARSE_TEST(name, scriptText, asserts) \
|
#define PARSE_TEST(name, scriptText, asserts) \
|
||||||
TEST_CASE(name) { \
|
TEST_CASE(name) { \
|
||||||
Diagnostics::Diagnostics diags; \
|
Diagnostics::Diagnostics diags; \
|
||||||
auto lexer = Parser::Lexer(name, scriptText, &diags); \
|
auto lexer = Parser::Lexer(u8##name, u8##scriptText, &diags); \
|
||||||
auto token = lexer.Lex(); \
|
auto token = lexer.Lex(); \
|
||||||
auto parser = Parser::Parser(name, token, &diags); \
|
auto parser = Parser::Parser(u8##name, token, &diags); \
|
||||||
auto script = parser.Parse(); \
|
auto script = parser.Parse(); \
|
||||||
asserts; \
|
asserts; \
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue