diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b6ccd4..20efbc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,8 @@ target_link_libraries(reflection ${LIBS}) file(GLOB UNIT_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/unittests/ ${CMAKE_CURRENT_SOURCE_DIR}/unittests/*.chai) +list(SORT UNIT_TESTS) + IF(BUILD_TESTING) option(UNIT_TEST_LIGHT "Unit tests light (expect module loading failures)" FALSE) diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index fba22b8..f14f421 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -63,35 +63,22 @@ namespace chaiscript struct AST_Node { std::string text; int identifier; - const char *filename; + boost::shared_ptr filename; File_Position start, end; - /* - bool is_cached; - Boxed_Value cached_value; - */ std::vector children; AST_NodePtr annotation; - AST_Node(const std::string &ast_node_text, int id, const char *fname, int start_line, int start_col, int end_line, int end_col) : - text(ast_node_text), identifier(id), filename(fname)/*, is_cached(false)*/ { - - start.line = start_line; - start.column = start_col; - end.line = end_line; - end.column = end_col; + 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 &ast_node_text, int id, const char *fname) : - text(ast_node_text), identifier(id), filename(fname)/*, is_cached(false)*/ { } + + AST_Node(const std::string &ast_node_text, int id, const boost::shared_ptr &fname) : + text(ast_node_text), identifier(id), filename(fname) {} virtual ~AST_Node() {} - /* - void cache_const(const Boxed_Value &value) { - this->cached_value = value; - this->is_cached = true; - } - */ - /** * Prints the contents of an AST node, including its children, recursively */ @@ -127,12 +114,12 @@ namespace chaiscript std::string reason; File_Position start_position; File_Position end_position; - const char *filename; + std::string filename; std::vector call_stack; - Eval_Error(const std::string &why, const File_Position &where, const char *fname) : + Eval_Error(const std::string &why, const File_Position &where, const std::string &fname) : std::runtime_error("Error: \"" + why + "\" " + - (std::string(fname) != "__EVAL__" ? ("in '" + std::string(fname) + "' ") : "during evaluation ") + + (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) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 1c132c2..3c352c4 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -236,10 +236,10 @@ namespace chaiscript /** * 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 &input, const std::string &filename = "__EVAL__", bool /* internal*/ = false) + { ChaiScript_Parser parser; - //debug_print(ast_nodes); Boxed_Value value; @@ -248,29 +248,29 @@ namespace chaiscript // around and copying strings // if (filename != "__EVAL__") - { + { #ifndef CHAISCRIPT_NO_THREADS - boost::unique_lock l(mutex); + boost::unique_lock l(mutex); #endif - loaded_files.insert(filename); - try { - if (parser.parse(input, loaded_files.find(filename)->c_str())) { + loaded_files.insert(filename); + try { + if (parser.parse(input, *(loaded_files.find(filename)))) { #ifndef CHAISCRIPT_NO_THREADS - l.unlock(); + l.unlock(); #endif - //parser.show_match_stack(); - value = parser.ast()->eval(engine);//eval_ast_node(engine, parser.ast()); - } + //parser.show_match_stack(); + value = parser.ast()->eval(engine);//eval_ast_node(engine, parser.ast()); } - catch (const Return_Value &rv) { - value = rv.retval; - } - } else { + } + catch (const Return_Value &rv) { + value = rv.retval; + } + } else { try { #ifndef CHAISCRIPT_NO_THREADS boost::shared_lock l(mutex); #endif - const char *fname = loaded_files.find("__EVAL__")->c_str(); + std::string fname = *(loaded_files.find("__EVAL__")); #ifndef CHAISCRIPT_NO_THREADS l.unlock(); #endif @@ -339,16 +339,17 @@ namespace chaiscript public: ChaiScript_System(const std::vector &t_modulepaths = std::vector(), const std::vector &t_usepaths = std::vector()) - : modulepaths(t_modulepaths), usepaths(t_usepaths) { + : modulepaths(t_modulepaths), usepaths(t_usepaths) + { if (modulepaths.empty()) - { - modulepaths.push_back(""); - } + { + modulepaths.push_back(""); + } if (usepaths.empty()) - { - usepaths.push_back(""); - } + { + usepaths.push_back(""); + } loaded_files.insert("__EVAL__"); // Make sure the default name is already registered build_eval_system(); @@ -538,13 +539,11 @@ namespace chaiscript std::streampos size = infile.tellg(); infile.seekg(0, std::ios::beg); - assert(size >= 0); + assert(size >= 0); std::vector v(static_cast(size)); infile.read(&v[0], size); - std::string ret_val (v.empty() ? std::string() : std::string (v.begin(), v.end()).c_str()); - - return ret_val; + return std::string(v.begin(), v.end()); } /** diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index e0f1836..1aff7e2 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -44,7 +44,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Binary_Operator_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -78,7 +78,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Error_AST_Node() {} @@ -86,7 +86,7 @@ namespace chaiscript struct Int_AST_Node : public AST_Node { public: - Int_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Int, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Int_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ @@ -97,7 +97,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Float_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ @@ -108,7 +108,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Id_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -137,28 +137,28 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Fun_Call_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -213,7 +213,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Inplace_Fun_Call_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -258,21 +258,21 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Equation_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -348,7 +348,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Var_Decl_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -365,28 +365,28 @@ namespace chaiscript 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Array_Call_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -422,7 +422,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Dot_Access_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -508,7 +508,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Quoted_String_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ @@ -519,7 +519,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Single_Quoted_String_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ @@ -530,7 +530,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Lambda_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -558,7 +558,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Block_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -598,7 +598,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Def_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -652,7 +652,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~While_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -707,7 +707,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~If_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -778,7 +778,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~For_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -889,7 +889,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Inline_Array_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -913,7 +913,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Inline_Map_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -940,7 +940,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Return_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -962,7 +962,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~File_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss) { @@ -985,7 +985,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Prefix_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -1001,7 +1001,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Break_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &){ @@ -1011,21 +1011,21 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Inline_Range_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -1047,14 +1047,14 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Try_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -1282,21 +1282,21 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Method_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -1373,7 +1373,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Attr_Decl_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -1392,42 +1392,42 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Logical_And_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ @@ -1469,7 +1469,7 @@ 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 char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : + 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) { } virtual ~Logical_Or_AST_Node() {} virtual Boxed_Value eval(Dispatch_Engine &ss){ diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 1c16e2d..ab88bf3 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -23,7 +23,7 @@ namespace chaiscript int line, col; std::string multiline_comment_begin, multiline_comment_end; std::string singleline_comment; - const char *filename; + boost::shared_ptr filename; std::vector match_stack; std::vector > operator_matches; @@ -457,7 +457,7 @@ namespace chaiscript while (has_more_input() && (*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(line, col), *filename); } else { ++input_pos; @@ -466,10 +466,10 @@ namespace chaiscript } if (start == input_pos) { - throw Eval_Error("Missing contents of identifier literal", File_Position(line, col), filename); + throw Eval_Error("Missing contents of identifier literal", File_Position(line, col), *filename); } else if (input_pos == input_end) { - throw Eval_Error("Incomplete identifier literal", File_Position(line, col), filename); + throw Eval_Error("Incomplete identifier literal", File_Position(line, col), *filename); } ++col; @@ -573,7 +573,7 @@ namespace chaiscript ++col; } else { - throw Eval_Error("Unclosed quoted string", File_Position(line, col), filename); + throw Eval_Error("Unclosed quoted string", File_Position(line, col), *filename); } } return retval; @@ -665,7 +665,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), *filename); } } else { @@ -694,7 +694,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), *filename); } } else if (*s == '$') { @@ -759,7 +759,7 @@ namespace chaiscript ++col; } else { - throw Eval_Error("Unclosed single-quoted string", File_Position(line, col), filename); + throw Eval_Error("Unclosed single-quoted string", File_Position(line, col), *filename); } } return retval; @@ -801,7 +801,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), *filename); } } else { @@ -868,7 +868,7 @@ namespace chaiscript if ((input_end - input_pos) >= len) { std::string::const_iterator tmp = input_pos; - for (size_t i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { if (*tmp != s[i]) { return false; } @@ -1069,7 +1069,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(line, col), *filename); } } while (retval && Char(',')); } @@ -1098,7 +1098,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(line, col), *filename); } } while (retval && Char(',')); } @@ -1111,7 +1111,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(line, col), *filename); } } while (retval && Char(',')); } @@ -1136,14 +1136,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(line, col), *filename); } } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete anonymous function", File_Position(line, col), filename); + throw Eval_Error("Incomplete anonymous function", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Lambda_AST_Node()), prev_stack_top); @@ -1174,7 +1174,7 @@ namespace chaiscript 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(line, col), *filename); } if (Symbol("::", false)) { @@ -1182,14 +1182,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(line, col), *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(line, col), *filename); } } @@ -1197,13 +1197,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(line, col), *filename); } } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete function definition", File_Position(line, col), filename); + throw Eval_Error("Incomplete function definition", File_Position(line, col), *filename); } if (is_method) { @@ -1235,7 +1235,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(line, col), *filename); } bool has_matches = true; @@ -1246,11 +1246,11 @@ namespace chaiscript size_t catch_stack_top = 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(line, col), *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(line, col), *filename); } } } @@ -1258,7 +1258,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(line, col), *filename); } build_match(AST_NodePtr(new Catch_AST_Node()), catch_stack_top); has_matches = true; @@ -1271,7 +1271,7 @@ namespace chaiscript while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'finally' block", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'finally' block", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Finally_AST_Node()), finally_stack_top); } @@ -1294,17 +1294,17 @@ namespace chaiscript retval = true; if (!Char('(')) { - throw Eval_Error("Incomplete 'if' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'if' expression", File_Position(line, col), *filename); } if (!(Operator() && Char(')'))) { - throw Eval_Error("Incomplete 'if' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'if' expression", File_Position(line, col), *filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'if' block", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'if' block", File_Position(line, col), *filename); } bool has_matches = true; @@ -1315,17 +1315,17 @@ namespace chaiscript if (Keyword("if")) { 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(line, col), *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(line, col), *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(line, col), *filename); } has_matches = true; } @@ -1333,7 +1333,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(line, col), *filename); } has_matches = true; } @@ -1358,17 +1358,17 @@ namespace chaiscript retval = true; if (!Char('(')) { - throw Eval_Error("Incomplete 'while' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'while' expression", File_Position(line, col), *filename); } if (!(Operator() && Char(')'))) { - throw Eval_Error("Incomplete 'while' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'while' expression", File_Position(line, col), *filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'while' block", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'while' block", File_Position(line, col), *filename); } build_match(AST_NodePtr(new While_AST_Node()), prev_stack_top); @@ -1387,7 +1387,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(line, col), *filename); } } @@ -1403,17 +1403,17 @@ namespace chaiscript retval = true; if (!Char('(')) { - throw Eval_Error("Incomplete 'for' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'for' expression", File_Position(line, col), *filename); } if (!(For_Guards() && Char(')'))) { - throw Eval_Error("Incomplete 'for' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'for' expression", File_Position(line, col), *filename); } while (Eol()) {} if (!Block()) { - throw Eval_Error("Incomplete 'for' block", File_Position(line, col), filename); + throw Eval_Error("Incomplete 'for' block", File_Position(line, col), *filename); } build_match(AST_NodePtr(new For_AST_Node()), prev_stack_top); @@ -1435,7 +1435,7 @@ namespace chaiscript Statements(); if (!Char('}')) { - throw Eval_Error("Incomplete block", File_Position(line, col), filename); + throw Eval_Error("Incomplete block", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Block_AST_Node()), prev_stack_top); @@ -1499,7 +1499,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(line, col), *filename); } build_match(AST_NodePtr(new Fun_Call_AST_Node()), prev_stack_top); @@ -1508,7 +1508,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(line, col), *filename); } build_match(AST_NodePtr(new Array_Call_AST_Node()), prev_stack_top); @@ -1531,7 +1531,7 @@ namespace chaiscript retval = true; if (!Id(true)) { - throw Eval_Error("Incomplete variable declaration", File_Position(line, col), filename); + throw Eval_Error("Incomplete variable declaration", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Var_Decl_AST_Node()), prev_stack_top); @@ -1540,13 +1540,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(line, col), *filename); } if (!Symbol("::", false)) { - throw Eval_Error("Incomplete attribute declaration", File_Position(line, col), filename); + throw Eval_Error("Incomplete attribute declaration", File_Position(line, col), *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(line, col), *filename); } @@ -1565,10 +1565,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(line, col), *filename); } if (!Char(')')) { - throw Eval_Error("Missing closing parenthesis", File_Position(line, col), filename); + throw Eval_Error("Missing closing parenthesis", File_Position(line, col), *filename); } } return retval; @@ -1586,7 +1586,7 @@ namespace chaiscript 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(line, col), *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) { @@ -1619,7 +1619,7 @@ namespace chaiscript retval = true; if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '++' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete '++' expression", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1628,7 +1628,7 @@ namespace chaiscript retval = true; if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '--' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete '--' expression", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1637,7 +1637,7 @@ namespace chaiscript retval = true; if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete unary '-' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete unary '-' expression", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1646,7 +1646,7 @@ namespace chaiscript retval = true; if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete unary '+' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete unary '+' expression", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1655,7 +1655,7 @@ namespace chaiscript retval = true; if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '!' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete '!' expression", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1664,7 +1664,7 @@ namespace chaiscript retval = true; if (!Operator(operators.size()-1)) { - throw Eval_Error("Incomplete '~' expression", File_Position(line, col), filename); + throw Eval_Error("Incomplete '~' expression", File_Position(line, col), *filename); } build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); @@ -1707,7 +1707,7 @@ namespace chaiscript do { if (!Operator(precedence+1)) { throw Eval_Error("Incomplete " + std::string(ast_node_type_to_string(operators[precedence])) + " expression", - File_Position(line, col), filename); + File_Position(line, col), *filename); } } while (Operator_Helper(precedence)); @@ -1746,7 +1746,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(line, col), *filename); } } } @@ -1772,7 +1772,7 @@ namespace chaiscript 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(line, col), *filename); } build_match(AST_NodePtr(new Map_Pair_AST_Node()), prev_stack_top); @@ -1803,7 +1803,7 @@ namespace chaiscript 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(line, col), *filename); } build_match(AST_NodePtr(new Value_Range_AST_Node()), prev_stack_top); @@ -1835,7 +1835,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(line, col), *filename); } build_match(AST_NodePtr(new Equation_AST_Node()), prev_stack_top); @@ -1860,7 +1860,7 @@ namespace chaiscript int prev_col = 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), *filename); } has_more = true; retval = true; @@ -1868,7 +1868,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), *filename); } has_more = true; retval = true; @@ -1876,7 +1876,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), *filename); } has_more = true; retval = true; @@ -1884,7 +1884,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), *filename); } has_more = true; retval = true; @@ -1892,7 +1892,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), *filename); } has_more = true; retval = true; @@ -1900,7 +1900,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), *filename); } has_more = true; retval = true; @@ -1908,7 +1908,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), *filename); } has_more = true; retval = true; @@ -1916,7 +1916,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), *filename); } has_more = true; retval = true; @@ -1943,11 +1943,12 @@ namespace chaiscript /** * Parses the given input string, tagging parsed ast_nodes with the given filename. */ - bool parse(const std::string &input, const char *fname) { + bool parse(const std::string &input, const std::string &fname) { input_pos = input.begin(); input_end = input.end(); - line = 1; col = 1; - filename = fname; + line = 1; + col = 1; + filename = boost::shared_ptr(new std::string(fname)); if ((input.size() > 1) && (input[0] == '#') && (input[1] == '!')) { while ((input_pos != input_end) && (!Eol())) { diff --git a/src/reflection.cpp b/src/reflection.cpp index 18fae77..ad87148 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -27,7 +27,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect CHAISCRIPT_CLASS( m, chaiscript::AST_Node, - (chaiscript::AST_Node (const std::string &, int, char *)), + (chaiscript::AST_Node (const std::string &, int, const boost::shared_ptr &)), ((text)) ((identifier)) ((filename)) diff --git a/unittests/empty.chai b/unittests/empty.chai new file mode 100644 index 0000000..e69de29 diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index e12f31d..a9f9472 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -1,7 +1,6 @@ load_module("reflection") -var fname = "INPUT" var parser := ChaiScript_Parser() -var parse_success = parser.parse("3 + 4", fname.c_str()) +var parse_success = parser.parse("3 + 4", "INPUT") var a := parser.ast() assert_equal(eval(a), 7) @@ -12,3 +11,4 @@ var node := childs[0] node.text = "9" assert_equal(eval(a), 13) +assert_equal(node.filename, "INPUT")