Fixes for tests, support for comments.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-01-09 13:43:29 +01:00
parent 59af34fac9
commit 0fbca3f01e
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
7 changed files with 153 additions and 133 deletions

View File

@ -9,6 +9,7 @@ namespace MalachScript::Parser {
Unknown, Unknown,
EndOfFile, EndOfFile,
Whitespace, Whitespace,
Comment,
// Symbols // Symbols
StarSymbol, StarSymbol,
@ -265,6 +266,7 @@ namespace MalachScript::Parser {
case LexTokenKind::IntegerLiteral: return "integer"; case LexTokenKind::IntegerLiteral: return "integer";
case LexTokenKind::StringLiteral: return "string"; case LexTokenKind::StringLiteral: return "string";
case LexTokenKind::Identifier: return "identifier"; case LexTokenKind::Identifier: return "identifier";
case LexTokenKind::Comment: return "Comment";
} }
return "FAIL"; return "FAIL";
} }

View File

@ -57,6 +57,25 @@ namespace MalachScript::Parser {
// /= // /=
return Create<LexTokenImpl<LexTokenKind::SlashEqualsSymbol>>( return Create<LexTokenImpl<LexTokenKind::SlashEqualsSymbol>>(
ScriptTextSpan(start, start + 2, _scriptName)); ScriptTextSpan(start, start + 2, _scriptName));
} else if (Peek() == '/') {
Progress();
while (true) {
auto next = Consume();
if (next == '\n' || next == '\0') {
return Create<LexTokenImpl<LexTokenKind::Comment>>(
ScriptTextSpan(start, _position, _scriptName));
}
}
} else if (Peek() == '*') {
Progress();
while (true) {
auto next = Consume();
if ((next == '*' && Peek() == '/') || next == '\0') {
Progress();
return Create<LexTokenImpl<LexTokenKind::Comment>>(
ScriptTextSpan(start, _position, _scriptName));
}
}
} }
// / // /
return Create<LexTokenImpl<LexTokenKind::SlashSymbol>>(ScriptTextSpan(start, start + 1, _scriptName)); return Create<LexTokenImpl<LexTokenKind::SlashSymbol>>(ScriptTextSpan(start, start + 1, _scriptName));

View File

@ -5,7 +5,7 @@
#define PROGRESS_TOKEN(token) \ #define PROGRESS_TOKEN(token) \
token = (token)->GetNext().get(); \ token = (token)->GetNext().get(); \
while ((token)->GetKind() == LexTokenKind::Whitespace) { \ while ((token)->GetKind() == LexTokenKind::Whitespace || (token)->GetKind() == LexTokenKind::Comment) { \
(token) = (token)->GetNext().get(); \ (token) = (token)->GetNext().get(); \
} }
@ -57,7 +57,7 @@ namespace MalachScript::Parser {
size_t currentAmount = 0; size_t currentAmount = 0;
const auto* current = currentToken; const auto* current = currentToken;
while (true) { while (true) {
while (current->GetKind() == LexTokenKind::Whitespace) { while (current->GetKind() == LexTokenKind::Whitespace || current->GetKind() == LexTokenKind::Comment) {
current = current->GetNext().get(); current = current->GetNext().get();
} }
if (current->GetKind() == LexTokenKind::EndOfFile) { if (current->GetKind() == LexTokenKind::EndOfFile) {

View File

@ -13,7 +13,7 @@ using namespace MalachScript;
vec[i]->SetNext(vec[i + 1]); \ vec[i]->SetNext(vec[i + 1]); \
} \ } \
Diagnostics::Logger diags; \ Diagnostics::Logger diags; \
auto* script = Parser::Parser::Parse(vec.front(), "scriptname", &diags); \ auto* script = Parser::Parser::Parse(vec.front(), &diags); \
REQUIRE(diags.GetMessages().empty()); \ REQUIRE(diags.GetMessages().empty()); \
asserts; \ asserts; \
delete vec[0]; \ delete vec[0]; \
@ -21,6 +21,7 @@ using namespace MalachScript;
} }
#define PARSER_TEST_TOKENS(...) __VA_ARGS__ #define PARSER_TEST_TOKENS(...) __VA_ARGS__
#define TextSpan(a, b) ScriptTextSpan(a, b, "")
PARSER_TEST("Parse basic class without body", PARSER_TEST("Parse basic class without body",
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)), PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),

View File

