Revert "Fix parsing inner class declaration when "pass" keyword is on the same line"
This reverts commit 5bcc3d476c
.
This commit is contained in:
parent
ff77fe81d1
commit
02fa77eb30
|
@ -97,51 +97,8 @@ void GDScriptParser::_set_end_statement_error(String p_name) {
|
|||
}
|
||||
|
||||
bool GDScriptParser::_enter_indent_block(BlockNode *p_block) {
|
||||
if (!_parse_colon()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) {
|
||||
// Be more Python-like.
|
||||
IndentLevel current_level = indent_level.back()->get();
|
||||
indent_level.push_back(current_level);
|
||||
return true;
|
||||
}
|
||||
|
||||
return _parse_indent_block_newlines(p_block);
|
||||
}
|
||||
|
||||
bool GDScriptParser::_enter_inner_class_indent_block() {
|
||||
if (!_parse_colon()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) {
|
||||
// Check Python-like one-liner class declaration "class Foo: pass".
|
||||
// Note: only "pass" is allowed on the same line after the colon.
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_CF_PASS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GDScriptTokenizer::Token token = tokenizer->get_token(1);
|
||||
if (token != GDScriptTokenizer::TK_NEWLINE && token != GDScriptTokenizer::TK_EOF) {
|
||||
int line = tokenizer->get_token_line();
|
||||
int col = tokenizer->get_token_column();
|
||||
String message = "Invalid syntax: unexpected \"";
|
||||
message += GDScriptTokenizer::get_token_name(token);
|
||||
message += "\".";
|
||||
_set_error(message, line, col);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return _parse_indent_block_newlines();
|
||||
}
|
||||
|
||||
bool GDScriptParser::_parse_colon() {
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_COLON) {
|
||||
// Report location at the previous token (on the previous line).
|
||||
// report location at the previous token (on the previous line)
|
||||
int error_line = tokenizer->get_token_line(-1);
|
||||
int error_column = tokenizer->get_token_column(-1);
|
||||
_set_error("':' expected at end of line.", error_line, error_column);
|
||||
|
@ -153,12 +110,19 @@ bool GDScriptParser::_parse_colon() {
|
|||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) {
|
||||
// be more python-like
|
||||
IndentLevel current_level = indent_level.back()->get();
|
||||
indent_level.push_back(current_level);
|
||||
return true;
|
||||
//_set_error("newline expected after ':'.");
|
||||
//return false;
|
||||
}
|
||||
|
||||
bool GDScriptParser::_parse_indent_block_newlines(BlockNode *p_block) {
|
||||
while (true) {
|
||||
if (tokenizer->get_token(1) == GDScriptTokenizer::TK_EOF) {
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) {
|
||||
return false; //wtf
|
||||
} else if (tokenizer->get_token(1) == GDScriptTokenizer::TK_EOF) {
|
||||
return false;
|
||||
} else if (tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE) {
|
||||
int indent = tokenizer->get_token_line_indent();
|
||||
|
@ -177,13 +141,14 @@ bool GDScriptParser::_parse_indent_block_newlines(BlockNode *p_block) {
|
|||
indent_level.push_back(new_indent);
|
||||
tokenizer->advance();
|
||||
return true;
|
||||
|
||||
} else if (p_block) {
|
||||
NewLineNode *nl = alloc_node<NewLineNode>();
|
||||
nl->line = tokenizer->get_token_line();
|
||||
p_block->statements.push_back(nl);
|
||||
}
|
||||
|
||||
tokenizer->advance(); // Go to the next newline.
|
||||
tokenizer->advance(); // go to next newline
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3934,18 +3899,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!_enter_inner_class_indent_block()) {
|
||||
if (!error_set) {
|
||||
_set_error("Indented block or \"pass\" expected.");
|
||||
}
|
||||
if (!_enter_indent_block()) {
|
||||
_set_error("Indented block expected.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_CF_PASS) {
|
||||
current_class = newclass;
|
||||
_parse_class(newclass);
|
||||
current_class = p_class;
|
||||
}
|
||||
current_class = newclass;
|
||||
_parse_class(newclass);
|
||||
current_class = p_class;
|
||||
|
||||
} break;
|
||||
/* this is for functions....
|
||||
|
|
|
@ -599,9 +599,6 @@ private:
|
|||
|
||||
bool _parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete = false, bool p_parsing_constant = false);
|
||||
bool _enter_indent_block(BlockNode *p_block = nullptr);
|
||||
bool _enter_inner_class_indent_block();
|
||||
bool _parse_colon();
|
||||
bool _parse_indent_block_newlines(BlockNode *p_block = nullptr);
|
||||
bool _parse_newline();
|
||||
Node *_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign = false, bool p_parsing_constant = false);
|
||||
Node *_reduce_expression(Node *p_node, bool p_to_const = false);
|
||||
|
|
Loading…
Reference in New Issue