소스 검색

Merge pull request #94386 from lawnjelly/revert_inner_parse

[3.x] Revert "Fix parsing inner class declaration"
Rémi Verschelde 1 년 전
부모
커밋
9bbed7bb3c
2개의 변경된 파일19개의 추가작업 그리고 62개의 파일을 삭제
  1. 19 59
      modules/gdscript/gdscript_parser.cpp
  2. 0 3
      modules/gdscript/gdscript_parser.h

+ 19 - 59
modules/gdscript/gdscript_parser.cpp

@@ -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....

+ 0 - 3
modules/gdscript/gdscript_parser.h

@@ -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);