Rename of Token to AST_Node to be more correct

This commit is contained in:
Jonathan Turner
2010-08-28 18:38:01 +00:00
parent 71de169e09
commit c6452c4bd6
4 changed files with 333 additions and 333 deletions

View File

@@ -16,7 +16,7 @@ namespace chaiscript
/** /**
* Types of AST nodes available to the parser and eval * Types of AST nodes available to the parser and eval
*/ */
class Token_Type { class AST_Node_Type {
public: public:
enum Type { Error, Int, Float, Id, Char, Str, Eol, Fun_Call, Inplace_Fun_Call, Arg_List, Variable, Equation, Var_Decl, 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, 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 * Helper lookup to get the name of each node type
*/ */
const char *token_type_to_string(int tokentype) { const char *ast_node_type_to_string(int ast_node_type) {
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_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", "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", "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", "Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
"Logical_And", "Logical_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) { } File_Position() : line(0), column(0) { }
}; };
typedef boost::shared_ptr<struct Token> TokenPtr; typedef boost::shared_ptr<struct AST_Node> 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; std::string text;
int identifier; int identifier;
char *filename; char *filename;
@@ -68,19 +68,19 @@ namespace chaiscript
bool is_cached; bool is_cached;
Boxed_Value cached_value; Boxed_Value cached_value;
std::vector<TokenPtr> children; std::vector<AST_NodePtr> children;
TokenPtr annotation; 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) : 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(token_text), identifier(id), filename(fname), is_cached(false) { text(ast_node_text), identifier(id), filename(fname), is_cached(false) {
start.line = start_line; start.line = start_line;
start.column = start_col; start.column = start_col;
end.line = end_line; end.line = end_line;
end.column = end_col; end.column = end_col;
} }
Token(const std::string &token_text, int id, char *fname) : AST_Node(const std::string &ast_node_text, int id, char *fname) :
text(token_text), identifier(id), filename(fname), is_cached(false) { } text(ast_node_text), identifier(id), filename(fname), is_cached(false) { }
void cache_const(const Boxed_Value &value) { void cache_const(const Boxed_Value &value) {
@@ -90,286 +90,286 @@ namespace chaiscript
virtual Boxed_Value eval(Dispatch_Engine &) { virtual Boxed_Value eval(Dispatch_Engine &) {
Boxed_Value bv; Boxed_Value bv;
throw std::runtime_error("Undispatched token (internal error)"); throw std::runtime_error("Undispatched ast_node (internal error)");
return bv; return bv;
} }
}; };
struct Error_Token : public Token { struct Error_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Float_Token : public Token { struct Float_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Id_Token : public Token { struct Id_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Char_Token : public Token { struct Char_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Inplace_Fun_Call_Token : public Token { struct Inplace_Fun_Call_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Arg_List_Token : public Token { struct Arg_List_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Var_Decl_Token : public Token { struct Var_Decl_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Comparison_Token : public Token { struct Comparison_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Additive_Token : public Token { struct Additive_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Multiplicative_Token : public Token { struct Multiplicative_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Array_Call_Token : public Token { struct Array_Call_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Dot_Access_Token : public Token { struct Dot_Access_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Quoted_String_Token : public Token { struct Quoted_String_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Single_Quoted_String_Token : public Token { struct Single_Quoted_String_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Lambda_Token : public Token { struct Lambda_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Block_Token : public Token { struct Block_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Def_Token : public Token { struct Def_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct While_Token : public Token { struct While_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct If_Token : public Token { struct If_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct For_Token : public Token { struct For_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Inline_Array_Token : public Token { struct Inline_Array_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Inline_Map_Token : public Token { struct Inline_Map_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Return_Token : public Token { struct Return_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct File_Token : public Token { struct File_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Prefix_Token : public Token { struct Prefix_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Break_Token : public Token { struct Break_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Map_Pair_Token : public Token { struct Map_Pair_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Annotation_Token : public Token { struct Annotation_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Catch_Token : public Token { struct Catch_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } 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: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Attr_Decl_Token : public Token { struct Attr_Decl_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Shift_Token : public Token { struct Shift_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Equality_Token : public Token { struct Equality_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Bitwise_And_Token : public Token { struct Bitwise_And_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Bitwise_Xor_Token : public Token { struct Bitwise_Xor_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Bitwise_Or_Token : public Token { struct Bitwise_Or_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Logical_And_Token : public Token { struct Logical_And_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
struct Logical_Or_Token : public Token { struct Logical_Or_AST_Node : public AST_Node {
public: 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) : 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) :
Token(token_text, id, fname, start_line, start_col, end_line, end_col) { } AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
Boxed_Value eval(Dispatch_Engine &ss); Boxed_Value eval(Dispatch_Engine &ss);
}; };
@@ -381,7 +381,7 @@ namespace chaiscript
File_Position start_position; File_Position start_position;
File_Position end_position; File_Position end_position;
const char *filename; const char *filename;
std::vector<TokenPtr> call_stack; std::vector<AST_NodePtr> 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 char *fname) :
std::runtime_error("Error: \"" + why + "\" " + std::runtime_error("Error: \"" + why + "\" " +

View File

@@ -244,7 +244,7 @@ namespace chaiscript
engine.sync_cache(); engine.sync_cache();
} }
//debug_print(tokens); //debug_print(ast_nodes);
Boxed_Value value; Boxed_Value value;
// Keep a cache of all loaded filenames and use the char * from this cache to pass // Keep a cache of all loaded filenames and use the char * from this cache to pass
@@ -263,7 +263,7 @@ namespace chaiscript
l.unlock(); l.unlock();
#endif #endif
//parser.show_match_stack(); //parser.show_match_stack();
value = parser.ast()->eval(engine);//eval_token<Eval_Engine>(engine, parser.ast()); value = parser.ast()->eval(engine);//eval_ast_node<Eval_Engine>(engine, parser.ast());
} }
} }
catch (const Return_Value &rv) { catch (const Return_Value &rv) {
@@ -518,8 +518,8 @@ namespace chaiscript
/** /**
* Prints the contents of an AST node, including its children, recursively * Prints the contents of an AST node, including its children, recursively
*/ */
void debug_print(TokenPtr t, std::string prepend = "") { void debug_print(AST_NodePtr t, std::string prepend = "") {
std::cout << prepend << "(" << token_type_to_string(t->identifier) << ") " std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") "
<< t->text << " : " << t->start.line << ", " << t->start.column << std::endl; << t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
for (unsigned int j = 0; j < t->children.size(); ++j) { for (unsigned int j = 0; j < t->children.size(); ++j) {
debug_print(t->children[j], prepend + " "); debug_print(t->children[j], prepend + " ");

View File

@@ -17,7 +17,7 @@ namespace chaiscript
* Helper function that will set up the scope around a function call, including handling the named function parameters * Helper function that will set up the scope around a function call, including handling the named function parameters
*/ */
template <typename Eval_System> template <typename Eval_System>
const Boxed_Value eval_function (Eval_System &ss, const TokenPtr &node, const std::vector<std::string> &param_names, const std::vector<Boxed_Value> &vals) { const Boxed_Value eval_function (Eval_System &ss, const AST_NodePtr &node, const std::vector<std::string> &param_names, const std::vector<Boxed_Value> &vals) {
ss.new_scope(); ss.new_scope();
for (unsigned int i = 0; i < param_names.size(); ++i) { for (unsigned int i = 0; i < param_names.size(); ++i) {
@@ -44,7 +44,7 @@ namespace chaiscript
/** /**
* Evaluates the top-level file node * 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(); const unsigned int size = this->children.size();
for (unsigned int i = 0; i < size; ++i) { for (unsigned int i = 0; i < size; ++i) {
try { try {
@@ -64,7 +64,7 @@ namespace chaiscript
/** /**
* Evaluates a variable or function name identifier * 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->text == "true") {
if (!this->is_cached) { if (!this->is_cached) {
cache_const(const_var(true)); cache_const(const_var(true));
@@ -102,7 +102,7 @@ namespace chaiscript
/** /**
* Evaluates a floating point number * Evaluates a floating point number
*/ */
Boxed_Value Float_Token::eval(Dispatch_Engine &) { Boxed_Value Float_AST_Node::eval(Dispatch_Engine &) {
if (!this->is_cached) { if (!this->is_cached) {
cache_const(const_var(double(atof(this->text.c_str())))); cache_const(const_var(double(atof(this->text.c_str()))));
} }
@@ -112,7 +112,7 @@ namespace chaiscript
/** /**
* Evaluates an integer * Evaluates an integer
*/ */
Boxed_Value Int_Token::eval(Dispatch_Engine &) { Boxed_Value Int_AST_Node::eval(Dispatch_Engine &) {
if (!this->is_cached) { if (!this->is_cached) {
cache_const(const_var(int(atoi(this->text.c_str())))); cache_const(const_var(int(atoi(this->text.c_str()))));
} }
@@ -122,7 +122,7 @@ namespace chaiscript
/** /**
* Evaluates a quoted string * 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); //return const_var(node->text);
/* /*
@@ -144,7 +144,7 @@ namespace chaiscript
* Evaluates a char group * 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) { if (!this->is_cached) {
cache_const(const_var(char(this->text[0]))); 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 * 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; int i;
Boxed_Value retval; Boxed_Value retval;
try { try {
@@ -227,7 +227,7 @@ namespace chaiscript
/** /**
* Evaluates a variable declaration * Evaluates a variable declaration
*/ */
Boxed_Value Var_Decl_Token::eval(Dispatch_Engine &ss) { Boxed_Value Var_Decl_AST_Node::eval(Dispatch_Engine &ss) {
try { try {
ss.add_object(this->children[0]->text, Boxed_Value()); ss.add_object(this->children[0]->text, Boxed_Value());
} }
@@ -240,7 +240,7 @@ namespace chaiscript
/** /**
* Evaluates an attribute declaration * Evaluates an attribute declaration
*/ */
Boxed_Value Attr_Decl_Token::eval(Dispatch_Engine &ss) { Boxed_Value Attr_Decl_AST_Node::eval(Dispatch_Engine &ss) {
try { try {
ss.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, this->children[0]->text, ss.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, this->children[0]->text,
this->children[1]->text, _1))), this->children[1]->text); this->children[1]->text, _1))), this->children[1]->text);
@@ -255,7 +255,7 @@ namespace chaiscript
/** /**
* Evaluates binary boolean operators. Respects short-circuiting rules. * 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; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -293,7 +293,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Logical_Or_Token::eval(Dispatch_Engine &ss) { Boxed_Value Logical_Or_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -334,7 +334,7 @@ namespace chaiscript
/** /**
* Evaluates comparison, additions, and multiplications and their relatives * 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; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -361,7 +361,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Bitwise_Xor_Token::eval(Dispatch_Engine &ss) { Boxed_Value Bitwise_Xor_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -388,7 +388,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Bitwise_Or_Token::eval(Dispatch_Engine &ss) { Boxed_Value Bitwise_Or_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -415,7 +415,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Additive_Token::eval(Dispatch_Engine &ss) { Boxed_Value Additive_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -442,7 +442,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Multiplicative_Token::eval(Dispatch_Engine &ss) { Boxed_Value Multiplicative_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -469,7 +469,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Comparison_Token::eval(Dispatch_Engine &ss) { Boxed_Value Comparison_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -496,7 +496,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Equality_Token::eval(Dispatch_Engine &ss) { Boxed_Value Equality_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -523,7 +523,7 @@ namespace chaiscript
return retval; return retval;
} }
Boxed_Value Shift_Token::eval(Dispatch_Engine &ss) { Boxed_Value Shift_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -554,7 +554,7 @@ namespace chaiscript
/** /**
* Evaluates an array lookup * 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; unsigned int i;
Boxed_Value retval; Boxed_Value retval;
@@ -588,7 +588,7 @@ namespace chaiscript
/** /**
* Evaluates any unary prefix * Evaluates any unary prefix
*/ */
Boxed_Value Prefix_Token::eval(Dispatch_Engine &ss) { Boxed_Value Prefix_AST_Node::eval(Dispatch_Engine &ss) {
try { try {
return ss.call_function(this->children[0]->text, this->children[1]->eval(ss)); 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 * 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; unsigned int i;
try { try {
@@ -631,7 +631,7 @@ namespace chaiscript
/** /**
* Evaluates (and generates) an inline range initialization * 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 { try {
return ss.call_function("generate_range", return ss.call_function("generate_range",
this->children[0]->children[0]->children[0]->eval(ss), this->children[0]->children[0]->children[0]->eval(ss),
@@ -649,7 +649,7 @@ namespace chaiscript
/** /**
* Evaluates (and generates) an inline map initialization * 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; unsigned int i;
try { 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. * 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; Param_List_Builder plb;
Dispatch_Engine::Stack prev_stack = ss.get_stack(); Dispatch_Engine::Stack prev_stack = ss.get_stack();
Dispatch_Engine::Stack new_stack = ss.new_stack(); Dispatch_Engine::Stack new_stack = ss.new_stack();
unsigned int i; 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) { for (i = 0; i < this->children[1]->children.size(); ++i) {
try { try {
plb << this->children[1]->children[i]->eval(ss); 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. * 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; Param_List_Builder plb;
unsigned int i; 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) { for (i = 0; i < this->children[1]->children.size(); ++i) {
try { try {
plb << this->children[1]->children[i]->eval(ss); plb << this->children[1]->children[i]->eval(ss);
@@ -771,7 +771,7 @@ namespace chaiscript
/** /**
* Evaluates a method/attributes invocation * 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 prev_stack = ss.get_stack();
Dispatch_Engine::Stack new_stack = ss.new_stack(); Dispatch_Engine::Stack new_stack = ss.new_stack();
unsigned int i, j; unsigned int i, j;
@@ -804,7 +804,7 @@ namespace chaiscript
std::string fun_name; std::string fun_name;
std::vector<std::pair<std::string, Proxy_Function > > funs; std::vector<std::pair<std::string, Proxy_Function > > 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; fun_name = this->children[i]->children[0]->text;
} }
else { else {
@@ -837,7 +837,7 @@ namespace chaiscript
/** /**
* Evaluates an if/elseif/else block * 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; Boxed_Value retval;
ss.new_scope(); ss.new_scope();
@@ -846,7 +846,7 @@ namespace chaiscript
} }
catch (Eval_Error &ee) { catch (Eval_Error &ee) {
ee.call_stack.push_back(this->children[0]); 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 { try {
this->children.back()->children[0]->eval(ss); this->children.back()->children[0]->eval(ss);
} }
@@ -863,11 +863,11 @@ namespace chaiscript
Boxed_Value except = Boxed_Value(boost::ref(e)); Boxed_Value except = Boxed_Value(boost::ref(e));
unsigned int end_point = this->children.size(); 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; end_point = this->children.size() - 1;
} }
for (unsigned int i = 1; i < end_point; ++i) { 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) { if (catch_block->children.size() == 1) {
//No variable capture, no guards //No variable capture, no guards
@@ -901,7 +901,7 @@ namespace chaiscript
try { try {
guard = boxed_cast<bool>(catch_block->children[1]->eval(ss)); guard = boxed_cast<bool>(catch_block->children[1]->eval(ss));
} catch (const bad_boxed_cast &) { } catch (const bad_boxed_cast &) {
if (this->children.back()->identifier == Token_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
this->children.back()->children[0]->eval(ss); this->children.back()->children[0]->eval(ss);
} }
@@ -927,7 +927,7 @@ namespace chaiscript
} }
} }
else { else {
if (this->children.back()->identifier == Token_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
this->children.back()->children[0]->eval(ss); this->children.back()->children[0]->eval(ss);
} }
@@ -945,7 +945,7 @@ namespace chaiscript
catch (Boxed_Value &bv) { catch (Boxed_Value &bv) {
Boxed_Value except = bv; Boxed_Value except = bv;
for (unsigned int i = 1; i < this->children.size(); ++i) { 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) { if (catch_block->children.size() == 1) {
//No variable capture, no guards //No variable capture, no guards
@@ -981,7 +981,7 @@ namespace chaiscript
guard = boxed_cast<bool>(catch_block->children[1]->eval(ss)); guard = boxed_cast<bool>(catch_block->children[1]->eval(ss));
} }
catch (const bad_boxed_cast &) { catch (const bad_boxed_cast &) {
if (this->children.back()->identifier == Token_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
this->children.back()->children[0]->eval(ss); this->children.back()->children[0]->eval(ss);
} }
@@ -1011,7 +1011,7 @@ namespace chaiscript
} }
} }
else { else {
if (this->children.back()->identifier == Token_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
this->children.back()->children[0]->eval(ss); this->children.back()->children[0]->eval(ss);
} }
@@ -1027,7 +1027,7 @@ namespace chaiscript
} }
} }
catch (...) { catch (...) {
if (this->children.back()->identifier == Token_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
this->children.back()->children[0]->eval(ss); this->children.back()->children[0]->eval(ss);
} }
@@ -1041,7 +1041,7 @@ namespace chaiscript
throw; throw;
} }
if (this->children.back()->identifier == Token_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
try { try {
retval = this->children.back()->children[0]->eval(ss); retval = this->children.back()->children[0]->eval(ss);
} }
@@ -1060,7 +1060,7 @@ namespace chaiscript
/** /**
* Evaluates an if/elseif/else block * 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; unsigned int i;
bool cond; bool cond;
@@ -1129,7 +1129,7 @@ namespace chaiscript
/** /**
* Evaluates a while block * Evaluates a while block
*/ */
Boxed_Value While_Token::eval(Dispatch_Engine &ss) { Boxed_Value While_AST_Node::eval(Dispatch_Engine &ss) {
bool cond; bool cond;
ss.new_scope(); ss.new_scope();
@@ -1180,7 +1180,7 @@ namespace chaiscript
/** /**
* Evaluates a for block, including the for's conditions, from left to right * 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; bool cond;
ss.new_scope(); ss.new_scope();
@@ -1287,7 +1287,7 @@ namespace chaiscript
/** /**
* Evaluates a function definition * Evaluates a function definition
*/ */
Boxed_Value Def_Token::eval(Dispatch_Engine &ss) { Boxed_Value Def_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
std::vector<std::string> param_names; std::vector<std::string> param_names;
@@ -1295,9 +1295,9 @@ namespace chaiscript
boost::shared_ptr<Dynamic_Proxy_Function> guard; boost::shared_ptr<Dynamic_Proxy_Function> guard;
size_t numparams = 0; size_t numparams = 0;
std::string function_name = this->children[0]->text; 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(); numparams = this->children[1]->children.size();
for (i = 0; i < numparams; ++i) { for (i = 0; i < numparams; ++i) {
param_names.push_back(this->children[1]->children[i]->text); param_names.push_back(this->children[1]->children[i]->text);
@@ -1339,7 +1339,7 @@ namespace chaiscript
/** /**
* Evaluates a function definition * Evaluates a function definition
*/ */
Boxed_Value Method_Token::eval(Dispatch_Engine &ss) { Boxed_Value Method_AST_Node::eval(Dispatch_Engine &ss) {
unsigned int i; unsigned int i;
std::vector<std::string> param_names; std::vector<std::string> param_names;
@@ -1348,12 +1348,12 @@ namespace chaiscript
size_t numparams; size_t numparams;
std::string class_name = this->children[0]->text; std::string class_name = this->children[0]->text;
std::string function_name = this->children[1]->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. //The first param of a method is always the implied this ptr.
param_names.push_back("this"); 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) { for (i = 0; i < this->children[2]->children.size(); ++i) {
param_names.push_back(this->children[2]->children[i]->text); param_names.push_back(this->children[2]->children[i]->text);
} }
@@ -1414,13 +1414,13 @@ namespace chaiscript
/** /**
* Evaluates a lambda (anonymous function) * 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; unsigned int i;
std::vector<std::string> param_names; std::vector<std::string> param_names;
size_t numparams = 0; 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(); numparams = this->children[0]->children.size();
for (i = 0; i < numparams; ++i) { for (i = 0; i < numparams; ++i) {
param_names.push_back(this->children[0]->children[i]->text); 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. * 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 i;
unsigned int num_children = this->children.size(); unsigned int num_children = this->children.size();
@@ -1477,7 +1477,7 @@ namespace chaiscript
/** /**
* Evaluates a return statement * 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) { if (this->children.size() > 0) {
try { try {
throw Return_Value(this->children[0]->eval(ss)); throw Return_Value(this->children[0]->eval(ss));
@@ -1495,7 +1495,7 @@ namespace chaiscript
/** /**
* Evaluates a break statement * Evaluates a break statement
*/ */
Boxed_Value Break_Token::eval(Dispatch_Engine &) { Boxed_Value Break_AST_Node::eval(Dispatch_Engine &) {
throw Break_Loop(); throw Break_Loop();
} }
} }

View File

@@ -25,10 +25,10 @@ namespace chaiscript
std::string multiline_comment_begin, multiline_comment_end; std::string multiline_comment_begin, multiline_comment_end;
std::string singleline_comment; std::string singleline_comment;
char *filename; char *filename;
std::vector<TokenPtr> match_stack; std::vector<AST_NodePtr> match_stack;
std::vector<std::vector<std::string> > operator_matches; std::vector<std::vector<std::string> > operator_matches;
std::vector<Token_Type::Type> operators; std::vector<AST_Node_Type::Type> operators;
public: public:
ChaiScript_Parser() { ChaiScript_Parser() {
@@ -45,73 +45,73 @@ namespace chaiscript
void setup_operators() { void setup_operators() {
using namespace boost::assign; using namespace boost::assign;
operators.push_back(Token_Type::Logical_Or); operators.push_back(AST_Node_Type::Logical_Or);
std::vector<std::string> logical_or; std::vector<std::string> logical_or;
logical_or += "||"; logical_or += "||";
operator_matches.push_back(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<std::string> logical_and; std::vector<std::string> logical_and;
logical_and += "&&"; logical_and += "&&";
operator_matches.push_back(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<std::string> bitwise_or; std::vector<std::string> bitwise_or;
bitwise_or += "|"; bitwise_or += "|";
operator_matches.push_back(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<std::string> bitwise_xor; std::vector<std::string> bitwise_xor;
bitwise_xor += "^"; bitwise_xor += "^";
operator_matches.push_back(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<std::string> bitwise_and; std::vector<std::string> bitwise_and;
bitwise_and += "&"; bitwise_and += "&";
operator_matches.push_back(bitwise_and); operator_matches.push_back(bitwise_and);
operators.push_back(Token_Type::Equality); operators.push_back(AST_Node_Type::Equality);
std::vector<std::string> equality; std::vector<std::string> equality;
equality += "==", "!="; equality += "==", "!=";
operator_matches.push_back(equality); operator_matches.push_back(equality);
operators.push_back(Token_Type::Comparison); operators.push_back(AST_Node_Type::Comparison);
std::vector<std::string> comparison; std::vector<std::string> comparison;
comparison += "<", "<=", ">", ">="; comparison += "<", "<=", ">", ">=";
operator_matches.push_back(comparison); operator_matches.push_back(comparison);
operators.push_back(Token_Type::Shift); operators.push_back(AST_Node_Type::Shift);
std::vector<std::string> shift; std::vector<std::string> shift;
shift += "<<", ">>"; shift += "<<", ">>";
operator_matches.push_back(shift); operator_matches.push_back(shift);
operators.push_back(Token_Type::Additive); operators.push_back(AST_Node_Type::Additive);
std::vector<std::string> additive; std::vector<std::string> additive;
additive += "+", "-"; additive += "+", "-";
operator_matches.push_back(additive); operator_matches.push_back(additive);
operators.push_back(Token_Type::Multiplicative); operators.push_back(AST_Node_Type::Multiplicative);
std::vector<std::string> multiplicative; std::vector<std::string> multiplicative;
multiplicative += "*", "/", "%"; multiplicative += "*", "/", "%";
operator_matches.push_back(multiplicative); operator_matches.push_back(multiplicative);
operators.push_back(Token_Type::Dot_Access); operators.push_back(AST_Node_Type::Dot_Access);
std::vector<std::string> dot_access; std::vector<std::string> dot_access;
dot_access += "."; dot_access += ".";
operator_matches.push_back(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 = "") { void debug_print(AST_NodePtr t, std::string prepend = "") {
std::cout << prepend << "(" << token_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl; 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) { for (unsigned int j = 0; j < t->children.size(); ++j) {
debug_print(t->children[j], prepend + " "); 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() { void show_match_stack() {
for (unsigned int i = 0; i < match_stack.size(); ++i) { 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() { void clear_match_stack() {
match_stack.clear(); match_stack.clear();
@@ -129,14 +129,14 @@ namespace chaiscript
/** /**
* Returns the front-most AST node * Returns the front-most AST node
*/ */
TokenPtr ast() { AST_NodePtr ast() {
return match_stack.front(); 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 pos_line_start, pos_col_start, pos_line_stop, pos_col_stop;
int is_deep = false; int is_deep = false;
@@ -167,7 +167,7 @@ namespace chaiscript
match_stack.push_back(t); match_stack.push_back(t);
} }
else { 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); match_stack.push_back(t);
} }
} }
@@ -370,7 +370,7 @@ namespace chaiscript
std::ostringstream out_int; std::ostringstream out_int;
out_int << int(temp_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); match_stack.push_back(t);
return true; return true;
} }
@@ -389,13 +389,13 @@ namespace chaiscript
std::ostringstream out_int; std::ostringstream out_int;
out_int << temp_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); match_stack.push_back(t);
return true; return true;
} }
if (Float_()) { if (Float_()) {
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -408,11 +408,11 @@ namespace chaiscript
std::ostringstream out_int; std::ostringstream out_int;
out_int << int(temp_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); match_stack.push_back(t);
} }
else { 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); match_stack.push_back(t);
} }
return true; return true;
@@ -483,13 +483,13 @@ namespace chaiscript
if (*start == '`') { if (*start == '`') {
//Id Literal //Id Literal
std::string match(start+1, input_pos-1); 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); match_stack.push_back(t);
return true; return true;
} }
else { else {
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -522,7 +522,7 @@ namespace chaiscript
} while (Symbol("#")); } while (Symbol("#"));
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -597,23 +597,23 @@ namespace chaiscript
if (is_interpolated) { if (is_interpolated) {
//If we've seen previous interpolation, add on instead of making a new one //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); 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); 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 { 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); match_stack.push_back(t);
} }
//We've finished with the part of the string up to this point, so clear it //We've finished with the part of the string up to this point, so clear it
match = ""; 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); match_stack.push_back(plus);
std::string eval_match; std::string eval_match;
@@ -629,28 +629,28 @@ namespace chaiscript
int tostr_stack_top = match_stack.size(); 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); match_stack.push_back(tostr);
int ev_stack_top = match_stack.size(); 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); match_stack.push_back(ev);
int arg_stack_top = match_stack.size(); 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); 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 { 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);
@@ -697,16 +697,16 @@ namespace chaiscript
} }
} }
if (is_interpolated) { 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); 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); 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 { 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); match_stack.push_back(t);
} }
return true; return true;
@@ -798,7 +798,7 @@ namespace chaiscript
is_escaped = false; 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); match_stack.push_back(t);
return true; return true;
} }
@@ -837,7 +837,7 @@ namespace chaiscript
int prev_line = line; int prev_line = line;
if (Char_(c)) { if (Char_(c)) {
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -910,7 +910,7 @@ namespace chaiscript
return false; return false;
} }
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -988,7 +988,7 @@ namespace chaiscript
} }
else { else {
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -1032,7 +1032,7 @@ namespace chaiscript
int prev_line = line; int prev_line = line;
if (Eol_()) { if (Eol_()) {
std::string match(start, input_pos); 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); match_stack.push_back(t);
return true; return true;
} }
@@ -1061,7 +1061,7 @@ namespace chaiscript
} }
} while (retval && Char(',')); } 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; return retval;
@@ -1077,7 +1077,7 @@ namespace chaiscript
if (Value_Range()) { if (Value_Range()) {
retval = true; 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()) { else if (Map_Pair()) {
retval = true; retval = true;
@@ -1090,7 +1090,7 @@ namespace chaiscript
} }
} while (retval && Char(',')); } 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; return retval;
@@ -1121,7 +1121,7 @@ namespace chaiscript
throw Eval_Error("Incomplete anonymous function", File_Position(line, col), filename); 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; return retval;
@@ -1134,7 +1134,7 @@ namespace chaiscript
bool retval = false; bool retval = false;
bool is_annotated = false; bool is_annotated = false;
bool is_method = false; bool is_method = false;
TokenPtr annotation; AST_NodePtr annotation;
if (Annotation()) { if (Annotation()) {
while (Eol_()) {} while (Eol_()) {}
@@ -1182,10 +1182,10 @@ namespace chaiscript
} }
if (is_method) { if (is_method) {
build_match(TokenPtr(new Method_Token()), prev_stack_top); build_match(AST_NodePtr(new Method_AST_Node()), prev_stack_top);
} }
else { else {
build_match(TokenPtr(new Def_Token()), prev_stack_top); build_match(AST_NodePtr(new Def_AST_Node()), prev_stack_top);
} }
if (is_annotated) { if (is_annotated) {
@@ -1235,7 +1235,7 @@ namespace chaiscript
if (!Block()) { 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(TokenPtr(new Catch_Token()), catch_stack_top); build_match(AST_NodePtr(new Catch_AST_Node()), catch_stack_top);
has_matches = true; has_matches = true;
} }
} }
@@ -1248,10 +1248,10 @@ namespace chaiscript
if (!Block()) { 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(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; 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; return retval;
@@ -1346,7 +1346,7 @@ namespace chaiscript
throw Eval_Error("Incomplete 'while' block", File_Position(line, col), filename); 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; return retval;
@@ -1391,7 +1391,7 @@ namespace chaiscript
throw Eval_Error("Incomplete 'for' block", File_Position(line, col), filename); 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; return retval;
@@ -1413,7 +1413,7 @@ namespace chaiscript
throw Eval_Error("Incomplete block", File_Position(line, col), filename); 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; return retval;
@@ -1431,7 +1431,7 @@ namespace chaiscript
retval = true; retval = true;
Operator(); Operator();
build_match(TokenPtr(new Return_Token()), prev_stack_top); build_match(AST_NodePtr(new Return_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1448,7 +1448,7 @@ namespace chaiscript
if (Keyword("break")) { if (Keyword("break")) {
retval = true; retval = true;
build_match(TokenPtr(new Break_Token()), prev_stack_top); build_match(AST_NodePtr(new Break_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1477,7 +1477,7 @@ namespace chaiscript
throw Eval_Error("Incomplete function call", File_Position(line, col), filename); 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('[')) { else if (Char('[')) {
has_more = true; has_more = true;
@@ -1486,7 +1486,7 @@ namespace chaiscript
throw Eval_Error("Incomplete array access", File_Position(line, col), filename); 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); 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")) { else if (Keyword("attr")) {
retval = true; 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; return retval;
@@ -1564,18 +1564,18 @@ namespace chaiscript
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 ((prev_stack_top != match_stack.size()) && (match_stack.back()->children.size() > 0)) {
if (match_stack.back()->children[0]->identifier == Token_Type::Value_Range) { if (match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
build_match(TokenPtr(new Inline_Range_Token()), prev_stack_top); build_match(AST_NodePtr(new Inline_Range_AST_Node()), prev_stack_top);
} }
else if (match_stack.back()->children[0]->identifier == Token_Type::Map_Pair) { else if (match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) {
build_match(TokenPtr(new Inline_Map_Token()), prev_stack_top); build_match(AST_NodePtr(new Inline_Map_AST_Node()), prev_stack_top);
} }
else { else {
build_match(TokenPtr(new Inline_Array_Token()), prev_stack_top); build_match(AST_NodePtr(new Inline_Array_AST_Node()), prev_stack_top);
} }
} }
else { 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); 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)) { else if (Symbol("--", true)) {
retval = true; retval = true;
@@ -1606,7 +1606,7 @@ namespace chaiscript
throw Eval_Error("Incomplete '--' expression", File_Position(line, col), filename); 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)) { else if (Char('-', true)) {
retval = true; retval = true;
@@ -1615,7 +1615,7 @@ namespace chaiscript
throw Eval_Error("Incomplete unary '-' expression", File_Position(line, col), filename); 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)) { else if (Char('+', true)) {
retval = true; retval = true;
@@ -1624,7 +1624,7 @@ namespace chaiscript
throw Eval_Error("Incomplete unary '+' expression", File_Position(line, col), filename); 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)) { else if (Char('!', true)) {
retval = true; retval = true;
@@ -1633,7 +1633,7 @@ namespace chaiscript
throw Eval_Error("Incomplete '!' expression", File_Position(line, col), filename); 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)) { else if (Char('~', true)) {
retval = true; retval = true;
@@ -1642,14 +1642,14 @@ namespace chaiscript
throw Eval_Error("Incomplete '~' expression", File_Position(line, col), filename); 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; 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() { bool Value() {
if (Var_Decl() || Lambda() || Id_Fun_Array() || Num(true) || Prefix() || Quoted_String(true) || Single_Quoted_String(true) || 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)) { if (Operator_Helper(precedence)) {
do { do {
if (!Operator(precedence+1)) { 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); File_Position(line, col), filename);
} }
} while (Operator_Helper(precedence)); } while (Operator_Helper(precedence));
switch (operators[precedence]) { switch (operators[precedence]) {
case(Token_Type::Comparison) : case(AST_Node_Type::Comparison) :
build_match(TokenPtr(new Comparison_Token()), prev_stack_top); build_match(AST_NodePtr(new Comparison_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Dot_Access) : case(AST_Node_Type::Dot_Access) :
build_match(TokenPtr(new Dot_Access_Token()), prev_stack_top); build_match(AST_NodePtr(new Dot_Access_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Additive) : case(AST_Node_Type::Additive) :
build_match(TokenPtr(new Additive_Token()), prev_stack_top); build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Multiplicative) : case(AST_Node_Type::Multiplicative) :
build_match(TokenPtr(new Multiplicative_Token()), prev_stack_top); build_match(AST_NodePtr(new Multiplicative_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Shift) : case(AST_Node_Type::Shift) :
build_match(TokenPtr(new Shift_Token()), prev_stack_top); build_match(AST_NodePtr(new Shift_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Equality) : case(AST_Node_Type::Equality) :
build_match(TokenPtr(new Equality_Token()), prev_stack_top); build_match(AST_NodePtr(new Equality_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Bitwise_And) : case(AST_Node_Type::Bitwise_And) :
build_match(TokenPtr(new Bitwise_And_Token()), prev_stack_top); build_match(AST_NodePtr(new Bitwise_And_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Bitwise_Xor) : case(AST_Node_Type::Bitwise_Xor) :
build_match(TokenPtr(new Bitwise_Xor_Token()), prev_stack_top); build_match(AST_NodePtr(new Bitwise_Xor_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Bitwise_Or) : case(AST_Node_Type::Bitwise_Or) :
build_match(TokenPtr(new Bitwise_Or_Token()), prev_stack_top); build_match(AST_NodePtr(new Bitwise_Or_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Logical_And) : case(AST_Node_Type::Logical_And) :
build_match(TokenPtr(new Logical_And_Token()), prev_stack_top); build_match(AST_NodePtr(new Logical_And_AST_Node()), prev_stack_top);
break; break;
case(Token_Type::Logical_Or) : case(AST_Node_Type::Logical_Or) :
build_match(TokenPtr(new Logical_Or_Token()), prev_stack_top); build_match(AST_NodePtr(new Logical_Or_AST_Node()), prev_stack_top);
break; break;
default: 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(":")); } 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); 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 { else {
input_pos = prev_pos; input_pos = prev_pos;
@@ -1806,7 +1806,7 @@ namespace chaiscript
throw Eval_Error("Incomplete equation", File_Position(line, col), filename); 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) { bool parse(std::string input, char *fname) {
input_pos = input.begin(); input_pos = input.begin();
@@ -1928,7 +1928,7 @@ namespace chaiscript
throw Eval_Error("Unparsed input", File_Position(line, col), fname); throw Eval_Error("Unparsed input", File_Position(line, col), fname);
} }
else { else {
build_match(TokenPtr(new File_Token()), 0); build_match(AST_NodePtr(new File_AST_Node()), 0);
return true; return true;
} }
} }