diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 70b27e5..0f1678b 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -87,7 +87,8 @@ namespace chaiscript */ struct Eval_Error : public std::runtime_error { std::string reason; - File_Position position; + File_Position start_position; + File_Position end_position; const char *filename; Eval_Error(const std::string &why, const File_Position &where, const char *fname) : @@ -95,7 +96,7 @@ namespace chaiscript (std::string(fname) != "__EVAL__" ? ("in '" + std::string(fname) + "' ") : "during evaluation ") + + "at (" + boost::lexical_cast(where.line) + ", " + boost::lexical_cast(where.column) + ")"), - reason(why), position(where), filename(fname) + reason(why), start_position(where), end_position(where), filename(fname) { } Eval_Error(const std::string &why, const TokenPtr &where) @@ -103,7 +104,7 @@ namespace chaiscript (std::string(where->filename) != "__EVAL__" ? ("in '" + std::string(where->filename) + "' ") : "during evaluation ") + "at (" + boost::lexical_cast(where->start.line) + ", " + boost::lexical_cast(where->start.column) + ")"), - reason(why), position(where->start), filename(where->filename) { + reason(why), start_position(where->start), end_position(where->end), filename(where->filename) { } virtual ~Eval_Error() throw() {} diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 1e82d70..8629844 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -171,7 +171,12 @@ namespace chaiscript */ template Boxed_Value eval_var_decl(Eval_System &ss, TokenPtr node) { - ss.add_object(node->children[0]->text, Boxed_Value()); + try { + ss.add_object(node->children[0]->text, Boxed_Value()); + } + catch (reserved_word_error &rwe) { + throw Eval_Error("Reserved word used as variable '" + node->children[0]->text + "'", node); + } return ss.get_object(node->children[0]->text); } @@ -671,12 +676,16 @@ namespace chaiscript param_names, _1), numparams)); } - ss.add(Proxy_Function - (new Dynamic_Proxy_Function(boost::bind(&eval_function, + try { + ss.add(Proxy_Function + (new Dynamic_Proxy_Function(boost::bind(&eval_function, boost::ref(ss), node->children.back(), param_names, _1), numparams, annotation, guard)), function_name); - + } + catch (reserved_word_error &rwe) { + throw Eval_Error("Reserved word used as function name '" + function_name + "'", node); + } return retval; }