diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 38cf8e65..7d0a6df8 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -32,7 +32,7 @@ namespace chaiscript /// Types of AST nodes available to the parser and eval - enum class AST_Node_Type { Error, Id, Char, Str, Eol, Fun_Call, Arg_List, Variable, Equation, Var_Decl, + enum class AST_Node_Type { Error, Id, Str, Eol, Fun_Call, Arg_List, Variable, Equation, Var_Decl, Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Continue, Map_Pair, Value_Range, Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or, @@ -44,7 +44,7 @@ namespace chaiscript /// Helper lookup to get the name of each node type const char *ast_node_type_to_string(AST_Node_Type ast_node_type) { - static const char * const ast_node_types[] = { "Internal Parser Error", "Id", "Char", "Str", "Eol", "Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl", + static const char * const ast_node_types[] = { "Internal Parser Error", "Id", "Str", "Eol", "Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl", "Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range", "Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or", diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index bb4fa3c8..63e4e859 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -165,10 +165,6 @@ namespace chaiscript mutable std::atomic_uint_fast32_t m_loc; }; - struct Char_AST_Node final : AST_Node { - Char_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : - AST_Node(std::move(t_ast_node_text), AST_Node_Type::Char, std::move(t_loc)) { } - }; struct Str_AST_Node final : AST_Node { Str_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : @@ -989,11 +985,11 @@ namespace chaiscript struct Prefix_AST_Node final : AST_Node { Prefix_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::Prefix, std::move(t_loc), std::move(t_children)), - m_oper(Operators::to_operator(children[0]->text, true)) + m_oper(Operators::to_operator(text, true)) { } Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ - Boxed_Value bv(children[1]->eval(t_ss)); + Boxed_Value bv(children[0]->eval(t_ss)); try { // short circuit arithmetic operations @@ -1003,10 +999,10 @@ namespace chaiscript } else { chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); fpp.save_params({bv}); - return t_ss->call_function(children[0]->text, m_loc, {std::move(bv)}, t_ss.conversions()); + return t_ss->call_function(text, m_loc, {std::move(bv)}, t_ss.conversions()); } } catch (const exception::dispatch_error &e) { - throw exception::eval_error("Error with prefix operator evaluation: '" + children[0]->text + "'", e.parameters, e.functions, false, *t_ss); + throw exception::eval_error("Error with prefix operator evaluation: '" + text + "'", e.parameters, e.functions, false, *t_ss); } } diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 2df9d3f9..aa922b27 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1247,20 +1247,9 @@ namespace chaiscript } /// Reads (and potentially captures) a char from input if it matches the parameter - bool Char(const char t_c, bool t_capture = false) { + bool Char(const char t_c) { SkipWS(); - - if (!t_capture) { - return Char_(t_c); - } else { - const auto start = m_position; - if (Char_(t_c)) { - m_match_stack.push_back(make_node(Position::str(start, m_position), start.line, start.col)); - return true; - } else { - return false; - } - } + return Char_(t_c); } /// Reads a string from input if it matches the parameter, without skipping initial whitespace @@ -2200,13 +2189,13 @@ namespace chaiscript for (const auto &oper : prefix_opers) { bool is_char = oper.size() == 1; - if ((is_char && Char(oper[0], true)) || (!is_char && Symbol(oper.c_str(), true))) + if ((is_char && Char(oper[0])) || (!is_char && Symbol(oper.c_str()))) { if (!Operator(m_operators.size()-1)) { throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_position.line, m_position.col), *m_filename); } - build_match(prev_stack_top); + build_match(prev_stack_top, oper); return true; } }