Merge pull request #72979 from dalexeev/gds-annotation-parsing

GDScript: Fix and improve annotation parsing
This commit is contained in:
Yuri Sizov 2023-04-17 17:14:58 +02:00 committed by GitHub
commit 6596a6c1b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 17 deletions

View file

@ -1439,27 +1439,32 @@ GDScriptParser::AnnotationNode *GDScriptParser::parse_annotation(uint32_t p_vali
valid = false;
}
if (match(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) {
if (check(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) {
push_multiline(true);
advance();
// Arguments.
push_completion_call(annotation);
make_completion_context(COMPLETION_ANNOTATION_ARGUMENTS, annotation, 0, true);
if (!check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE) && !is_at_end()) {
push_multiline(true);
int argument_index = 0;
do {
make_completion_context(COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index, true);
set_last_completion_call_arg(argument_index++);
ExpressionNode *argument = parse_expression(false);
if (argument == nullptr) {
valid = false;
continue;
}
annotation->arguments.push_back(argument);
} while (match(GDScriptTokenizer::Token::COMMA));
pop_multiline();
int argument_index = 0;
do {
if (check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) {
// Allow for trailing comma.
break;
}
consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected ")" after annotation arguments.)*");
}
make_completion_context(COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index, true);
set_last_completion_call_arg(argument_index++);
ExpressionNode *argument = parse_expression(false);
if (argument == nullptr) {
push_error("Expected expression as the annotation argument.");
valid = false;
continue;
}
annotation->arguments.push_back(argument);
} while (match(GDScriptTokenizer::Token::COMMA) && !is_at_end());
pop_multiline();
consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected ")" after annotation arguments.)*");
pop_completion_call();
}
complete_extents(annotation);