@ -13,7 +13,7 @@ using namespace MalachScript;
vec[i]->SetNext(vec[i + 1]); \ vec[i]->SetNext(vec[i + 1]); \
} \ } \
Diagnostics::Logger diags; \ Diagnostics::Logger diags; \
auto* script = Parser::Parser::Parse(vec.front(), "scriptname", &diags); \ auto* script = Parser::Parser::Parse(vec.front(), &diags); \
REQUIRE(diags.GetMessages().empty()); \ REQUIRE(diags.GetMessages().empty()); \
asserts; \ asserts; \
delete vec[0]; \ delete vec[0]; \
@ -21,6 +21,7 @@ using namespace MalachScript;
} }
#define PARSER_TEST_TOKENS(...) __VA_ARGS__ #define PARSER_TEST_TOKENS(...) __VA_ARGS__
#define TextSpan(a, b) ScriptTextSpan(a, b, "")
PARSER_TEST("Parse ``void foobar();``", PARSER_TEST("Parse ``void foobar();``",
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::VoidKeyword>(TextSpan(0, 0)), PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::VoidKeyword>(TextSpan(0, 0)),

View File

@ -9,7 +9,7 @@ using namespace MalachScript;
Diagnostics::Logger diags; \ Diagnostics::Logger diags; \
auto lexer = Parser::Lexer(name, scriptText, &diags); \ auto lexer = Parser::Lexer(name, scriptText, &diags); \
auto token = lexer.Lex(); \ auto token = lexer.Lex(); \
auto script = Parser::Parser::Parse(token, name, &diags); \ auto script = Parser::Parser::Parse(token, &diags); \
asserts; \ asserts; \
delete script; \ delete script; \
} }

View File

