diff options
Diffstat (limited to 'modules/gdscript/gd_parser.cpp')
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 95e172e26e..c4175e048d 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -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(); @@ -259,6 +267,13 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ constant->value=tokenizer->get_token_constant(); tokenizer->advance(); expr=constant; + } else if (tokenizer->get_token()==GDTokenizer::TK_CONST_PI) { + + //constant defined by tokenizer + ConstantNode *constant = alloc_node<ConstantNode>(); + constant->value=Math_PI; + tokenizer->advance(); + expr=constant; } else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) { //constant defined by tokenizer @@ -1588,6 +1603,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 +1663,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 +1678,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 +1689,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 +1730,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 +1782,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; } @@ -1850,6 +1869,17 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { return; } } break; + case GDTokenizer::TK_PR_BREAKPOINT: { + + tokenizer->advance(); + BreakpointNode *bn = alloc_node<BreakpointNode>(); + p_block->statements.push_back(bn); + + if (!_end_statement()) { + _set_error("Expected end of statement after breakpoint."); + return; + } + } break; default: { Node *expression = _parse_and_reduce_expression(p_block,p_static,false,true); @@ -2058,6 +2088,8 @@ void GDParser::_parse_class(ClassNode *p_class) { ClassNode *newclass = alloc_node<ClassNode>(); newclass->initializer = alloc_node<BlockNode>(); newclass->initializer->parent_class=newclass; + newclass->ready = alloc_node<BlockNode>(); + newclass->ready->parent_class=newclass; newclass->name=name; newclass->owner=p_class; @@ -2769,12 +2801,8 @@ void GDParser::_parse_class(ClassNode *p_class) { }; //fallthrough to var case GDTokenizer::TK_PR_ONREADY: { - if (tokenizer->get_token(-1)==GDTokenizer::TK_PR_EXPORT) { - current_export=PropertyInfo(); - _set_error("Expected 'var' (can't combine with 'onready')."); - return; - } else { - + if (token==GDTokenizer::TK_PR_ONREADY) { + //may be fallthrough from export, ignore if so tokenizer->advance(); if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR) { _set_error("Expected 'var'."); |