diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 5c1c9b5..ff90cd1 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -16,7 +16,7 @@ namespace chaiscript /** * Types of AST nodes available to the parser and eval */ - class Token_Type { + class AST_Node_Type { public: enum Type { Error, Int, Float, Id, Char, Str, Eol, Fun_Call, Inplace_Fun_Call, Arg_List, Variable, Equation, Var_Decl, Comparison, Additive, Multiplicative, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String, @@ -31,14 +31,14 @@ namespace chaiscript /** * Helper lookup to get the name of each node type */ - const char *token_type_to_string(int tokentype) { - const char *token_types[] = { "Internal Parser Error", "Int", "Float", "Id", "Char", "Str", "Eol", "Fun_Call", "Inplace_Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl", + const char *ast_node_type_to_string(int ast_node_type) { + const char *ast_node_types[] = { "Internal Parser Error", "Int", "Float", "Id", "Char", "Str", "Eol", "Fun_Call", "Inplace_Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl", "Comparison", "Additive", "Multiplicative", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String", "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Map_Pair", "Value_Range", "Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or", "Logical_And", "Logical_Or"}; - return token_types[tokentype]; + return ast_node_types[ast_node_type]; } } @@ -55,12 +55,12 @@ namespace chaiscript File_Position() : line(0), column(0) { } }; - typedef boost::shared_ptr TokenPtr; + typedef boost::shared_ptr AST_NodePtr; /** - * The struct that doubles as both a parser token and an AST node + * The struct that doubles as both a parser ast_node and an AST node */ - struct Token { + struct AST_Node { std::string text; int identifier; char *filename; @@ -68,19 +68,19 @@ namespace chaiscript bool is_cached; Boxed_Value cached_value; - std::vector children; - TokenPtr annotation; + std::vector children; + AST_NodePtr annotation; - Token(const std::string &token_text, int id, char *fname, int start_line, int start_col, int end_line, int end_col) : - text(token_text), identifier(id), filename(fname), is_cached(false) { + AST_Node(const std::string &ast_node_text, int id, 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; } - Token(const std::string &token_text, int id, char *fname) : - text(token_text), identifier(id), filename(fname), is_cached(false) { } + AST_Node(const std::string &ast_node_text, int id, char *fname) : + text(ast_node_text), identifier(id), filename(fname), is_cached(false) { } void cache_const(const Boxed_Value &value) { @@ -90,286 +90,286 @@ namespace chaiscript virtual Boxed_Value eval(Dispatch_Engine &) { Boxed_Value bv; - throw std::runtime_error("Undispatched token (internal error)"); + throw std::runtime_error("Undispatched ast_node (internal error)"); return bv; } }; - struct Error_Token : public Token { + struct Error_AST_Node : public AST_Node { public: - Error_Token(const std::string &token_text = "", int id = Token_Type::Error, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Error_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Error, char *fname = NULL, 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) { } }; - struct Int_Token : public Token { + struct Int_AST_Node : public AST_Node { public: - Int_Token(const std::string &token_text = "", int id = Token_Type::Int, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Int_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Int, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Float_Token : public Token { + struct Float_AST_Node : public AST_Node { public: - Float_Token(const std::string &token_text = "", int id = Token_Type::Float, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Float_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Float, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Id_Token : public Token { + struct Id_AST_Node : public AST_Node { public: - Id_Token(const std::string &token_text = "", int id = Token_Type::Id, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Id_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Id, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Char_Token : public Token { + struct Char_AST_Node : public AST_Node { public: - Char_Token(const std::string &token_text = "", int id = Token_Type::Char, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Char_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Char, char *fname = NULL, 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) { } }; - struct Str_Token : public Token { + struct Str_AST_Node : public AST_Node { public: - Str_Token(const std::string &token_text = "", int id = Token_Type::Str, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Str_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Str, char *fname = NULL, 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) { } }; - struct Eol_Token : public Token { + struct Eol_AST_Node : public AST_Node { public: - Eol_Token(const std::string &token_text = "", int id = Token_Type::Eol, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Eol_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Eol, char *fname = NULL, 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) { } }; - struct Fun_Call_Token : public Token { + struct Fun_Call_AST_Node : public AST_Node { public: - Fun_Call_Token(const std::string &token_text = "", int id = Token_Type::Fun_Call, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Fun_Call, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Inplace_Fun_Call_Token : public Token { + struct Inplace_Fun_Call_AST_Node : public AST_Node { public: - Inplace_Fun_Call_Token(const std::string &token_text = "", int id = Token_Type::Inplace_Fun_Call, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Inplace_Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inplace_Fun_Call, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Arg_List_Token : public Token { + struct Arg_List_AST_Node : public AST_Node { public: - Arg_List_Token(const std::string &token_text = "", int id = Token_Type::Arg_List, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Arg_List_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Arg_List, char *fname = NULL, 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) { } }; - struct Variable_Token : public Token { + struct Variable_AST_Node : public AST_Node { public: - Variable_Token(const std::string &token_text = "", int id = Token_Type::Variable, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Variable_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Variable, char *fname = NULL, 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) { } }; - struct Equation_Token : public Token { + struct Equation_AST_Node : public AST_Node { public: - Equation_Token(const std::string &token_text = "", int id = Token_Type::Equation, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Equation_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Equation, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Var_Decl_Token : public Token { + struct Var_Decl_AST_Node : public AST_Node { public: - Var_Decl_Token(const std::string &token_text = "", int id = Token_Type::Var_Decl, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Var_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Var_Decl, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Comparison_Token : public Token { + struct Comparison_AST_Node : public AST_Node { public: - Comparison_Token(const std::string &token_text = "", int id = Token_Type::Comparison, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Comparison_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Comparison, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Additive_Token : public Token { + struct Additive_AST_Node : public AST_Node { public: - Additive_Token(const std::string &token_text = "", int id = Token_Type::Additive, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Additive_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Additive, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Multiplicative_Token : public Token { + struct Multiplicative_AST_Node : public AST_Node { public: - Multiplicative_Token(const std::string &token_text = "", int id = Token_Type::Multiplicative, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Multiplicative_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Multiplicative, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Array_Call_Token : public Token { + struct Array_Call_AST_Node : public AST_Node { public: - Array_Call_Token(const std::string &token_text = "", int id = Token_Type::Array_Call, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Array_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Array_Call, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Dot_Access_Token : public Token { + struct Dot_Access_AST_Node : public AST_Node { public: - Dot_Access_Token(const std::string &token_text = "", int id = Token_Type::Dot_Access, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Dot_Access_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Dot_Access, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Quoted_String_Token : public Token { + struct Quoted_String_AST_Node : public AST_Node { public: - Quoted_String_Token(const std::string &token_text = "", int id = Token_Type::Quoted_String, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Quoted_String, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Single_Quoted_String_Token : public Token { + struct Single_Quoted_String_AST_Node : public AST_Node { public: - Single_Quoted_String_Token(const std::string &token_text = "", int id = Token_Type::Single_Quoted_String, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Single_Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Single_Quoted_String, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Lambda_Token : public Token { + struct Lambda_AST_Node : public AST_Node { public: - Lambda_Token(const std::string &token_text = "", int id = Token_Type::Lambda, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Lambda_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Lambda, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Block_Token : public Token { + struct Block_AST_Node : public AST_Node { public: - Block_Token(const std::string &token_text = "", int id = Token_Type::Block, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Block_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Block, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Def_Token : public Token { + struct Def_AST_Node : public AST_Node { public: - Def_Token(const std::string &token_text = "", int id = Token_Type::Def, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Def_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Def, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct While_Token : public Token { + struct While_AST_Node : public AST_Node { public: - While_Token(const std::string &token_text = "", int id = Token_Type::While, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + While_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::While, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct If_Token : public Token { + struct If_AST_Node : public AST_Node { public: - If_Token(const std::string &token_text = "", int id = Token_Type::If, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + If_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::If, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct For_Token : public Token { + struct For_AST_Node : public AST_Node { public: - For_Token(const std::string &token_text = "", int id = Token_Type::For, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + For_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::For, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Inline_Array_Token : public Token { + struct Inline_Array_AST_Node : public AST_Node { public: - Inline_Array_Token(const std::string &token_text = "", int id = Token_Type::Inline_Array, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Inline_Array_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Array, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Inline_Map_Token : public Token { + struct Inline_Map_AST_Node : public AST_Node { public: - Inline_Map_Token(const std::string &token_text = "", int id = Token_Type::Inline_Map, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Inline_Map_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Map, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Return_Token : public Token { + struct Return_AST_Node : public AST_Node { public: - Return_Token(const std::string &token_text = "", int id = Token_Type::Return, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Return_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Return, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct File_Token : public Token { + struct File_AST_Node : public AST_Node { public: - File_Token(const std::string &token_text = "", int id = Token_Type::File, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + File_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::File, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Prefix_Token : public Token { + struct Prefix_AST_Node : public AST_Node { public: - Prefix_Token(const std::string &token_text = "", int id = Token_Type::Prefix, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Prefix_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Prefix, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Break_Token : public Token { + struct Break_AST_Node : public AST_Node { public: - Break_Token(const std::string &token_text = "", int id = Token_Type::Break, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Break_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Break, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Map_Pair_Token : public Token { + struct Map_Pair_AST_Node : public AST_Node { public: - Map_Pair_Token(const std::string &token_text = "", int id = Token_Type::Map_Pair, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Map_Pair_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Map_Pair, char *fname = NULL, 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) { } }; - struct Value_Range_Token : public Token { + struct Value_Range_AST_Node : public AST_Node { public: - Value_Range_Token(const std::string &token_text = "", int id = Token_Type::Value_Range, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Value_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Value_Range, char *fname = NULL, 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) { } }; - struct Inline_Range_Token : public Token { + struct Inline_Range_AST_Node : public AST_Node { public: - Inline_Range_Token(const std::string &token_text = "", int id = Token_Type::Inline_Range, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Inline_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Range, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Annotation_Token : public Token { + struct Annotation_AST_Node : public AST_Node { public: - Annotation_Token(const std::string &token_text = "", int id = Token_Type::Annotation, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Annotation_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Annotation, char *fname = NULL, 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) { } }; - struct Try_Token : public Token { + struct Try_AST_Node : public AST_Node { public: - Try_Token(const std::string &token_text = "", int id = Token_Type::Try, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Try_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Try, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Catch_Token : public Token { + struct Catch_AST_Node : public AST_Node { public: - Catch_Token(const std::string &token_text = "", int id = Token_Type::Catch, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Catch_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Catch, char *fname = NULL, 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) { } }; - struct Finally_Token : public Token { + struct Finally_AST_Node : public AST_Node { public: - Finally_Token(const std::string &token_text = "", int id = Token_Type::Finally, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Finally_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Finally, char *fname = NULL, 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) { } }; - struct Method_Token : public Token { + struct Method_AST_Node : public AST_Node { public: - Method_Token(const std::string &token_text = "", int id = Token_Type::Method, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Method_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Method, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Attr_Decl_Token : public Token { + struct Attr_Decl_AST_Node : public AST_Node { public: - Attr_Decl_Token(const std::string &token_text = "", int id = Token_Type::Attr_Decl, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Attr_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Attr_Decl, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Shift_Token : public Token { + struct Shift_AST_Node : public AST_Node { public: - Shift_Token(const std::string &token_text = "", int id = Token_Type::Shift, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Shift_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Shift, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Equality_Token : public Token { + struct Equality_AST_Node : public AST_Node { public: - Equality_Token(const std::string &token_text = "", int id = Token_Type::Equality, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Equality_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Equality, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Bitwise_And_Token : public Token { + struct Bitwise_And_AST_Node : public AST_Node { public: - Bitwise_And_Token(const std::string &token_text = "", int id = Token_Type::Bitwise_And, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Bitwise_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_And, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Bitwise_Xor_Token : public Token { + struct Bitwise_Xor_AST_Node : public AST_Node { public: - Bitwise_Xor_Token(const std::string &token_text = "", int id = Token_Type::Bitwise_Xor, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Bitwise_Xor_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Xor, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Bitwise_Or_Token : public Token { + struct Bitwise_Or_AST_Node : public AST_Node { public: - Bitwise_Or_Token(const std::string &token_text = "", int id = Token_Type::Bitwise_Or, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Bitwise_Or_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Or, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Logical_And_Token : public Token { + struct Logical_And_AST_Node : public AST_Node { public: - Logical_And_Token(const std::string &token_text = "", int id = Token_Type::Logical_And, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Logical_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_And, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; - struct Logical_Or_Token : public Token { + struct Logical_Or_AST_Node : public AST_Node { public: - Logical_Or_Token(const std::string &token_text = "", int id = Token_Type::Logical_Or, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) : - Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } + Logical_Or_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_Or, char *fname = NULL, 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) { } Boxed_Value eval(Dispatch_Engine &ss); }; @@ -381,7 +381,7 @@ namespace chaiscript File_Position start_position; File_Position end_position; const char *filename; - std::vector call_stack; + std::vector call_stack; Eval_Error(const std::string &why, const File_Position &where, const char *fname) : std::runtime_error("Error: \"" + why + "\" " + diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 155074a..0167d0d 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -244,7 +244,7 @@ namespace chaiscript engine.sync_cache(); } - //debug_print(tokens); + //debug_print(ast_nodes); Boxed_Value value; // Keep a cache of all loaded filenames and use the char * from this cache to pass @@ -263,7 +263,7 @@ namespace chaiscript l.unlock(); #endif //parser.show_match_stack(); - value = parser.ast()->eval(engine);//eval_token(engine, parser.ast()); + value = parser.ast()->eval(engine);//eval_ast_node(engine, parser.ast()); } } catch (const Return_Value &rv) { @@ -518,8 +518,8 @@ namespace chaiscript /** * Prints the contents of an AST node, including its children, recursively */ - void debug_print(TokenPtr t, std::string prepend = "") { - std::cout << prepend << "(" << token_type_to_string(t->identifier) << ") " + void debug_print(AST_NodePtr t, std::string prepend = "") { + std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl; for (unsigned int j = 0; j < t->children.size(); ++j) { debug_print(t->children[j], prepend + " "); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 4775c1e..7598f32 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -17,7 +17,7 @@ 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 TokenPtr &node, const std::vector ¶m_names, const std::vector &vals) { + const Boxed_Value eval_function (Eval_System &ss, const AST_NodePtr &node, const std::vector ¶m_names, const std::vector &vals) { ss.new_scope(); for (unsigned int i = 0; i < param_names.size(); ++i) { @@ -44,7 +44,7 @@ namespace chaiscript /** * Evaluates the top-level file node */ - Boxed_Value File_Token::eval(Dispatch_Engine &ss) { + Boxed_Value File_AST_Node::eval(Dispatch_Engine &ss) { const unsigned int size = this->children.size(); for (unsigned int i = 0; i < size; ++i) { try { @@ -64,7 +64,7 @@ namespace chaiscript /** * Evaluates a variable or function name identifier */ - Boxed_Value Id_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Id_AST_Node::eval(Dispatch_Engine &ss) { if (this->text == "true") { if (!this->is_cached) { cache_const(const_var(true)); @@ -102,7 +102,7 @@ namespace chaiscript /** * Evaluates a floating point number */ - Boxed_Value Float_Token::eval(Dispatch_Engine &) { + Boxed_Value Float_AST_Node::eval(Dispatch_Engine &) { if (!this->is_cached) { cache_const(const_var(double(atof(this->text.c_str())))); } @@ -112,7 +112,7 @@ namespace chaiscript /** * Evaluates an integer */ - Boxed_Value Int_Token::eval(Dispatch_Engine &) { + Boxed_Value Int_AST_Node::eval(Dispatch_Engine &) { if (!this->is_cached) { cache_const(const_var(int(atoi(this->text.c_str())))); } @@ -122,7 +122,7 @@ namespace chaiscript /** * Evaluates a quoted string */ - Boxed_Value Quoted_String_Token::eval(Dispatch_Engine &) { + Boxed_Value Quoted_String_AST_Node::eval(Dispatch_Engine &) { //return const_var(node->text); /* @@ -144,7 +144,7 @@ namespace chaiscript * Evaluates a char group */ - Boxed_Value Single_Quoted_String_Token::eval(Dispatch_Engine &) { + Boxed_Value Single_Quoted_String_AST_Node::eval(Dispatch_Engine &) { if (!this->is_cached) { cache_const(const_var(char(this->text[0]))); } @@ -154,7 +154,7 @@ namespace chaiscript /** * Evaluates a string of equations in reverse order so that the right-most side has precedence */ - Boxed_Value Equation_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Equation_AST_Node::eval(Dispatch_Engine &ss) { int i; Boxed_Value retval; try { @@ -227,7 +227,7 @@ namespace chaiscript /** * Evaluates a variable declaration */ - Boxed_Value Var_Decl_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Var_Decl_AST_Node::eval(Dispatch_Engine &ss) { try { ss.add_object(this->children[0]->text, Boxed_Value()); } @@ -240,7 +240,7 @@ namespace chaiscript /** * Evaluates an attribute declaration */ - Boxed_Value Attr_Decl_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Attr_Decl_AST_Node::eval(Dispatch_Engine &ss) { try { ss.add(fun(boost::function(boost::bind(&Dynamic_Object_Attribute::func, this->children[0]->text, this->children[1]->text, _1))), this->children[1]->text); @@ -255,7 +255,7 @@ namespace chaiscript /** * Evaluates binary boolean operators. Respects short-circuiting rules. */ - Boxed_Value Logical_And_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Logical_And_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -293,7 +293,7 @@ namespace chaiscript return retval; } - Boxed_Value Logical_Or_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Logical_Or_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -334,7 +334,7 @@ namespace chaiscript /** * Evaluates comparison, additions, and multiplications and their relatives */ - Boxed_Value Bitwise_And_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Bitwise_And_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -361,7 +361,7 @@ namespace chaiscript return retval; } - Boxed_Value Bitwise_Xor_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Bitwise_Xor_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -388,7 +388,7 @@ namespace chaiscript return retval; } - Boxed_Value Bitwise_Or_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Bitwise_Or_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -415,7 +415,7 @@ namespace chaiscript return retval; } - Boxed_Value Additive_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Additive_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -442,7 +442,7 @@ namespace chaiscript return retval; } - Boxed_Value Multiplicative_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Multiplicative_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -469,7 +469,7 @@ namespace chaiscript return retval; } - Boxed_Value Comparison_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Comparison_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -496,7 +496,7 @@ namespace chaiscript return retval; } - Boxed_Value Equality_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Equality_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -523,7 +523,7 @@ namespace chaiscript return retval; } - Boxed_Value Shift_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Shift_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -554,7 +554,7 @@ namespace chaiscript /** * Evaluates an array lookup */ - Boxed_Value Array_Call_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Array_Call_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; Boxed_Value retval; @@ -588,7 +588,7 @@ namespace chaiscript /** * Evaluates any unary prefix */ - Boxed_Value Prefix_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Prefix_AST_Node::eval(Dispatch_Engine &ss) { try { return ss.call_function(this->children[0]->text, this->children[1]->eval(ss)); } @@ -600,7 +600,7 @@ namespace chaiscript /** * Evaluates (and generates) an inline array initialization */ - Boxed_Value Inline_Array_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Inline_Array_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; try { @@ -631,7 +631,7 @@ namespace chaiscript /** * Evaluates (and generates) an inline range initialization */ - Boxed_Value Inline_Range_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Inline_Range_AST_Node::eval(Dispatch_Engine &ss) { try { return ss.call_function("generate_range", this->children[0]->children[0]->children[0]->eval(ss), @@ -649,7 +649,7 @@ namespace chaiscript /** * Evaluates (and generates) an inline map initialization */ - Boxed_Value Inline_Map_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Inline_Map_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; try { @@ -678,13 +678,13 @@ namespace chaiscript /** * Evaluates a function call, starting with its arguments. Handles resetting the scope to the previous one after the call. */ - Boxed_Value Fun_Call_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Fun_Call_AST_Node::eval(Dispatch_Engine &ss) { Param_List_Builder plb; Dispatch_Engine::Stack prev_stack = ss.get_stack(); Dispatch_Engine::Stack new_stack = ss.new_stack(); unsigned int i; - if ((this->children.size() > 1) && (this->children[1]->identifier == Token_Type::Arg_List)) { + if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { for (i = 0; i < this->children[1]->children.size(); ++i) { try { plb << this->children[1]->children[i]->eval(ss); @@ -729,11 +729,11 @@ namespace chaiscript /** * Evaluates a function call, starting with its arguments. Does NOT change scope. */ - Boxed_Value Inplace_Fun_Call_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Inplace_Fun_Call_AST_Node::eval(Dispatch_Engine &ss) { Param_List_Builder plb; unsigned int i; - if ((this->children.size() > 1) && (this->children[1]->identifier == Token_Type::Arg_List)) { + if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { for (i = 0; i < this->children[1]->children.size(); ++i) { try { plb << this->children[1]->children[i]->eval(ss); @@ -771,7 +771,7 @@ namespace chaiscript /** * Evaluates a method/attributes invocation */ - Boxed_Value Dot_Access_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Dot_Access_AST_Node::eval(Dispatch_Engine &ss) { Dispatch_Engine::Stack prev_stack = ss.get_stack(); Dispatch_Engine::Stack new_stack = ss.new_stack(); unsigned int i, j; @@ -804,7 +804,7 @@ namespace chaiscript std::string fun_name; std::vector > funs; - if (this->children[i]->identifier == Token_Type::Fun_Call) { + if (this->children[i]->identifier == AST_Node_Type::Fun_Call) { fun_name = this->children[i]->children[0]->text; } else { @@ -837,7 +837,7 @@ namespace chaiscript /** * Evaluates an if/elseif/else block */ - Boxed_Value Try_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Try_AST_Node::eval(Dispatch_Engine &ss) { Boxed_Value retval; ss.new_scope(); @@ -846,7 +846,7 @@ namespace chaiscript } catch (Eval_Error &ee) { ee.call_stack.push_back(this->children[0]); - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { this->children.back()->children[0]->eval(ss); } @@ -863,11 +863,11 @@ namespace chaiscript Boxed_Value except = Boxed_Value(boost::ref(e)); unsigned int end_point = this->children.size(); - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { end_point = this->children.size() - 1; } for (unsigned int i = 1; i < end_point; ++i) { - TokenPtr catch_block = this->children[i]; + AST_NodePtr catch_block = this->children[i]; if (catch_block->children.size() == 1) { //No variable capture, no guards @@ -901,7 +901,7 @@ namespace chaiscript try { guard = boxed_cast(catch_block->children[1]->eval(ss)); } catch (const bad_boxed_cast &) { - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { this->children.back()->children[0]->eval(ss); } @@ -927,7 +927,7 @@ namespace chaiscript } } else { - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { this->children.back()->children[0]->eval(ss); } @@ -945,7 +945,7 @@ namespace chaiscript catch (Boxed_Value &bv) { Boxed_Value except = bv; for (unsigned int i = 1; i < this->children.size(); ++i) { - TokenPtr catch_block = this->children[i]; + AST_NodePtr catch_block = this->children[i]; if (catch_block->children.size() == 1) { //No variable capture, no guards @@ -981,7 +981,7 @@ namespace chaiscript guard = boxed_cast(catch_block->children[1]->eval(ss)); } catch (const bad_boxed_cast &) { - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { this->children.back()->children[0]->eval(ss); } @@ -1011,7 +1011,7 @@ namespace chaiscript } } else { - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { this->children.back()->children[0]->eval(ss); } @@ -1027,7 +1027,7 @@ namespace chaiscript } } catch (...) { - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { this->children.back()->children[0]->eval(ss); } @@ -1041,7 +1041,7 @@ namespace chaiscript throw; } - if (this->children.back()->identifier == Token_Type::Finally) { + if (this->children.back()->identifier == AST_Node_Type::Finally) { try { retval = this->children.back()->children[0]->eval(ss); } @@ -1060,7 +1060,7 @@ namespace chaiscript /** * Evaluates an if/elseif/else block */ - Boxed_Value If_Token::eval(Dispatch_Engine &ss) { + Boxed_Value If_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; bool cond; @@ -1129,7 +1129,7 @@ namespace chaiscript /** * Evaluates a while block */ - Boxed_Value While_Token::eval(Dispatch_Engine &ss) { + Boxed_Value While_AST_Node::eval(Dispatch_Engine &ss) { bool cond; ss.new_scope(); @@ -1180,7 +1180,7 @@ namespace chaiscript /** * Evaluates a for block, including the for's conditions, from left to right */ - Boxed_Value For_Token::eval(Dispatch_Engine &ss) { + Boxed_Value For_AST_Node::eval(Dispatch_Engine &ss) { bool cond; ss.new_scope(); @@ -1287,7 +1287,7 @@ namespace chaiscript /** * Evaluates a function definition */ - Boxed_Value Def_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Def_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; std::vector param_names; @@ -1295,9 +1295,9 @@ namespace chaiscript boost::shared_ptr guard; size_t numparams = 0; std::string function_name = this->children[0]->text; - TokenPtr guardnode; + AST_NodePtr guardnode; - if ((this->children.size() > 2) && (this->children[1]->identifier == Token_Type::Arg_List)) { + if ((this->children.size() > 2) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { numparams = this->children[1]->children.size(); for (i = 0; i < numparams; ++i) { param_names.push_back(this->children[1]->children[i]->text); @@ -1339,7 +1339,7 @@ namespace chaiscript /** * Evaluates a function definition */ - Boxed_Value Method_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Method_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; std::vector param_names; @@ -1348,12 +1348,12 @@ namespace chaiscript size_t numparams; std::string class_name = this->children[0]->text; std::string function_name = this->children[1]->text; - TokenPtr guardnode; + AST_NodePtr guardnode; //The first param of a method is always the implied this ptr. param_names.push_back("this"); - if ((this->children.size() > 3) && (this->children[2]->identifier == Token_Type::Arg_List)) { + if ((this->children.size() > 3) && (this->children[2]->identifier == AST_Node_Type::Arg_List)) { for (i = 0; i < this->children[2]->children.size(); ++i) { param_names.push_back(this->children[2]->children[i]->text); } @@ -1414,13 +1414,13 @@ namespace chaiscript /** * Evaluates a lambda (anonymous function) */ - Boxed_Value Lambda_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Lambda_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; std::vector param_names; size_t numparams = 0; - if ((this->children.size() > 0) && (this->children[0]->identifier == Token_Type::Arg_List)) { + if ((this->children.size() > 0) && (this->children[0]->identifier == AST_Node_Type::Arg_List)) { numparams = this->children[0]->children.size(); for (i = 0; i < numparams; ++i) { param_names.push_back(this->children[0]->children[i]->text); @@ -1440,7 +1440,7 @@ namespace chaiscript /** * Evaluates a scoped block. Handles resetting the scope after the block has completed. */ - Boxed_Value Block_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Block_AST_Node::eval(Dispatch_Engine &ss) { unsigned int i; unsigned int num_children = this->children.size(); @@ -1477,7 +1477,7 @@ namespace chaiscript /** * Evaluates a return statement */ - Boxed_Value Return_Token::eval(Dispatch_Engine &ss) { + Boxed_Value Return_AST_Node::eval(Dispatch_Engine &ss) { if (this->children.size() > 0) { try { throw Return_Value(this->children[0]->eval(ss)); @@ -1495,7 +1495,7 @@ namespace chaiscript /** * Evaluates a break statement */ - Boxed_Value Break_Token::eval(Dispatch_Engine &) { + Boxed_Value Break_AST_Node::eval(Dispatch_Engine &) { throw Break_Loop(); } } diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 2e05f62..8c1ba6d 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -25,10 +25,10 @@ namespace chaiscript std::string multiline_comment_begin, multiline_comment_end; std::string singleline_comment; char *filename; - std::vector match_stack; + std::vector match_stack; std::vector > operator_matches; - std::vector operators; + std::vector operators; public: ChaiScript_Parser() { @@ -45,73 +45,73 @@ namespace chaiscript void setup_operators() { using namespace boost::assign; - operators.push_back(Token_Type::Logical_Or); + operators.push_back(AST_Node_Type::Logical_Or); std::vector logical_or; logical_or += "||"; operator_matches.push_back(logical_or); - operators.push_back(Token_Type::Logical_And); + operators.push_back(AST_Node_Type::Logical_And); std::vector logical_and; logical_and += "&&"; operator_matches.push_back(logical_and); - operators.push_back(Token_Type::Bitwise_Or); + operators.push_back(AST_Node_Type::Bitwise_Or); std::vector bitwise_or; bitwise_or += "|"; operator_matches.push_back(bitwise_or); - operators.push_back(Token_Type::Bitwise_Xor); + operators.push_back(AST_Node_Type::Bitwise_Xor); std::vector bitwise_xor; bitwise_xor += "^"; operator_matches.push_back(bitwise_xor); - operators.push_back(Token_Type::Bitwise_And); + operators.push_back(AST_Node_Type::Bitwise_And); std::vector bitwise_and; bitwise_and += "&"; operator_matches.push_back(bitwise_and); - operators.push_back(Token_Type::Equality); + operators.push_back(AST_Node_Type::Equality); std::vector equality; equality += "==", "!="; operator_matches.push_back(equality); - operators.push_back(Token_Type::Comparison); + operators.push_back(AST_Node_Type::Comparison); std::vector comparison; comparison += "<", "<=", ">", ">="; operator_matches.push_back(comparison); - operators.push_back(Token_Type::Shift); + operators.push_back(AST_Node_Type::Shift); std::vector shift; shift += "<<", ">>"; operator_matches.push_back(shift); - operators.push_back(Token_Type::Additive); + operators.push_back(AST_Node_Type::Additive); std::vector additive; additive += "+", "-"; operator_matches.push_back(additive); - operators.push_back(Token_Type::Multiplicative); + operators.push_back(AST_Node_Type::Multiplicative); std::vector multiplicative; multiplicative += "*", "/", "%"; operator_matches.push_back(multiplicative); - operators.push_back(Token_Type::Dot_Access); + operators.push_back(AST_Node_Type::Dot_Access); std::vector dot_access; dot_access += "."; operator_matches.push_back(dot_access); } /** - * Prints the parsed tokens as a tree + * Prints the parsed ast_nodes as a tree */ - void debug_print(TokenPtr t, std::string prepend = "") { - std::cout << prepend << "(" << token_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl; + void debug_print(AST_NodePtr t, std::string prepend = "") { + std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl; for (unsigned int j = 0; j < t->children.size(); ++j) { debug_print(t->children[j], prepend + " "); } } /** - * Shows the current stack of matched tokens + * Shows the current stack of matched ast_nodes */ void show_match_stack() { for (unsigned int i = 0; i < match_stack.size(); ++i) { @@ -120,7 +120,7 @@ namespace chaiscript } /** - * Clears the stack of matched tokens + * Clears the stack of matched ast_nodes */ void clear_match_stack() { match_stack.clear(); @@ -129,14 +129,14 @@ namespace chaiscript /** * Returns the front-most AST node */ - TokenPtr ast() { + AST_NodePtr ast() { return match_stack.front(); } /** - * Helper function that collects tokens from a starting position to the top of the stack into a new AST node + * Helper function that collects ast_nodes from a starting position to the top of the stack into a new AST node */ - void build_match(TokenPtr t, int match_start) { + void build_match(AST_NodePtr t, int match_start) { int pos_line_start, pos_col_start, pos_line_stop, pos_col_stop; int is_deep = false; @@ -167,7 +167,7 @@ namespace chaiscript match_stack.push_back(t); } else { - //todo: fix the fact that a successful match that captured no tokens doesn't have any real start position + //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); } } @@ -370,7 +370,7 @@ namespace chaiscript std::ostringstream out_int; out_int << int(temp_int); - TokenPtr t(new Int_Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col)); + 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); return true; } @@ -389,13 +389,13 @@ namespace chaiscript std::ostringstream out_int; out_int << temp_int; - TokenPtr t(new Int_Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col)); + 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); return true; } if (Float_()) { std::string match(start, input_pos); - TokenPtr t(new Float_Token(match, Token_Type::Float, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Float_AST_Node(match, AST_Node_Type::Float, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -408,11 +408,11 @@ namespace chaiscript std::ostringstream out_int; out_int << int(temp_int); - TokenPtr t(new Int_Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col)); + 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); } else { - TokenPtr t(new Int_Token(match, Token_Type::Int, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Int_AST_Node(match, AST_Node_Type::Int, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); } return true; @@ -483,13 +483,13 @@ namespace chaiscript if (*start == '`') { //Id Literal std::string match(start+1, input_pos-1); - TokenPtr t(new Id_Token(match, Token_Type::Id, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } else { std::string match(start, input_pos); - TokenPtr t(new Id_Token(match, Token_Type::Id, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -522,7 +522,7 @@ namespace chaiscript } while (Symbol("#")); std::string match(start, input_pos); - TokenPtr t(new Annotation_Token(match, Token_Type::Annotation, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Annotation_AST_Node(match, AST_Node_Type::Annotation, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -597,23 +597,23 @@ namespace chaiscript if (is_interpolated) { //If we've seen previous interpolation, add on instead of making a new one - TokenPtr plus(new Str_Token("+", Token_Type::Str, filename, prev_line, prev_col, line, col)); + AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); match_stack.push_back(plus); - TokenPtr t(new Quoted_String_Token(match, Token_Type::Quoted_String, filename, prev_line, prev_col, line, col)); + 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); - build_match(TokenPtr(new Additive_Token()), prev_stack_top); + build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); } else { - TokenPtr t(new Quoted_String_Token(match, Token_Type::Quoted_String, filename, prev_line, prev_col, line, col)); + 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); } //We've finished with the part of the string up to this point, so clear it match = ""; - TokenPtr plus(new Str_Token("+", Token_Type::Str, filename, prev_line, prev_col, line, col)); + AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); match_stack.push_back(plus); std::string eval_match; @@ -629,28 +629,28 @@ namespace chaiscript int tostr_stack_top = match_stack.size(); - TokenPtr tostr(new Id_Token("to_string", Token_Type::Id, filename, prev_line, prev_col, line, col)); + 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); int ev_stack_top = match_stack.size(); - TokenPtr ev(new Id_Token("eval", Token_Type::Id, filename, prev_line, prev_col, line, col)); + AST_NodePtr ev(new Id_AST_Node("eval", AST_Node_Type::Id, filename, prev_line, prev_col, line, col)); match_stack.push_back(ev); int arg_stack_top = match_stack.size(); - TokenPtr t(new Quoted_String_Token(eval_match, Token_Type::Quoted_String, filename, prev_line, prev_col, line, col)); + 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); - build_match(TokenPtr(new Arg_List_Token()), arg_stack_top); + build_match(AST_NodePtr(new Arg_List_AST_Node()), arg_stack_top); - build_match(TokenPtr(new Inplace_Fun_Call_Token()), ev_stack_top); + build_match(AST_NodePtr(new Inplace_Fun_Call_AST_Node()), ev_stack_top); - build_match(TokenPtr(new Arg_List_Token()), ev_stack_top); + build_match(AST_NodePtr(new Arg_List_AST_Node()), ev_stack_top); - build_match(TokenPtr(new Fun_Call_Token()), tostr_stack_top); + build_match(AST_NodePtr(new Fun_Call_AST_Node()), tostr_stack_top); - build_match(TokenPtr(new Additive_Token()), prev_stack_top); + 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); @@ -697,16 +697,16 @@ namespace chaiscript } } if (is_interpolated) { - TokenPtr plus(new Str_Token("+", Token_Type::Str, filename, prev_line, prev_col, line, col)); + AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); match_stack.push_back(plus); - TokenPtr t(new Quoted_String_Token(match, Token_Type::Quoted_String, filename, prev_line, prev_col, line, col)); + 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); - build_match(TokenPtr(new Additive_Token()), prev_stack_top); + build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); } else { - TokenPtr t(new Quoted_String_Token(match, Token_Type::Quoted_String, filename, prev_line, prev_col, line, col)); + 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); } return true; @@ -798,7 +798,7 @@ namespace chaiscript is_escaped = false; } } - TokenPtr t(new Single_Quoted_String_Token(match, Token_Type::Single_Quoted_String, filename, prev_line, prev_col, line, col)); + 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); return true; } @@ -837,7 +837,7 @@ namespace chaiscript int prev_line = line; if (Char_(c)) { std::string match(start, input_pos); - TokenPtr t(new Char_Token(match, Token_Type::Char, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Char_AST_Node(match, AST_Node_Type::Char, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -910,7 +910,7 @@ namespace chaiscript return false; } std::string match(start, input_pos); - TokenPtr t(new Str_Token(match, Token_Type::Str, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -988,7 +988,7 @@ namespace chaiscript } else { std::string match(start, input_pos); - TokenPtr t(new Str_Token(match, Token_Type::Str, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -1032,7 +1032,7 @@ namespace chaiscript int prev_line = line; if (Eol_()) { std::string match(start, input_pos); - TokenPtr t(new Eol_Token(match, Token_Type::Eol, filename, prev_line, prev_col, line, col)); + AST_NodePtr t(new Eol_AST_Node(match, AST_Node_Type::Eol, filename, prev_line, prev_col, line, col)); match_stack.push_back(t); return true; } @@ -1061,7 +1061,7 @@ namespace chaiscript } } while (retval && Char(',')); } - build_match(TokenPtr(new Arg_List_Token()), prev_stack_top); + build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); } return retval; @@ -1077,7 +1077,7 @@ namespace chaiscript if (Value_Range()) { retval = true; - build_match(TokenPtr(new Arg_List_Token()), prev_stack_top); + build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); } else if (Map_Pair()) { retval = true; @@ -1090,7 +1090,7 @@ namespace chaiscript } } while (retval && Char(',')); } - build_match(TokenPtr(new Arg_List_Token()), prev_stack_top); + build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); } return retval; @@ -1121,7 +1121,7 @@ namespace chaiscript throw Eval_Error("Incomplete anonymous function", File_Position(line, col), filename); } - build_match(TokenPtr(new Lambda_Token()), prev_stack_top); + build_match(AST_NodePtr(new Lambda_AST_Node()), prev_stack_top); } return retval; @@ -1134,7 +1134,7 @@ namespace chaiscript bool retval = false; bool is_annotated = false; bool is_method = false; - TokenPtr annotation; + AST_NodePtr annotation; if (Annotation()) { while (Eol_()) {} @@ -1182,10 +1182,10 @@ namespace chaiscript } if (is_method) { - build_match(TokenPtr(new Method_Token()), prev_stack_top); + build_match(AST_NodePtr(new Method_AST_Node()), prev_stack_top); } else { - build_match(TokenPtr(new Def_Token()), prev_stack_top); + build_match(AST_NodePtr(new Def_AST_Node()), prev_stack_top); } if (is_annotated) { @@ -1235,7 +1235,7 @@ namespace chaiscript if (!Block()) { throw Eval_Error("Incomplete 'catch' block", File_Position(line, col), filename); } - build_match(TokenPtr(new Catch_Token()), catch_stack_top); + build_match(AST_NodePtr(new Catch_AST_Node()), catch_stack_top); has_matches = true; } } @@ -1248,10 +1248,10 @@ namespace chaiscript if (!Block()) { throw Eval_Error("Incomplete 'finally' block", File_Position(line, col), filename); } - build_match(TokenPtr(new Finally_Token()), finally_stack_top); + build_match(AST_NodePtr(new Finally_AST_Node()), finally_stack_top); } - build_match(TokenPtr(new Try_Token()), prev_stack_top); + build_match(AST_NodePtr(new Try_AST_Node()), prev_stack_top); } return retval; @@ -1315,7 +1315,7 @@ namespace chaiscript } } - build_match(TokenPtr(new If_Token()), prev_stack_top); + build_match(AST_NodePtr(new If_AST_Node()), prev_stack_top); } return retval; @@ -1346,7 +1346,7 @@ namespace chaiscript throw Eval_Error("Incomplete 'while' block", File_Position(line, col), filename); } - build_match(TokenPtr(new While_Token()), prev_stack_top); + build_match(AST_NodePtr(new While_AST_Node()), prev_stack_top); } return retval; @@ -1391,7 +1391,7 @@ namespace chaiscript throw Eval_Error("Incomplete 'for' block", File_Position(line, col), filename); } - build_match(TokenPtr(new For_Token()), prev_stack_top); + build_match(AST_NodePtr(new For_AST_Node()), prev_stack_top); } return retval; @@ -1413,7 +1413,7 @@ namespace chaiscript throw Eval_Error("Incomplete block", File_Position(line, col), filename); } - build_match(TokenPtr(new Block_Token()), prev_stack_top); + build_match(AST_NodePtr(new Block_AST_Node()), prev_stack_top); } return retval; @@ -1431,7 +1431,7 @@ namespace chaiscript retval = true; Operator(); - build_match(TokenPtr(new Return_Token()), prev_stack_top); + build_match(AST_NodePtr(new Return_AST_Node()), prev_stack_top); } return retval; @@ -1448,7 +1448,7 @@ namespace chaiscript if (Keyword("break")) { retval = true; - build_match(TokenPtr(new Break_Token()), prev_stack_top); + build_match(AST_NodePtr(new Break_AST_Node()), prev_stack_top); } return retval; @@ -1477,7 +1477,7 @@ namespace chaiscript throw Eval_Error("Incomplete function call", File_Position(line, col), filename); } - build_match(TokenPtr(new Fun_Call_Token()), prev_stack_top); + build_match(AST_NodePtr(new Fun_Call_AST_Node()), prev_stack_top); } else if (Char('[')) { has_more = true; @@ -1486,7 +1486,7 @@ namespace chaiscript throw Eval_Error("Incomplete array access", File_Position(line, col), filename); } - build_match(TokenPtr(new Array_Call_Token()), prev_stack_top); + build_match(AST_NodePtr(new Array_Call_AST_Node()), prev_stack_top); } } } @@ -1509,7 +1509,7 @@ namespace chaiscript throw Eval_Error("Incomplete variable declaration", File_Position(line, col), filename); } - build_match(TokenPtr(new Var_Decl_Token()), prev_stack_top); + build_match(AST_NodePtr(new Var_Decl_AST_Node()), prev_stack_top); } else if (Keyword("attr")) { retval = true; @@ -1525,7 +1525,7 @@ namespace chaiscript } - build_match(TokenPtr(new Attr_Decl_Token()), prev_stack_top); + build_match(AST_NodePtr(new Attr_Decl_AST_Node()), prev_stack_top); } return retval; @@ -1564,18 +1564,18 @@ namespace chaiscript 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 == Token_Type::Value_Range) { - build_match(TokenPtr(new Inline_Range_Token()), prev_stack_top); + if (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 == Token_Type::Map_Pair) { - build_match(TokenPtr(new Inline_Map_Token()), prev_stack_top); + else if (match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) { + build_match(AST_NodePtr(new Inline_Map_AST_Node()), prev_stack_top); } else { - build_match(TokenPtr(new Inline_Array_Token()), prev_stack_top); + build_match(AST_NodePtr(new Inline_Array_AST_Node()), prev_stack_top); } } else { - build_match(TokenPtr(new Inline_Array_Token()), prev_stack_top); + build_match(AST_NodePtr(new Inline_Array_AST_Node()), prev_stack_top); } } @@ -1597,7 +1597,7 @@ namespace chaiscript throw Eval_Error("Incomplete '++' expression", File_Position(line, col), filename); } - build_match(TokenPtr(new Prefix_Token()), prev_stack_top); + build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); } else if (Symbol("--", true)) { retval = true; @@ -1606,7 +1606,7 @@ namespace chaiscript throw Eval_Error("Incomplete '--' expression", File_Position(line, col), filename); } - build_match(TokenPtr(new Prefix_Token()), prev_stack_top); + build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); } else if (Char('-', true)) { retval = true; @@ -1615,7 +1615,7 @@ namespace chaiscript throw Eval_Error("Incomplete unary '-' expression", File_Position(line, col), filename); } - build_match(TokenPtr(new Prefix_Token()), prev_stack_top); + build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); } else if (Char('+', true)) { retval = true; @@ -1624,7 +1624,7 @@ namespace chaiscript throw Eval_Error("Incomplete unary '+' expression", File_Position(line, col), filename); } - build_match(TokenPtr(new Prefix_Token()), prev_stack_top); + build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); } else if (Char('!', true)) { retval = true; @@ -1633,7 +1633,7 @@ namespace chaiscript throw Eval_Error("Incomplete '!' expression", File_Position(line, col), filename); } - build_match(TokenPtr(new Prefix_Token()), prev_stack_top); + build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); } else if (Char('~', true)) { retval = true; @@ -1642,14 +1642,14 @@ namespace chaiscript throw Eval_Error("Incomplete '~' expression", File_Position(line, col), filename); } - build_match(TokenPtr(new Prefix_Token()), prev_stack_top); + build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); } return retval; } /** - * Parses any of a group of 'value' style token groups from input + * Parses any of a group of 'value' style ast_node groups from input */ bool Value() { if (Var_Decl() || Lambda() || Id_Fun_Array() || Num(true) || Prefix() || Quoted_String(true) || Single_Quoted_String(true) || @@ -1681,47 +1681,47 @@ namespace chaiscript if (Operator_Helper(precedence)) { do { if (!Operator(precedence+1)) { - throw Eval_Error("Incomplete " + std::string(token_type_to_string(operators[precedence])) + " expression", + throw Eval_Error("Incomplete " + std::string(ast_node_type_to_string(operators[precedence])) + " expression", File_Position(line, col), filename); } } while (Operator_Helper(precedence)); switch (operators[precedence]) { - case(Token_Type::Comparison) : - build_match(TokenPtr(new Comparison_Token()), prev_stack_top); + case(AST_Node_Type::Comparison) : + build_match(AST_NodePtr(new Comparison_AST_Node()), prev_stack_top); break; - case(Token_Type::Dot_Access) : - build_match(TokenPtr(new Dot_Access_Token()), prev_stack_top); + case(AST_Node_Type::Dot_Access) : + build_match(AST_NodePtr(new Dot_Access_AST_Node()), prev_stack_top); break; - case(Token_Type::Additive) : - build_match(TokenPtr(new Additive_Token()), prev_stack_top); + case(AST_Node_Type::Additive) : + build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); break; - case(Token_Type::Multiplicative) : - build_match(TokenPtr(new Multiplicative_Token()), prev_stack_top); + case(AST_Node_Type::Multiplicative) : + build_match(AST_NodePtr(new Multiplicative_AST_Node()), prev_stack_top); break; - case(Token_Type::Shift) : - build_match(TokenPtr(new Shift_Token()), prev_stack_top); + case(AST_Node_Type::Shift) : + build_match(AST_NodePtr(new Shift_AST_Node()), prev_stack_top); break; - case(Token_Type::Equality) : - build_match(TokenPtr(new Equality_Token()), prev_stack_top); + case(AST_Node_Type::Equality) : + build_match(AST_NodePtr(new Equality_AST_Node()), prev_stack_top); break; - case(Token_Type::Bitwise_And) : - build_match(TokenPtr(new Bitwise_And_Token()), prev_stack_top); + case(AST_Node_Type::Bitwise_And) : + build_match(AST_NodePtr(new Bitwise_And_AST_Node()), prev_stack_top); break; - case(Token_Type::Bitwise_Xor) : - build_match(TokenPtr(new Bitwise_Xor_Token()), prev_stack_top); + case(AST_Node_Type::Bitwise_Xor) : + build_match(AST_NodePtr(new Bitwise_Xor_AST_Node()), prev_stack_top); break; - case(Token_Type::Bitwise_Or) : - build_match(TokenPtr(new Bitwise_Or_Token()), prev_stack_top); + case(AST_Node_Type::Bitwise_Or) : + build_match(AST_NodePtr(new Bitwise_Or_AST_Node()), prev_stack_top); break; - case(Token_Type::Logical_And) : - build_match(TokenPtr(new Logical_And_Token()), prev_stack_top); + case(AST_Node_Type::Logical_And) : + build_match(AST_NodePtr(new Logical_And_AST_Node()), prev_stack_top); break; - case(Token_Type::Logical_Or) : - build_match(TokenPtr(new Logical_Or_Token()), prev_stack_top); + case(AST_Node_Type::Logical_Or) : + build_match(AST_NodePtr(new Logical_Or_AST_Node()), prev_stack_top); break; default: - throw Eval_Error("Internal error: unhandled token", File_Position(line, col), filename); + throw Eval_Error("Internal error: unhandled ast_node", File_Position(line, col), filename); } } } @@ -1750,7 +1750,7 @@ namespace chaiscript } } while (retval && Symbol(":")); - build_match(TokenPtr(new Map_Pair_Token()), prev_stack_top); + build_match(AST_NodePtr(new Map_Pair_AST_Node()), prev_stack_top); } } @@ -1774,7 +1774,7 @@ namespace chaiscript throw Eval_Error("Incomplete value range", File_Position(line, col), filename); } - build_match(TokenPtr(new Value_Range_Token()), prev_stack_top); + build_match(AST_NodePtr(new Value_Range_AST_Node()), prev_stack_top); } else { input_pos = prev_pos; @@ -1806,7 +1806,7 @@ namespace chaiscript throw Eval_Error("Incomplete equation", File_Position(line, col), filename); } - build_match(TokenPtr(new Equation_Token()), prev_stack_top); + build_match(AST_NodePtr(new Equation_AST_Node()), prev_stack_top); } } @@ -1909,7 +1909,7 @@ namespace chaiscript } /** - * Parses the given input string, tagging parsed tokens with the given filename. + * Parses the given input string, tagging parsed ast_nodes with the given filename. */ bool parse(std::string input, char *fname) { input_pos = input.begin(); @@ -1928,7 +1928,7 @@ namespace chaiscript throw Eval_Error("Unparsed input", File_Position(line, col), fname); } else { - build_match(TokenPtr(new File_Token()), 0); + build_match(AST_NodePtr(new File_AST_Node()), 0); return true; } }