mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Merge pull request #52905 from vnen/gdscript-single-line-declaration
This commit is contained in:
commit
b3b4860d2e
6 changed files with 63 additions and 8 deletions
|
@ -579,7 +579,7 @@ void GDScriptParser::parse_program() {
|
|||
}
|
||||
}
|
||||
|
||||
parse_class_body();
|
||||
parse_class_body(true);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
for (Map<int, GDScriptTokenizer::CommentData>::Element *E = tokenizer.get_comments().front(); E; E = E->next()) {
|
||||
|
@ -615,9 +615,10 @@ GDScriptParser::ClassNode *GDScriptParser::parse_class() {
|
|||
}
|
||||
|
||||
consume(GDScriptTokenizer::Token::COLON, R"(Expected ":" after class declaration.)");
|
||||
consume(GDScriptTokenizer::Token::NEWLINE, R"(Expected newline after class declaration.)");
|
||||
|
||||
if (!consume(GDScriptTokenizer::Token::INDENT, R"(Expected indented block after class declaration.)")) {
|
||||
bool multiline = match(GDScriptTokenizer::Token::NEWLINE);
|
||||
|
||||
if (multiline && !consume(GDScriptTokenizer::Token::INDENT, R"(Expected indented block after class declaration.)")) {
|
||||
current_class = previous_class;
|
||||
return n_class;
|
||||
}
|
||||
|
@ -630,9 +631,11 @@ GDScriptParser::ClassNode *GDScriptParser::parse_class() {
|
|||
end_statement("superclass");
|
||||
}
|
||||
|
||||
parse_class_body();
|
||||
parse_class_body(multiline);
|
||||
|
||||
consume(GDScriptTokenizer::Token::DEDENT, R"(Missing unindent at the end of the class body.)");
|
||||
if (multiline) {
|
||||
consume(GDScriptTokenizer::Token::DEDENT, R"(Missing unindent at the end of the class body.)");
|
||||
}
|
||||
|
||||
current_class = previous_class;
|
||||
return n_class;
|
||||
|
@ -747,7 +750,7 @@ void GDScriptParser::parse_class_member(T *(GDScriptParser::*p_parse_function)()
|
|||
}
|
||||
}
|
||||
|
||||
void GDScriptParser::parse_class_body() {
|
||||
void GDScriptParser::parse_class_body(bool p_is_multiline) {
|
||||
bool class_end = false;
|
||||
while (!class_end && !is_at_end()) {
|
||||
switch (current.type) {
|
||||
|
@ -793,6 +796,9 @@ void GDScriptParser::parse_class_body() {
|
|||
if (panic_mode) {
|
||||
synchronize();
|
||||
}
|
||||
if (!p_is_multiline) {
|
||||
class_end = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1361,6 +1367,9 @@ GDScriptParser::SuiteNode *GDScriptParser::parse_suite(const String &p_context,
|
|||
int error_count = 0;
|
||||
|
||||
do {
|
||||
if (!multiline && previous.type == GDScriptTokenizer::Token::SEMICOLON && check(GDScriptTokenizer::Token::NEWLINE)) {
|
||||
break;
|
||||
}
|
||||
Node *statement = parse_statement();
|
||||
if (statement == nullptr) {
|
||||
if (error_count++ > 100) {
|
||||
|
@ -1401,7 +1410,7 @@ GDScriptParser::SuiteNode *GDScriptParser::parse_suite(const String &p_context,
|
|||
break;
|
||||
}
|
||||
|
||||
} while (multiline && !check(GDScriptTokenizer::Token::DEDENT) && !lambda_ended && !is_at_end());
|
||||
} while ((multiline || previous.type == GDScriptTokenizer::Token::SEMICOLON) && !check(GDScriptTokenizer::Token::DEDENT) && !lambda_ended && !is_at_end());
|
||||
|
||||
if (multiline) {
|
||||
if (!lambda_ended) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue