Reduce instances of Str_AST_Node

This commit is contained in:
Jason Turner
2016-04-10 21:38:44 -06:00
parent 5e97f459d8
commit 866db4ee8b
2 changed files with 29 additions and 33 deletions

View File

@@ -327,13 +327,13 @@ namespace chaiscript
struct Equation_AST_Node final : AST_Node {
Equation_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::Equation, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(children[1]->text))
{ assert(children.size() == 3); }
m_oper(Operators::to_operator(text))
{ assert(children.size() == 2); }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
Boxed_Value rhs = this->children[2]->eval(t_ss);
Boxed_Value rhs = this->children[1]->eval(t_ss);
Boxed_Value lhs = this->children[0]->eval(t_ss);
if (m_oper != Operators::Opers::invalid && lhs.get_type_info().is_arithmetic() &&
@@ -371,17 +371,17 @@ namespace chaiscript
}
try {
return t_ss->call_function(this->children[1]->text, m_loc, {std::move(lhs), rhs}, t_ss.conversions());
return t_ss->call_function(this->text, m_loc, {std::move(lhs), rhs}, t_ss.conversions());
}
catch(const exception::dispatch_error &e){
throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, e.functions, false, *t_ss);
throw exception::eval_error("Unable to find appropriate'" + this->text + "' operator.", e.parameters, e.functions, false, *t_ss);
}
}
catch(const exception::dispatch_error &e){
throw exception::eval_error("Missing clone or copy constructor for right hand side of equation", e.parameters, e.functions, false, *t_ss);
}
}
else if (this->children[1]->text == ":=") {
else if (this->text == ":=") {
if (lhs.is_undef() || Boxed_Value::type_match(lhs, rhs)) {
lhs.assign(rhs);
lhs.reset_return_value();
@@ -391,9 +391,9 @@ namespace chaiscript
}
else {
try {
return t_ss->call_function(this->children[1]->text, m_loc, {std::move(lhs), rhs}, t_ss.conversions());
return t_ss->call_function(this->text, m_loc, {std::move(lhs), rhs}, t_ss.conversions());
} catch(const exception::dispatch_error &e){
throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, e.functions, false, *t_ss);
throw exception::eval_error("Unable to find appropriate'" + this->text + "' operator.", e.parameters, e.functions, false, *t_ss);
}
}

View File

@@ -1272,7 +1272,7 @@ namespace chaiscript
}
/// Reads (and potentially captures) a string from input if it matches the parameter
bool Keyword(const char *t_s, bool t_capture = false) {
bool Keyword(const char *t_s) {
SkipWS();
const auto start = m_position;
bool retval = Keyword_(t_s);
@@ -1282,9 +1282,6 @@ namespace chaiscript
retval = false;
}
if ( t_capture && retval ) {
m_match_stack.push_back(make_node<eval::Str_AST_Node>(Position::str(start, m_position), start.line, start.col));
}
return retval;
}
@@ -1553,7 +1550,7 @@ namespace chaiscript
bool is_method = false;
if (Symbol("::", false)) {
if (Symbol("::")) {
//We're now a method
is_method = true;
@@ -1682,12 +1679,11 @@ namespace chaiscript
while (has_matches) {
while (Eol()) {}
has_matches = false;
if (Keyword("else", true)) {
const auto line = m_position.line;
const auto col = m_position.col;
if (Keyword("else")) {
if (Keyword("if")) {
const AST_NodePtr back(m_match_stack.back());
m_match_stack.back() =
chaiscript::make_shared<AST_Node, eval::If_AST_Node>("else if", back->location, back->children);
m_match_stack.back()->annotation = back->annotation;
m_match_stack.emplace_back(make_node<eval::If_AST_Node>("else if", line, col, std::vector<AST_NodePtr>()));
if (!Char('(')) {
throw exception::eval_error("Incomplete 'else if' expression", File_Position(m_position.line, m_position.col), *m_filename);
}
@@ -1703,6 +1699,7 @@ namespace chaiscript
}
has_matches = true;
} else {
m_match_stack.emplace_back(make_node<eval::If_AST_Node>("else", line, col, std::vector<AST_NodePtr>()));
while (Eol()) {}
if (!Block()) {
@@ -2105,7 +2102,7 @@ namespace chaiscript
if (!Id()) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_position.line, m_position.col), *m_filename);
}
if (!Symbol("::", false)) {
if (!Symbol("::")) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_position.line, m_position.col), *m_filename);
}
if (!Id()) {
@@ -2169,7 +2166,7 @@ namespace chaiscript
bool Reference() {
const auto prev_stack_top = m_match_stack.size();
if (Symbol("&", false)) {
if (Symbol("&")) {
if (!Id()) {
throw exception::eval_error("Incomplete '&' expression", File_Position(m_position.line, m_position.col), *m_filename);
}
@@ -2345,26 +2342,25 @@ namespace chaiscript
/// Parses a string of binary equation operators
bool Equation() {
bool retval = false;
const auto prev_stack_top = m_match_stack.size();
if (Operator()) {
retval = true;
if (Symbol("=", true, true) || Symbol(":=", true, true) || Symbol("+=", true, true) ||
Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) ||
Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) ||
Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) {
for (const auto sym : {"=", ":=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", "&=", "^=", "|="})
{
if (Symbol(sym, false, true)) {
SkipWS(true);
if (!Equation()) {
throw exception::eval_error("Incomplete equation", File_Position(m_position.line, m_position.col), *m_filename);
}
build_match<eval::Equation_AST_Node>(prev_stack_top);
build_match<eval::Equation_AST_Node>(prev_stack_top, sym);
return true;
}
}
return true;
}
return retval;
return false;
}
/// Parses statements allowed inside of a class block