Add Eval_Error end extents and reserved word errors
This commit is contained in:
@@ -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<std::string>(where.line) + ", " +
|
||||
boost::lexical_cast<std::string>(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<std::string>(where->start.line) + ", " +
|
||||
boost::lexical_cast<std::string>(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() {}
|
||||
|
@@ -171,7 +171,12 @@ namespace chaiscript
|
||||
*/
|
||||
template <typename Eval_System>
|
||||
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<Eval_System>,
|
||||
try {
|
||||
ss.add(Proxy_Function
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>,
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user