mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-07 10:19:57 +08:00
Register AST_Node and Parser, overloaded eval for AST_Node and some const correctness fixes
This commit is contained in:
parent
c6452c4bd6
commit
7ef12f634d
@ -63,7 +63,7 @@ namespace chaiscript
|
|||||||
struct AST_Node {
|
struct AST_Node {
|
||||||
std::string text;
|
std::string text;
|
||||||
int identifier;
|
int identifier;
|
||||||
char *filename;
|
const char *filename;
|
||||||
File_Position start, end;
|
File_Position start, end;
|
||||||
bool is_cached;
|
bool is_cached;
|
||||||
Boxed_Value cached_value;
|
Boxed_Value cached_value;
|
||||||
@ -71,7 +71,7 @@ namespace chaiscript
|
|||||||
std::vector<AST_NodePtr> children;
|
std::vector<AST_NodePtr> children;
|
||||||
AST_NodePtr annotation;
|
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) {
|
text(ast_node_text), identifier(id), filename(fname), is_cached(false) {
|
||||||
|
|
||||||
start.line = start_line;
|
start.line = start_line;
|
||||||
@ -79,7 +79,7 @@ namespace chaiscript
|
|||||||
end.line = end_line;
|
end.line = end_line;
|
||||||
end.column = end_col;
|
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) { }
|
text(ast_node_text), identifier(id), filename(fname), is_cached(false) { }
|
||||||
|
|
||||||
|
|
||||||
@ -97,278 +97,278 @@ namespace chaiscript
|
|||||||
|
|
||||||
struct Error_AST_Node : public AST_Node {
|
struct Error_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Int_AST_Node : public AST_Node {
|
struct Int_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Float_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Id_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Char_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Str_AST_Node : public AST_Node {
|
struct Str_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Eol_AST_Node : public AST_Node {
|
struct Eol_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Fun_Call_AST_Node : public AST_Node {
|
struct Fun_Call_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Inplace_Fun_Call_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Arg_List_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Variable_AST_Node : public AST_Node {
|
struct Variable_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Equation_AST_Node : public AST_Node {
|
struct Equation_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Var_Decl_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Comparison_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Additive_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Multiplicative_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Array_Call_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Dot_Access_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Quoted_String_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Single_Quoted_String_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Lambda_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Block_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Def_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct While_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct If_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct For_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Inline_Array_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Inline_Map_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Return_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct File_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Prefix_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Break_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Map_Pair_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Value_Range_AST_Node : public AST_Node {
|
struct Value_Range_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Inline_Range_AST_Node : public AST_Node {
|
struct Inline_Range_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Annotation_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Try_AST_Node : public AST_Node {
|
struct Try_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Catch_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Finally_AST_Node : public AST_Node {
|
struct Finally_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
AST_Node(ast_node_text, id, fname, start_line, start_col, end_line, end_col) { }
|
||||||
};
|
};
|
||||||
struct Method_AST_Node : public AST_Node {
|
struct Method_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Attr_Decl_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Shift_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Equality_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Bitwise_And_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Bitwise_Xor_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Bitwise_Or_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Logical_And_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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_AST_Node : public AST_Node {
|
struct Logical_Or_AST_Node : public AST_Node {
|
||||||
public:
|
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) { }
|
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);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -258,7 +258,7 @@ namespace chaiscript
|
|||||||
#endif
|
#endif
|
||||||
loaded_files.insert(filename);
|
loaded_files.insert(filename);
|
||||||
try {
|
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
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
l.unlock();
|
l.unlock();
|
||||||
#endif
|
#endif
|
||||||
@ -274,7 +274,7 @@ namespace chaiscript
|
|||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
boost::shared_lock<boost::shared_mutex> l(mutex);
|
boost::shared_lock<boost::shared_mutex> l(mutex);
|
||||||
#endif
|
#endif
|
||||||
char *fname = (char *)loaded_files.find("__EVAL__")->c_str();
|
const char *fname = loaded_files.find("__EVAL__")->c_str();
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
l.unlock();
|
l.unlock();
|
||||||
#endif
|
#endif
|
||||||
@ -297,6 +297,12 @@ namespace chaiscript
|
|||||||
return value;
|
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
|
* 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)
|
void load_module(const std::string &t_module_name)
|
||||||
{
|
{
|
||||||
|
std::vector<load_module_error> errors;
|
||||||
|
|
||||||
std::vector<std::string> prefixes;
|
std::vector<std::string> prefixes;
|
||||||
prefixes.push_back("lib");
|
prefixes.push_back("lib");
|
||||||
prefixes.push_back("");
|
prefixes.push_back("");
|
||||||
@ -452,14 +460,29 @@ namespace chaiscript
|
|||||||
std::string name = modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
|
std::string name = modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
|
||||||
load_module(t_module_name, name);
|
load_module(t_module_name, name);
|
||||||
return;
|
return;
|
||||||
} catch (const load_module_error &) {
|
} catch (const load_module_error &e) {
|
||||||
|
errors.push_back(e);
|
||||||
// Try next set
|
// 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>::use, this), "use");
|
||||||
engine.add(fun(&ChaiScript_System<Eval_Engine>::internal_eval, this), "eval");
|
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");
|
do_eval(chaiscript_prelude, "standard prelude");
|
||||||
|
|||||||
@ -20,11 +20,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
class ChaiScript_Parser {
|
class ChaiScript_Parser {
|
||||||
|
|
||||||
std::string::iterator input_pos, input_end;
|
std::string::const_iterator input_pos, input_end;
|
||||||
int line, col;
|
int line, col;
|
||||||
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;
|
const char *filename;
|
||||||
std::vector<AST_NodePtr> match_stack;
|
std::vector<AST_NodePtr> match_stack;
|
||||||
|
|
||||||
std::vector<std::vector<std::string> > operator_matches;
|
std::vector<std::vector<std::string> > operator_matches;
|
||||||
@ -252,7 +252,7 @@ namespace chaiscript
|
|||||||
*/
|
*/
|
||||||
bool Float_() {
|
bool Float_() {
|
||||||
bool retval = false;
|
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 == '.'))) {
|
if (has_more_input() && (char_between('0', '9') || (*input_pos == '.'))) {
|
||||||
while (has_more_input() && char_between('0', '9')) {
|
while (has_more_input() && char_between('0', '9')) {
|
||||||
@ -358,7 +358,7 @@ namespace chaiscript
|
|||||||
return Hex_() || Float_();
|
return Hex_() || Float_();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (has_more_input() && (char_between('0', '9') || (*input_pos == '.')) ) {
|
if (has_more_input() && (char_between('0', '9') || (*input_pos == '.')) ) {
|
||||||
@ -441,7 +441,7 @@ namespace chaiscript
|
|||||||
retval = true;
|
retval = true;
|
||||||
++col;
|
++col;
|
||||||
++input_pos;
|
++input_pos;
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
|
|
||||||
while (has_more_input() && (*input_pos != '`')) {
|
while (has_more_input() && (*input_pos != '`')) {
|
||||||
if (Eol()) {
|
if (Eol()) {
|
||||||
@ -476,7 +476,7 @@ namespace chaiscript
|
|||||||
return Id_();
|
return Id_();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Id_()) {
|
if (Id_()) {
|
||||||
@ -505,7 +505,7 @@ namespace chaiscript
|
|||||||
*/
|
*/
|
||||||
bool Annotation() {
|
bool Annotation() {
|
||||||
SkipWS();
|
SkipWS();
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Symbol_("#")) {
|
if (Symbol_("#")) {
|
||||||
@ -577,7 +577,7 @@ namespace chaiscript
|
|||||||
return Quoted_String_();
|
return Quoted_String_();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Quoted_String_()) {
|
if (Quoted_String_()) {
|
||||||
@ -588,7 +588,7 @@ namespace chaiscript
|
|||||||
int prev_stack_top = match_stack.size();
|
int prev_stack_top = match_stack.size();
|
||||||
|
|
||||||
//for (std::string::iterator s = start + 1, end = input_pos - 1; s != end; ++s) {
|
//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) {
|
while (s != end) {
|
||||||
if (saw_interpolation_marker) {
|
if (saw_interpolation_marker) {
|
||||||
@ -763,13 +763,13 @@ namespace chaiscript
|
|||||||
return Single_Quoted_String_();
|
return Single_Quoted_String_();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Single_Quoted_String_()) {
|
if (Single_Quoted_String_()) {
|
||||||
std::string match;
|
std::string match;
|
||||||
bool is_escaped = false;
|
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 (*s == '\\') {
|
||||||
if (is_escaped) {
|
if (is_escaped) {
|
||||||
match.push_back('\\');
|
match.push_back('\\');
|
||||||
@ -832,7 +832,7 @@ namespace chaiscript
|
|||||||
return Char_(c);
|
return Char_(c);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Char_(c)) {
|
if (Char_(c)) {
|
||||||
@ -855,7 +855,7 @@ namespace chaiscript
|
|||||||
int len = strlen(s);
|
int len = strlen(s);
|
||||||
|
|
||||||
if ((input_end - input_pos) >= len) {
|
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) {
|
for (int i = 0; i < len; ++i) {
|
||||||
if (*tmp != s[i]) {
|
if (*tmp != s[i]) {
|
||||||
return false;
|
return false;
|
||||||
@ -877,7 +877,7 @@ namespace chaiscript
|
|||||||
SkipWS();
|
SkipWS();
|
||||||
|
|
||||||
if (!capture) {
|
if (!capture) {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
bool retval = Keyword_(s);
|
bool retval = Keyword_(s);
|
||||||
@ -897,7 +897,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Keyword_(s)) {
|
if (Keyword_(s)) {
|
||||||
@ -928,7 +928,7 @@ namespace chaiscript
|
|||||||
int len = strlen(s);
|
int len = strlen(s);
|
||||||
|
|
||||||
if ((input_end - input_pos) >= len) {
|
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) {
|
for (int i = 0; i < len; ++i) {
|
||||||
if (*tmp != s[i]) {
|
if (*tmp != s[i]) {
|
||||||
return false;
|
return false;
|
||||||
@ -950,7 +950,7 @@ namespace chaiscript
|
|||||||
SkipWS();
|
SkipWS();
|
||||||
|
|
||||||
if (!capture) {
|
if (!capture) {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
bool retval = Symbol_(s);
|
bool retval = Symbol_(s);
|
||||||
@ -972,7 +972,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Symbol_(s)) {
|
if (Symbol_(s)) {
|
||||||
@ -1027,7 +1027,7 @@ namespace chaiscript
|
|||||||
return Eol_();
|
return Eol_();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string::iterator start = input_pos;
|
std::string::const_iterator start = input_pos;
|
||||||
int prev_col = col;
|
int prev_col = col;
|
||||||
int prev_line = line;
|
int prev_line = line;
|
||||||
if (Eol_()) {
|
if (Eol_()) {
|
||||||
@ -1459,7 +1459,7 @@ namespace chaiscript
|
|||||||
*/
|
*/
|
||||||
bool Id_Fun_Array() {
|
bool Id_Fun_Array() {
|
||||||
bool retval = false;
|
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();
|
unsigned int prev_stack_top = match_stack.size();
|
||||||
if (Id(true)) {
|
if (Id(true)) {
|
||||||
@ -1764,7 +1764,7 @@ namespace chaiscript
|
|||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
unsigned int prev_stack_top = match_stack.size();
|
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;
|
int prev_col = col;
|
||||||
|
|
||||||
if (Operator()) {
|
if (Operator()) {
|
||||||
@ -1911,7 +1911,7 @@ namespace chaiscript
|
|||||||
/**
|
/**
|
||||||
* Parses the given input string, tagging parsed ast_nodes with the given filename.
|
* Parses the given input string, tagging parsed ast_nodes with the given filename.
|
||||||
*/
|
*/
|
||||||
bool parse(std::string input, char *fname) {
|
bool parse(const std::string &input, const char *fname) {
|
||||||
input_pos = input.begin();
|
input_pos = input.begin();
|
||||||
input_end = input.end();
|
input_end = input.end();
|
||||||
line = 1; col = 1;
|
line = 1; col = 1;
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
BOOST_PP_SEQ_ELEM(3, _info) (BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(0, _method ) ) )
|
BOOST_PP_SEQ_ELEM(3, _info) (BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(0, _method ) ) )
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_NAME(_info) \
|
#define CHAISCRIPT_CLASS_NAME(_info) \
|
||||||
BOOST_PP_STRINGIZE(CHAISCRIPT_CLASS_ELEM(_info))
|
BOOST_PP_SEQ_ELEM(2, _info) (BOOST_PP_STRINGIZE(CHAISCRIPT_CLASS_ELEM(_info) ) )
|
||||||
|
|
||||||
#define CHAISCRIPT_METHOD_SIGNATURE_PART(_r, _info, _i, _method_part) \
|
#define CHAISCRIPT_METHOD_SIGNATURE_PART(_r, _info, _i, _method_part) \
|
||||||
BOOST_PP_EXPR_IF(BOOST_PP_EQUAL(_i, 1), < _method_part > )
|
BOOST_PP_EXPR_IF(BOOST_PP_EQUAL(_i, 1), < _method_part > )
|
||||||
@ -39,7 +39,7 @@
|
|||||||
#define CHAISCRIPT_CLASS_EX(_module, _class_name, _class_name_translator, _method_name_translator, _constructors, _methods) \
|
#define CHAISCRIPT_CLASS_EX(_module, _class_name, _class_name_translator, _method_name_translator, _constructors, _methods) \
|
||||||
{ \
|
{ \
|
||||||
_module->add(chaiscript::user_type<_class_name>(), _class_name_translator (BOOST_PP_STRINGIZE(_class_name))); \
|
_module->add(chaiscript::user_type<_class_name>(), _class_name_translator (BOOST_PP_STRINGIZE(_class_name))); \
|
||||||
CHAISCRIPT_CLASS_CONSTRUCTORS((_module)(_class_name), _constructors) \
|
CHAISCRIPT_CLASS_CONSTRUCTORS((_module)(_class_name)(_class_name_translator), _constructors) \
|
||||||
CHAISCRIPT_CLASS_METHODS((_module)(_class_name)(_class_name_translator)(_method_name_translator), _methods) \
|
CHAISCRIPT_CLASS_METHODS((_module)(_class_name)(_class_name_translator)(_method_name_translator), _methods) \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,12 +53,24 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
inline std::string class_name_translator(const std::string &t_name)
|
inline std::string class_name_translator(const std::string &t_name)
|
||||||
{
|
{
|
||||||
return t_name;
|
size_t colon = t_name.find_last_of("::");
|
||||||
|
if (colon != std::string::npos)
|
||||||
|
{
|
||||||
|
return t_name.substr(colon+1, std::string::npos);
|
||||||
|
} else {
|
||||||
|
return t_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string method_name_translator(const std::string &t_name)
|
inline std::string method_name_translator(const std::string &t_name)
|
||||||
{
|
{
|
||||||
return t_name;
|
size_t colon = t_name.find_last_of("::");
|
||||||
|
if (colon != std::string::npos)
|
||||||
|
{
|
||||||
|
return t_name.substr(colon+1, std::string::npos);
|
||||||
|
} else {
|
||||||
|
return t_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,7 +145,7 @@ int main(int argc, char *argv[]) {
|
|||||||
std::cout << "during evaluation at (" << ee.call_stack[0]->filename << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
|
std::cout << "during evaluation at (" << ee.call_stack[0]->filename << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
|
||||||
for (unsigned int j = 1; j < ee.call_stack.size(); ++j) {
|
for (unsigned int j = 1; j < ee.call_stack.size(); ++j) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << " > " << ee.call_stack[j]->filename << " (" << ee.call_stack[j]->start.line << ", " << ee.call_stack[j]->start.column << ")";
|
std::cout << " from " << ee.call_stack[j]->filename << " (" << ee.call_stack[j]->start.line << ", " << ee.call_stack[j]->start.column << ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|||||||
@ -1,23 +1,40 @@
|
|||||||
|
|
||||||
#include <chaiscript/chaiscript.hpp>
|
#include <chaiscript/chaiscript.hpp>
|
||||||
|
#include <chaiscript/utility/utility.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflection()
|
CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflection()
|
||||||
{
|
{
|
||||||
chaiscript::ModulePtr m(new chaiscript::Module());
|
chaiscript::ModulePtr m(new chaiscript::Module());
|
||||||
|
|
||||||
/*
|
chaiscript::bootstrap::vector_type<std::vector<boost::shared_ptr<chaiscript::AST_Node> > >("AST_NodeVector", m);
|
||||||
CHAISCRIPT_CLASS( m,
|
|
||||||
,
|
CHAISCRIPT_CLASS( m,
|
||||||
(Test ())
|
chaiscript::File_Position,
|
||||||
(Test (const Test &)),
|
(chaiscript::File_Position())
|
||||||
((function))
|
(chaiscript::File_Position(int,int)),
|
||||||
((function2))
|
((line))
|
||||||
((function3))
|
((column))
|
||||||
((functionOverload)(std::string (Test::*)(double)))
|
);
|
||||||
((functionOverload)(std::string (Test::*)(int)))
|
|
||||||
|
CHAISCRIPT_CLASS( m,
|
||||||
|
chaiscript::AST_Node,
|
||||||
|
(chaiscript::AST_Node (const std::string &, int, char *)),
|
||||||
|
((text))
|
||||||
|
((identifier))
|
||||||
|
((filename))
|
||||||
|
((start))
|
||||||
|
((end))
|
||||||
|
((children))
|
||||||
|
);
|
||||||
|
|
||||||
|
CHAISCRIPT_CLASS( m,
|
||||||
|
chaiscript::ChaiScript_Parser,
|
||||||
|
(chaiscript::ChaiScript_Parser ()),
|
||||||
|
((parse))
|
||||||
|
((ast))
|
||||||
|
((show_match_stack))
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user