GDScript: Fix multiline and trailing comma for assert

This commit is contained in:
Dmitrii Maganov 2022-12-28 04:34:00 +02:00
parent b6e06038f8
commit 71f7c8a9d3
3 changed files with 33 additions and 2 deletions

View file

@ -1799,24 +1799,29 @@ GDScriptParser::AssertNode *GDScriptParser::parse_assert() {
// TODO: Add assert message.
AssertNode *assert = alloc_node<AssertNode>();
push_multiline(true);
consume(GDScriptTokenizer::Token::PARENTHESIS_OPEN, R"(Expected "(" after "assert".)");
assert->condition = parse_expression(false);
if (assert->condition == nullptr) {
push_error("Expected expression to assert.");
pop_multiline();
complete_extents(assert);
return nullptr;
}
if (match(GDScriptTokenizer::Token::COMMA)) {
// Error message.
if (match(GDScriptTokenizer::Token::COMMA) && !check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) {
assert->message = parse_expression(false);
if (assert->message == nullptr) {
push_error(R"(Expected error message for assert after ",".)");
pop_multiline();
complete_extents(assert);
return nullptr;
}
match(GDScriptTokenizer::Token::COMMA);
}
pop_multiline();
consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected ")" after assert expression.)*");
complete_extents(assert);

View file

@ -0,0 +1,24 @@
func test():
var x := 5
assert(x > 0)
assert(x > 0,)
assert(x > 0, 'message')
assert(x > 0, 'message',)
assert(
x > 0
)
assert(
x > 0,
)
assert(
x > 0,
'message'
)
assert(
x > 0,
'message',
)
print('OK')

View file

@ -0,0 +1,2 @@
GDTEST_OK
OK