Register AST_Node and Parser, overloaded eval for AST_Node and some const correctness fixes
This commit is contained in:
@@ -63,7 +63,7 @@ namespace chaiscript
|
||||
struct AST_Node {
|
||||
std::string text;
|
||||
int identifier;
|
||||
char *filename;
|
||||
const char *filename;
|
||||
File_Position start, end;
|
||||
bool is_cached;
|
||||
Boxed_Value cached_value;
|
||||
@@ -71,7 +71,7 @@ namespace chaiscript
|
||||
std::vector<AST_NodePtr> children;
|
||||
AST_NodePtr annotation;
|
||||
|
||||
AST_Node(const std::string &ast_node_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, const char *fname, int start_line, int start_col, int end_line, int end_col) :
|
||||
text(ast_node_text), identifier(id), filename(fname), is_cached(false) {
|
||||
|
||||
start.line = start_line;
|
||||
@@ -79,7 +79,7 @@ namespace chaiscript
|
||||
end.line = end_line;
|
||||
end.column = end_col;
|
||||
}
|
||||
AST_Node(const std::string &ast_node_text, int id, char *fname) :
|
||||
AST_Node(const std::string &ast_node_text, int id, const char *fname) :
|
||||
text(ast_node_text), identifier(id), filename(fname), is_cached(false) { }
|
||||
|
||||
|
||||
@@ -97,278 +97,278 @@ namespace chaiscript
|
||||
|
||||
struct Error_AST_Node : public AST_Node {
|
||||
public:
|
||||
Error_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Error, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Error_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Error, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Int_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Int_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Int, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Float_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Float_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Float, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Id_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Id_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Id, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Char_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Char_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Char, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Str_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Str_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Str, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Eol_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Eol_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Eol, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Fun_Call_AST_Node : public AST_Node {
|
||||
public:
|
||||
Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Fun_Call, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Fun_Call, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Inplace_Fun_Call_AST_Node : public AST_Node {
|
||||
public:
|
||||
Inplace_Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inplace_Fun_Call, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Inplace_Fun_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inplace_Fun_Call, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Arg_List_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Arg_List_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Arg_List, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Variable_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Variable_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Variable, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Equation_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Equation_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Equation, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Var_Decl_AST_Node : public AST_Node {
|
||||
public:
|
||||
Var_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Var_Decl, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Var_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Var_Decl, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Comparison_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Comparison_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Comparison, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Additive_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Additive_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Additive, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Multiplicative_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Multiplicative_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Multiplicative, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Array_Call_AST_Node : public AST_Node {
|
||||
public:
|
||||
Array_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Array_Call, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Array_Call_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Array_Call, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Dot_Access_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Dot_Access_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Dot_Access, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Quoted_String_AST_Node : public AST_Node {
|
||||
public:
|
||||
Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Quoted_String, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Quoted_String, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Single_Quoted_String_AST_Node : public AST_Node {
|
||||
public:
|
||||
Single_Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Single_Quoted_String, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Single_Quoted_String_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Single_Quoted_String, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Lambda_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Lambda_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Lambda, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Block_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Block_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Block, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Def_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Def_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Def, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct While_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
While_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::While, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct If_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
If_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::If, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct For_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
For_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::For, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Inline_Array_AST_Node : public AST_Node {
|
||||
public:
|
||||
Inline_Array_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Array, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Inline_Array_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Array, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Inline_Map_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Inline_Map_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Map, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Return_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Return_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Return, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct File_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
File_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::File, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Prefix_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Prefix_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Prefix, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Break_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Break_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Break, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Map_Pair_AST_Node : public AST_Node {
|
||||
public:
|
||||
Map_Pair_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Map_Pair, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Map_Pair_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Map_Pair, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Value_Range_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Value_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Value_Range, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Inline_Range_AST_Node : public AST_Node {
|
||||
public:
|
||||
Inline_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Range, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Inline_Range_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Inline_Range, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Annotation_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Annotation_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Annotation, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Try_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Try_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Try, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Catch_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Catch_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Catch, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Finally_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Finally_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Finally, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
};
|
||||
struct Method_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Method_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Method, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Attr_Decl_AST_Node : public AST_Node {
|
||||
public:
|
||||
Attr_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Attr_Decl, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Attr_Decl_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Attr_Decl, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Shift_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Shift_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Shift, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Equality_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Equality_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Equality, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Bitwise_And_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Bitwise_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_And, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Bitwise_Xor_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Bitwise_Xor_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Xor, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Bitwise_Or_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Bitwise_Or_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Bitwise_Or, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Logical_And_AST_Node : public AST_Node {
|
||||
public:
|
||||
Logical_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_And, char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
Logical_And_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_And, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
struct Logical_Or_AST_Node : public AST_Node {
|
||||
public:
|
||||
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) :
|
||||
Logical_Or_AST_Node(const std::string &ast_node_text = "", int id = AST_Node_Type::Logical_Or, const char *fname = NULL, int start_line = 0, int start_col = 0, int end_line = 0, int end_col = 0) :
|
||||
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||
Boxed_Value eval(Dispatch_Engine &ss);
|
||||
};
|
||||
|
@@ -258,7 +258,7 @@ namespace chaiscript
|
||||
#endif
|
||||
loaded_files.insert(filename);
|
||||
try {
|
||||
if (parser.parse(input, (char *)loaded_files.find(filename)->c_str())) {
|
||||
if (parser.parse(input, loaded_files.find(filename)->c_str())) {
|
||||
#ifndef CHAISCRIPT_NO_THREADS
|
||||
l.unlock();
|
||||
#endif
|
||||
@@ -274,7 +274,7 @@ namespace chaiscript
|
||||
#ifndef CHAISCRIPT_NO_THREADS
|
||||
boost::shared_lock<boost::shared_mutex> l(mutex);
|
||||
#endif
|
||||
char *fname = (char *)loaded_files.find("__EVAL__")->c_str();
|
||||
const char *fname = loaded_files.find("__EVAL__")->c_str();
|
||||
#ifndef CHAISCRIPT_NO_THREADS
|
||||
l.unlock();
|
||||
#endif
|
||||
@@ -297,6 +297,12 @@ namespace chaiscript
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
const Boxed_Value internal_eval_ast(const AST_NodePtr &ast)
|
||||
{
|
||||
return ast->eval(engine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the given boxed string, used during eval() inside of a script
|
||||
*/
|
||||
@@ -433,6 +439,8 @@ namespace chaiscript
|
||||
*/
|
||||
void load_module(const std::string &t_module_name)
|
||||
{
|
||||
std::vector<load_module_error> errors;
|
||||
|
||||
std::vector<std::string> prefixes;
|
||||
prefixes.push_back("lib");
|
||||
prefixes.push_back("");
|
||||
@@ -452,14 +460,29 @@ namespace chaiscript
|
||||
std::string name = modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
|
||||
load_module(t_module_name, name);
|
||||
return;
|
||||
} catch (const load_module_error &) {
|
||||
} catch (const load_module_error &e) {
|
||||
errors.push_back(e);
|
||||
// Try next set
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw load_module_error("Unable to find module: " + t_module_name);
|
||||
std::string errstring;
|
||||
|
||||
for (std::vector<load_module_error>::const_iterator itr = errors.begin();
|
||||
itr != errors.end();
|
||||
++itr)
|
||||
{
|
||||
if (!errstring.empty())
|
||||
{
|
||||
errstring += "; ";
|
||||
}
|
||||
|
||||
errstring += itr->what();
|
||||
}
|
||||
|
||||
throw load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -594,6 +617,8 @@ namespace chaiscript
|
||||
|
||||
engine.add(fun(&ChaiScript_System<Eval_Engine>::use, this), "use");
|
||||
engine.add(fun(&ChaiScript_System<Eval_Engine>::internal_eval, this), "eval");
|
||||
engine.add(fun(&ChaiScript_System<Eval_Engine>::internal_eval_ast, this), "eval");
|
||||
|
||||
|
||||
|
||||
do_eval(chaiscript_prelude, "standard prelude");
|
||||
|
@@ -20,11 +20,11 @@ namespace chaiscript
|
||||
{
|
||||
class ChaiScript_Parser {
|
||||
|
||||
std::string::iterator input_pos, input_end;
|
||||
std::string::const_iterator input_pos, input_end;
|
||||
int line, col;
|
||||
std::string multiline_comment_begin, multiline_comment_end;
|
||||
std::string singleline_comment;
|
||||
char *filename;
|
||||
const char *filename;
|
||||
std::vector<AST_NodePtr> match_stack;
|
||||
|
||||
std::vector<std::vector<std::string> > operator_matches;
|
||||
@@ -252,7 +252,7 @@ namespace chaiscript
|
||||
*/
|
||||
bool Float_() {
|
||||
bool retval = false;
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
|
||||
if (has_more_input() && (char_between('0', '9') || (*input_pos == '.'))) {
|
||||
while (has_more_input() && char_between('0', '9')) {
|
||||
@@ -358,7 +358,7 @@ namespace chaiscript
|
||||
return Hex_() || Float_();
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (has_more_input() && (char_between('0', '9') || (*input_pos == '.')) ) {
|
||||
@@ -441,7 +441,7 @@ namespace chaiscript
|
||||
retval = true;
|
||||
++col;
|
||||
++input_pos;
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
|
||||
while (has_more_input() && (*input_pos != '`')) {
|
||||
if (Eol()) {
|
||||
@@ -476,7 +476,7 @@ namespace chaiscript
|
||||
return Id_();
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Id_()) {
|
||||
@@ -505,7 +505,7 @@ namespace chaiscript
|
||||
*/
|
||||
bool Annotation() {
|
||||
SkipWS();
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Symbol_("#")) {
|
||||
@@ -577,7 +577,7 @@ namespace chaiscript
|
||||
return Quoted_String_();
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Quoted_String_()) {
|
||||
@@ -588,7 +588,7 @@ namespace chaiscript
|
||||
int prev_stack_top = match_stack.size();
|
||||
|
||||
//for (std::string::iterator s = start + 1, end = input_pos - 1; s != end; ++s) {
|
||||
std::string::iterator s = start + 1, end = input_pos - 1;
|
||||
std::string::const_iterator s = start + 1, end = input_pos - 1;
|
||||
|
||||
while (s != end) {
|
||||
if (saw_interpolation_marker) {
|
||||
@@ -763,13 +763,13 @@ namespace chaiscript
|
||||
return Single_Quoted_String_();
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Single_Quoted_String_()) {
|
||||
std::string match;
|
||||
bool is_escaped = false;
|
||||
for (std::string::iterator s = start + 1, end = input_pos - 1; s != end; ++s) {
|
||||
for (std::string::const_iterator s = start + 1, end = input_pos - 1; s != end; ++s) {
|
||||
if (*s == '\\') {
|
||||
if (is_escaped) {
|
||||
match.push_back('\\');
|
||||
@@ -832,7 +832,7 @@ namespace chaiscript
|
||||
return Char_(c);
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Char_(c)) {
|
||||
@@ -855,7 +855,7 @@ namespace chaiscript
|
||||
int len = strlen(s);
|
||||
|
||||
if ((input_end - input_pos) >= len) {
|
||||
std::string::iterator tmp = input_pos;
|
||||
std::string::const_iterator tmp = input_pos;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (*tmp != s[i]) {
|
||||
return false;
|
||||
@@ -877,7 +877,7 @@ namespace chaiscript
|
||||
SkipWS();
|
||||
|
||||
if (!capture) {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
bool retval = Keyword_(s);
|
||||
@@ -897,7 +897,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Keyword_(s)) {
|
||||
@@ -928,7 +928,7 @@ namespace chaiscript
|
||||
int len = strlen(s);
|
||||
|
||||
if ((input_end - input_pos) >= len) {
|
||||
std::string::iterator tmp = input_pos;
|
||||
std::string::const_iterator tmp = input_pos;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (*tmp != s[i]) {
|
||||
return false;
|
||||
@@ -950,7 +950,7 @@ namespace chaiscript
|
||||
SkipWS();
|
||||
|
||||
if (!capture) {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
bool retval = Symbol_(s);
|
||||
@@ -972,7 +972,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Symbol_(s)) {
|
||||
@@ -1027,7 +1027,7 @@ namespace chaiscript
|
||||
return Eol_();
|
||||
}
|
||||
else {
|
||||
std::string::iterator start = input_pos;
|
||||
std::string::const_iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if (Eol_()) {
|
||||
@@ -1459,7 +1459,7 @@ namespace chaiscript
|
||||
*/
|
||||
bool Id_Fun_Array() {
|
||||
bool retval = false;
|
||||
std::string::iterator prev_pos = input_pos;
|
||||
std::string::const_iterator prev_pos = input_pos;
|
||||
|
||||
unsigned int prev_stack_top = match_stack.size();
|
||||
if (Id(true)) {
|
||||
@@ -1764,7 +1764,7 @@ namespace chaiscript
|
||||
bool retval = false;
|
||||
|
||||
unsigned int prev_stack_top = match_stack.size();
|
||||
std::string::iterator prev_pos = input_pos;
|
||||
std::string::const_iterator prev_pos = input_pos;
|
||||
int prev_col = col;
|
||||
|
||||
if (Operator()) {
|
||||
@@ -1911,7 +1911,7 @@ namespace chaiscript
|
||||
/**
|
||||
* Parses the given input string, tagging parsed ast_nodes with the given filename.
|
||||
*/
|
||||
bool parse(std::string input, char *fname) {
|
||||
bool parse(const std::string &input, const char *fname) {
|
||||
input_pos = input.begin();
|
||||
input_end = input.end();
|
||||
line = 1; col = 1;
|
||||
|
Reference in New Issue
Block a user