diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index f14f421..ec8c4c1 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -49,8 +49,8 @@ namespace chaiscript int line; int column; - File_Position(int file_line, int file_column) - : line(file_line), column(file_column) { } + File_Position(int t_file_line, int t_file_column) + : line(t_file_line), column(t_file_column) { } File_Position() : line(0), column(0) { } }; @@ -68,28 +68,29 @@ namespace chaiscript std::vector children; AST_NodePtr annotation; - AST_Node(const std::string &ast_node_text, int id, const boost::shared_ptr &fname, int start_line, int start_col, int end_line, int end_col) : - text(ast_node_text), identifier(id), filename(fname), - start(start_line, start_col), end(end_line, end_col) + AST_Node(const std::string &t_ast_node_text, int t_id, const boost::shared_ptr &t_fname, + int t_start_line, int t_start_col, int t_end_line, int t_end_col) : + text(t_ast_node_text), identifier(t_id), filename(t_fname), + start(t_start_line, t_start_col), end(t_end_line, t_end_col) { } - AST_Node(const std::string &ast_node_text, int id, const boost::shared_ptr &fname) : - text(ast_node_text), identifier(id), filename(fname) {} + AST_Node(const std::string &t_ast_node_text, int t_id, const boost::shared_ptr &t_fname) : + text(t_ast_node_text), identifier(t_id), filename(t_fname) {} virtual ~AST_Node() {} /** * Prints the contents of an AST node, including its children, recursively */ - std::string to_string(std::string prepend = "") { + std::string to_string(std::string t_prepend = "") { std::ostringstream oss; - oss << prepend << "(" << ast_node_type_to_string(this->identifier) << ") " + oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") " << this->text << " : " << this->start.line << ", " << this->start.column << std::endl; for (unsigned int j = 0; j < this->children.size(); ++j) { - oss << this->children[j]->to_string(prepend + " "); + oss << this->children[j]->to_string(t_prepend + " "); } return oss.str(); } @@ -117,17 +118,18 @@ namespace chaiscript std::string filename; std::vector call_stack; - Eval_Error(const std::string &why, const File_Position &where, const std::string &fname) : - std::runtime_error("Error: \"" + why + "\" " + - (std::string(fname) != "__EVAL__" ? ("in '" + fname + "' ") : "during evaluation ") + - + "at (" + boost::lexical_cast(where.line) + ", " + - boost::lexical_cast(where.column) + ")"), - reason(why), start_position(where), end_position(where), filename(fname) + Eval_Error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) : + std::runtime_error("Error: \"" + t_why + "\" " + + (t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") + + + "at (" + boost::lexical_cast(t_where.line) + ", " + + boost::lexical_cast(t_where.column) + ")"), + reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) { } - Eval_Error(const std::string &why) - : std::runtime_error("Error: \"" + why + "\" "), - reason(why) {} + Eval_Error(const std::string &t_why) + : std::runtime_error("Error: \"" + t_why + "\" "), + reason(t_why) + {} virtual ~Eval_Error() throw() {} }; @@ -136,8 +138,8 @@ namespace chaiscript * Errors generated when loading a file */ struct File_Not_Found_Error : public std::runtime_error { - File_Not_Found_Error(const std::string &filename) - : std::runtime_error("File Not Found: " + filename) + File_Not_Found_Error(const std::string &t_filename) + : std::runtime_error("File Not Found: " + t_filename) { } virtual ~File_Not_Found_Error() throw() {} @@ -150,7 +152,7 @@ namespace chaiscript struct Return_Value { Boxed_Value retval; - Return_Value(const Boxed_Value &return_value) : retval(return_value) { } + Return_Value(const Boxed_Value &t_return_value) : retval(t_return_value) { } }; /** diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 3c352c4..9573b76 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -29,8 +29,8 @@ namespace chaiscript { struct load_module_error : std::runtime_error { - load_module_error(const std::string &reason) throw() - : std::runtime_error(reason) + load_module_error(const std::string &t_reason) throw() + : std::runtime_error(t_reason) { } @@ -97,32 +97,32 @@ namespace chaiscript struct Loadable_Module { template - static std::wstring towstring(const T &str) + static std::wstring towstring(const T &t_str) { - return std::wstring(str.begin(), str.end()); + return std::wstring(t_str.begin(), t_str.end()); } template - static std::string tostring(const T &str) + static std::string tostring(const T &t_str) { - return std::string(str.begin(), str.end()); + return std::string(t_str.begin(), t_str.end()); } #ifdef _UNICODE template - static std::wstring toproperstring(const T &str) + static std::wstring toproperstring(const T &t_str) { - return towstring(str); + return towstring(t_str); } #else template - static std::string toproperstring(const T &str) + static std::string toproperstring(const T &t_str) { - return tostring(str); + return tostring(t_str); } #endif - static std::string GetErrorMessage(DWORD err) + static std::string GetErrorMessage(DWORD t_err) { #ifdef _UNICODE typedef LPWSTR StringType; @@ -134,19 +134,19 @@ namespace chaiscript StringType lpMsgBuf = 0; FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (StringType)&lpMsgBuf, - 0, NULL ); + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + t_err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (StringType)&lpMsgBuf, + 0, NULL ); if (lpMsgBuf) - { - retval = lpMsgBuf; - } + { + retval = lpMsgBuf; + } LocalFree(lpMsgBuf); return tostring(retval); @@ -215,159 +215,118 @@ namespace chaiscript typedef boost::shared_ptr Loadable_Module_Ptr; - - template - class ChaiScript_System { + class ChaiScript { #ifndef CHAISCRIPT_NO_THREADS - mutable boost::shared_mutex mutex; - mutable boost::recursive_mutex use_mutex; + mutable boost::shared_mutex m_mutex; + mutable boost::recursive_mutex m_use_mutex; #endif - std::set loaded_files; - std::map loaded_modules; - std::set active_loaded_modules; + std::set m_used_files; + std::map m_loaded_modules; + std::set m_active_loaded_modules; - std::vector modulepaths; - std::vector usepaths; + std::vector m_modulepaths; + std::vector m_usepaths; - Eval_Engine engine; + Dispatch_Engine m_engine; /** * Evaluates the given string in by parsing it and running the results through the evaluator */ - Boxed_Value do_eval(const std::string &input, const std::string &filename = "__EVAL__", bool /* internal*/ = false) + Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false) { - ChaiScript_Parser parser; - - //debug_print(ast_nodes); - Boxed_Value value; - - // Keep a cache of all loaded filenames and use the char * from this cache to pass - // to the parser. This is so that the parser does not have the overhead of passing - // around and copying strings - // - if (filename != "__EVAL__") - { -#ifndef CHAISCRIPT_NO_THREADS - boost::unique_lock l(mutex); -#endif - loaded_files.insert(filename); - try { - if (parser.parse(input, *(loaded_files.find(filename)))) { -#ifndef CHAISCRIPT_NO_THREADS - l.unlock(); -#endif - //parser.show_match_stack(); - value = parser.ast()->eval(engine);//eval_ast_node(engine, parser.ast()); - } - } - catch (const Return_Value &rv) { - value = rv.retval; - } - } else { - try { -#ifndef CHAISCRIPT_NO_THREADS - boost::shared_lock l(mutex); -#endif - std::string fname = *(loaded_files.find("__EVAL__")); -#ifndef CHAISCRIPT_NO_THREADS - l.unlock(); -#endif - - if (parser.parse(input, fname)) { - //parser.show_match_stack(); - value = parser.ast()->eval(engine); - } - } - catch (const Return_Value &rv) { - value = rv.retval; + try { + ChaiScript_Parser parser; + if (parser.parse(t_input, t_filename)) { + //parser.show_match_stack(); + return parser.ast()->eval(m_engine); + } else { + return Boxed_Value(); } } - - return value; + catch (const Return_Value &rv) { + return rv.retval; + } } - const Boxed_Value internal_eval_ast(const AST_NodePtr &ast) + const Boxed_Value internal_eval_ast(const AST_NodePtr &t_ast) { - return ast->eval(engine); + return t_ast->eval(m_engine); } /** * Evaluates the given boxed string, used during eval() inside of a script */ - const Boxed_Value internal_eval(const std::string &e) { - return do_eval(e, "__EVAL__", true); + const Boxed_Value internal_eval(const std::string &t_e) { + return do_eval(t_e, "__EVAL__", true); } - void use(const std::string &filename) + void use(const std::string &t_filename) { - for (size_t i = 0; i < usepaths.size(); ++i) - { + for (size_t i = 0; i < m_usepaths.size(); ++i) + { - try { - - const std::string appendedpath = usepaths[i] + filename; + try { + const std::string appendedpath = m_usepaths[i] + t_filename; #ifndef CHAISCRIPT_NO_THREADS - boost::lock_guard l(use_mutex); - boost::shared_lock l2(mutex); + boost::lock_guard l(m_use_mutex); + boost::shared_lock l2(m_mutex); #endif - if (loaded_files.count(appendedpath) == 0) - { + if (m_used_files.count(appendedpath) == 0) + { #ifndef CHAISCRIPT_NO_THREADS - l2.unlock(); + m_used_files.insert(appendedpath); + l2.unlock(); #endif - eval_file(appendedpath); - } - } catch (const File_Not_Found_Error &) { - if (i == usepaths.size() - 1) - { - throw File_Not_Found_Error(filename); - } - - // failed to load, try the next path + eval_file(appendedpath); + } + } catch (const File_Not_Found_Error &) { + if (i == m_usepaths.size() - 1) + { + throw File_Not_Found_Error(t_filename); } + // failed to load, try the next path } - + } } public: - ChaiScript_System(const std::vector &t_modulepaths = std::vector(), + ChaiScript(const std::vector &t_modulepaths = std::vector(), const std::vector &t_usepaths = std::vector()) - : modulepaths(t_modulepaths), usepaths(t_usepaths) + : m_modulepaths(t_modulepaths), m_usepaths(t_usepaths) { - if (modulepaths.empty()) + if (m_modulepaths.empty()) { - modulepaths.push_back(""); + m_modulepaths.push_back(""); } - if (usepaths.empty()) + if (m_usepaths.empty()) { - usepaths.push_back(""); + m_usepaths.push_back(""); } - loaded_files.insert("__EVAL__"); // Make sure the default name is already registered build_eval_system(); } /** * Adds a shared object, that can be used by all threads, to the system */ - ChaiScript_System &add_global_const(const Boxed_Value &bv, const std::string &name) + ChaiScript &add_global_const(const Boxed_Value &t_bv, const std::string &t_name) { - engine.add_global_const(bv, name); + m_engine.add_global_const(t_bv, t_name); return *this; } struct State { - std::set loaded_files; - typename Eval_Engine::State engine_state; + std::set used_files; + Dispatch_Engine::State engine_state; std::set active_loaded_modules; }; @@ -379,14 +338,14 @@ namespace chaiscript State get_state() { #ifndef CHAISCRIPT_NO_THREADS - boost::lock_guard l(use_mutex); - boost::shared_lock l2(mutex); + boost::lock_guard l(m_use_mutex); + boost::shared_lock l2(m_mutex); #endif State s; - s.loaded_files = loaded_files; - s.engine_state = engine.get_state(); - s.active_loaded_modules = active_loaded_modules; + s.used_files = m_used_files; + s.engine_state = m_engine.get_state(); + s.active_loaded_modules = m_active_loaded_modules; return s; } @@ -396,31 +355,31 @@ namespace chaiscript void set_state(const State &t_state) { #ifndef CHAISCRIPT_NO_THREADS - boost::lock_guard l(use_mutex); - boost::shared_lock l2(mutex); + boost::lock_guard l(m_use_mutex); + boost::shared_lock l2(m_mutex); #endif - loaded_files = t_state.loaded_files; - active_loaded_modules = t_state.active_loaded_modules; - engine.set_state(t_state.engine_state); + m_used_files = t_state.used_files; + m_active_loaded_modules = t_state.active_loaded_modules; + m_engine.set_state(t_state.engine_state); } /** * Adds an object to the system: type, function, object */ template - ChaiScript_System &add(const T &t, const std::string &name) + ChaiScript &add(const T &t_t, const std::string &t_name) { - engine.add(t, name); + m_engine.add(t_t, t_name); return *this; } /** * Adds a module object to the system */ - ChaiScript_System &add(const ModulePtr &p) + ChaiScript &add(const ModulePtr &t_p) { - p->apply(*this, this->get_eval_engine()); + t_p->apply(*this, this->get_eval_engine()); return *this; } @@ -440,14 +399,14 @@ namespace chaiscript postfixes.push_back(".so"); postfixes.push_back(""); - for (size_t i = 0; i < modulepaths.size(); ++i) + for (size_t i = 0; i < m_modulepaths.size(); ++i) { for (size_t j = 0; j < prefixes.size(); ++j) { for (size_t k = 0; k < postfixes.size(); ++k) { try { - std::string name = modulepaths[i] + prefixes[j] + t_module_name + postfixes[k]; + std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k]; load_module(t_module_name, name); return; } catch (const load_module_error &e) { @@ -481,18 +440,18 @@ namespace chaiscript void load_module(const std::string &t_module_name, const std::string &t_filename) { #ifndef CHAISCRIPT_NO_THREADS - boost::lock_guard l(use_mutex); + boost::lock_guard l(m_use_mutex); #endif - if (loaded_modules.count(t_module_name) == 0) + if (m_loaded_modules.count(t_module_name) == 0) { Loadable_Module_Ptr lm(new Loadable_Module(t_module_name, t_filename)); - loaded_modules[t_module_name] = lm; - active_loaded_modules.insert(t_module_name); + m_loaded_modules[t_module_name] = lm; + m_active_loaded_modules.insert(t_module_name); add(lm->m_moduleptr); - } else if (active_loaded_modules.count(t_module_name) == 0) { - active_loaded_modules.insert(t_module_name); - add(loaded_modules[t_module_name]->m_moduleptr); + } else if (m_active_loaded_modules.count(t_module_name) == 0) { + m_active_loaded_modules.insert(t_module_name); + add(m_loaded_modules[t_module_name]->m_moduleptr); } } @@ -505,35 +464,35 @@ namespace chaiscript * \param[in] script Script code to build a function from */ template - boost::function functor(const std::string &script) + boost::function functor(const std::string &t_script) { - return chaiscript::functor(eval(script)); + return chaiscript::functor(eval(t_script)); } /** * Evaluate a string via eval method */ - Boxed_Value operator()(const std::string &script) + Boxed_Value operator()(const std::string &t_script) { - return do_eval(script); + return do_eval(t_script); } /** - * Returns the current evaluation engine + * Returns the current evaluation m_engine */ - Eval_Engine &get_eval_engine() { - return engine; + Dispatch_Engine &get_eval_engine() { + return m_engine; } /** * Helper function for loading a file */ - std::string load_file(const std::string &filename) { - std::ifstream infile (filename.c_str(), std::ios::in | std::ios::ate); + std::string load_file(const std::string &t_filename) { + std::ifstream infile(t_filename.c_str(), std::ios::in | std::ios::ate); if (!infile.is_open()) { - throw File_Not_Found_Error(filename); + throw File_Not_Found_Error(t_filename); } std::streampos size = infile.tellg(); @@ -551,82 +510,79 @@ namespace chaiscript */ void build_eval_system() { using namespace bootstrap; - engine.add_reserved_word("def"); - engine.add_reserved_word("fun"); - engine.add_reserved_word("while"); - engine.add_reserved_word("for"); - engine.add_reserved_word("if"); - engine.add_reserved_word("else"); - engine.add_reserved_word("&&"); - engine.add_reserved_word("||"); - engine.add_reserved_word(","); - engine.add_reserved_word(":="); - engine.add_reserved_word("var"); - engine.add_reserved_word("return"); - engine.add_reserved_word("break"); - engine.add_reserved_word("true"); - engine.add_reserved_word("false"); - engine.add_reserved_word("_"); + m_engine.add_reserved_word("def"); + m_engine.add_reserved_word("fun"); + m_engine.add_reserved_word("while"); + m_engine.add_reserved_word("for"); + m_engine.add_reserved_word("if"); + m_engine.add_reserved_word("else"); + m_engine.add_reserved_word("&&"); + m_engine.add_reserved_word("||"); + m_engine.add_reserved_word(","); + m_engine.add_reserved_word(":="); + m_engine.add_reserved_word("var"); + m_engine.add_reserved_word("return"); + m_engine.add_reserved_word("break"); + m_engine.add_reserved_word("true"); + m_engine.add_reserved_word("false"); + m_engine.add_reserved_word("_"); add(Bootstrap::bootstrap()); - engine.add(fun(&Eval_Engine::dump_system, boost::ref(engine)), "dump_system"); - engine.add(fun(&Eval_Engine::dump_object, boost::ref(engine)), "dump_object"); - engine.add(fun(&Eval_Engine::is_type, boost::ref(engine)), "is_type"); - engine.add(fun(&Eval_Engine::type_name, boost::ref(engine)), "type_name"); - engine.add(fun(&Eval_Engine::function_exists, boost::ref(engine)), "function_exists"); + m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system"); + m_engine.add(fun(&Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object"); + m_engine.add(fun(&Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type"); + m_engine.add(fun(&Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name"); + m_engine.add(fun(&Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists"); - engine.add(fun(&Eval_Engine::get_type_name, boost::ref(engine)), "name"); + m_engine.add(fun(&Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name"); - typedef void (ChaiScript_System::*load_mod_1)(const std::string&); - typedef void (ChaiScript_System::*load_mod_2)(const std::string&, const std::string&); + typedef void (ChaiScript::*load_mod_1)(const std::string&); + typedef void (ChaiScript::*load_mod_2)(const std::string&, const std::string&); - engine.add(fun(static_cast(&ChaiScript_System::load_module), this), "load_module"); - engine.add(fun(static_cast(&ChaiScript_System::load_module), this), "load_module"); + m_engine.add(fun(static_cast(&ChaiScript::load_module), this), "load_module"); + m_engine.add(fun(static_cast(&ChaiScript::load_module), this), "load_module"); add(vector_type >("Vector")); add(string_type("string")); add(map_type >("Map")); add(pair_type >("Pair")); - engine.add(fun(&ChaiScript_System::use, this), "use"); - engine.add(fun(&ChaiScript_System::internal_eval, this), "eval"); - engine.add(fun(&ChaiScript_System::internal_eval_ast, this), "eval"); - - + m_engine.add(fun(&ChaiScript::use, this), "use"); + m_engine.add(fun(&ChaiScript::internal_eval, this), "eval"); + m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval"); do_eval(chaiscript_prelude, "standard prelude"); } template - T eval(const std::string &input) + T eval(const std::string &t_input) { - return boxed_cast(do_eval(input)); + return boxed_cast(do_eval(t_input)); } - Boxed_Value eval(const std::string &input) + Boxed_Value eval(const std::string &t_input) { - return do_eval(input); + return do_eval(t_input); } /** * Loads the file specified by filename, evaluates it, and returns the result */ - Boxed_Value eval_file(const std::string &filename) { - return do_eval(load_file(filename), filename); + Boxed_Value eval_file(const std::string &t_filename) { + return do_eval(load_file(t_filename), t_filename); } /** * Loads the file specified by filename, evaluates it, and returns the as the specified type */ template - T eval_file(const std::string &filename) { - return boxed_cast(do_eval(load_file(filename), filename)); + T eval_file(const std::string &t_filename) { + return boxed_cast(do_eval(load_file(t_filename), t_filename)); } }; - typedef ChaiScript_System ChaiScript; } #endif /* CHAISCRIPT_ENGINE_HPP_ */ diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 1aff7e2..c717525 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -17,26 +17,26 @@ namespace chaiscript * Helper function that will set up the scope around a function call, including handling the named function parameters */ template - const Boxed_Value eval_function (Eval_System &ss, const AST_NodePtr &node, const std::vector ¶m_names, const std::vector &vals) { - ss.new_scope(); + const Boxed_Value eval_function (Eval_System &t_ss, const AST_NodePtr &t_node, const std::vector &t_param_names, const std::vector &t_vals) { + t_ss.new_scope(); - for (unsigned int i = 0; i < param_names.size(); ++i) { - ss.add_object(param_names[i], vals[i]); + for (unsigned int i = 0; i < t_param_names.size(); ++i) { + t_ss.add_object(t_param_names[i], t_vals[i]); } try { - Boxed_Value retval(node->eval(ss)); - ss.pop_scope(); + Boxed_Value retval(t_node->eval(t_ss)); + t_ss.pop_scope(); return retval; } catch (const Return_Value &rv) { - ss.pop_scope(); + t_ss.pop_scope(); return rv.retval; } catch (Eval_Error &ee) { - ee.call_stack.push_back(node); - ss.pop_scope(); + ee.call_stack.push_back(t_node); + t_ss.pop_scope(); throw; } catch (...) { - ss.pop_scope(); + t_ss.pop_scope(); throw; } } @@ -44,14 +44,14 @@ namespace chaiscript struct Binary_Operator_AST_Node : public AST_Node { public: - Binary_Operator_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Binary_Operator_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; try { - retval = this->children[0]->eval(ss); + retval = this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -60,7 +60,7 @@ namespace chaiscript for (size_t i = 1; i < this->children.size(); i += 2) { try { - retval = ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(ss)); + retval = t_ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(t_ss)); } catch(const dispatch_error &){ throw Eval_Error("Can not find appropriate '" + this->children[i]->text + "'"); @@ -78,16 +78,16 @@ namespace chaiscript struct Error_AST_Node : public AST_Node { public: - Error_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Error, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Error_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Error, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Error_AST_Node() {} }; struct Int_AST_Node : public AST_Node { public: - Int_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Int, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Int_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ return const_var(int(atoi(this->text.c_str()))); @@ -97,8 +97,8 @@ namespace chaiscript struct Float_AST_Node : public AST_Node { public: - Float_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Float, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Float_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ return const_var(double(atof(this->text.c_str()))); @@ -108,10 +108,10 @@ namespace chaiscript struct Id_AST_Node : public AST_Node { public: - Id_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Id, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Id_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Id, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Id_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ if (this->text == "true") { return const_var(true); } @@ -126,7 +126,7 @@ namespace chaiscript } else { try { - return ss.get_object(this->text); + return t_ss.get_object(this->text); } catch (std::exception &) { throw Eval_Error("Can not find object: " + this->text); @@ -137,37 +137,37 @@ namespace chaiscript struct Char_AST_Node : public AST_Node { public: - Char_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Char, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Char_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Char, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Char_AST_Node() {} }; struct Str_AST_Node : public AST_Node { public: - Str_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Str, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Str_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Str, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Str_AST_Node() {} }; struct Eol_AST_Node : public AST_Node { public: - Eol_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Eol, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Eol_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Eol, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Eol_AST_Node() {} }; struct Fun_Call_AST_Node : public AST_Node { public: - Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Fun_Call, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Fun_Call, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Fun_Call_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Param_List_Builder plb; if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { for (size_t i = 0; i < this->children[1]->children.size(); ++i) { try { - plb << this->children[1]->children[i]->eval(ss); + plb << this->children[1]->children[i]->eval(t_ss); } catch(Eval_Error &ee) { ee.call_stack.push_back(this->children[1]->children[i]); @@ -176,34 +176,34 @@ namespace chaiscript } } - Dispatch_Engine::Stack prev_stack = ss.get_stack(); - Dispatch_Engine::Stack new_stack = ss.new_stack(); + Dispatch_Engine::Stack prev_stack = t_ss.get_stack(); + Dispatch_Engine::Stack new_stack = t_ss.new_stack(); try { - Boxed_Value fn = this->children[0]->eval(ss); + Boxed_Value fn = this->children[0]->eval(t_ss); try { - ss.set_stack(new_stack); + t_ss.set_stack(new_stack); const Boxed_Value &retval = (*boxed_cast(fn))(plb); - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); return retval; } catch(const dispatch_error &e){ - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); } catch(Return_Value &rv) { - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); return rv.retval; } catch(...) { - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); throw; } } catch(Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); throw Eval_Error(ee.reason); } @@ -213,16 +213,16 @@ namespace chaiscript struct Inplace_Fun_Call_AST_Node : public AST_Node { public: - Inplace_Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inplace_Fun_Call, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Inplace_Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inplace_Fun_Call, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inplace_Fun_Call_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Param_List_Builder plb; if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { for (size_t i = 0; i < this->children[1]->children.size(); ++i) { try { - plb << this->children[1]->children[i]->eval(ss); + plb << this->children[1]->children[i]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[1]->children[i]); @@ -232,7 +232,7 @@ namespace chaiscript } try { - Boxed_Value fn = this->children[0]->eval(ss); + Boxed_Value fn = this->children[0]->eval(t_ss); try { return (*boxed_cast(fn))(plb); @@ -258,27 +258,27 @@ namespace chaiscript struct Arg_List_AST_Node : public AST_Node { public: - Arg_List_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Arg_List, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Arg_List_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Arg_List, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Arg_List_AST_Node() {} }; struct Variable_AST_Node : public AST_Node { public: - Variable_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Variable, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Variable_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Variable, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Variable_AST_Node() {} }; struct Equation_AST_Node : public AST_Node { public: - Equation_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Equation, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Equation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equation, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Equation_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; try { - retval = this->children.back()->eval(ss); + retval = this->children.back()->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()); @@ -289,16 +289,16 @@ namespace chaiscript for (int i = static_cast(this->children.size())-3; i >= 0; i -= 2) { if (this->children[i+1]->text == "=") { try { - Boxed_Value lhs = this->children[i]->eval(ss); + Boxed_Value lhs = this->children[i]->eval(t_ss); try { if (lhs.is_undef()) { - retval = ss.call_function("clone", retval); + retval = t_ss.call_function("clone", retval); retval.clear_dependencies(); } try { - retval = ss.call_function(this->children[i+1]->text, lhs, retval); + retval = t_ss.call_function(this->children[i+1]->text, lhs, retval); } catch(const dispatch_error &){ throw Eval_Error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":".")); @@ -315,7 +315,7 @@ namespace chaiscript } else if (this->children[i+1]->text == ":=") { try { - Boxed_Value lhs = this->children[i]->eval(ss); + Boxed_Value lhs = this->children[i]->eval(t_ss); if (lhs.is_undef() || type_match(lhs, retval)) { lhs.assign(retval); } @@ -330,7 +330,7 @@ namespace chaiscript } else { try { - retval = ss.call_function(this->children[i+1]->text, this->children[i]->eval(ss), retval); + retval = t_ss.call_function(this->children[i+1]->text, this->children[i]->eval(t_ss), retval); } catch(const dispatch_error &){ throw Eval_Error("Can not find appropriate '" + this->children[i+1]->text + "'"); @@ -348,52 +348,52 @@ namespace chaiscript struct Var_Decl_AST_Node : public AST_Node { public: - Var_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Var_Decl, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Var_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Var_Decl, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Var_Decl_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ try { - ss.add_object(this->children[0]->text, Boxed_Value()); + t_ss.add_object(this->children[0]->text, Boxed_Value()); } catch (reserved_word_error &) { throw Eval_Error("Reserved word used as variable '" + this->children[0]->text + "'"); } - return ss.get_object(this->children[0]->text); + return t_ss.get_object(this->children[0]->text); } }; struct Comparison_AST_Node : public Binary_Operator_AST_Node { public: - Comparison_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Comparison, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Comparison_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Comparison, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Comparison_AST_Node() {} }; struct Additive_AST_Node : public Binary_Operator_AST_Node { public: - Additive_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Additive, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Additive_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Additive, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Additive_AST_Node() {} }; struct Multiplicative_AST_Node : public Binary_Operator_AST_Node { public: - Multiplicative_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Multiplicative, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Multiplicative_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Multiplicative, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Multiplicative_AST_Node() {} }; struct Array_Call_AST_Node : public AST_Node { public: - Array_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Array_Call, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Array_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Array_Call, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Array_Call_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; try { - retval = this->children[0]->eval(ss); + retval = this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -402,7 +402,7 @@ namespace chaiscript for (size_t i = 1; i < this->children.size(); ++i) { try { - retval = ss.call_function("[]", retval, this->children[i]->eval(ss)); + retval = t_ss.call_function("[]", retval, this->children[i]->eval(t_ss)); } catch(std::out_of_range &) { throw Eval_Error("Out of bounds exception"); @@ -422,13 +422,13 @@ namespace chaiscript struct Dot_Access_AST_Node : public AST_Node { public: - Dot_Access_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Dot_Access, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Dot_Access_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Dot_Access, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Dot_Access_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; try { - retval = this->children[0]->eval(ss); + retval = this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -443,7 +443,7 @@ namespace chaiscript if (this->children[i]->children.size() > 1) { for (size_t j = 0; j < this->children[i]->children[1]->children.size(); ++j) { try { - plb << this->children[i]->children[1]->children[j]->eval(ss); + plb << this->children[i]->children[1]->children[j]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[i]->children[1]->children[j]); @@ -461,30 +461,30 @@ namespace chaiscript fun_name = this->children[i]->text; } - Dispatch_Engine::Stack prev_stack = ss.get_stack(); - Dispatch_Engine::Stack new_stack = ss.new_stack(); + Dispatch_Engine::Stack prev_stack = t_ss.get_stack(); + Dispatch_Engine::Stack new_stack = t_ss.new_stack(); try { - ss.set_stack(new_stack); - retval = ss.call_function(fun_name, plb); - ss.set_stack(prev_stack); + t_ss.set_stack(new_stack); + retval = t_ss.call_function(fun_name, plb); + t_ss.set_stack(prev_stack); } catch(const dispatch_error &e){ - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); throw Eval_Error(std::string(e.what())); } catch(Return_Value &rv) { - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); retval = rv.retval; } catch(...) { - ss.set_stack(prev_stack); + t_ss.set_stack(prev_stack); throw; } if (this->children[i]->identifier == AST_Node_Type::Array_Call) { for (size_t j = 1; j < this->children[i]->children.size(); ++j) { try { - retval = ss.call_function("[]", retval, this->children[i]->children[j]->eval(ss)); + retval = t_ss.call_function("[]", retval, this->children[i]->children[j]->eval(t_ss)); } catch(std::out_of_range &) { throw Eval_Error("Out of bounds exception"); @@ -508,8 +508,8 @@ namespace chaiscript struct Quoted_String_AST_Node : public AST_Node { public: - Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Quoted_String, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Quoted_String_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ return const_var(this->text); @@ -519,8 +519,8 @@ namespace chaiscript struct Single_Quoted_String_AST_Node : public AST_Node { public: - Single_Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Single_Quoted_String_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ return const_var(char(this->text[0])); @@ -530,17 +530,17 @@ namespace chaiscript struct Lambda_AST_Node : public AST_Node { public: - Lambda_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Lambda, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Lambda_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Lambda, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Lambda_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ - std::vector param_names; + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ + std::vector t_param_names; size_t numparams = 0; if ((this->children.size() > 0) && (this->children[0]->identifier == AST_Node_Type::Arg_List)) { numparams = this->children[0]->children.size(); for (size_t i = 0; i < numparams; ++i) { - param_names.push_back(this->children[0]->children[i]->text); + t_param_names.push_back(this->children[0]->children[i]->text); } } @@ -550,7 +550,7 @@ namespace chaiscript } return Boxed_Value(Proxy_Function(new Dynamic_Proxy_Function - (boost::bind(&eval_function, boost::ref(ss), this->children.back(), param_names, _1), + (boost::bind(&eval_function, boost::ref(t_ss), this->children.back(), t_param_names, _1), static_cast(numparams)))); } @@ -558,39 +558,39 @@ namespace chaiscript struct Block_AST_Node : public AST_Node { public: - Block_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Block, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Block_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Block, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Block_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ size_t num_children = this->children.size(); - ss.new_scope(); + t_ss.new_scope(); for (size_t i = 0; i < num_children; ++i) { try { - const Boxed_Value &retval = this->children[i]->eval(ss); + const Boxed_Value &retval = this->children[i]->eval(t_ss); if (i + 1 == num_children) { - ss.pop_scope(); + t_ss.pop_scope(); return retval; } } catch (const chaiscript::Return_Value &) { - ss.pop_scope(); + t_ss.pop_scope(); throw; } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[i]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } catch (...) { - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); return Boxed_Value(); } @@ -598,18 +598,18 @@ namespace chaiscript struct Def_AST_Node : public AST_Node { public: - Def_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Def, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Def_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Def, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Def_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ - std::vector param_names; + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ + std::vector t_param_names; size_t numparams = 0; AST_NodePtr guardnode; if ((this->children.size() > 2) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { numparams = this->children[1]->children.size(); for (size_t i = 0; i < numparams; ++i) { - param_names.push_back(this->children[1]->children[i]->text); + t_param_names.push_back(this->children[1]->children[i]->text); } if (this->children.size() > 3) { @@ -629,17 +629,17 @@ namespace chaiscript if (guardnode) { guard = boost::shared_ptr (new Dynamic_Proxy_Function(boost::bind(&eval_function, - boost::ref(ss), guardnode, - param_names, _1), static_cast(numparams))); + boost::ref(t_ss), guardnode, + t_param_names, _1), static_cast(numparams))); } try { const std::string & function_name = this->children[0]->text; const std::string & annotation = this->annotation?this->annotation->text:""; - ss.add(Proxy_Function + t_ss.add(Proxy_Function (new Dynamic_Proxy_Function(boost::bind(&eval_function, - boost::ref(ss), this->children.back(), - param_names, _1), static_cast(numparams), + boost::ref(t_ss), this->children.back(), + t_param_names, _1), static_cast(numparams), annotation, guard)), function_name); } catch (reserved_word_error &e) { @@ -652,30 +652,30 @@ namespace chaiscript struct While_AST_Node : public AST_Node { public: - While_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::While, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + While_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::While, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~While_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ bool cond; - ss.new_scope(); + t_ss.new_scope(); try { - cond = boxed_cast(this->children[0]->eval(ss)); + cond = boxed_cast(this->children[0]->eval(t_ss)); } catch (const bad_boxed_cast &) { - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("While condition not boolean"); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } while (cond) { try { try { - this->children[1]->eval(ss); + this->children[1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[1]); @@ -683,15 +683,15 @@ namespace chaiscript } try { - cond = boxed_cast(this->children[0]->eval(ss)); + cond = boxed_cast(this->children[0]->eval(t_ss)); } catch (const bad_boxed_cast &) { - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("While condition not boolean"); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } @@ -699,7 +699,7 @@ namespace chaiscript cond = false; } } - ss.pop_scope(); + t_ss.pop_scope(); return Boxed_Value(); } ; @@ -707,13 +707,13 @@ namespace chaiscript struct If_AST_Node : public AST_Node { public: - If_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::If, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + If_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::If, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~If_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ bool cond; try { - cond = boxed_cast(this->children[0]->eval(ss)); + cond = boxed_cast(this->children[0]->eval(t_ss)); } catch (const bad_boxed_cast &) { throw Eval_Error("If condition not boolean"); @@ -725,7 +725,7 @@ namespace chaiscript if (cond) { try { - return this->children[1]->eval(ss); + return this->children[1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[1]); @@ -738,7 +738,7 @@ namespace chaiscript while ((!cond) && (i < this->children.size())) { if (this->children[i]->text == "else") { try { - return this->children[i+1]->eval(ss); + return this->children[i+1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[i+1]); @@ -747,7 +747,7 @@ namespace chaiscript } else if (this->children[i]->text == "else if") { try { - cond = boxed_cast(this->children[i+1]->eval(ss)); + cond = boxed_cast(this->children[i+1]->eval(t_ss)); } catch (const bad_boxed_cast &) { throw Eval_Error("'else if' condition not boolean"); @@ -758,7 +758,7 @@ namespace chaiscript } if (cond) { try { - return this->children[i+2]->eval(ss); + return this->children[i+2]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[i+2]); @@ -778,18 +778,18 @@ namespace chaiscript struct For_AST_Node : public AST_Node { public: - For_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::For, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + For_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::For, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~For_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ bool cond; - ss.new_scope(); + t_ss.new_scope(); try { if (this->children.size() == 4) { try { - this->children[0]->eval(ss); + this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -797,7 +797,7 @@ namespace chaiscript } try { - cond = boxed_cast(this->children[1]->eval(ss)); + cond = boxed_cast(this->children[1]->eval(t_ss)); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[1]); @@ -806,24 +806,24 @@ namespace chaiscript } else { try { - cond = boxed_cast(this->children[0]->eval(ss)); + cond = boxed_cast(this->children[0]->eval(t_ss)); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } } catch (const bad_boxed_cast &) { - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("For condition not boolean"); } while (cond) { try { if (this->children.size() == 4) { try { - this->children[3]->eval(ss); + this->children[3]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[3]); @@ -831,7 +831,7 @@ namespace chaiscript } try { - this->children[2]->eval(ss); + this->children[2]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[2]); @@ -839,7 +839,7 @@ namespace chaiscript } try { - cond = boxed_cast(this->children[1]->eval(ss)); + cond = boxed_cast(this->children[1]->eval(t_ss)); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[1]); @@ -848,7 +848,7 @@ namespace chaiscript } else { try { - this->children[2]->eval(ss); + this->children[2]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[2]); @@ -856,7 +856,7 @@ namespace chaiscript } try { - this->children[1]->eval(ss); + this->children[1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[1]); @@ -864,24 +864,24 @@ namespace chaiscript } try { - cond = boxed_cast(this->children[0]->eval(ss)); + cond = boxed_cast(this->children[0]->eval(t_ss)); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } } catch (const bad_boxed_cast &) { - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("For condition not boolean"); } catch (Break_Loop &) { cond = false; } } - ss.pop_scope(); + t_ss.pop_scope(); return Boxed_Value(); } @@ -889,15 +889,15 @@ namespace chaiscript struct Inline_Array_AST_Node : public AST_Node { public: - Inline_Array_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Array, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Inline_Array_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Array, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inline_Array_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ std::vector vec; if (this->children.size() > 0) { for (size_t i = 0; i < this->children[0]->children.size(); ++i) { try { - vec.push_back(this->children[0]->children[i]->eval(ss)); + vec.push_back(this->children[0]->children[i]->eval(t_ss)); } catch(Eval_Error &ee) { ee.call_stack.push_back(this->children[0]->children[i]); @@ -913,16 +913,16 @@ namespace chaiscript struct Inline_Map_AST_Node : public AST_Node { public: - Inline_Map_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Map, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Inline_Map_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Map, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inline_Map_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ try { std::map retval; for (size_t i = 0; i < this->children[0]->children.size(); ++i) { try { - retval[boxed_cast(this->children[0]->children[i]->children[0]->eval(ss))] - = ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(ss)); + retval[boxed_cast(this->children[0]->children[i]->children[0]->eval(t_ss))] + = t_ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(t_ss)); } catch(Eval_Error &ee) { ee.call_stack.push_back(this->children[0]->children[i]); @@ -940,13 +940,13 @@ namespace chaiscript struct Return_AST_Node : public AST_Node { public: - Return_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Return, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Return_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Return, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Return_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ if (this->children.size() > 0) { try { - throw Return_Value(this->children[0]->eval(ss)); + throw Return_Value(this->children[0]->eval(t_ss)); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -962,14 +962,14 @@ namespace chaiscript struct File_AST_Node : public AST_Node { public: - File_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::File, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + File_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::File, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~File_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss) { + virtual Boxed_Value eval(Dispatch_Engine &t_ss) { const size_t size = this->children.size(); for (size_t i = 0; i < size; ++i) { try { - const Boxed_Value &retval = this->children[i]->eval(ss); + const Boxed_Value &retval = this->children[i]->eval(t_ss); if (i + 1 == size) { return retval; } @@ -985,12 +985,12 @@ namespace chaiscript struct Prefix_AST_Node : public AST_Node { public: - Prefix_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Prefix, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Prefix_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ try { - return ss.call_function(this->children[0]->text, this->children[1]->eval(ss)); + return t_ss.call_function(this->children[0]->text, this->children[1]->eval(t_ss)); } catch(std::exception &){ throw Eval_Error("Can not find appropriate unary '" + this->children[0]->text + "'"); @@ -1001,8 +1001,8 @@ namespace chaiscript struct Break_AST_Node : public AST_Node { public: - Break_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Break, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Break_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Break, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Break_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ throw Break_Loop(); @@ -1011,28 +1011,28 @@ namespace chaiscript struct Map_Pair_AST_Node : public AST_Node { public: - Map_Pair_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Map_Pair, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Map_Pair_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Map_Pair, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Map_Pair_AST_Node() {} }; struct Value_Range_AST_Node : public AST_Node { public: - Value_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Value_Range, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Value_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Value_Range, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Value_Range_AST_Node() {} }; struct Inline_Range_AST_Node : public AST_Node { public: - Inline_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Range, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Inline_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Range, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inline_Range_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ try { - return ss.call_function("generate_range", - this->children[0]->children[0]->children[0]->eval(ss), - this->children[0]->children[0]->children[1]->eval(ss)); + return t_ss.call_function("generate_range", + this->children[0]->children[0]->children[0]->eval(t_ss), + this->children[0]->children[0]->children[1]->eval(t_ss)); } catch (const dispatch_error &) { throw Eval_Error("Unable to generate range vector"); @@ -1047,36 +1047,36 @@ namespace chaiscript struct Annotation_AST_Node : public AST_Node { public: - Annotation_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Annotation, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Annotation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Annotation, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Annotation_AST_Node() {} }; struct Try_AST_Node : public AST_Node { public: - Try_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Try, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Try_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Try, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Try_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; - ss.new_scope(); + t_ss.new_scope(); try { - retval = this->children[0]->eval(ss); + retval = this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - this->children.back()->children[0]->eval(ss); + this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); throw; } catch (const std::exception &e) { @@ -1093,7 +1093,7 @@ namespace chaiscript if (catch_block->children.size() == 1) { //No variable capture, no guards try { - retval = catch_block->children[0]->eval(ss); + retval = catch_block->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(catch_block->children[0]); @@ -1103,9 +1103,9 @@ namespace chaiscript } else if (catch_block->children.size() == 2) { //Variable capture, no guards - ss.add_object(catch_block->children[0]->text, except); + t_ss.add_object(catch_block->children[0]->text, except); try { - retval = catch_block->children[1]->eval(ss); + retval = catch_block->children[1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(catch_block->children[1]); @@ -1116,28 +1116,28 @@ namespace chaiscript } else if (catch_block->children.size() == 3) { //Variable capture, no guards - ss.add_object(catch_block->children[0]->text, except); + t_ss.add_object(catch_block->children[0]->text, except); bool guard; try { - guard = boxed_cast(catch_block->children[1]->eval(ss)); + guard = boxed_cast(catch_block->children[1]->eval(t_ss)); } catch (const bad_boxed_cast &) { if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - this->children.back()->children[0]->eval(ss); + this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("Guard condition not boolean"); } if (guard) { try { - retval = catch_block->children[2]->eval(ss); + retval = catch_block->children[2]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(catch_block->children[2]); @@ -1150,15 +1150,15 @@ namespace chaiscript else { if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - this->children.back()->children[0]->eval(ss); + this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("Internal error: catch block size unrecognized"); } } @@ -1171,7 +1171,7 @@ namespace chaiscript if (catch_block->children.size() == 1) { //No variable capture, no guards try { - retval = catch_block->children[0]->eval(ss); + retval = catch_block->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(catch_block->children[0]); @@ -1182,9 +1182,9 @@ namespace chaiscript } else if (catch_block->children.size() == 2) { //Variable capture, no guards - ss.add_object(catch_block->children[0]->text, except); + t_ss.add_object(catch_block->children[0]->text, except); try { - retval = catch_block->children[1]->eval(ss); + retval = catch_block->children[1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(catch_block->children[1]); @@ -1195,25 +1195,25 @@ namespace chaiscript } else if (catch_block->children.size() == 3) { //Variable capture, no guards - ss.add_object(catch_block->children[0]->text, except); + t_ss.add_object(catch_block->children[0]->text, except); bool guard; try { - guard = boxed_cast(catch_block->children[1]->eval(ss)); + guard = boxed_cast(catch_block->children[1]->eval(t_ss)); } catch (const bad_boxed_cast &) { if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - this->children.back()->children[0]->eval(ss); + this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("Guard condition not boolean"); } catch (Eval_Error &ee) { @@ -1222,7 +1222,7 @@ namespace chaiscript } if (guard) { try { - retval = catch_block->children[2]->eval(ss); + retval = catch_block->children[2]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(catch_block->children[2]); @@ -1234,15 +1234,15 @@ namespace chaiscript else { if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - this->children.back()->children[0]->eval(ss); + this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); throw Eval_Error("Internal error: catch block size unrecognized"); } } @@ -1250,30 +1250,30 @@ namespace chaiscript catch (...) { if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - this->children.back()->children[0]->eval(ss); + this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); throw; } if (this->children.back()->identifier == AST_Node_Type::Finally) { try { - retval = this->children.back()->children[0]->eval(ss); + retval = this->children.back()->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children.back()->children[0]); - ss.pop_scope(); + t_ss.pop_scope(); throw; } } - ss.pop_scope(); + t_ss.pop_scope(); return retval; } @@ -1282,34 +1282,34 @@ namespace chaiscript struct Catch_AST_Node : public AST_Node { public: - Catch_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Catch, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Catch_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Catch, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Catch_AST_Node() {} }; struct Finally_AST_Node : public AST_Node { public: - Finally_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Finally, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Finally_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Finally, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Finally_AST_Node() {} }; struct Method_AST_Node : public AST_Node { public: - Method_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Method, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Method_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Method, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Method_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ - std::vector param_names; + std::vector t_param_names; AST_NodePtr guardnode; //The first param of a method is always the implied this ptr. - param_names.push_back("this"); + t_param_names.push_back("this"); if ((this->children.size() > 3) && (this->children[2]->identifier == AST_Node_Type::Arg_List)) { for (size_t i = 0; i < this->children[2]->children.size(); ++i) { - param_names.push_back(this->children[2]->children[i]->text); + t_param_names.push_back(this->children[2]->children[i]->text); } if (this->children.size() > 4) { @@ -1324,14 +1324,14 @@ namespace chaiscript } } - size_t numparams = param_names.size(); + size_t numparams = t_param_names.size(); boost::shared_ptr guard; if (guardnode) { guard = boost::shared_ptr (new Dynamic_Proxy_Function(boost::bind(&eval_function, - boost::ref(ss), guardnode, - param_names, _1), static_cast(numparams))); + boost::ref(t_ss), guardnode, + t_param_names, _1), static_cast(numparams))); } try { @@ -1339,26 +1339,26 @@ namespace chaiscript const std::string & class_name = this->children[0]->text; const std::string & function_name = this->children[1]->text; if (function_name == class_name) { - ss.add(Proxy_Function + t_ss.add(Proxy_Function (new Dynamic_Object_Constructor(class_name, Proxy_Function (new Dynamic_Proxy_Function(boost::bind(&eval_function, - boost::ref(ss), this->children.back(), - param_names, _1), static_cast(numparams), + boost::ref(t_ss), this->children.back(), + t_param_names, _1), static_cast(numparams), annotation, guard)))), function_name); } else { boost::optional ti; try { - ti = ss.get_type(class_name); + ti = t_ss.get_type(class_name); } catch (const std::range_error &) { // No biggie, the type name is just not known } - ss.add(Proxy_Function + t_ss.add(Proxy_Function (new Dynamic_Object_Function(class_name, Proxy_Function (new Dynamic_Proxy_Function(boost::bind(&eval_function, - boost::ref(ss), this->children.back(), - param_names, _1), static_cast(numparams), + boost::ref(t_ss), this->children.back(), + t_param_names, _1), static_cast(numparams), annotation, guard)), ti)), function_name); } @@ -1373,12 +1373,12 @@ namespace chaiscript struct Attr_Decl_AST_Node : public AST_Node { public: - Attr_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Attr_Decl, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Attr_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Attr_Decl, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Attr_Decl_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ try { - ss.add(fun(boost::function(boost::bind(&Dynamic_Object_Attribute::func, this->children[0]->text, + t_ss.add(fun(boost::function(boost::bind(&Dynamic_Object_Attribute::func, this->children[0]->text, this->children[1]->text, _1))), this->children[1]->text); } @@ -1392,48 +1392,48 @@ namespace chaiscript struct Shift_AST_Node : public Binary_Operator_AST_Node { public: - Shift_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Shift, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Shift_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Shift, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Shift_AST_Node() {} }; struct Equality_AST_Node : public Binary_Operator_AST_Node { public: - Equality_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Equality, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Equality_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equality, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Equality_AST_Node() {} }; struct Bitwise_And_AST_Node : public Binary_Operator_AST_Node { public: - Bitwise_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_And, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Bitwise_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_And, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Bitwise_And_AST_Node() {} }; struct Bitwise_Xor_AST_Node : public Binary_Operator_AST_Node { public: - Bitwise_Xor_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Bitwise_Xor_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Bitwise_Xor_AST_Node() {} }; struct Bitwise_Or_AST_Node : public Binary_Operator_AST_Node { public: - Bitwise_Or_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Or, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Binary_Operator_AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Bitwise_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Or, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Bitwise_Or_AST_Node() {} }; struct Logical_And_AST_Node : public AST_Node { public: - Logical_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_And, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Logical_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_And, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Logical_And_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; try { - retval = this->children[0]->eval(ss); + retval = this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -1451,7 +1451,7 @@ namespace chaiscript } if (lhs) { try { - retval = this->children[i+1]->eval(ss); + retval = this->children[i+1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[i+1]); @@ -1469,14 +1469,14 @@ namespace chaiscript struct Logical_Or_AST_Node : public AST_Node { public: - Logical_Or_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_Or, const boost::shared_ptr &fname=boost::shared_ptr(), int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { } + Logical_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_Or, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Logical_Or_AST_Node() {} - virtual Boxed_Value eval(Dispatch_Engine &ss){ + virtual Boxed_Value eval(Dispatch_Engine &t_ss){ Boxed_Value retval; try { - retval = this->children[0]->eval(ss); + retval = this->children[0]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); @@ -1497,7 +1497,7 @@ namespace chaiscript } else { try { - retval = this->children[i+1]->eval(ss); + retval = this->children[i+1]->eval(t_ss); } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[i+1]); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index ab88bf3..bad548f 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -19,92 +19,93 @@ namespace chaiscript { class ChaiScript_Parser { - std::string::const_iterator input_pos, input_end; - int line, col; - std::string multiline_comment_begin, multiline_comment_end; - std::string singleline_comment; - boost::shared_ptr filename; - std::vector match_stack; + std::string::const_iterator m_input_pos, m_input_end; + int m_line, m_col; + std::string m_multiline_comment_begin; + std::string m_multiline_comment_end; + std::string m_singleline_comment; + boost::shared_ptr m_filename; + std::vector m_match_stack; - std::vector > operator_matches; - std::vector operators; + std::vector > m_operator_matches; + std::vector m_operators; public: - ChaiScript_Parser() { - multiline_comment_begin = "/*"; - multiline_comment_end = "*/"; - singleline_comment = "//"; - + ChaiScript_Parser() + : m_multiline_comment_begin("/*"), + m_multiline_comment_end("*/"), + m_singleline_comment("//") + { setup_operators(); } ChaiScript_Parser(const ChaiScript_Parser &); // explicitly unimplemented copy constructor ChaiScript_Parser &operator=(const ChaiScript_Parser &); // explicitly unimplemented assignment operator - void setup_operators() { - - operators.push_back(AST_Node_Type::Logical_Or); + void setup_operators() + { + m_operators.push_back(AST_Node_Type::Logical_Or); std::vector logical_or; logical_or.push_back("||"); - operator_matches.push_back(logical_or); + m_operator_matches.push_back(logical_or); - operators.push_back(AST_Node_Type::Logical_And); + m_operators.push_back(AST_Node_Type::Logical_And); std::vector logical_and; logical_and.push_back("&&"); - operator_matches.push_back(logical_and); + m_operator_matches.push_back(logical_and); - operators.push_back(AST_Node_Type::Bitwise_Or); + m_operators.push_back(AST_Node_Type::Bitwise_Or); std::vector bitwise_or; bitwise_or.push_back("|"); - operator_matches.push_back(bitwise_or); + m_operator_matches.push_back(bitwise_or); - operators.push_back(AST_Node_Type::Bitwise_Xor); + m_operators.push_back(AST_Node_Type::Bitwise_Xor); std::vector bitwise_xor; bitwise_xor.push_back("^"); - operator_matches.push_back(bitwise_xor); + m_operator_matches.push_back(bitwise_xor); - operators.push_back(AST_Node_Type::Bitwise_And); + m_operators.push_back(AST_Node_Type::Bitwise_And); std::vector bitwise_and; bitwise_and.push_back("&"); - operator_matches.push_back(bitwise_and); + m_operator_matches.push_back(bitwise_and); - operators.push_back(AST_Node_Type::Equality); + m_operators.push_back(AST_Node_Type::Equality); std::vector equality; equality.push_back("=="); equality.push_back("!="); - operator_matches.push_back(equality); + m_operator_matches.push_back(equality); - operators.push_back(AST_Node_Type::Comparison); + m_operators.push_back(AST_Node_Type::Comparison); std::vector comparison; comparison.push_back("<"); comparison.push_back("<="); comparison.push_back(">"); comparison.push_back(">="); - operator_matches.push_back(comparison); + m_operator_matches.push_back(comparison); - operators.push_back(AST_Node_Type::Shift); + m_operators.push_back(AST_Node_Type::Shift); std::vector shift; shift.push_back("<<"); shift.push_back(">>"); - operator_matches.push_back(shift); + m_operator_matches.push_back(shift); - operators.push_back(AST_Node_Type::Additive); + m_operators.push_back(AST_Node_Type::Additive); std::vector additive; additive.push_back("+"); additive.push_back("-"); - operator_matches.push_back(additive); + m_operator_matches.push_back(additive); - operators.push_back(AST_Node_Type::Multiplicative); + m_operators.push_back(AST_Node_Type::Multiplicative); std::vector multiplicative; multiplicative.push_back("*"); multiplicative.push_back("/"); multiplicative.push_back("%"); - operator_matches.push_back(multiplicative); + m_operator_matches.push_back(multiplicative); - operators.push_back(AST_Node_Type::Dot_Access); + m_operators.push_back(AST_Node_Type::Dot_Access); std::vector dot_access; dot_access.push_back("."); - operator_matches.push_back(dot_access); + m_operator_matches.push_back(dot_access); } /** * Prints the parsed ast_nodes as a tree @@ -122,9 +123,9 @@ namespace chaiscript * Shows the current stack of matched ast_nodes */ void show_match_stack() { - for (unsigned int i = 0; i < match_stack.size(); ++i) { + for (unsigned int i = 0; i < m_match_stack.size(); ++i) { //debug_print(match_stack[i]); - std::cout << match_stack[i]->to_string(); + std::cout << m_match_stack[i]->to_string(); } } @@ -132,60 +133,60 @@ namespace chaiscript * Clears the stack of matched ast_nodes */ void clear_match_stack() { - match_stack.clear(); + m_match_stack.clear(); } /** * Returns the front-most AST node */ AST_NodePtr ast() { - return match_stack.front(); + return m_match_stack.front(); } /** * Helper function that collects ast_nodes from a starting position to the top of the stack into a new AST node */ - void build_match(AST_NodePtr t, size_t match_start) { + void build_match(AST_NodePtr t_t, size_t t_match_start) { int pos_line_start, pos_col_start, pos_line_stop, pos_col_stop; int is_deep = false; //so we want to take everything to the right of this and make them children - if (match_start != match_stack.size()) { - pos_line_start = match_stack[match_start]->start.line; - pos_col_start = match_stack[match_start]->start.column; - pos_line_stop = line; - pos_col_stop = col; + if (t_match_start != m_match_stack.size()) { + pos_line_start = m_match_stack[t_match_start]->start.line; + pos_col_start = m_match_stack[t_match_start]->start.column; + pos_line_stop = m_line; + pos_col_stop = m_col; is_deep = true; } else { - pos_line_start = line; - pos_col_start = col; - pos_line_stop = line; - pos_col_stop = col; + pos_line_start = m_line; + pos_col_start = m_col; + pos_line_stop = m_line; + pos_col_stop = m_col; } - t->filename = filename; - t->start.line = pos_line_start; - t->start.column = pos_col_start; - t->end.line = pos_line_stop; - t->end.column = pos_col_stop; + t_t->filename = m_filename; + t_t->start.line = pos_line_start; + t_t->start.column = pos_col_start; + t_t->end.line = pos_line_stop; + t_t->end.column = pos_col_stop; if (is_deep) { - t->children.assign(match_stack.begin() + match_start, match_stack.end()); - match_stack.erase(match_stack.begin() + match_start, match_stack.end()); - match_stack.push_back(t); + t_t->children.assign(m_match_stack.begin() + t_match_start, m_match_stack.end()); + m_match_stack.erase(m_match_stack.begin() + t_match_start, m_match_stack.end()); + m_match_stack.push_back(t_t); } else { //todo: fix the fact that a successful match that captured no ast_nodes doesn't have any real start position - match_stack.push_back(t); + m_match_stack.push_back(t_t); } } /** * Does ranged char check */ - inline bool char_between(char start, char end) { - if ((*input_pos >= start) && (*input_pos <= end)) { + inline bool char_between(char t_start, char t_end) { + if ((*m_input_pos >= t_start) && (*m_input_pos <= t_end)) { return true; } else { @@ -197,7 +198,7 @@ namespace chaiscript * Check to see if there is more text parse */ inline bool has_more_input() { - return (input_pos != input_end); + return (m_input_pos != m_input_end); } /** @@ -206,31 +207,31 @@ namespace chaiscript bool SkipComment() { bool retval = false; - if (Symbol_(multiline_comment_begin.c_str())) { - while (input_pos != input_end) { - if (Symbol_(multiline_comment_end.c_str())) { + if (Symbol_(m_multiline_comment_begin.c_str())) { + while (m_input_pos != m_input_end) { + if (Symbol_(m_multiline_comment_end.c_str())) { break; } else if (!Eol_()) { - ++col; - ++input_pos; + ++m_col; + ++m_input_pos; } } retval = true; } - else if (Symbol_(singleline_comment.c_str())) { - while (input_pos != input_end) { + else if (Symbol_(m_singleline_comment.c_str())) { + while (m_input_pos != m_input_end) { if (Symbol_("\r\n")) { - input_pos -= 2; + m_input_pos -= 2; break; } else if (Char_('\n')) { - --input_pos; + --m_input_pos; break; } else { - ++col; - ++input_pos; + ++m_col; + ++m_input_pos; } } retval = true; @@ -244,9 +245,9 @@ namespace chaiscript bool SkipWS() { bool retval = false; while (has_more_input()) { - if ((*input_pos == ' ') || (*input_pos == '\t')) { - ++input_pos; - ++col; + if ((*m_input_pos == ' ') || (*m_input_pos == '\t')) { + ++m_input_pos; + ++m_col; retval = true; } else if (SkipComment()) { @@ -264,26 +265,26 @@ namespace chaiscript */ bool Float_() { bool retval = false; - std::string::const_iterator start = input_pos; + std::string::const_iterator start = m_input_pos; - if (has_more_input() && (char_between('0', '9') || (*input_pos == '.'))) { + if (has_more_input() && (char_between('0', '9') || (*m_input_pos == '.'))) { while (has_more_input() && char_between('0', '9')) { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } - if (has_more_input() && (*input_pos == '.')) { - ++input_pos; - ++col; + if (has_more_input() && (*m_input_pos == '.')) { + ++m_input_pos; + ++m_col; if (has_more_input() && char_between('0', '9')) { retval = true; while (has_more_input() && char_between('0', '9')) { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } else { - --input_pos; - --col; + --m_input_pos; + --m_col; } } } @@ -295,13 +296,13 @@ namespace chaiscript */ bool Hex_() { bool retval = false; - if (has_more_input() && (*input_pos == '0')) { - ++input_pos; - ++col; + if (has_more_input() && (*m_input_pos == '0')) { + ++m_input_pos; + ++m_col; - if (has_more_input() && ((*input_pos == 'x') || (*input_pos == 'X'))) { - ++input_pos; - ++col; + if (has_more_input() && ((*m_input_pos == 'x') || (*m_input_pos == 'X'))) { + ++m_input_pos; + ++m_col; if (has_more_input() && (char_between('0', '9') || char_between('a', 'f') || char_between('A', 'F'))) { @@ -309,18 +310,18 @@ namespace chaiscript while (has_more_input() && (char_between('0', '9') || char_between('a', 'f') || char_between('A', 'F'))) { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } else { - --input_pos; - --col; + --m_input_pos; + --m_col; } } else { - --input_pos; - --col; + --m_input_pos; + --m_col; } } @@ -332,28 +333,28 @@ namespace chaiscript */ bool Binary_() { bool retval = false; - if (has_more_input() && (*input_pos == '0')) { - ++input_pos; - ++col; + if (has_more_input() && (*m_input_pos == '0')) { + ++m_input_pos; + ++m_col; - if (has_more_input() && ((*input_pos == 'b') || (*input_pos == 'B'))) { - ++input_pos; - ++col; + if (has_more_input() && ((*m_input_pos == 'b') || (*m_input_pos == 'B'))) { + ++m_input_pos; + ++m_col; if (has_more_input() && char_between('0', '1')) { retval = true; while (has_more_input() && char_between('0', '1')) { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } else { - --input_pos; - --col; + --m_input_pos; + --m_col; } } else { - --input_pos; - --col; + --m_input_pos; + --m_col; } } @@ -363,31 +364,31 @@ namespace chaiscript /** * Reads a number from the input, detecting if it's an integer or floating point */ - bool Num(bool capture = false) { + bool Num(bool t_capture = false) { SkipWS(); - if (!capture) { + if (!t_capture) { return Hex_() || Float_(); } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; - if (has_more_input() && (char_between('0', '9') || (*input_pos == '.')) ) { + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; + if (has_more_input() && (char_between('0', '9') || (*m_input_pos == '.')) ) { if (Hex_()) { - std::string match(start, input_pos); + std::string match(start, m_input_pos); std::stringstream ss(match); unsigned int temp_int; ss >> std::hex >> temp_int; std::ostringstream out_int; out_int << int(temp_int); - AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } if (Binary_()) { - std::string match(start, input_pos); + std::string match(start, m_input_pos); int temp_int = 0; size_t pos = 0, end = match.length(); @@ -401,18 +402,18 @@ namespace chaiscript std::ostringstream out_int; out_int << temp_int; - AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } if (Float_()) { - std::string match(start, input_pos); - AST_NodePtr t(new Float_AST_Node(match, AST_Node_Type::Float, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start, m_input_pos); + AST_NodePtr t(new Float_AST_Node(match, AST_Node_Type::Float, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { - std::string match(start, input_pos); + std::string match(start, m_input_pos); if ((match.size() > 0) && (match[0] == '0')) { std::stringstream ss(match); unsigned int temp_int; @@ -420,12 +421,12 @@ namespace chaiscript std::ostringstream out_int; out_int << int(temp_int); - AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); } else { - AST_NodePtr t(new Int_AST_Node(match, AST_Node_Type::Int, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Int_AST_Node(match, AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); } return true; } @@ -441,39 +442,39 @@ namespace chaiscript */ bool Id_() { bool retval = false; - if (has_more_input() && (char_between('A', 'Z') || (*input_pos == '_') || char_between('a', 'z'))) { + if (has_more_input() && (char_between('A', 'Z') || (*m_input_pos == '_') || char_between('a', 'z'))) { retval = true; - while (has_more_input() && (char_between('A', 'Z') || (*input_pos == '_') || + while (has_more_input() && (char_between('A', 'Z') || (*m_input_pos == '_') || char_between('a', 'z') || char_between('0', '9'))) { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } - else if (has_more_input() && (*input_pos == '`')) { + else if (has_more_input() && (*m_input_pos == '`')) { retval = true; - ++col; - ++input_pos; - std::string::const_iterator start = input_pos; + ++m_col; + ++m_input_pos; + std::string::const_iterator start = m_input_pos; - while (has_more_input() && (*input_pos != '`')) { + while (has_more_input() && (*m_input_pos != '`')) { if (Eol()) { - throw Eval_Error("Carriage return in identifier literal", File_Position(line, col), *filename); + throw Eval_Error("Carriage return in identifier literal", File_Position(m_line, m_col), *m_filename); } else { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } - if (start == input_pos) { - throw Eval_Error("Missing contents of identifier literal", File_Position(line, col), *filename); + if (start == m_input_pos) { + throw Eval_Error("Missing contents of identifier literal", File_Position(m_line, m_col), *m_filename); } - else if (input_pos == input_end) { - throw Eval_Error("Incomplete identifier literal", File_Position(line, col), *filename); + else if (m_input_pos == m_input_end) { + throw Eval_Error("Incomplete identifier literal", File_Position(m_line, m_col), *m_filename); } - ++col; - ++input_pos; + ++m_col; + ++m_input_pos; } return retval; } @@ -481,28 +482,28 @@ namespace chaiscript /** * Reads (and potentially captures) an identifier from input */ - bool Id(bool capture = false) { + bool Id(bool t_capture = false) { SkipWS(); - if (!capture) { + if (!t_capture) { return Id_(); } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; if (Id_()) { if (*start == '`') { //Id Literal - std::string match(start+1, input_pos-1); - AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start+1, m_input_pos-1); + AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { - std::string match(start, input_pos); - AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start, m_input_pos); + AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } } @@ -517,25 +518,25 @@ namespace chaiscript */ bool Annotation() { SkipWS(); - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; if (Symbol_("#")) { do { - while (input_pos != input_end) { + while (m_input_pos != m_input_end) { if (Eol_()) { break; } else { - ++col; - ++input_pos; + ++m_col; + ++m_input_pos; } } } while (Symbol("#")); - std::string match(start, input_pos); - AST_NodePtr t(new Annotation_AST_Node(match, AST_Node_Type::Annotation, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start, m_input_pos); + AST_NodePtr t(new Annotation_AST_Node(match, AST_Node_Type::Annotation, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { @@ -549,31 +550,31 @@ namespace chaiscript bool Quoted_String_() { bool retval = false; char prev_char = 0; - if (has_more_input() && (*input_pos == '\"')) { + if (has_more_input() && (*m_input_pos == '\"')) { retval = true; - prev_char = *input_pos; - ++input_pos; - ++col; + prev_char = *m_input_pos; + ++m_input_pos; + ++m_col; - while (has_more_input() && ((*input_pos != '\"') || ((*input_pos == '\"') && (prev_char == '\\')))) { + while (has_more_input() && ((*m_input_pos != '\"') || ((*m_input_pos == '\"') && (prev_char == '\\')))) { if (!Eol_()) { if (prev_char == '\\') { prev_char = 0; } else { - prev_char = *input_pos; + prev_char = *m_input_pos; } - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } if (has_more_input()) { - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } else { - throw Eval_Error("Unclosed quoted string", File_Position(line, col), *filename); + throw Eval_Error("Unclosed quoted string", File_Position(m_line, m_col), *m_filename); } } return retval; @@ -582,25 +583,25 @@ namespace chaiscript /** * Reads (and potentially captures) a quoted string from input. Translates escaped sequences. */ - bool Quoted_String(bool capture = false) { + bool Quoted_String(bool t_capture = false) { SkipWS(); - if (!capture) { + if (!t_capture) { return Quoted_String_(); } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; if (Quoted_String_()) { std::string match; bool is_escaped = false; bool is_interpolated = false; bool saw_interpolation_marker = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); - //for (std::string::iterator s = start + 1, end = input_pos - 1; s != end; ++s) { - std::string::const_iterator s = start + 1, end = input_pos - 1; + //for (std::string::iterator s = start + 1, end = m_input_pos - 1; s != end; ++s) { + std::string::const_iterator s = start + 1, end = m_input_pos - 1; while (s != end) { if (saw_interpolation_marker) { @@ -609,24 +610,24 @@ namespace chaiscript if (is_interpolated) { //If we've seen previous interpolation, add on instead of making a new one - AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); - match_stack.push_back(plus); + AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(plus); - AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); } else { - AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); } //We've finished with the part of the string up to this point, so clear it match = ""; - AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); - match_stack.push_back(plus); + AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(plus); std::string eval_match; @@ -639,20 +640,20 @@ namespace chaiscript is_interpolated = true; ++s; - size_t tostr_stack_top = match_stack.size(); + size_t tostr_stack_top = m_match_stack.size(); - AST_NodePtr tostr(new Id_AST_Node("to_string", AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); - match_stack.push_back(tostr); + AST_NodePtr tostr(new Id_AST_Node("to_string", AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(tostr); - size_t ev_stack_top = match_stack.size(); + size_t ev_stack_top = m_match_stack.size(); - AST_NodePtr ev(new Id_AST_Node("eval", AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); - match_stack.push_back(ev); + AST_NodePtr ev(new Id_AST_Node("eval", AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(ev); - size_t arg_stack_top = match_stack.size(); + size_t arg_stack_top = m_match_stack.size(); - AST_NodePtr t(new Quoted_String_AST_Node(eval_match, AST_Node_Type::Quoted_String, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Quoted_String_AST_Node(eval_match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); build_match(AST_NodePtr(new Arg_List_AST_Node()), arg_stack_top); @@ -665,7 +666,7 @@ namespace chaiscript build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); } else { - throw Eval_Error("Unclosed in-string eval", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename); } } else { @@ -694,7 +695,7 @@ namespace chaiscript case ('\'') : match.push_back('\''); break; case ('\"') : match.push_back('\"'); break; case ('$') : match.push_back('$'); break; - default: throw Eval_Error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *filename); + default: throw Eval_Error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *m_filename); } } else if (*s == '$') { @@ -709,17 +710,17 @@ namespace chaiscript } } if (is_interpolated) { - AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); - match_stack.push_back(plus); + AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(plus); - AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); } else { - AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); } return true; } @@ -735,31 +736,31 @@ namespace chaiscript bool Single_Quoted_String_() { bool retval = false; char prev_char = 0; - if (has_more_input() && (*input_pos == '\'')) { + if (has_more_input() && (*m_input_pos == '\'')) { retval = true; - prev_char = *input_pos; - ++input_pos; - ++col; + prev_char = *m_input_pos; + ++m_input_pos; + ++m_col; - while (has_more_input() && ((*input_pos != '\'') || ((*input_pos == '\'') && (prev_char == '\\')))) { + while (has_more_input() && ((*m_input_pos != '\'') || ((*m_input_pos == '\'') && (prev_char == '\\')))) { if (!Eol_()) { if (prev_char == '\\') { prev_char = 0; } else { - prev_char = *input_pos; + prev_char = *m_input_pos; } - ++input_pos; - ++col; + ++m_input_pos; + ++m_col; } } - if (input_pos != input_end) { - ++input_pos; - ++col; + if (m_input_pos != m_input_end) { + ++m_input_pos; + ++m_col; } else { - throw Eval_Error("Unclosed single-quoted string", File_Position(line, col), *filename); + throw Eval_Error("Unclosed single-quoted string", File_Position(m_line, m_col), *m_filename); } } return retval; @@ -768,20 +769,20 @@ namespace chaiscript /** * Reads (and potentially captures) a char group from input. Translates escaped sequences. */ - bool Single_Quoted_String(bool capture = false) { + bool Single_Quoted_String(bool t_capture = false) { SkipWS(); - if (!capture) { + if (!t_capture) { return Single_Quoted_String_(); } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; if (Single_Quoted_String_()) { std::string match; bool is_escaped = false; - for (std::string::const_iterator s = start + 1, end = input_pos - 1; s != end; ++s) { + for (std::string::const_iterator s = start + 1, end = m_input_pos - 1; s != end; ++s) { if (*s == '\\') { if (is_escaped) { match.push_back('\\'); @@ -801,7 +802,7 @@ namespace chaiscript case ('t') : match.push_back('\t'); break; case ('\'') : match.push_back('\''); break; case ('\"') : match.push_back('\"'); break; - default: throw Eval_Error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *filename); + default: throw Eval_Error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *m_filename); } } else { @@ -810,8 +811,8 @@ namespace chaiscript is_escaped = false; } } - AST_NodePtr t(new Single_Quoted_String_AST_Node(match, AST_Node_Type::Single_Quoted_String, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + AST_NodePtr t(new Single_Quoted_String_AST_Node(match, AST_Node_Type::Single_Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { @@ -825,9 +826,9 @@ namespace chaiscript */ bool Char_(char c) { bool retval = false; - if (has_more_input() && (*input_pos == c)) { - ++input_pos; - ++col; + if (has_more_input() && (*m_input_pos == c)) { + ++m_input_pos; + ++m_col; retval = true; } @@ -837,20 +838,20 @@ namespace chaiscript /** * Reads (and potentially captures) a char from input if it matches the parameter */ - bool Char(char c, bool capture = false) { + bool Char(char t_c, bool t_capture = false) { SkipWS(); - if (!capture) { - return Char_(c); + if (!t_capture) { + return Char_(t_c); } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; - if (Char_(c)) { - std::string match(start, input_pos); - AST_NodePtr t(new Char_AST_Node(match, AST_Node_Type::Char, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; + if (Char_(t_c)) { + std::string match(start, m_input_pos); + AST_NodePtr t(new Char_AST_Node(match, AST_Node_Type::Char, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { @@ -862,21 +863,21 @@ namespace chaiscript /** * Reads a string from input if it matches the parameter, without skipping initial whitespace */ - bool Keyword_(const char *s) { + bool Keyword_(const char *t_s) { bool retval = false; - int len = static_cast(strlen(s)); + int len = static_cast(strlen(t_s)); - if ((input_end - input_pos) >= len) { - std::string::const_iterator tmp = input_pos; + if ((m_input_end - m_input_pos) >= len) { + std::string::const_iterator tmp = m_input_pos; for (int i = 0; i < len; ++i) { - if (*tmp != s[i]) { + if (*tmp != t_s[i]) { return false; } ++tmp; } retval = true; - input_pos = tmp; - col += len; + m_input_pos = tmp; + m_col += len; } return retval; @@ -885,21 +886,21 @@ namespace chaiscript /** * Reads (and potentially captures) a string from input if it matches the parameter */ - bool Keyword(const char *s, bool capture = false) { + bool Keyword(const char *t_s, bool t_capture = false) { SkipWS(); - if (!capture) { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; - bool retval = Keyword_(s); + if (!t_capture) { + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; + bool retval = Keyword_(t_s); if (retval) { //todo: fix this. Hacky workaround for preventing substring matches - if (has_more_input() && (char_between('A', 'Z') || (*input_pos == '_') || + if (has_more_input() && (char_between('A', 'Z') || (*m_input_pos == '_') || char_between('a', 'z') || char_between('0', '9'))) { - input_pos = start; - col = prev_col; - line = prev_line; + m_input_pos = start; + m_col = prev_col; + m_line = prev_line; return false; } return true; @@ -909,21 +910,21 @@ namespace chaiscript } } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; - if (Keyword_(s)) { + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; + if (Keyword_(t_s)) { //todo: fix this. Hacky workaround for preventing substring matches - if (has_more_input() && (char_between('A', 'Z') || (*input_pos == '_') || + if (has_more_input() && (char_between('A', 'Z') || (*m_input_pos == '_') || char_between('a', 'z') || char_between('0', '9'))) { - input_pos = start; - col = prev_col; - line = prev_line; + m_input_pos = start; + m_col = prev_col; + m_line = prev_line; return false; } - std::string match(start, input_pos); - AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start, m_input_pos); + AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { @@ -935,21 +936,21 @@ namespace chaiscript /** * Reads a symbol group from input if it matches the parameter, without skipping initial whitespace */ - bool Symbol_(const char *s) { + bool Symbol_(const char *t_s) { bool retval = false; - int len = static_cast(strlen(s)); + int len = static_cast(strlen(t_s)); - if ((input_end - input_pos) >= len) { - std::string::const_iterator tmp = input_pos; + if ((m_input_end - m_input_pos) >= len) { + std::string::const_iterator tmp = m_input_pos; for (int i = 0; i < len; ++i) { - if (*tmp != s[i]) { + if (*tmp != t_s[i]) { return false; } ++tmp; } retval = true; - input_pos = tmp; - col += len; + m_input_pos = tmp; + m_col += len; } return retval; @@ -958,23 +959,23 @@ namespace chaiscript /** * Reads (and potentially captures) a symbol group from input if it matches the parameter */ - bool Symbol(const char *s, bool capture = false, bool disallow_prevention=false) { + bool Symbol(const char *t_s, bool t_capture = false, bool t_disallow_prevention=false) { SkipWS(); - if (!capture) { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; - bool retval = Symbol_(s); + if (!t_capture) { + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; + bool retval = Symbol_(t_s); if (retval) { //todo: fix this. Hacky workaround for preventing substring matches - if (has_more_input() && (disallow_prevention == false) && - ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') || - (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || - (*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) { - input_pos = start; - col = prev_col; - line = prev_line; + if (has_more_input() && (t_disallow_prevention == false) && + ((*m_input_pos == '+') || (*m_input_pos == '-') || (*m_input_pos == '*') || (*m_input_pos == '/') || + (*m_input_pos == '|') || (*m_input_pos == '&') || (*m_input_pos == '^') || (*m_input_pos == '=') || + (*m_input_pos == '.') || (*m_input_pos == '<') || (*m_input_pos == '>'))) { + m_input_pos = start; + m_col = prev_col; + m_line = prev_line; return false; } return true; @@ -984,24 +985,24 @@ namespace chaiscript } } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; - if (Symbol_(s)) { + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; + if (Symbol_(t_s)) { //todo: fix this. Hacky workaround for preventing substring matches - if (has_more_input() && (disallow_prevention == false) && - ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') || - (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || - (*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) { - input_pos = start; - col = prev_col; - line = prev_line; + if (has_more_input() && (t_disallow_prevention == false) && + ((*m_input_pos == '+') || (*m_input_pos == '-') || (*m_input_pos == '*') || (*m_input_pos == '/') || + (*m_input_pos == '|') || (*m_input_pos == '&') || (*m_input_pos == '^') || (*m_input_pos == '=') || + (*m_input_pos == '.') || (*m_input_pos == '<') || (*m_input_pos == '>'))) { + m_input_pos = start; + m_col = prev_col; + m_line = prev_line; return false; } else { - std::string match(start, input_pos); - AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start, m_input_pos); + AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } } @@ -1019,8 +1020,8 @@ namespace chaiscript if (has_more_input() && (Symbol_("\r\n") || Char_('\n'))) { retval = true; - ++line; - col = 1; + ++m_line; + m_col = 1; } else if (has_more_input() && Char_(';')) { retval = true; @@ -1032,20 +1033,20 @@ namespace chaiscript /** * Reads (and potentially captures) an end-of-line group from input */ - bool Eol(bool capture = false) { + bool Eol(bool t_capture = false) { SkipWS(); - if (!capture) { + if (!t_capture) { return Eol_(); } else { - std::string::const_iterator start = input_pos; - int prev_col = col; - int prev_line = line; + std::string::const_iterator start = m_input_pos; + int prev_col = m_col; + int prev_line = m_line; if (Eol_()) { - std::string match(start, input_pos); - AST_NodePtr t(new Eol_AST_Node(match, AST_Node_Type::Eol, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); + std::string match(start, m_input_pos); + AST_NodePtr t(new Eol_AST_Node(match, AST_Node_Type::Eol, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(t); return true; } else { @@ -1060,7 +1061,7 @@ namespace chaiscript bool Arg_List() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Equation()) { retval = true; @@ -1069,7 +1070,7 @@ namespace chaiscript do { while (Eol()) {} if (!Equation()) { - throw Eval_Error("Unexpected value in parameter list", File_Position(line, col), *filename); + throw Eval_Error("Unexpected value in parameter list", File_Position(m_line, m_col), *m_filename); } } while (retval && Char(',')); } @@ -1085,7 +1086,7 @@ namespace chaiscript bool Container_Arg_List() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Value_Range()) { retval = true; @@ -1098,7 +1099,7 @@ namespace chaiscript do { while (Eol()) {} if (!Map_Pair()) { - throw Eval_Error("Unexpected value in container", File_Position(line, col), *filename); + throw Eval_Error("Unexpected value in container", File_Position(m_line, m_col), *m_filename); } } while (retval && Char(',')); } @@ -1111,7 +1112,7 @@ namespace chaiscript do { while (Eol()) {} if (!Operator()) { - throw Eval_Error("Unexpected value in container", File_Position(line, col), *filename); + throw Eval_Error("Unexpected value in container", File_Position(m_line, m_col), *m_filename); } } while (retval && Char(',')); } @@ -1128,7 +1129,7 @@ namespace chaiscript bool Lambda() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("fun")) { retval = true; @@ -1136,14 +1137,14 @@ namespace chaiscript if (Char('(')) { Arg_List(); if (!Char(')')) { - throw Eval_Error("Incomplete anonymous function", File_Position(line, col), *filename); + throw Eval_Error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename); } } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete anonymous function", File_Position(line, col), *filename); + throw Eval_Error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Lambda_AST_Node()), prev_stack_top); @@ -1163,18 +1164,18 @@ namespace chaiscript if (Annotation()) { while (Eol_()) {} - annotation = match_stack.back(); - match_stack.pop_back(); + annotation = m_match_stack.back(); + m_match_stack.pop_back(); is_annotated = true; } - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("def")) { retval = true; if (!Id(true)) { - throw Eval_Error("Missing function name in definition", File_Position(line, col), *filename); + throw Eval_Error("Missing function name in definition", File_Position(m_line, m_col), *m_filename); } if (Symbol("::", false)) { @@ -1182,14 +1183,14 @@ namespace chaiscript is_method = true; if (!Id(true)) { - throw Eval_Error("Missing method name in definition", File_Position(line, col), *filename); + throw Eval_Error("Missing method name in definition", File_Position(m_line, m_col), *m_filename); } } if (Char('(')) { Arg_List(); if (!Char(')')) { - throw Eval_Error("Incomplete function definition", File_Position(line, col), *filename); + throw Eval_Error("Incomplete function definition", File_Position(m_line, m_col), *m_filename); } } @@ -1197,13 +1198,13 @@ namespace chaiscript if (Char(':')) { if (!Operator()) { - throw Eval_Error("Missing guard expression for function", File_Position(line, col), *filename); + throw Eval_Error("Missing guard expression for function", File_Position(m_line, m_col), *m_filename); } } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete function definition", File_Position(line, col), *filename); + throw Eval_Error("Incomplete function definition", File_Position(m_line, m_col), *m_filename); } if (is_method) { @@ -1214,7 +1215,7 @@ namespace chaiscript } if (is_annotated) { - match_stack.back()->annotation = annotation; + m_match_stack.back()->annotation = annotation; } } @@ -1227,7 +1228,7 @@ namespace chaiscript bool Try() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("try")) { retval = true; @@ -1235,7 +1236,7 @@ namespace chaiscript while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'try' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'try' block", File_Position(m_line, m_col), *m_filename); } bool has_matches = true; @@ -1243,14 +1244,14 @@ namespace chaiscript while (Eol()) {} has_matches = false; if (Keyword("catch", false)) { - size_t catch_stack_top = match_stack.size(); + size_t catch_stack_top = m_match_stack.size(); if (Char('(')) { if (!(Id(true) && Char(')'))) { - throw Eval_Error("Incomplete 'catch' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'catch' expression", File_Position(m_line, m_col), *m_filename); } if (Char(':')) { if (!Operator()) { - throw Eval_Error("Missing guard expression for catch", File_Position(line, col), *filename); + throw Eval_Error("Missing guard expression for catch", File_Position(m_line, m_col), *m_filename); } } } @@ -1258,7 +1259,7 @@ namespace chaiscript while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'catch' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Catch_AST_Node()), catch_stack_top); has_matches = true; @@ -1266,12 +1267,12 @@ namespace chaiscript } while (Eol()) {} if (Keyword("finally", false)) { - size_t finally_stack_top = match_stack.size(); + size_t finally_stack_top = m_match_stack.size(); while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'finally' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Finally_AST_Node()), finally_stack_top); } @@ -1288,23 +1289,23 @@ namespace chaiscript bool If() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("if")) { retval = true; if (!Char('(')) { - throw Eval_Error("Incomplete 'if' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'if' expression", File_Position(m_line, m_col), *m_filename); } if (!(Operator() && Char(')'))) { - throw Eval_Error("Incomplete 'if' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'if' expression", File_Position(m_line, m_col), *m_filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'if' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'if' block", File_Position(m_line, m_col), *m_filename); } bool has_matches = true; @@ -1313,19 +1314,19 @@ namespace chaiscript has_matches = false; if (Keyword("else", true)) { if (Keyword("if")) { - match_stack.back()->text = "else if"; + m_match_stack.back()->text = "else if"; if (!Char('(')) { - throw Eval_Error("Incomplete 'else if' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename); } if (!(Operator() && Char(')'))) { - throw Eval_Error("Incomplete 'else if' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'else if' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'else if' block", File_Position(m_line, m_col), *m_filename); } has_matches = true; } @@ -1333,7 +1334,7 @@ namespace chaiscript while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'else' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'else' block", File_Position(m_line, m_col), *m_filename); } has_matches = true; } @@ -1352,23 +1353,23 @@ namespace chaiscript bool While() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("while")) { retval = true; if (!Char('(')) { - throw Eval_Error("Incomplete 'while' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'while' expression", File_Position(m_line, m_col), *m_filename); } if (!(Operator() && Char(')'))) { - throw Eval_Error("Incomplete 'while' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'while' expression", File_Position(m_line, m_col), *m_filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'while' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new While_AST_Node()), prev_stack_top); @@ -1387,7 +1388,7 @@ namespace chaiscript return true; } else { - throw Eval_Error("Incomplete conditions in 'for' loop", File_Position(line, col), *filename); + throw Eval_Error("Incomplete conditions in 'for' loop", File_Position(m_line, m_col), *m_filename); } } @@ -1397,23 +1398,23 @@ namespace chaiscript bool For() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("for")) { retval = true; if (!Char('(')) { - throw Eval_Error("Incomplete 'for' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'for' expression", File_Position(m_line, m_col), *m_filename); } if (!(For_Guards() && Char(')'))) { - throw Eval_Error("Incomplete 'for' expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'for' expression", File_Position(m_line, m_col), *m_filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'for' block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new For_AST_Node()), prev_stack_top); @@ -1428,14 +1429,14 @@ namespace chaiscript bool Block() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Char('{')) { retval = true; Statements(); if (!Char('}')) { - throw Eval_Error("Incomplete block", File_Position(line, col), *filename); + throw Eval_Error("Incomplete block", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Block_AST_Node()), prev_stack_top); @@ -1450,7 +1451,7 @@ namespace chaiscript bool Return() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("return")) { retval = true; @@ -1468,7 +1469,7 @@ namespace chaiscript bool Break() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("break")) { retval = true; @@ -1484,9 +1485,9 @@ namespace chaiscript */ bool Id_Fun_Array() { bool retval = false; - std::string::const_iterator prev_pos = input_pos; + std::string::const_iterator prev_pos = m_input_pos; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Id(true)) { retval = true; bool has_more = true; @@ -1499,7 +1500,7 @@ namespace chaiscript Arg_List(); if (!Char(')')) { - throw Eval_Error("Incomplete function call", File_Position(line, col), *filename); + throw Eval_Error("Incomplete function call", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Fun_Call_AST_Node()), prev_stack_top); @@ -1508,7 +1509,7 @@ namespace chaiscript has_more = true; if (!(Operator() && Char(']'))) { - throw Eval_Error("Incomplete array access", File_Position(line, col), *filename); + throw Eval_Error("Incomplete array access", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Array_Call_AST_Node()), prev_stack_top); @@ -1525,13 +1526,13 @@ namespace chaiscript bool Var_Decl() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Keyword("var")) { retval = true; if (!Id(true)) { - throw Eval_Error("Incomplete variable declaration", File_Position(line, col), *filename); + throw Eval_Error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Var_Decl_AST_Node()), prev_stack_top); @@ -1540,13 +1541,13 @@ namespace chaiscript retval = true; if (!Id(true)) { - throw Eval_Error("Incomplete attribute declaration", File_Position(line, col), *filename); + throw Eval_Error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); } if (!Symbol("::", false)) { - throw Eval_Error("Incomplete attribute declaration", File_Position(line, col), *filename); + throw Eval_Error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); } if (!Id(true)) { - throw Eval_Error("Missing attribute name in definition", File_Position(line, col), *filename); + throw Eval_Error("Missing attribute name in definition", File_Position(m_line, m_col), *m_filename); } @@ -1565,10 +1566,10 @@ namespace chaiscript if (Char('(')) { retval = true; if (!Operator()) { - throw Eval_Error("Incomplete expression", File_Position(line, col), *filename); + throw Eval_Error("Incomplete expression", File_Position(m_line, m_col), *m_filename); } if (!Char(')')) { - throw Eval_Error("Missing closing parenthesis", File_Position(line, col), *filename); + throw Eval_Error("Missing closing parenthesis", File_Position(m_line, m_col), *m_filename); } } return retval; @@ -1580,19 +1581,19 @@ namespace chaiscript bool Inline_Container() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Char('[')) { retval = true; Container_Arg_List(); if (!Char(']')) { - throw Eval_Error("Missing closing square bracket", File_Position(line, col), *filename); + throw Eval_Error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename); } - if ((prev_stack_top != match_stack.size()) && (match_stack.back()->children.size() > 0)) { - if (match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) { + if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { + if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) { build_match(AST_NodePtr(new Inline_Range_AST_Node()), prev_stack_top); } - else if (match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) { + else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) { build_match(AST_NodePtr(new Inline_Map_AST_Node()), prev_stack_top); } else { @@ -1613,13 +1614,13 @@ namespace chaiscript bool Prefix() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Symbol("++", true)) { retval = true; - if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '++' expression", File_Position(line, col), *filename); + if (!Operator(m_operators.size()-1)) { + throw Eval_Error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1627,8 +1628,8 @@ namespace chaiscript else if (Symbol("--", true)) { retval = true; - if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '--' expression", File_Position(line, col), *filename); + if (!Operator(m_operators.size()-1)) { + throw Eval_Error("Incomplete '--' expression", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1636,8 +1637,8 @@ namespace chaiscript else if (Char('-', true)) { retval = true; - if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete unary '-' expression", File_Position(line, col), *filename); + if (!Operator(m_operators.size()-1)) { + throw Eval_Error("Incomplete unary '-' expression", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1645,8 +1646,8 @@ namespace chaiscript else if (Char('+', true)) { retval = true; - if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete unary '+' expression", File_Position(line, col), *filename); + if (!Operator(m_operators.size()-1)) { + throw Eval_Error("Incomplete unary '+' expression", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1654,8 +1655,8 @@ namespace chaiscript else if (Char('!', true)) { retval = true; - if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '!' expression", File_Position(line, col), *filename); + if (!Operator(m_operators.size()-1)) { + throw Eval_Error("Incomplete '!' expression", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1663,8 +1664,8 @@ namespace chaiscript else if (Char('~', true)) { retval = true; - if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '~' expression", File_Position(line, col), *filename); + if (!Operator(m_operators.size()-1)) { + throw Eval_Error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1686,32 +1687,33 @@ namespace chaiscript } } - bool Operator_Helper(size_t precedence) { - for (size_t i = 0; i < operator_matches[precedence].size(); ++i) { - if (Symbol(operator_matches[precedence][i].c_str(), true)) { + bool Operator_Helper(size_t t_precedence) { + for (size_t i = 0; i < m_operator_matches[t_precedence].size(); ++i) { + if (Symbol(m_operator_matches[t_precedence][i].c_str(), true)) { return true; } } return false; } - bool Operator(size_t precedence = 0) { + bool Operator(size_t t_precedence = 0) { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); - if (precedence < operators.size()) { - if (Operator(precedence+1)) { + if (t_precedence < m_operators.size()) { + if (Operator(t_precedence+1)) { retval = true; - if (Operator_Helper(precedence)) { + if (Operator_Helper(t_precedence)) { do { - if (!Operator(precedence+1)) { - throw Eval_Error("Incomplete " + std::string(ast_node_type_to_string(operators[precedence])) + " expression", - File_Position(line, col), *filename); + if (!Operator(t_precedence+1)) { + throw Eval_Error("Incomplete " + + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", + File_Position(m_line, m_col), *m_filename); } - } while (Operator_Helper(precedence)); + } while (Operator_Helper(t_precedence)); - switch (operators[precedence]) { + switch (m_operators[t_precedence]) { case(AST_Node_Type::Comparison) : build_match(AST_NodePtr(new Comparison_AST_Node()), prev_stack_top); break; @@ -1746,7 +1748,7 @@ namespace chaiscript build_match(AST_NodePtr(new Logical_Or_AST_Node()), prev_stack_top); break; default: - throw Eval_Error("Internal error: unhandled ast_node", File_Position(line, col), *filename); + throw Eval_Error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename); } } } @@ -1764,24 +1766,24 @@ namespace chaiscript bool Map_Pair() { bool retval = false; - size_t prev_stack_top = match_stack.size(); - std::string::const_iterator prev_pos = input_pos; - int prev_col = col; + size_t prev_stack_top = m_match_stack.size(); + std::string::const_iterator prev_pos = m_input_pos; + int prev_col = m_col; if (Operator()) { if (Symbol(":")) { retval = true; if (!Operator()) { - throw Eval_Error("Incomplete map pair", File_Position(line, col), *filename); + throw Eval_Error("Incomplete map pair", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Map_Pair_AST_Node()), prev_stack_top); } else { - input_pos = prev_pos; - col = prev_col; - while (prev_stack_top != match_stack.size()) { - match_stack.pop_back(); + m_input_pos = prev_pos; + m_col = prev_col; + while (prev_stack_top != m_match_stack.size()) { + m_match_stack.pop_back(); } } } @@ -1795,24 +1797,24 @@ namespace chaiscript bool Value_Range() { bool retval = false; - size_t prev_stack_top = match_stack.size(); - std::string::const_iterator prev_pos = input_pos; - int prev_col = col; + size_t prev_stack_top = m_match_stack.size(); + std::string::const_iterator prev_pos = m_input_pos; + int prev_col = m_col; if (Operator()) { if (Symbol("..")) { retval = true; if (!Operator()) { - throw Eval_Error("Incomplete value range", File_Position(line, col), *filename); + throw Eval_Error("Incomplete value range", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Value_Range_AST_Node()), prev_stack_top); } else { - input_pos = prev_pos; - col = prev_col; - while (prev_stack_top != match_stack.size()) { - match_stack.pop_back(); + m_input_pos = prev_pos; + m_col = prev_col; + while (prev_stack_top != m_match_stack.size()) { + m_match_stack.pop_back(); } } } @@ -1826,7 +1828,7 @@ namespace chaiscript bool Equation() { bool retval = false; - size_t prev_stack_top = match_stack.size(); + size_t prev_stack_top = m_match_stack.size(); if (Operator()) { retval = true; @@ -1835,7 +1837,7 @@ namespace chaiscript Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) || Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) { if (!Equation()) { - throw Eval_Error("Incomplete equation", File_Position(line, col), *filename); + throw Eval_Error("Incomplete equation", File_Position(m_line, m_col), *m_filename); } build_match(AST_NodePtr(new Equation_AST_Node()), prev_stack_top); @@ -1856,11 +1858,11 @@ namespace chaiscript while (has_more) { has_more = false; - int prev_line = line; - int prev_col = col; + int prev_line = m_line; + int prev_col = m_col; if (Def()) { if (!saw_eol) { - throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1868,7 +1870,7 @@ namespace chaiscript } else if (Try()) { if (!saw_eol) { - throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1876,7 +1878,7 @@ namespace chaiscript } else if (If()) { if (!saw_eol) { - throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1884,7 +1886,7 @@ namespace chaiscript } else if (While()) { if (!saw_eol) { - throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1892,7 +1894,7 @@ namespace chaiscript } else if (For()) { if (!saw_eol) { - throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1900,7 +1902,7 @@ namespace chaiscript } else if (Return()) { if (!saw_eol) { - throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1908,7 +1910,7 @@ namespace chaiscript } else if (Break()) { if (!saw_eol) { - throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1916,7 +1918,7 @@ namespace chaiscript } else if (Equation()) { if (!saw_eol) { - throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *filename); + throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename); } has_more = true; retval = true; @@ -1941,24 +1943,24 @@ namespace chaiscript } /** - * Parses the given input string, tagging parsed ast_nodes with the given filename. + * Parses the given input string, tagging parsed ast_nodes with the given m_filename. */ - bool parse(const std::string &input, const std::string &fname) { - input_pos = input.begin(); - input_end = input.end(); - line = 1; - col = 1; - filename = boost::shared_ptr(new std::string(fname)); + bool parse(const std::string &t_input, const std::string &t_fname) { + m_input_pos = t_input.begin(); + m_input_end = t_input.end(); + m_line = 1; + m_col = 1; + m_filename = boost::shared_ptr(new std::string(t_fname)); - if ((input.size() > 1) && (input[0] == '#') && (input[1] == '!')) { - while ((input_pos != input_end) && (!Eol())) { - ++input_pos; + if ((t_input.size() > 1) && (t_input[0] == '#') && (t_input[1] == '!')) { + while ((m_input_pos != m_input_end) && (!Eol())) { + ++m_input_pos; } } if (Statements()) { - if (input_pos != input_end) { - throw Eval_Error("Unparsed input", File_Position(line, col), fname); + if (m_input_pos != m_input_end) { + throw Eval_Error("Unparsed input", File_Position(m_line, m_col), t_fname); } else { build_match(AST_NodePtr(new File_AST_Node()), 0); diff --git a/unittests/use.chai b/unittests/use.chai index 67dd933..efd587d 100644 --- a/unittests/use.chai +++ b/unittests/use.chai @@ -2,3 +2,8 @@ use("use.inc") assert_equal("hello", greet()) +// Include it a second time and see if there are any errors +use("use.inc") + +assert_equal("hello", greet()) + diff --git a/unittests/use.inc b/unittests/use.inc index 5a0dd99..204cec4 100644 --- a/unittests/use.inc +++ b/unittests/use.inc @@ -1,3 +1,4 @@ def greet { return("hello") } +