diff options
Diffstat (limited to 'modules/gdscript/gd_parser.cpp')
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 86b97e27a9..cd16fef6b3 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -76,7 +77,7 @@ bool GDParser::_enter_indent_block(BlockNode *p_block) { // be more python-like int current = tab_level.back()->get(); - tab_level.push_back(current + 1); + tab_level.push_back(current); return true; //_set_error("newline expected after ':'."); //return false; @@ -1021,7 +1022,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool OperatorNode::Operator op; bool valid = true; -//assign, if allowed is only alowed on the first operator +//assign, if allowed is only allowed on the first operator #define _VALIDATE_ASSIGN \ if (!p_allow_assign) { \ _set_error("Unexpected assign."); \ @@ -1253,7 +1254,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators after ternary if."); return NULL; @@ -1263,7 +1264,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators after ternary else."); return NULL; @@ -1300,7 +1301,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by an unary op in a valid combination, - // due to how precedence works, unaries will always dissapear first + // due to how precedence works, unaries will always disappear first _set_error("Unexpected two consecutive operators."); return NULL; @@ -2258,7 +2259,16 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { p_block->statements.push_back(nl); #endif + bool is_first_line = true; + while (true) { + if (!is_first_line && tab_level.back()->prev() && tab_level.back()->prev()->get() == indent_level) { + // pythonic single-line expression, don't parse future lines + tab_level.pop_back(); + p_block->end_line = tokenizer->get_token_line(); + return; + } + is_first_line = false; GDTokenizer::Token token = tokenizer->get_token(); if (error_set) @@ -2412,7 +2422,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'"); + _set_error("Expected indented block after 'if'"); p_block->end_line = tokenizer->get_token_line(); return; } @@ -2427,9 +2437,8 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { while (true) { - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { - tokenizer->advance(); - } + while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline()) + ; if (tab_level.back()->get() < indent_level) { //not at current indent level p_block->end_line = tokenizer->get_token_line(); |