@ -13,7 +13,7 @@ using namespace MalachScript;
vec[i]->SetNext(vec[i + 1]); \ vec[i]->SetNext(vec[i + 1]); \
} \ } \
Diagnostics::Logger diags; \ Diagnostics::Logger diags; \
auto* script = Parser::Parser::Parse(vec.front(), "scriptname", &diags); \ auto* script = Parser::Parser::Parse(vec.front(), &diags); \
REQUIRE(diags.GetMessages().empty()); \ REQUIRE(diags.GetMessages().empty()); \
asserts; \ asserts; \
delete vec[0]; \ delete vec[0]; \
@ -21,113 +21,111 @@ using namespace MalachScript;
} }
#define PARSER_TEST_TOKENS(...) __VA_ARGS__ #define PARSER_TEST_TOKENS(...) __VA_ARGS__
#define TextSpan(a, b) ScriptTextSpan(a, b, "")
PARSER_TEST( PARSER_TEST("Parse class foobar { bool foo { get; set; } }",
"Parse class foobar { bool foo { get; set; } }", PARSER_TEST_TOKENS(
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"), new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
new Parser::IdentifierToken(TextSpan(0, 0), "foo"), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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::SetKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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))), {
{ REQUIRE(script->GetStatements().size() == 1);
REQUIRE(script->GetStatements().size() == 1); auto firstStatement = script->GetStatements()[0].get();
auto firstStatement = script->GetStatements()[0].get(); REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class);
REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class); auto firstClassStatement =
auto firstClassStatement = dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[0].get();
dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[0].get(); REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp);
REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp); auto virtPropStatement =
auto virtPropStatement = dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement); REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public); REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo"); REQUIRE(virtPropStatement->HasGet());
REQUIRE(virtPropStatement->HasGet()); REQUIRE(virtPropStatement->HasSet());
REQUIRE(virtPropStatement->HasSet()); REQUIRE_FALSE(virtPropStatement->IsGetConst());
REQUIRE_FALSE(virtPropStatement->IsGetConst()); REQUIRE_FALSE(virtPropStatement->IsSetConst());
REQUIRE_FALSE(virtPropStatement->IsSetConst()); REQUIRE(virtPropStatement->GetGetStatement() == nullptr);
REQUIRE(virtPropStatement->GetGetStatement() == nullptr); REQUIRE(virtPropStatement->GetSetStatement() == nullptr);
REQUIRE(virtPropStatement->GetSetStatement() == nullptr); })
})
PARSER_TEST( PARSER_TEST("Parse class foobar { bool foo { get const; set const; } }",
"Parse class foobar { bool foo { get const; set const; } }", PARSER_TEST_TOKENS(
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"), new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
new Parser::IdentifierToken(TextSpan(0, 0), "foo"), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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::SetKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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))), {
{ REQUIRE(script->GetStatements().size() == 1);
REQUIRE(script->GetStatements().size() == 1); auto firstStatement = script->GetStatements()[0].get();
auto firstStatement = script->GetStatements()[0].get(); REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class);
REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class); auto firstClassStatement =
auto firstClassStatement = dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[0].get();
dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[0].get(); REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp);
REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp); auto virtPropStatement =
auto virtPropStatement = dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement); REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public); REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo"); REQUIRE(virtPropStatement->HasGet());
REQUIRE(virtPropStatement->HasGet()); REQUIRE(virtPropStatement->HasSet());
REQUIRE(virtPropStatement->HasSet()); REQUIRE(virtPropStatement->IsGetConst());
REQUIRE(virtPropStatement->IsGetConst()); REQUIRE(virtPropStatement->IsSetConst());
REQUIRE(virtPropStatement->IsSetConst()); REQUIRE(virtPropStatement->GetGetStatement() == nullptr);
REQUIRE(virtPropStatement->GetGetStatement() == nullptr); REQUIRE(virtPropStatement->GetSetStatement() == nullptr);
REQUIRE(virtPropStatement->GetSetStatement() == nullptr); })
})
PARSER_TEST( PARSER_TEST("Parse class foobar { bool foo { get const override; set const override; } }",
"Parse class foobar { bool foo { get const override; set const override; } }", PARSER_TEST_TOKENS(
PARSER_TEST_TOKENS(new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"), new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "bool"), new Parser::IdentifierToken(TextSpan(0, 0), "foo"),
new Parser::IdentifierToken(TextSpan(0, 0), "foo"), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::GetKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::OverrideKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::OverrideKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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::SetKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::ConstKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::OverrideKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::OverrideKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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))), {
{ REQUIRE(script->GetStatements().size() == 1);
REQUIRE(script->GetStatements().size() == 1); auto firstStatement = script->GetStatements()[0].get();
auto firstStatement = script->GetStatements()[0].get(); REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class);
REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class); auto firstClassStatement =
auto firstClassStatement = dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[0].get();
dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[0].get(); REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp);
REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp); auto virtPropStatement =
auto virtPropStatement = dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement); REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public); REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo"); REQUIRE(virtPropStatement->HasGet());
REQUIRE(virtPropStatement->HasGet()); REQUIRE(virtPropStatement->HasSet());
REQUIRE(virtPropStatement->HasSet()); REQUIRE(virtPropStatement->IsGetConst());
REQUIRE(virtPropStatement->IsGetConst()); REQUIRE(virtPropStatement->IsSetConst());
REQUIRE(virtPropStatement->IsSetConst()); REQUIRE(FuncAttrHelpers::Contains(virtPropStatement->GetGetFuncAttr(), FuncAttr::Override));
REQUIRE(FuncAttrHelpers::Contains(virtPropStatement->GetGetFuncAttr(), FuncAttr::Override)); REQUIRE(FuncAttrHelpers::Contains(virtPropStatement->GetSetFuncAttr(), FuncAttr::Override));
REQUIRE(FuncAttrHelpers::Contains(virtPropStatement->GetSetFuncAttr(), FuncAttr::Override)); REQUIRE(virtPropStatement->GetGetStatement() == nullptr);
REQUIRE(virtPropStatement->GetGetStatement() == nullptr); REQUIRE(virtPropStatement->GetSetStatement() == nullptr);
REQUIRE(virtPropStatement->GetSetStatement() == nullptr); })
})
/// class foobar { /// class foobar {
// int i; // int i;
@ -143,9 +141,8 @@ PARSER_TEST(
// } // }
//} //}
PARSER_TEST( PARSER_TEST("Virtprops with bodies",
"Virtprops with bodies", PARSER_TEST_TOKENS(
PARSER_TEST_TOKENS(
new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::ClassKeyword>(TextSpan(0, 0)),
new Parser::IdentifierToken(TextSpan(0, 0), "foobar"), new Parser::IdentifierToken(TextSpan(0, 0), "foobar"),
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)), new Parser::LexTokenImpl<Parser::LexTokenKind::OpenCurlyParenthesisSymbol>(TextSpan(0, 0)),
@ -164,8 +161,8 @@ PARSER_TEST(
new Parser::LexTokenImpl<Parser::LexTokenKind::TrueKeyword>(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::SemicolonSymbol>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::ReturnKeyword>(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::FalseKeyword>(TextSpan(0, 0)),
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(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::SetKeyword>(TextSpan(0, 0)),
@ -186,21 +183,21 @@ PARSER_TEST(
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); REQUIRE(script->GetStatements().size() == 1);
auto firstStatement = script->GetStatements()[0].get(); auto firstStatement = script->GetStatements()[0].get();
REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class); REQUIRE(firstStatement->GetKind() == Parser::ParsedStatementKind::Class);
auto firstClassStatement = auto firstClassStatement =
dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[1].get(); dynamic_cast<const MalachScript::Parser::ParsedClassStatement*>(firstStatement)->GetBody()[1].get();
REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp); REQUIRE(firstClassStatement->GetKind() == Parser::ParsedStatementKind::VirtProp);
auto virtPropStatement = auto virtPropStatement =
dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement); dynamic_cast<const MalachScript::Parser::ParsedVirtPropStatement*>(firstClassStatement);
REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public); REQUIRE(virtPropStatement->GetAccess() == MalachScript::AccessModifier::Public);
REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo"); REQUIRE(virtPropStatement->GetIdentifier().GetString() == "foo");
REQUIRE(virtPropStatement->HasGet()); REQUIRE(virtPropStatement->HasGet());
REQUIRE(virtPropStatement->HasSet()); REQUIRE(virtPropStatement->HasSet());
REQUIRE_FALSE(virtPropStatement->IsGetConst()); REQUIRE_FALSE(virtPropStatement->IsGetConst());
REQUIRE_FALSE(virtPropStatement->IsSetConst()); REQUIRE_FALSE(virtPropStatement->IsSetConst());
REQUIRE(virtPropStatement->GetGetStatement() != nullptr); REQUIRE(virtPropStatement->GetGetStatement() != nullptr);
REQUIRE(virtPropStatement->GetSetStatement() != nullptr); REQUIRE(virtPropStatement->GetSetStatement() != nullptr);
}) })