GDScript: Allow empty parentheses for property getter declaration

This commit is contained in:
Danil Alexeev 2023-10-10 21:19:15 +03:00
parent c5291a3555
commit 668ba2d1a5
No known key found for this signature in database
GPG key ID: 124453E157DA8DC7
3 changed files with 13 additions and 3 deletions

View file

@ -1116,7 +1116,12 @@ void GDScriptParser::parse_property_getter(VariableNode *p_variable) {
case VariableNode::PROP_INLINE: {
FunctionNode *function = alloc_node<FunctionNode>();
consume(GDScriptTokenizer::Token::COLON, R"(Expected ":" after "get".)");
if (match(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) {
consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected ")" after "get(".)*");
consume(GDScriptTokenizer::Token::COLON, R"*(Expected ":" after "get()".)*");
} else {
consume(GDScriptTokenizer::Token::COLON, R"(Expected ":" or "(" after "get".)");
}
IdentifierNode *identifier = alloc_node<IdentifierNode>();
complete_extents(identifier);
@ -1264,8 +1269,7 @@ GDScriptParser::EnumNode *GDScriptParser::parse_enum(bool p_is_static) {
EnumNode *enum_node = alloc_node<EnumNode>();
bool named = false;
if (check(GDScriptTokenizer::Token::IDENTIFIER)) {
advance();
if (match(GDScriptTokenizer::Token::IDENTIFIER)) {
enum_node->identifier = parse_identifier();
named = true;
}

View file

@ -6,6 +6,9 @@ var property:
set(value):
_backing = value - 1000
var property_2:
get(): # Allow parentheses.
return 123
func test():
print("Not using self:")
@ -35,3 +38,5 @@ func test():
self.property = 5000
print(self.property)
print(self._backing)
print(property_2)

View file

@ -17,3 +17,4 @@ Using self:
-50
5000
4000
123