Throw eval exception if a variable or function is redefined #28

This commit is contained in:
Jason Turner
2012-05-16 11:40:43 -06:00
parent 7deb2311f5
commit 4bcaa75fa4
9 changed files with 83 additions and 29 deletions

View File

@@ -340,6 +340,8 @@ namespace chaiscript
}
catch (const exception::reserved_word_error &) {
throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'");
} catch (const exception::name_conflict_error &e) {
throw exception::eval_error("Variable redefined '" + e.name() + "'");
}
return t_ss.get_object(this->children[0]->text);
}
@@ -639,6 +641,8 @@ namespace chaiscript
}
catch (const exception::reserved_word_error &e) {
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
} catch (const exception::name_conflict_error &e) {
throw exception::eval_error("Function redefined '" + e.name() + "'");
}
return Boxed_Value();
}
@@ -950,6 +954,7 @@ namespace chaiscript
end_point = this->children.size() - 1;
}
for (unsigned int i = 1; i < end_point; ++i) {
chaiscript::eval::detail::Scope_Push_Pop catchscope(t_ss);
AST_NodePtr catch_block = this->children[i];
if (catch_block->children.size() == 1) {
@@ -992,6 +997,7 @@ namespace chaiscript
}
catch (Boxed_Value &except) {
for (size_t i = 1; i < this->children.size(); ++i) {
chaiscript::eval::detail::Scope_Push_Pop catchscope(t_ss);
AST_NodePtr catch_block = this->children[i];
if (catch_block->children.size() == 1) {
@@ -1006,7 +1012,7 @@ namespace chaiscript
break;
}
else if (catch_block->children.size() == 3) {
//Variable capture, no guards
//Variable capture, guards
t_ss.add_object(catch_block->children[0]->text, except);
bool guard;
@@ -1134,6 +1140,8 @@ namespace chaiscript
}
catch (const exception::reserved_word_error &e) {
throw exception::eval_error("Reserved word used as method name '" + e.word() + "'");
} catch (const exception::name_conflict_error &e) {
throw exception::eval_error("Method redefined '" + e.name() + "'");
}
return Boxed_Value();
}
@@ -1161,6 +1169,8 @@ namespace chaiscript
}
catch (const exception::reserved_word_error &) {
throw exception::eval_error("Reserved word used as attribute '" + this->children[1]->text + "'");
} catch (const exception::name_conflict_error &e) {
throw exception::eval_error("Attribute redefined '" + e.name() + "'");
}
return Boxed_Value();
}