From 99736e63e45b323d06411926bd92210a08c717c2 Mon Sep 17 00:00:00 2001 From: reduz Date: Tue, 29 Dec 2015 11:41:37 -0300 Subject: [PATCH] -fixed bug with some indent blocks not properly checked, fixes #2570 -added ability to do one-line blocks, such as: if something: print("hello") , to be more python-like --- modules/gdscript/gd_parser.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 3da12fc38b7..f924f1de316 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -75,20 +75,28 @@ bool GDParser::_enter_indent_block(BlockNode* p_block) { if (tokenizer->get_token()!=GDTokenizer::TK_NEWLINE) { - _set_error("newline expected after ':'."); - return false; + // be more python-like + int current = tab_level.back()->get(); + tab_level.push_back(current+1); + return true; + //_set_error("newline expected after ':'."); + //return false; } while(true) { if (tokenizer->get_token()!=GDTokenizer::TK_NEWLINE) { + print_line("no newline"); return false; //wtf } else if (tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE) { int indent = tokenizer->get_token_line_indent(); int current = tab_level.back()->get(); - if (indent<=current) + if (indent<=current) { + print_line("current: "+itos(current)+" indent: "+itos(indent)); + print_line("less than current"); return false; + } tab_level.push_back(indent); tokenizer->advance(); @@ -1588,6 +1596,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { p_block->sub_blocks.push_back(cf_if->body); if (!_enter_indent_block(cf_if->body)) { + _set_error("Expected intended block after 'if'"); p_block->end_line=tokenizer->get_token_line(); return; } @@ -1647,6 +1656,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { if (!_enter_indent_block(cf_if->body)) { + _set_error("Expected indented block after 'elif'"); p_block->end_line=tokenizer->get_token_line(); return; } @@ -1661,7 +1671,6 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } else if (tokenizer->get_token()==GDTokenizer::TK_CF_ELSE) { if (tab_level.back()->get() > indent_level) { - _set_error("Invalid indent"); return; } @@ -1673,6 +1682,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { p_block->sub_blocks.push_back(cf_if->body_else); if (!_enter_indent_block(cf_if->body_else)) { + _set_error("Expected indented block after 'else'"); p_block->end_line=tokenizer->get_token_line(); return; } @@ -1713,6 +1723,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { p_block->sub_blocks.push_back(cf_while->body); if (!_enter_indent_block(cf_while->body)) { + _set_error("Expected indented block after 'while'"); p_block->end_line=tokenizer->get_token_line(); return; } @@ -1764,6 +1775,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { p_block->sub_blocks.push_back(cf_for->body); if (!_enter_indent_block(cf_for->body)) { + _set_error("Expected indented block after 'while'"); p_block->end_line=tokenizer->get_token_line(); return; }