Remove Char_AST_Node
This commit is contained in:
@@ -32,7 +32,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
/// Types of AST nodes available to the parser and eval
|
/// 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,
|
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,
|
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,
|
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
|
/// Helper lookup to get the name of each node type
|
||||||
const char *ast_node_type_to_string(AST_Node_Type ast_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",
|
"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",
|
"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",
|
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
|
||||||
|
|||||||
@@ -165,10 +165,6 @@ namespace chaiscript
|
|||||||
mutable std::atomic_uint_fast32_t m_loc;
|
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 {
|
struct Str_AST_Node final : AST_Node {
|
||||||
Str_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
|
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 {
|
struct Prefix_AST_Node final : AST_Node {
|
||||||
Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
|
||||||
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Prefix, std::move(t_loc), std::move(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 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 {
|
try {
|
||||||
// short circuit arithmetic operations
|
// short circuit arithmetic operations
|
||||||
@@ -1003,10 +999,10 @@ namespace chaiscript
|
|||||||
} else {
|
} else {
|
||||||
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
|
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
|
||||||
fpp.save_params({bv});
|
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) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1247,20 +1247,9 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads (and potentially captures) a char from input if it matches the parameter
|
/// 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();
|
SkipWS();
|
||||||
|
return Char_(t_c);
|
||||||
if (!t_capture) {
|
|
||||||
return Char_(t_c);
|
|
||||||
} else {
|
|
||||||
const auto start = m_position;
|
|
||||||
if (Char_(t_c)) {
|
|
||||||
m_match_stack.push_back(make_node<eval::Char_AST_Node>(Position::str(start, m_position), start.line, start.col));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a string from input if it matches the parameter, without skipping initial whitespace
|
/// 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)
|
for (const auto &oper : prefix_opers)
|
||||||
{
|
{
|
||||||
bool is_char = oper.size() == 1;
|
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)) {
|
if (!Operator(m_operators.size()-1)) {
|
||||||
throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_position.line, m_position.col), *m_filename);
|
throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_position.line, m_position.col), *m_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
build_match<eval::Prefix_AST_Node>(prev_stack_top);
|
build_match<eval::Prefix_AST_Node>(prev_stack_top, oper);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user