diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 7debbec..e1a2e19 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -505,8 +505,8 @@ namespace chaiscript Dot_Access_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector t_children) : AST_Node(std::move(t_ast_node_text), AST_Node_Type::Dot_Access, std::move(t_loc), std::move(t_children)), m_fun_name( - ((children[2]->identifier == AST_Node_Type::Fun_Call) || (children[2]->identifier == AST_Node_Type::Array_Call))? - children[2]->children[0]->text:children[2]->text) { } + ((children[1]->identifier == AST_Node_Type::Fun_Call) || (children[1]->identifier == AST_Node_Type::Array_Call))? + children[1]->children[0]->text:children[1]->text) { } Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); @@ -516,9 +516,9 @@ namespace chaiscript std::vector params{retval}; bool has_function_params = false; - if (children[2]->children.size() > 1) { + if (children[1]->children.size() > 1) { has_function_params = true; - for (const auto &child : children[2]->children[1]->children) { + for (const auto &child : children[1]->children[1]->children) { params.push_back(child->eval(t_ss)); } } @@ -540,9 +540,9 @@ namespace chaiscript retval = std::move(rv.retval); } - if (this->children[2]->identifier == AST_Node_Type::Array_Call) { + if (this->children[1]->identifier == AST_Node_Type::Array_Call) { try { - retval = t_ss->call_function("[]", m_array_loc, {retval, this->children[2]->children[1]->eval(t_ss)}, t_ss.conversions()); + retval = t_ss->call_function("[]", m_array_loc, {retval, this->children[1]->children[1]->eval(t_ss)}, t_ss.conversions()); } catch(const exception::dispatch_error &e){ throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, e.functions, true, *t_ss); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 9b4370f..879ab60 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -2036,7 +2036,7 @@ namespace chaiscript func_call->children.insert(func_call->children.begin(), dot_access->children.back()); dot_access->children.pop_back(); dot_access->children.push_back(std::move(func_call)); - if (dot_access->children.size() != 3) throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); + if (dot_access->children.size() != 2) throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); m_match_stack.push_back(std::move(dot_access)); } } @@ -2049,13 +2049,13 @@ namespace chaiscript build_match(prev_stack_top); } - else if (Symbol(".", true)) { + else if (Symbol(".")) { has_more = true; if (!(Id())) { throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); } - if ( std::distance(m_match_stack.begin() + static_cast(prev_stack_top), m_match_stack.end()) != 3) { + if ( std::distance(m_match_stack.begin() + static_cast(prev_stack_top), m_match_stack.end()) != 2) { throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); } build_match(prev_stack_top); @@ -2221,61 +2221,59 @@ namespace chaiscript if (t_precedence < m_operators.size()) { if (Operator(t_precedence+1)) { retval = true; - if (Operator_Helper(t_precedence)) { - do { - while (Eol()) {} - if (!Operator(t_precedence+1)) { - throw exception::eval_error("Incomplete " - + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", - File_Position(m_position.line, m_position.col), *m_filename); - } + while (Operator_Helper(t_precedence)) { + while (Eol()) {} + if (!Operator(t_precedence+1)) { + throw exception::eval_error("Incomplete " + + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", + File_Position(m_position.line, m_position.col), *m_filename); + } - AST_NodePtr oper = m_match_stack.at(m_match_stack.size()-2); + AST_NodePtr oper = m_match_stack.at(m_match_stack.size()-2); - switch (m_operators[t_precedence]) { - case(AST_Node_Type::Ternary_Cond) : - m_match_stack.erase(advance_copy(m_match_stack.begin(), m_match_stack.size() - 2), - advance_copy(m_match_stack.begin(), m_match_stack.size() - 1)); - if (Symbol(":")) { - if (!Operator(t_precedence+1)) { - throw exception::eval_error("Incomplete " - + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", - File_Position(m_position.line, m_position.col), *m_filename); - } - build_match(prev_stack_top); - } - else { + switch (m_operators[t_precedence]) { + case(AST_Node_Type::Ternary_Cond) : + m_match_stack.erase(advance_copy(m_match_stack.begin(), m_match_stack.size() - 2), + advance_copy(m_match_stack.begin(), m_match_stack.size() - 1)); + if (Symbol(":")) { + if (!Operator(t_precedence+1)) { throw exception::eval_error("Incomplete " + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", File_Position(m_position.line, m_position.col), *m_filename); } - break; + build_match(prev_stack_top); + } + else { + throw exception::eval_error("Incomplete " + + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", + File_Position(m_position.line, m_position.col), *m_filename); + } + break; - case(AST_Node_Type::Addition) : - case(AST_Node_Type::Multiplication) : - case(AST_Node_Type::Shift) : - case(AST_Node_Type::Equality) : - case(AST_Node_Type::Bitwise_And) : - case(AST_Node_Type::Bitwise_Xor) : - case(AST_Node_Type::Bitwise_Or) : - case(AST_Node_Type::Comparison) : - assert(m_match_stack.size() > 1); - m_match_stack.erase(advance_copy(m_match_stack.begin(), m_match_stack.size() - 2), - advance_copy(m_match_stack.begin(), m_match_stack.size() - 1)); - build_match(prev_stack_top, oper->text); - break; + case(AST_Node_Type::Addition) : + case(AST_Node_Type::Multiplication) : + case(AST_Node_Type::Shift) : + case(AST_Node_Type::Equality) : + case(AST_Node_Type::Bitwise_And) : + case(AST_Node_Type::Bitwise_Xor) : + case(AST_Node_Type::Bitwise_Or) : + case(AST_Node_Type::Comparison) : + assert(m_match_stack.size() > 1); + m_match_stack.erase(advance_copy(m_match_stack.begin(), m_match_stack.size() - 2), + advance_copy(m_match_stack.begin(), m_match_stack.size() - 1)); + build_match(prev_stack_top, oper->text); + break; - case(AST_Node_Type::Logical_And) : - build_match(prev_stack_top); - break; - case(AST_Node_Type::Logical_Or) : - build_match(prev_stack_top); - break; + case(AST_Node_Type::Logical_And) : + build_match(prev_stack_top); + break; + case(AST_Node_Type::Logical_Or) : + build_match(prev_stack_top); + break; - default: - throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_position.line, m_position.col), *m_filename); - } - } while (Operator_Helper(t_precedence)); + default: + throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_position.line, m_position.col), *m_filename); + } } } }