From c6f262c675ca72be74bc16c7be028e1c231cc89a Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 23 Jul 2015 15:21:39 -0600 Subject: [PATCH] Parse in-string eval at regular parse time - don't delay and overcomplicate with an eval --- include/chaiscript/language/chaiscript_parser.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 4ba2f54..089ed7f 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -954,15 +954,14 @@ namespace chaiscript const auto ev_stack_top = m_match_stack.size(); - /// \todo can we evaluate this in place and save the runtime cost of evaluating with each execution of the node? - m_match_stack.push_back(make_node("eval", prev_line, prev_col)); + try { + ChaiScript_Parser parser; + parser.parse(eval_match, "instr eval"); + m_match_stack.push_back(parser.ast()); + } catch (const exception::eval_error &e) { + throw exception::eval_error(e.what(), File_Position(prev_line, prev_col), *m_filename); + } - const auto arg_stack_top = m_match_stack.size(); - - m_match_stack.push_back(make_node(eval_match, prev_line, prev_col)); - - build_match(arg_stack_top); - build_match(ev_stack_top); build_match(ev_stack_top); build_match(tostr_stack_top); build_match(prev_stack_top, "+");