Initial work on type registration in the binder.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||
#define KEYWORD_TEST(script, symbol) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
CHECK(token->GetKind() == LexTokenKind::symbol); \
|
||||
@@ -79,10 +79,8 @@ KEYWORD_TEST("while", WhileKeyword);
|
||||
KEYWORD_TEST("xor", XorKeyword);
|
||||
|
||||
namespace doctest {
|
||||
template <> struct StringMaker<std::u8string> {
|
||||
static String convert(const std::u8string& value) {
|
||||
return String(reinterpret_cast<const char*>(value.data()));
|
||||
}
|
||||
template <> struct StringMaker<std::string> {
|
||||
static String convert(const std::string& value) { return String(reinterpret_cast<const char*>(value.data())); }
|
||||
};
|
||||
template <> struct StringMaker<LexTokenKind> {
|
||||
static String convert(LexTokenKind value) { return String(std::to_string((uint32_t)value).c_str()); }
|
||||
@@ -93,12 +91,12 @@ namespace doctest {
|
||||
#define IDENTIFIER_TEST(identifier) \
|
||||
TEST_CASE("Lex identifier " identifier) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##identifier, u8##identifier, &diag); \
|
||||
auto lexer = Lexer(identifier, identifier, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::Identifier); \
|
||||
auto value = ((IdentifierToken*)token)->GetValue().GetString(); \
|
||||
CHECK(value == std::u8string(reinterpret_cast<const char8_t*>(identifier))); \
|
||||
CHECK(value == std::string(reinterpret_cast<const char*>(identifier))); \
|
||||
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile); \
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||
#define LEX_TEST(script, ...) \
|
||||
TEST_CASE("Lex: " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
std::vector<LexTokenKind> vec = {__VA_ARGS__, LexTokenKind::EndOfFile}; \
|
||||
|
||||
@@ -6,7 +6,7 @@ using namespace MalachScript::Parser;
|
||||
#define INTEGER_TEST(script, expected) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, 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::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, script, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::FloatLiteral); \
|
||||
|
||||
@@ -6,12 +6,12 @@ using namespace MalachScript::Parser;
|
||||
#define STRING_TEST(str, constraint) \
|
||||
TEST_CASE("Lex string " constraint str constraint) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##str, u8##constraint str constraint, &diag); \
|
||||
auto lexer = Lexer(str, constraint str constraint, &diag); \
|
||||
const auto* token = lexer.Lex(); \
|
||||
CHECK(diag.GetMessages().empty()); \
|
||||
REQUIRE(token->GetKind() == LexTokenKind::StringLiteral); \
|
||||
auto value = ((const StringLiteral*)token)->GetValue(); \
|
||||
CHECK(value == std::u8string(reinterpret_cast<const char8_t*>(str))); \
|
||||
CHECK(value == std::string(reinterpret_cast<const char*>(str))); \
|
||||
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile); \
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ STRING_TEST("\"\"foo bar\"\"", "\"\"\"");
|
||||
|
||||
TEST_CASE("Lex multiline string") {
|
||||
MalachScript::Diagnostics::Logger diag;
|
||||
auto lexer = Lexer(u8"multiline", u8R"("""foo
|
||||
auto lexer = Lexer("multiline", R"("""foo
|
||||
bar""")",
|
||||
&diag);
|
||||
const auto* token = lexer.Lex();
|
||||
CHECK(diag.GetMessages().empty());
|
||||
REQUIRE(token->GetKind() == LexTokenKind::StringLiteral);
|
||||
auto value = (dynamic_cast<const StringLiteral*>(token))->GetValue();
|
||||
CHECK(value == std::u8string(reinterpret_cast<const char8_t*>(R"(foo
|
||||
CHECK(value == std::string(reinterpret_cast<const char*>(R"(foo
|
||||
bar)")));
|
||||
CHECK(token->GetNext()->GetKind() == LexTokenKind::EndOfFile);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using namespace MalachScript::Parser;
|
||||
#define SYMBOL_TEST(script, symbol) \
|
||||
TEST_CASE("Lex " script) { \
|
||||
MalachScript::Diagnostics::Logger diag; \
|
||||
auto lexer = Lexer(u8##script, u8##script, &diag); \
|
||||
auto lexer = Lexer(script, 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 = {u8" ", u8"\t", u8"\n", u8"\r", u8"\xef\xbb\xbf"};
|
||||
auto whitespace = {" ", "\t", "\n", "\r", "\xef\xbb\xbf"};
|
||||
for (const auto* v : whitespace) {
|
||||
MalachScript::Diagnostics::Logger diag;
|
||||
auto lexer = Lexer(u8"whitespace", v, &diag);
|
||||
auto lexer = Lexer("whitespace", v, &diag);
|
||||
const auto* token = lexer.Lex();
|
||||
CHECK(diag.GetMessages().empty());
|
||||
CHECK(token->GetKind() == LexTokenKind::Whitespace);
|
||||
|
||||
@@ -13,7 +13,7 @@ using namespace MalachScript;
|
||||
vec[i]->SetNext(vec[i + 1]); \
|
||||
} \
|
||||
Diagnostics::Logger diags; \
|
||||
auto* script = Parser::Parser::Parse(vec.front(), u8"scriptname", &diags); \
|
||||
auto* script = Parser::Parser::Parse(vec.front(), "scriptname", &diags); \
|
||||
REQUIRE(diags.GetMessages().empty()); \
|
||||
asserts; \
|
||||
delete vec[0]; \
|
||||
@@ -24,7 +24,7 @@ using namespace MalachScript;
|
||||
|
||||
PARSER_TEST("Parse basic class without body",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||
{
|
||||
REQUIRE(script->GetStatements().size() == 1);
|
||||
@@ -34,7 +34,7 @@ PARSER_TEST("Parse basic class without body",
|
||||
PARSER_TEST("Parse basic class without body with whitespaces",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||
{
|
||||
@@ -45,7 +45,7 @@ PARSER_TEST("Parse basic class without body with whitespaces",
|
||||
PARSER_TEST(
|
||||
"Parse basic class with empty body",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0))),
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ using namespace MalachScript;
|
||||
vec[i]->SetNext(vec[i + 1]); \
|
||||
} \
|
||||
Diagnostics::Logger diags; \
|
||||
auto* script = Parser::Parser::Parse(vec.front(), u8"scriptname", &diags); \
|
||||
auto* script = Parser::Parser::Parse(vec.front(), "scriptname", &diags); \
|
||||
REQUIRE(diags.GetMessages().empty()); \
|
||||
asserts; \
|
||||
delete vec[0]; \
|
||||
@@ -25,7 +25,7 @@ using namespace MalachScript;
|
||||
PARSER_TEST("Parse ``void foobar();``",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::VoidKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||
@@ -41,9 +41,9 @@ PARSER_TEST("Parse ``void foobar();``",
|
||||
CHECK_FALSE(type->IsArray());
|
||||
CHECK_FALSE(type->IsHandle());
|
||||
auto& id = type->GetScopedIdentifier();
|
||||
CHECK(id.GetIdentifier().GetString() == u8"void");
|
||||
CHECK(id.GetIdentifier().GetString() == "void");
|
||||
CHECK_FALSE(funcStat->ReturnsReference());
|
||||
CHECK(funcStat->GetIdentifier().GetString() == u8"foobar");
|
||||
CHECK(funcStat->GetIdentifier().GetString() == "foobar");
|
||||
auto paramList = (const MalachScript::Parser::ParsedParamListStatement*)funcStat->GetParamList().get();
|
||||
CHECK(paramList->GetParameters().empty());
|
||||
CHECK_FALSE(funcStat->IsConst());
|
||||
@@ -52,13 +52,13 @@ PARSER_TEST("Parse ``void foobar();``",
|
||||
})
|
||||
|
||||
PARSER_TEST("Parse scoped function without body.",
|
||||
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"baz"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "baz"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||
@@ -74,11 +74,11 @@ PARSER_TEST("Parse scoped function without body.",
|
||||
CHECK_FALSE(type->IsArray());
|
||||
CHECK_FALSE(type->IsHandle());
|
||||
auto& id = type->GetScopedIdentifier();
|
||||
CHECK(id.GetIdentifier().GetString() == u8"baz");
|
||||
CHECK(id.GetScope()[1].GetString() == u8"bar");
|
||||
CHECK(id.GetScope()[0].GetString() == u8"foo");
|
||||
CHECK(id.GetIdentifier().GetString() == "baz");
|
||||
CHECK(id.GetScope()[1].GetString() == "bar");
|
||||
CHECK(id.GetScope()[0].GetString() == "foo");
|
||||
CHECK_FALSE(funcStat->ReturnsReference());
|
||||
CHECK(funcStat->GetIdentifier().GetString() == u8"foobar");
|
||||
CHECK(funcStat->GetIdentifier().GetString() == "foobar");
|
||||
auto paramList = (const MalachScript::Parser::ParsedParamListStatement*)funcStat->GetParamList().get();
|
||||
CHECK(paramList->GetParameters().empty());
|
||||
CHECK_FALSE(funcStat->IsConst());
|
||||
@@ -87,24 +87,24 @@ PARSER_TEST("Parse scoped function without body.",
|
||||
})
|
||||
|
||||
PARSER_TEST("Parse scoped function with parameters without body.",
|
||||
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"baz"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "baz"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::IntKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"par1"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "par1"),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CommaSymbol>(TextSpan(0, 0)),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::BoolKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"par2"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "par2"),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||
@@ -120,11 +120,11 @@ PARSER_TEST("Parse scoped function with parameters without body.",
|
||||
CHECK_FALSE(type->IsArray());
|
||||
CHECK_FALSE(type->IsHandle());
|
||||
auto& id = type->GetScopedIdentifier();
|
||||
CHECK(id.GetIdentifier().GetString() == u8"baz");
|
||||
CHECK(id.GetScope()[1].GetString() == u8"bar");
|
||||
CHECK(id.GetScope()[0].GetString() == u8"foo");
|
||||
CHECK(id.GetIdentifier().GetString() == "baz");
|
||||
CHECK(id.GetScope()[1].GetString() == "bar");
|
||||
CHECK(id.GetScope()[0].GetString() == "foo");
|
||||
CHECK_FALSE(funcStat->ReturnsReference());
|
||||
CHECK(funcStat->GetIdentifier().GetString() == u8"foobar");
|
||||
CHECK(funcStat->GetIdentifier().GetString() == "foobar");
|
||||
auto paramList = (const MalachScript::Parser::ParsedParamListStatement*)funcStat->GetParamList().get();
|
||||
CHECK(paramList->GetParameters().size() == 2);
|
||||
|
||||
@@ -133,9 +133,9 @@ PARSER_TEST("Parse scoped function with parameters without body.",
|
||||
CHECK_FALSE(par1.GetTypeStatement()->IsArray());
|
||||
CHECK_FALSE(par1.GetTypeStatement()->IsHandle());
|
||||
auto& par1TypeId = par1.GetTypeStatement()->GetScopedIdentifier();
|
||||
CHECK(par1TypeId.GetIdentifier().GetString() == u8"int");
|
||||
CHECK(par1TypeId.GetIdentifier().GetString() == "int");
|
||||
CHECK(par1.GetTypeMod() == TypeMod::None);
|
||||
CHECK(par1.GetIdentifier().GetString() == u8"par1");
|
||||
CHECK(par1.GetIdentifier().GetString() == "par1");
|
||||
CHECK(par1.GetDefaultExpression() == nullptr);
|
||||
|
||||
auto& par2 = *paramList->GetParameters()[1];
|
||||
@@ -143,9 +143,9 @@ PARSER_TEST("Parse scoped function with parameters without body.",
|
||||
CHECK_FALSE(par2.GetTypeStatement()->IsArray());
|
||||
CHECK_FALSE(par2.GetTypeStatement()->IsHandle());
|
||||
auto& par2TypeId = par2.GetTypeStatement()->GetScopedIdentifier();
|
||||
CHECK(par2TypeId.GetIdentifier().GetString() == u8"bool");
|
||||
CHECK(par2TypeId.GetIdentifier().GetString() == "bool");
|
||||
CHECK(par2.GetTypeMod() == TypeMod::None);
|
||||
CHECK(par2.GetIdentifier().GetString() == u8"par2");
|
||||
CHECK(par2.GetIdentifier().GetString() == "par2");
|
||||
CHECK(par2.GetDefaultExpression() == nullptr);
|
||||
|
||||
CHECK_FALSE(funcStat->IsConst());
|
||||
@@ -154,20 +154,20 @@ PARSER_TEST("Parse scoped function with parameters without body.",
|
||||
})
|
||||
|
||||
PARSER_TEST("Parse scoped function with reference parameters without body.",
|
||||
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"baz"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "baz"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::IntKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::AmpersandSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::InKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"par1"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "par1"),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CommaSymbol>(TextSpan(0, 0)),
|
||||
|
||||
@@ -175,7 +175,7 @@ PARSER_TEST("Parse scoped function with reference parameters without body.",
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::AmpersandSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OutKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"par2"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "par2"),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||
@@ -191,11 +191,11 @@ PARSER_TEST("Parse scoped function with reference parameters without body.",
|
||||
CHECK_FALSE(type->IsArray());
|
||||
CHECK_FALSE(type->IsHandle());
|
||||
auto& id = type->GetScopedIdentifier();
|
||||
CHECK(id.GetIdentifier().GetString() == u8"baz");
|
||||
CHECK(id.GetScope()[1].GetString() == u8"bar");
|
||||
CHECK(id.GetScope()[0].GetString() == u8"foo");
|
||||
CHECK(id.GetIdentifier().GetString() == "baz");
|
||||
CHECK(id.GetScope()[1].GetString() == "bar");
|
||||
CHECK(id.GetScope()[0].GetString() == "foo");
|
||||
CHECK_FALSE(funcStat->ReturnsReference());
|
||||
CHECK(funcStat->GetIdentifier().GetString() == u8"foobar");
|
||||
CHECK(funcStat->GetIdentifier().GetString() == "foobar");
|
||||
auto paramList = (const MalachScript::Parser::ParsedParamListStatement*)funcStat->GetParamList().get();
|
||||
CHECK(paramList->GetParameters().size() == 2);
|
||||
|
||||
@@ -204,9 +204,9 @@ PARSER_TEST("Parse scoped function with reference parameters without body.",
|
||||
CHECK_FALSE(par1.GetTypeStatement()->IsArray());
|
||||
CHECK_FALSE(par1.GetTypeStatement()->IsHandle());
|
||||
auto& par1TypeId = par1.GetTypeStatement()->GetScopedIdentifier();
|
||||
CHECK(par1TypeId.GetIdentifier().GetString() == u8"int");
|
||||
CHECK(par1TypeId.GetIdentifier().GetString() == "int");
|
||||
CHECK(par1.GetTypeMod() == TypeMod::RefIn);
|
||||
CHECK(par1.GetIdentifier().GetString() == u8"par1");
|
||||
CHECK(par1.GetIdentifier().GetString() == "par1");
|
||||
CHECK(par1.GetDefaultExpression() == nullptr);
|
||||
|
||||
auto& par2 = *paramList->GetParameters()[1];
|
||||
@@ -214,9 +214,9 @@ PARSER_TEST("Parse scoped function with reference parameters without body.",
|
||||
CHECK_FALSE(par2.GetTypeStatement()->IsArray());
|
||||
CHECK_FALSE(par2.GetTypeStatement()->IsHandle());
|
||||
auto& par2TypeId = par2.GetTypeStatement()->GetScopedIdentifier();
|
||||
CHECK(par2TypeId.GetIdentifier().GetString() == u8"bool");
|
||||
CHECK(par2TypeId.GetIdentifier().GetString() == "bool");
|
||||
CHECK(par2.GetTypeMod() == TypeMod::RefOut);
|
||||
CHECK(par2.GetIdentifier().GetString() == u8"par2");
|
||||
CHECK(par2.GetIdentifier().GetString() == "par2");
|
||||
CHECK(par2.GetDefaultExpression() == nullptr);
|
||||
|
||||
CHECK_FALSE(funcStat->IsConst());
|
||||
|
||||
@@ -7,9 +7,9 @@ using namespace MalachScript;
|
||||
#define PARSE_TEST(name, scriptText, asserts) \
|
||||
TEST_CASE(name) { \
|
||||
Diagnostics::Logger diags; \
|
||||
auto lexer = Parser::Lexer(u8##name, u8##scriptText, &diags); \
|
||||
auto lexer = Parser::Lexer(name, scriptText, &diags); \
|
||||
auto token = lexer.Lex(); \
|
||||
auto script = Parser::Parser::Parse(token, u8##name, &diags); \
|
||||
auto script = Parser::Parser::Parse(token, name, &diags); \
|
||||
asserts; \
|
||||
delete script; \
|
||||
}
|
||||
@@ -42,7 +42,7 @@ PARSE_TEST("Parse class with virtprop", "class foobar { private bool foo { get;
|
||||
REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp);
|
||||
auto virtPropStatement = dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
|
||||
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Private);
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == u8"foo");
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
|
||||
REQUIRE(virtPropStatement->HasGet());
|
||||
REQUIRE(virtPropStatement->HasSet());
|
||||
REQUIRE(virtPropStatement->GetGetStatement() == nullptr);
|
||||
|
||||
@@ -13,7 +13,7 @@ using namespace MalachScript;
|
||||
vec[i]->SetNext(vec[i + 1]); \
|
||||
} \
|
||||
Diagnostics::Logger diags; \
|
||||
auto* script = Parser::Parser::Parse(vec.front(), u8"scriptname", &diags); \
|
||||
auto* script = Parser::Parser::Parse(vec.front(), "scriptname", &diags); \
|
||||
REQUIRE(diags.GetMessages().empty()); \
|
||||
asserts; \
|
||||
delete vec[0]; \
|
||||
@@ -25,10 +25,10 @@ using namespace MalachScript;
|
||||
PARSER_TEST(
|
||||
"Parse class foobar { bool foo { get; set; } }",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
@@ -46,7 +46,7 @@ PARSER_TEST(
|
||||
auto virtPropStatement =
|
||||
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
|
||||
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == u8"foo");
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
|
||||
REQUIRE(virtPropStatement->HasGet());
|
||||
REQUIRE(virtPropStatement->HasSet());
|
||||
REQUIRE_FALSE(virtPropStatement->IsGetConst());
|
||||
@@ -58,10 +58,10 @@ PARSER_TEST(
|
||||
PARSER_TEST(
|
||||
"Parse class foobar { bool foo { get const; set const; } }",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)),
|
||||
@@ -81,7 +81,7 @@ PARSER_TEST(
|
||||
auto virtPropStatement =
|
||||
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
|
||||
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == u8"foo");
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
|
||||
REQUIRE(virtPropStatement->HasGet());
|
||||
REQUIRE(virtPropStatement->HasSet());
|
||||
REQUIRE(virtPropStatement->IsGetConst());
|
||||
@@ -93,10 +93,10 @@ PARSER_TEST(
|
||||
PARSER_TEST(
|
||||
"Parse class foobar { bool foo { get const override; set const override; } }",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)),
|
||||
@@ -118,7 +118,7 @@ PARSER_TEST(
|
||||
auto virtPropStatement =
|
||||
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
|
||||
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == u8"foo");
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
|
||||
REQUIRE(virtPropStatement->HasGet());
|
||||
REQUIRE(virtPropStatement->HasSet());
|
||||
REQUIRE(virtPropStatement->IsGetConst());
|
||||
@@ -145,48 +145,47 @@ PARSER_TEST(
|
||||
|
||||
PARSER_TEST(
|
||||
"Virtprops with bodies",
|
||||
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"int"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"i"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
PARSER_TEST_TOKENS(
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "int"), new Parser::IdentifierToken(TextSpan(0, 0), "i"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"bool"),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::IfKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::TrueKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ReturnKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::TrueKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ReturnKeyword>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::IfKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::TrueKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ReturnKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::TrueKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::ReturnKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::FalseKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::IfKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IntegerLiteral(TextSpan(0, 0), 1),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::EqualsEqualsSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IntegerLiteral(TextSpan(0, 0), 1),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"i"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::PlusPlusSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), u8"i"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::MinusMinusSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SetKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::IfKeyword>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IntegerLiteral(TextSpan(0, 0), 1),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::EqualsEqualsSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IntegerLiteral(TextSpan(0, 0), 1),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "i"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::PlusPlusSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
new Parser::IdentifierToken(TextSpan(0, 0), "i"),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::MinusMinusSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0)),
|
||||
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0))),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0)),
|
||||
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseCurlyParenthesisSymbol>(TextSpan(0, 0))),
|
||||
{
|
||||
REQUIRE(script->GetStatements().size() == 1);
|
||||
auto firstStatement = script->GetStatements()[0].get();
|
||||
@@ -197,7 +196,7 @@ PARSER_TEST(
|
||||
auto virtPropStatement =
|
||||
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
|
||||
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == u8"foo");
|
||||
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
|
||||
REQUIRE(virtPropStatement->HasGet());
|
||||
REQUIRE(virtPropStatement->HasSet());
|
||||
REQUIRE_FALSE(virtPropStatement->IsGetConst());
|
||||
|
||||
Reference in New Issue
Block a user