Further namespace reorganization and cleanup to limit to the user the

most important aspect of the API and make documenation easier.
This commit is contained in:
Jason Turner
2011-03-24 09:23:05 -06:00
parent 637164e457
commit cd8bead54a
10 changed files with 2156 additions and 2136 deletions

View File

@@ -49,7 +49,7 @@ namespace chaiscript
try {
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
// either way, we are not responsible if it doesn't work
return detail::Cast_Helper<Type>::cast(boxed_dynamic_cast<Type>(bv));
return detail::Cast_Helper<Type>::cast(detail::boxed_dynamic_cast<Type>(bv));
} catch (const boost::bad_any_cast &) {
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
}

View File

@@ -201,7 +201,7 @@ namespace chaiscript
protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params) const
{
return dispatch(m_funcs.begin(), m_funcs.end(), params);
return detail::dispatch(m_funcs.begin(), m_funcs.end(), params);
}
private:
@@ -647,7 +647,7 @@ namespace chaiscript
{
std::vector<Proxy_Function> functions = get_function(t_name);
return dispatch(functions.begin(), functions.end(), params);
return detail::dispatch(functions.begin(), functions.end(), params);
}
Boxed_Value call_function(const std::string &t_name) const

View File

@@ -254,6 +254,8 @@ namespace chaiscript
return detail::Dynamic_Conversions::create<Base, Derived>();
}
namespace detail
{
template<typename Base, typename Derived>
bool dynamic_cast_converts()
{
@@ -276,7 +278,7 @@ namespace chaiscript
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unable to perform dynamic_cast operation");
}
}
}
}

View File

@@ -139,7 +139,7 @@ namespace chaiscript
|| (!bv.get_type_info().is_undef()
&& (ti.bare_equal(user_type<Boxed_POD_Value>())
|| ti.bare_equal(bv.get_type_info())
|| dynamic_cast_converts(ti, bv.get_type_info())
|| detail::dynamic_cast_converts(ti, bv.get_type_info())
|| bv.get_type_info().bare_equal(user_type<boost::shared_ptr<const Proxy_Function_Base> >())
)
)
@@ -594,6 +594,8 @@ namespace chaiscript
};
}
namespace detail
{
/**
* Take a vector of functions and a vector of parameters. Attempt to execute
* each function against the set of parameters, in order, until a matching
@@ -636,6 +638,7 @@ namespace chaiscript
return dispatch(funcs.begin(), funcs.end(), plist);
}
}
}
#endif

View File

@@ -108,17 +108,19 @@ namespace chaiscript
namespace exception
{
/**
* Errors generated during parsing or evaluation
*/
struct Eval_Error : public std::runtime_error {
struct eval_error : public std::runtime_error {
std::string reason;
File_Position start_position;
File_Position end_position;
std::string filename;
std::vector<AST_NodePtr> call_stack;
Eval_Error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) :
eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() :
std::runtime_error("Error: \"" + t_why + "\" " +
(t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") +
+ "at (" + boost::lexical_cast<std::string>(t_where.line) + ", " +
@@ -126,26 +128,29 @@ namespace chaiscript
reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname)
{ }
Eval_Error(const std::string &t_why)
eval_error(const std::string &t_why) throw()
: std::runtime_error("Error: \"" + t_why + "\" "),
reason(t_why)
{}
virtual ~Eval_Error() throw() {}
virtual ~eval_error() throw() {}
};
/**
* Errors generated when loading a file
*/
struct File_Not_Found_Error : public std::runtime_error {
File_Not_Found_Error(const std::string &t_filename)
struct file_not_found_error : public std::runtime_error {
file_not_found_error(const std::string &t_filename) throw()
: std::runtime_error("File Not Found: " + t_filename)
{ }
virtual ~File_Not_Found_Error() throw() {}
virtual ~file_not_found_error() throw() {}
};
}
namespace detail
{
/**
* Special type for returned values
*/
@@ -162,6 +167,7 @@ namespace chaiscript
Break_Loop() { }
};
}
}
#endif /* _CHAISCRIPT_COMMON_HPP */

View File

@@ -27,6 +27,8 @@
#include <chaiscript/language/chaiscript_parser.hpp>
namespace chaiscript
{
namespace exception
{
struct load_module_error : std::runtime_error
{
@@ -39,7 +41,10 @@ namespace chaiscript
{
}
};
}
namespace detail
{
#ifdef _POSIX_VERSION
struct Loadable_Module
{
@@ -50,7 +55,7 @@ namespace chaiscript
{
if (!m_data)
{
throw load_module_error(dlerror());
throw exception::load_module_error(dlerror());
}
}
@@ -73,7 +78,7 @@ namespace chaiscript
{
if (!m_symbol)
{
throw load_module_error(dlerror());
throw exception::load_module_error(dlerror());
}
}
@@ -160,7 +165,7 @@ namespace chaiscript
{
if (!m_data)
{
throw load_module_error(GetErrorMessage(GetLastError()));
throw exception::load_module_error(GetErrorMessage(GetLastError()));
}
}
@@ -180,7 +185,7 @@ namespace chaiscript
{
if (!m_symbol)
{
throw load_module_error(GetErrorMessage(GetLastError()));
throw exception::load_module_error(GetErrorMessage(GetLastError()));
}
}
@@ -203,18 +208,19 @@ namespace chaiscript
{
Loadable_Module(const std::string &, const std::string &)
{
throw load_module_error("Loadable module support not available for your platform");
throw exception::load_module_error("Loadable module support not available for your platform");
}
ModulePtr get()
{
throw load_module_error("Loadable module support not available for your platform");
throw exception::load_module_error("Loadable module support not available for your platform");
}
};
#endif
#endif
typedef boost::shared_ptr<Loadable_Module> Loadable_Module_Ptr;
}
class ChaiScript {
#ifndef CHAISCRIPT_NO_THREADS
@@ -223,7 +229,7 @@ namespace chaiscript
#endif
std::set<std::string> m_used_files;
std::map<std::string, Loadable_Module_Ptr> m_loaded_modules;
std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules;
std::set<std::string> m_active_loaded_modules;
std::vector<std::string> m_modulepaths;
@@ -238,7 +244,7 @@ namespace chaiscript
Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
{
try {
ChaiScript_Parser parser;
parser::ChaiScript_Parser parser;
if (parser.parse(t_input, t_filename)) {
//parser.show_match_stack();
return parser.ast()->eval(m_engine);
@@ -246,7 +252,7 @@ namespace chaiscript
return Boxed_Value();
}
}
catch (const Return_Value &rv) {
catch (const detail::Return_Value &rv) {
return rv.retval;
}
}
@@ -287,10 +293,10 @@ namespace chaiscript
#endif
eval_file(appendedpath);
}
} catch (const File_Not_Found_Error &) {
} catch (const exception::file_not_found_error &) {
if (i == m_usepaths.size() - 1)
{
throw File_Not_Found_Error(t_filename);
throw exception::file_not_found_error(t_filename);
}
// failed to load, try the next path
@@ -305,6 +311,56 @@ namespace chaiscript
return m_engine;
}
/**
* Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude.
*/
void build_eval_system() {
using namespace bootstrap;
m_engine.add_reserved_word("def");
m_engine.add_reserved_word("fun");
m_engine.add_reserved_word("while");
m_engine.add_reserved_word("for");
m_engine.add_reserved_word("if");
m_engine.add_reserved_word("else");
m_engine.add_reserved_word("&&");
m_engine.add_reserved_word("||");
m_engine.add_reserved_word(",");
m_engine.add_reserved_word(":=");
m_engine.add_reserved_word("var");
m_engine.add_reserved_word("return");
m_engine.add_reserved_word("break");
m_engine.add_reserved_word("true");
m_engine.add_reserved_word("false");
m_engine.add_reserved_word("_");
add(Bootstrap::bootstrap());
m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system");
m_engine.add(fun(&Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object");
m_engine.add(fun(&Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type");
m_engine.add(fun(&Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name");
m_engine.add(fun(&Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists");
m_engine.add(fun(&Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name");
typedef void (ChaiScript::*load_mod_1)(const std::string&);
typedef void (ChaiScript::*load_mod_2)(const std::string&, const std::string&);
m_engine.add(fun(static_cast<load_mod_1>(&ChaiScript::load_module), this), "load_module");
m_engine.add(fun(static_cast<load_mod_2>(&ChaiScript::load_module), this), "load_module");
add(standard_library::vector_type<std::vector<Boxed_Value> >("Vector"));
add(standard_library::string_type<std::string>("string"));
add(standard_library::map_type<std::map<std::string, Boxed_Value> >("Map"));
add(standard_library::pair_type<std::pair<Boxed_Value, Boxed_Value > >("Pair"));
m_engine.add(fun(&ChaiScript::use, this), "use");
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
do_eval(chaiscript_prelude, "standard prelude");
}
public:
ChaiScript(const std::vector<std::string> &t_modulepaths = std::vector<std::string>(),
@@ -398,7 +454,7 @@ namespace chaiscript
*/
void load_module(const std::string &t_module_name)
{
std::vector<load_module_error> errors;
std::vector<exception::load_module_error> errors;
std::vector<std::string> prefixes;
prefixes.push_back("lib");
@@ -419,7 +475,7 @@ namespace chaiscript
std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
load_module(t_module_name, name);
return;
} catch (const load_module_error &e) {
} catch (const exception::load_module_error &e) {
errors.push_back(e);
// Try next set
}
@@ -429,7 +485,7 @@ namespace chaiscript
std::string errstring;
for (std::vector<load_module_error>::const_iterator itr = errors.begin();
for (std::vector<exception::load_module_error>::const_iterator itr = errors.begin();
itr != errors.end();
++itr)
{
@@ -441,7 +497,7 @@ namespace chaiscript
errstring += itr->what();
}
throw load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring);
throw exception::load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring);
}
/**
@@ -455,7 +511,7 @@ namespace chaiscript
if (m_loaded_modules.count(t_module_name) == 0)
{
Loadable_Module_Ptr lm(new Loadable_Module(t_module_name, t_filename));
detail::Loadable_Module_Ptr lm(new detail::Loadable_Module(t_module_name, t_filename));
m_loaded_modules[t_module_name] = lm;
m_active_loaded_modules.insert(t_module_name);
add(lm->m_moduleptr);
@@ -495,7 +551,7 @@ namespace chaiscript
std::ifstream infile(t_filename.c_str(), std::ios::in | std::ios::ate | std::ios::binary );
if (!infile.is_open()) {
throw File_Not_Found_Error(t_filename);
throw exception::file_not_found_error(t_filename);
}
std::streampos size = infile.tellg();
@@ -513,56 +569,6 @@ namespace chaiscript
}
}
/**
* Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude.
*/
void build_eval_system() {
using namespace bootstrap;
m_engine.add_reserved_word("def");
m_engine.add_reserved_word("fun");
m_engine.add_reserved_word("while");
m_engine.add_reserved_word("for");
m_engine.add_reserved_word("if");
m_engine.add_reserved_word("else");
m_engine.add_reserved_word("&&");
m_engine.add_reserved_word("||");
m_engine.add_reserved_word(",");
m_engine.add_reserved_word(":=");
m_engine.add_reserved_word("var");
m_engine.add_reserved_word("return");
m_engine.add_reserved_word("break");
m_engine.add_reserved_word("true");
m_engine.add_reserved_word("false");
m_engine.add_reserved_word("_");
add(Bootstrap::bootstrap());
m_engine.add(fun(&Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system");
m_engine.add(fun(&Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object");
m_engine.add(fun(&Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type");
m_engine.add(fun(&Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name");
m_engine.add(fun(&Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists");
m_engine.add(fun(&Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name");
typedef void (ChaiScript::*load_mod_1)(const std::string&);
typedef void (ChaiScript::*load_mod_2)(const std::string&, const std::string&);
m_engine.add(fun(static_cast<load_mod_1>(&ChaiScript::load_module), this), "load_module");
m_engine.add(fun(static_cast<load_mod_2>(&ChaiScript::load_module), this), "load_module");
add(standard_library::vector_type<std::vector<Boxed_Value> >("Vector"));
add(standard_library::string_type<std::string>("string"));
add(standard_library::map_type<std::map<std::string, Boxed_Value> >("Map"));
add(standard_library::pair_type<std::pair<Boxed_Value, Boxed_Value > >("Pair"));
m_engine.add(fun(&ChaiScript::use, this), "use");
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
do_eval(chaiscript_prelude, "standard prelude");
}
template<typename T>
T eval(const std::string &t_input)

View File

@@ -28,10 +28,10 @@ namespace chaiscript
Boxed_Value retval(t_node->eval(t_ss));
t_ss.pop_scope();
return retval;
} catch (const Return_Value &rv) {
} catch (const detail::Return_Value &rv) {
t_ss.pop_scope();
return rv.retval;
} catch (Eval_Error &ee) {
} catch (exception::eval_error &ee) {
ee.call_stack.push_back(t_node);
t_ss.pop_scope();
throw;
@@ -55,7 +55,7 @@ namespace chaiscript
try {
retval = this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -65,9 +65,9 @@ namespace chaiscript
retval = t_ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(t_ss));
}
catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate '" + this->children[i]->text + "'");
throw exception::eval_error("Can not find appropriate '" + this->children[i]->text + "'");
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]);
throw;
}
@@ -131,7 +131,7 @@ namespace chaiscript
return t_ss.get_object(this->text);
}
catch (std::exception &) {
throw Eval_Error("Can not find object: " + this->text);
throw exception::eval_error("Can not find object: " + this->text);
}
}
}
@@ -171,7 +171,7 @@ namespace chaiscript
try {
plb << this->children[1]->children[i]->eval(t_ss);
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]->children[i]);
throw;
}
@@ -192,9 +192,9 @@ namespace chaiscript
}
catch(const exception::dispatch_error &e){
t_ss.set_stack(prev_stack);
throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
}
catch(Return_Value &rv) {
catch(detail::Return_Value &rv) {
t_ss.set_stack(prev_stack);
return rv.retval;
}
@@ -203,10 +203,10 @@ namespace chaiscript
throw;
}
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
t_ss.set_stack(prev_stack);
throw Eval_Error(ee.reason);
throw exception::eval_error(ee.reason);
}
}
@@ -226,7 +226,7 @@ namespace chaiscript
try {
plb << this->children[1]->children[i]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]->children[i]);
throw;
}
@@ -240,18 +240,18 @@ namespace chaiscript
return (*boxed_cast<Const_Proxy_Function >(fn))(plb);
}
catch(const exception::dispatch_error &e){
throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
}
catch(Return_Value &rv) {
catch(detail::Return_Value &rv) {
return rv.retval;
}
catch(...) {
throw;
}
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw Eval_Error(ee.reason);
throw exception::eval_error(ee.reason);
}
}
@@ -282,7 +282,7 @@ namespace chaiscript
try {
retval = this->children.back()->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back());
throw;
}
@@ -303,14 +303,14 @@ namespace chaiscript
retval = t_ss.call_function(this->children[i+1]->text, lhs, retval);
}
catch(const exception::dispatch_error &){
throw Eval_Error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":"."));
throw exception::eval_error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":"."));
}
}
catch(const exception::dispatch_error &){
throw Eval_Error("Can not clone right hand side of equation");
throw exception::eval_error("Can not clone right hand side of equation");
}
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]);
throw;
}
@@ -322,10 +322,10 @@ namespace chaiscript
lhs.assign(retval);
}
else {
throw Eval_Error("Mismatched types in equation");
throw exception::eval_error("Mismatched types in equation");
}
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]);
throw;
}
@@ -335,9 +335,9 @@ namespace chaiscript
retval = t_ss.call_function(this->children[i+1]->text, this->children[i]->eval(t_ss), retval);
}
catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate '" + this->children[i+1]->text + "'");
throw exception::eval_error("Can not find appropriate '" + this->children[i+1]->text + "'");
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]);
throw;
}
@@ -358,7 +358,7 @@ namespace chaiscript
t_ss.add_object(this->children[0]->text, Boxed_Value());
}
catch (const exception::reserved_word_error &) {
throw Eval_Error("Reserved word used as variable '" + this->children[0]->text + "'");
throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'");
}
return t_ss.get_object(this->children[0]->text);
}
@@ -397,7 +397,7 @@ namespace chaiscript
try {
retval = this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -407,12 +407,12 @@ namespace chaiscript
retval = t_ss.call_function("[]", retval, this->children[i]->eval(t_ss));
}
catch(std::out_of_range &) {
throw Eval_Error("Out of bounds exception");
throw exception::eval_error("Out of bounds exception");
}
catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate array lookup '[]' ");
throw exception::eval_error("Can not find appropriate array lookup '[]' ");
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]);
throw;
}
@@ -432,7 +432,7 @@ namespace chaiscript
try {
retval = this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -447,7 +447,7 @@ namespace chaiscript
try {
plb << this->children[i]->children[1]->children[j]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]->children[1]->children[j]);
throw;
}
@@ -472,9 +472,9 @@ namespace chaiscript
}
catch(const exception::dispatch_error &e){
t_ss.set_stack(prev_stack);
throw Eval_Error(std::string(e.what()));
throw exception::eval_error(std::string(e.what()));
}
catch(Return_Value &rv) {
catch(detail::Return_Value &rv) {
t_ss.set_stack(prev_stack);
retval = rv.retval;
}
@@ -488,12 +488,12 @@ namespace chaiscript
retval = t_ss.call_function("[]", retval, this->children[i]->children[j]->eval(t_ss));
}
catch(std::out_of_range &) {
throw Eval_Error("Out of bounds exception");
throw exception::eval_error("Out of bounds exception");
}
catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate array lookup '[]' ");
throw exception::eval_error("Can not find appropriate array lookup '[]' ");
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]->children[j]);
throw;
}
@@ -576,11 +576,11 @@ namespace chaiscript
return retval;
}
}
catch (const chaiscript::Return_Value &) {
catch (const chaiscript::detail::Return_Value &) {
t_ss.pop_scope();
throw;
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]);
t_ss.pop_scope();
throw;
@@ -644,7 +644,7 @@ namespace chaiscript
l_annotation, guard)), l_function_name);
}
catch (const exception::reserved_word_error &e) {
throw Eval_Error("Reserved word used as function name '" + e.word() + "'");
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
}
return Boxed_Value();
}
@@ -666,9 +666,9 @@ namespace chaiscript
}
catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope();
throw Eval_Error("While condition not boolean");
throw exception::eval_error("While condition not boolean");
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope();
throw;
@@ -678,7 +678,7 @@ namespace chaiscript
try {
this->children[1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]);
throw;
}
@@ -688,15 +688,15 @@ namespace chaiscript
}
catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope();
throw Eval_Error("While condition not boolean");
throw exception::eval_error("While condition not boolean");
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope();
throw;
}
}
catch (Break_Loop &) {
catch (detail::Break_Loop &) {
cond = false;
}
}
@@ -717,9 +717,9 @@ namespace chaiscript
cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
}
catch (const exception::bad_boxed_cast &) {
throw Eval_Error("If condition not boolean");
throw exception::eval_error("If condition not boolean");
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -728,7 +728,7 @@ namespace chaiscript
try {
return this->children[1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]);
throw;
}
@@ -741,7 +741,7 @@ namespace chaiscript
try {
return this->children[i+1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]);
throw;
}
@@ -751,9 +751,9 @@ namespace chaiscript
cond = boxed_cast<bool>(this->children[i+1]->eval(t_ss));
}
catch (const exception::bad_boxed_cast &) {
throw Eval_Error("'else if' condition not boolean");
throw exception::eval_error("'else if' condition not boolean");
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]);
throw;
}
@@ -761,7 +761,7 @@ namespace chaiscript
try {
return this->children[i+2]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+2]);
throw;
}
@@ -792,7 +792,7 @@ namespace chaiscript
try {
this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -800,7 +800,7 @@ namespace chaiscript
try {
cond = boxed_cast<bool>(this->children[1]->eval(t_ss));
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]);
throw;
}
@@ -809,7 +809,7 @@ namespace chaiscript
try {
cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope();
throw;
@@ -818,7 +818,7 @@ namespace chaiscript
}
catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope();
throw Eval_Error("For condition not boolean");
throw exception::eval_error("For condition not boolean");
}
while (cond) {
try {
@@ -826,7 +826,7 @@ namespace chaiscript
try {
this->children[3]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[3]);
throw;
}
@@ -834,7 +834,7 @@ namespace chaiscript
try {
this->children[2]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[2]);
throw;
}
@@ -842,7 +842,7 @@ namespace chaiscript
try {
cond = boxed_cast<bool>(this->children[1]->eval(t_ss));
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]);
throw;
}
@@ -851,7 +851,7 @@ namespace chaiscript
try {
this->children[2]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[2]);
throw;
}
@@ -859,7 +859,7 @@ namespace chaiscript
try {
this->children[1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[1]);
throw;
}
@@ -867,7 +867,7 @@ namespace chaiscript
try {
cond = boxed_cast<bool>(this->children[0]->eval(t_ss));
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
t_ss.pop_scope();
throw;
@@ -876,9 +876,9 @@ namespace chaiscript
}
catch (const exception::bad_boxed_cast &) {
t_ss.pop_scope();
throw Eval_Error("For condition not boolean");
throw exception::eval_error("For condition not boolean");
}
catch (Break_Loop &) {
catch (detail::Break_Loop &) {
cond = false;
}
}
@@ -900,7 +900,7 @@ namespace chaiscript
try {
vec.push_back(this->children[0]->children[i]->eval(t_ss));
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]->children[i]);
throw;
}
@@ -925,7 +925,7 @@ namespace chaiscript
retval[boxed_cast<std::string>(this->children[0]->children[i]->children[0]->eval(t_ss))]
= t_ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(t_ss));
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]->children[i]);
throw;
}
@@ -933,7 +933,7 @@ namespace chaiscript
return const_var(retval);
}
catch (const exception::dispatch_error &) {
throw Eval_Error("Can not find appropriate 'Map()'");
throw exception::eval_error("Can not find appropriate 'Map()'");
}
}
@@ -947,15 +947,15 @@ namespace chaiscript
virtual Boxed_Value eval(Dispatch_Engine &t_ss){
if (this->children.size() > 0) {
try {
throw Return_Value(this->children[0]->eval(t_ss));
throw detail::Return_Value(this->children[0]->eval(t_ss));
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
}
else {
throw Return_Value(Boxed_Value());
throw detail::Return_Value(Boxed_Value());
}
}
@@ -975,7 +975,7 @@ namespace chaiscript
return retval;
}
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i]);
throw;
}
@@ -994,7 +994,7 @@ namespace chaiscript
return t_ss.call_function(this->children[0]->text, this->children[1]->eval(t_ss));
}
catch(std::exception &){
throw Eval_Error("Can not find appropriate unary '" + this->children[0]->text + "'");
throw exception::eval_error("Can not find appropriate unary '" + this->children[0]->text + "'");
}
}
@@ -1006,7 +1006,7 @@ namespace chaiscript
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Break_AST_Node() {}
virtual Boxed_Value eval(Dispatch_Engine &){
throw Break_Loop();
throw detail::Break_Loop();
}
};
@@ -1036,9 +1036,9 @@ namespace chaiscript
this->children[0]->children[0]->children[1]->eval(t_ss));
}
catch (const exception::dispatch_error &) {
throw Eval_Error("Unable to generate range vector");
throw exception::eval_error("Unable to generate range vector");
}
catch(Eval_Error &ee) {
catch(exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]->children[0]);
throw;
}
@@ -1065,13 +1065,13 @@ namespace chaiscript
try {
retval = this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
if (this->children.back()->identifier == AST_Node_Type::Finally) {
try {
this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee2) {
catch (exception::eval_error &ee2) {
ee2.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
@@ -1096,7 +1096,7 @@ namespace chaiscript
try {
retval = catch_block->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[0]);
throw;
}
@@ -1108,7 +1108,7 @@ namespace chaiscript
try {
retval = catch_block->children[1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[1]);
throw;
}
@@ -1127,20 +1127,20 @@ namespace chaiscript
try {
this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
}
}
t_ss.pop_scope();
throw Eval_Error("Guard condition not boolean");
throw exception::eval_error("Guard condition not boolean");
}
if (guard) {
try {
retval = catch_block->children[2]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[2]);
throw;
}
@@ -1153,14 +1153,14 @@ namespace chaiscript
try {
this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
}
}
t_ss.pop_scope();
throw Eval_Error("Internal error: catch block size unrecognized");
throw exception::eval_error("Internal error: catch block size unrecognized");
}
}
}
@@ -1174,7 +1174,7 @@ namespace chaiscript
try {
retval = catch_block->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[0]);
throw;
}
@@ -1187,7 +1187,7 @@ namespace chaiscript
try {
retval = catch_block->children[1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[1]);
throw;
}
@@ -1207,7 +1207,7 @@ namespace chaiscript
try {
this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
@@ -1215,9 +1215,9 @@ namespace chaiscript
}
t_ss.pop_scope();
throw Eval_Error("Guard condition not boolean");
throw exception::eval_error("Guard condition not boolean");
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[1]);
throw;
}
@@ -1225,7 +1225,7 @@ namespace chaiscript
try {
retval = catch_block->children[2]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(catch_block->children[2]);
throw;
}
@@ -1237,14 +1237,14 @@ namespace chaiscript
try {
this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
}
}
t_ss.pop_scope();
throw Eval_Error("Internal error: catch block size unrecognized");
throw exception::eval_error("Internal error: catch block size unrecognized");
}
}
}
@@ -1253,7 +1253,7 @@ namespace chaiscript
try {
this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
@@ -1267,7 +1267,7 @@ namespace chaiscript
try {
retval = this->children.back()->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children.back()->children[0]);
t_ss.pop_scope();
throw;
@@ -1365,7 +1365,7 @@ namespace chaiscript
}
}
catch (const exception::reserved_word_error &e) {
throw Eval_Error("Reserved word used as method name '" + e.word() + "'");
throw exception::eval_error("Reserved word used as method name '" + e.word() + "'");
}
return Boxed_Value();
}
@@ -1384,7 +1384,7 @@ namespace chaiscript
}
catch (const exception::reserved_word_error &) {
throw Eval_Error("Reserved word used as attribute '" + this->children[1]->text + "'");
throw exception::eval_error("Reserved word used as attribute '" + this->children[1]->text + "'");
}
return Boxed_Value();
}
@@ -1436,7 +1436,7 @@ namespace chaiscript
try {
retval = this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -1448,13 +1448,13 @@ namespace chaiscript
lhs = boxed_cast<bool>(retval);
}
catch (const exception::bad_boxed_cast &) {
throw Eval_Error("Condition not boolean");
throw exception::eval_error("Condition not boolean");
}
if (lhs) {
try {
retval = this->children[i+1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]);
throw;
}
@@ -1479,7 +1479,7 @@ namespace chaiscript
try {
retval = this->children[0]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[0]);
throw;
}
@@ -1491,7 +1491,7 @@ namespace chaiscript
lhs = boxed_cast<bool>(retval);
}
catch (const exception::bad_boxed_cast &) {
throw Eval_Error("Condition not boolean");
throw exception::eval_error("Condition not boolean");
}
if (lhs) {
retval = Boxed_Value(true);
@@ -1500,7 +1500,7 @@ namespace chaiscript
try {
retval = this->children[i+1]->eval(t_ss);
}
catch (Eval_Error &ee) {
catch (exception::eval_error &ee) {
ee.call_stack.push_back(this->children[i+1]);
throw;
}

View File

@@ -15,6 +15,8 @@
#include "chaiscript_common.hpp"
namespace chaiscript
{
namespace parser
{
namespace detail
{
@@ -509,7 +511,7 @@ namespace chaiscript
while (has_more_input() && (*m_input_pos != '`')) {
if (Eol()) {
throw Eval_Error("Carriage return in identifier literal", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Carriage return in identifier literal", File_Position(m_line, m_col), *m_filename);
}
else {
++m_input_pos;
@@ -518,10 +520,10 @@ namespace chaiscript
}
if (start == m_input_pos) {
throw Eval_Error("Missing contents of identifier literal", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing contents of identifier literal", File_Position(m_line, m_col), *m_filename);
}
else if (m_input_pos == m_input_end) {
throw Eval_Error("Incomplete identifier literal", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete identifier literal", File_Position(m_line, m_col), *m_filename);
}
++m_col;
@@ -625,7 +627,7 @@ namespace chaiscript
++m_col;
}
else {
throw Eval_Error("Unclosed quoted string", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Unclosed quoted string", File_Position(m_line, m_col), *m_filename);
}
}
return retval;
@@ -717,7 +719,7 @@ namespace chaiscript
build_match(AST_NodePtr(new eval::Additive_AST_Node()), prev_stack_top);
}
else {
throw Eval_Error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename);
}
}
else {
@@ -746,7 +748,7 @@ namespace chaiscript
case ('\'') : match.push_back('\''); break;
case ('\"') : match.push_back('\"'); break;
case ('$') : match.push_back('$'); break;
default: throw Eval_Error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *m_filename);
default: throw exception::eval_error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *m_filename);
}
}
else if (*s == '$') {
@@ -811,7 +813,7 @@ namespace chaiscript
++m_col;
}
else {
throw Eval_Error("Unclosed single-quoted string", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Unclosed single-quoted string", File_Position(m_line, m_col), *m_filename);
}
}
return retval;
@@ -853,7 +855,7 @@ namespace chaiscript
case ('t') : match.push_back('\t'); break;
case ('\'') : match.push_back('\''); break;
case ('\"') : match.push_back('\"'); break;
default: throw Eval_Error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *m_filename);
default: throw exception::eval_error("Unknown escaped sequence in string", File_Position(prev_line, prev_col), *m_filename);
}
}
else {
@@ -1066,7 +1068,7 @@ namespace chaiscript
do {
while (Eol()) {}
if (!Equation()) {
throw Eval_Error("Unexpected value in parameter list", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Unexpected value in parameter list", File_Position(m_line, m_col), *m_filename);
}
} while (retval && Char(','));
}
@@ -1095,7 +1097,7 @@ namespace chaiscript
do {
while (Eol()) {}
if (!Map_Pair()) {
throw Eval_Error("Unexpected value in container", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Unexpected value in container", File_Position(m_line, m_col), *m_filename);
}
} while (retval && Char(','));
}
@@ -1108,7 +1110,7 @@ namespace chaiscript
do {
while (Eol()) {}
if (!Operator()) {
throw Eval_Error("Unexpected value in container", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Unexpected value in container", File_Position(m_line, m_col), *m_filename);
}
} while (retval && Char(','));
}
@@ -1133,14 +1135,14 @@ namespace chaiscript
if (Char('(')) {
Arg_List();
if (!Char(')')) {
throw Eval_Error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
}
}
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Lambda_AST_Node()), prev_stack_top);
@@ -1171,7 +1173,7 @@ namespace chaiscript
retval = true;
if (!Id(true)) {
throw Eval_Error("Missing function name in definition", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing function name in definition", File_Position(m_line, m_col), *m_filename);
}
if (Symbol("::", false)) {
@@ -1179,14 +1181,14 @@ namespace chaiscript
is_method = true;
if (!Id(true)) {
throw Eval_Error("Missing method name in definition", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing method name in definition", File_Position(m_line, m_col), *m_filename);
}
}
if (Char('(')) {
Arg_List();
if (!Char(')')) {
throw Eval_Error("Incomplete function definition", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete function definition", File_Position(m_line, m_col), *m_filename);
}
}
@@ -1194,13 +1196,13 @@ namespace chaiscript
if (Char(':')) {
if (!Operator()) {
throw Eval_Error("Missing guard expression for function", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing guard expression for function", File_Position(m_line, m_col), *m_filename);
}
}
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete function definition", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete function definition", File_Position(m_line, m_col), *m_filename);
}
if (is_method) {
@@ -1232,7 +1234,7 @@ namespace chaiscript
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'try' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'try' block", File_Position(m_line, m_col), *m_filename);
}
bool has_matches = true;
@@ -1243,11 +1245,11 @@ namespace chaiscript
size_t catch_stack_top = m_match_stack.size();
if (Char('(')) {
if (!(Id(true) && Char(')'))) {
throw Eval_Error("Incomplete 'catch' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'catch' expression", File_Position(m_line, m_col), *m_filename);
}
if (Char(':')) {
if (!Operator()) {
throw Eval_Error("Missing guard expression for catch", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing guard expression for catch", File_Position(m_line, m_col), *m_filename);
}
}
}
@@ -1255,7 +1257,7 @@ namespace chaiscript
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Catch_AST_Node()), catch_stack_top);
has_matches = true;
@@ -1268,7 +1270,7 @@ namespace chaiscript
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Finally_AST_Node()), finally_stack_top);
}
@@ -1291,17 +1293,17 @@ namespace chaiscript
retval = true;
if (!Char('(')) {
throw Eval_Error("Incomplete 'if' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'if' expression", File_Position(m_line, m_col), *m_filename);
}
if (!(Operator() && Char(')'))) {
throw Eval_Error("Incomplete 'if' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'if' expression", File_Position(m_line, m_col), *m_filename);
}
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'if' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'if' block", File_Position(m_line, m_col), *m_filename);
}
bool has_matches = true;
@@ -1312,17 +1314,17 @@ namespace chaiscript
if (Keyword("if")) {
m_match_stack.back()->text = "else if";
if (!Char('(')) {
throw Eval_Error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename);
}
if (!(Operator() && Char(')'))) {
throw Eval_Error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'else if' expression", File_Position(m_line, m_col), *m_filename);
}
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'else if' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'else if' block", File_Position(m_line, m_col), *m_filename);
}
has_matches = true;
}
@@ -1330,7 +1332,7 @@ namespace chaiscript
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'else' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'else' block", File_Position(m_line, m_col), *m_filename);
}
has_matches = true;
}
@@ -1355,17 +1357,17 @@ namespace chaiscript
retval = true;
if (!Char('(')) {
throw Eval_Error("Incomplete 'while' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'while' expression", File_Position(m_line, m_col), *m_filename);
}
if (!(Operator() && Char(')'))) {
throw Eval_Error("Incomplete 'while' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'while' expression", File_Position(m_line, m_col), *m_filename);
}
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::While_AST_Node()), prev_stack_top);
@@ -1384,7 +1386,7 @@ namespace chaiscript
return true;
}
else {
throw Eval_Error("Incomplete conditions in 'for' loop", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete conditions in 'for' loop", File_Position(m_line, m_col), *m_filename);
}
}
@@ -1400,17 +1402,17 @@ namespace chaiscript
retval = true;
if (!Char('(')) {
throw Eval_Error("Incomplete 'for' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'for' expression", File_Position(m_line, m_col), *m_filename);
}
if (!(For_Guards() && Char(')'))) {
throw Eval_Error("Incomplete 'for' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'for' expression", File_Position(m_line, m_col), *m_filename);
}
while (Eol()) {}
if (!Block()) {
throw Eval_Error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::For_AST_Node()), prev_stack_top);
@@ -1432,7 +1434,7 @@ namespace chaiscript
Statements();
if (!Char('}')) {
throw Eval_Error("Incomplete block", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Block_AST_Node()), prev_stack_top);
@@ -1496,7 +1498,7 @@ namespace chaiscript
Arg_List();
if (!Char(')')) {
throw Eval_Error("Incomplete function call", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete function call", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Fun_Call_AST_Node()), prev_stack_top);
@@ -1505,7 +1507,7 @@ namespace chaiscript
has_more = true;
if (!(Operator() && Char(']'))) {
throw Eval_Error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Array_Call_AST_Node()), prev_stack_top);
@@ -1528,7 +1530,7 @@ namespace chaiscript
retval = true;
if (!Id(true)) {
throw Eval_Error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Var_Decl_AST_Node()), prev_stack_top);
@@ -1537,13 +1539,13 @@ namespace chaiscript
retval = true;
if (!Id(true)) {
throw Eval_Error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
if (!Symbol("::", false)) {
throw Eval_Error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
if (!Id(true)) {
throw Eval_Error("Missing attribute name in definition", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing attribute name in definition", File_Position(m_line, m_col), *m_filename);
}
@@ -1562,10 +1564,10 @@ namespace chaiscript
if (Char('(')) {
retval = true;
if (!Operator()) {
throw Eval_Error("Incomplete expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete expression", File_Position(m_line, m_col), *m_filename);
}
if (!Char(')')) {
throw Eval_Error("Missing closing parenthesis", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing closing parenthesis", File_Position(m_line, m_col), *m_filename);
}
}
return retval;
@@ -1583,7 +1585,7 @@ namespace chaiscript
retval = true;
Container_Arg_List();
if (!Char(']')) {
throw Eval_Error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename);
}
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
@@ -1616,7 +1618,7 @@ namespace chaiscript
retval = true;
if (!Operator(m_operators.size()-1)) {
throw Eval_Error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
@@ -1625,7 +1627,7 @@ namespace chaiscript
retval = true;
if (!Operator(m_operators.size()-1)) {
throw Eval_Error("Incomplete '--' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete '--' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
@@ -1634,7 +1636,7 @@ namespace chaiscript
retval = true;
if (!Operator(m_operators.size()-1)) {
throw Eval_Error("Incomplete unary '-' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete unary '-' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
@@ -1643,7 +1645,7 @@ namespace chaiscript
retval = true;
if (!Operator(m_operators.size()-1)) {
throw Eval_Error("Incomplete unary '+' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete unary '+' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
@@ -1652,7 +1654,7 @@ namespace chaiscript
retval = true;
if (!Operator(m_operators.size()-1)) {
throw Eval_Error("Incomplete '!' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete '!' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
@@ -1661,7 +1663,7 @@ namespace chaiscript
retval = true;
if (!Operator(m_operators.size()-1)) {
throw Eval_Error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
@@ -1703,7 +1705,7 @@ namespace chaiscript
if (Operator_Helper(t_precedence)) {
do {
if (!Operator(t_precedence+1)) {
throw Eval_Error("Incomplete "
throw exception::eval_error("Incomplete "
+ std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression",
File_Position(m_line, m_col), *m_filename);
}
@@ -1744,7 +1746,7 @@ namespace chaiscript
build_match(AST_NodePtr(new eval::Logical_Or_AST_Node()), prev_stack_top);
break;
default:
throw Eval_Error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename);
}
}
}
@@ -1770,7 +1772,7 @@ namespace chaiscript
if (Symbol(":")) {
retval = true;
if (!Operator()) {
throw Eval_Error("Incomplete map pair", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete map pair", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Map_Pair_AST_Node()), prev_stack_top);
@@ -1801,7 +1803,7 @@ namespace chaiscript
if (Symbol("..")) {
retval = true;
if (!Operator()) {
throw Eval_Error("Incomplete value range", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete value range", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Value_Range_AST_Node()), prev_stack_top);
@@ -1833,7 +1835,7 @@ namespace chaiscript
Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) ||
Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) {
if (!Equation()) {
throw Eval_Error("Incomplete equation", File_Position(m_line, m_col), *m_filename);
throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename);
}
build_match(AST_NodePtr(new eval::Equation_AST_Node()), prev_stack_top);
@@ -1858,7 +1860,7 @@ namespace chaiscript
int prev_col = m_col;
if (Def()) {
if (!saw_eol) {
throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1866,7 +1868,7 @@ namespace chaiscript
}
else if (Try()) {
if (!saw_eol) {
throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1874,7 +1876,7 @@ namespace chaiscript
}
else if (If()) {
if (!saw_eol) {
throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1882,7 +1884,7 @@ namespace chaiscript
}
else if (While()) {
if (!saw_eol) {
throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1890,7 +1892,7 @@ namespace chaiscript
}
else if (For()) {
if (!saw_eol) {
throw Eval_Error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1898,7 +1900,7 @@ namespace chaiscript
}
else if (Return()) {
if (!saw_eol) {
throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1906,7 +1908,7 @@ namespace chaiscript
}
else if (Break()) {
if (!saw_eol) {
throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1914,7 +1916,7 @@ namespace chaiscript
}
else if (Equation()) {
if (!saw_eol) {
throw Eval_Error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename);
}
has_more = true;
retval = true;
@@ -1957,7 +1959,7 @@ namespace chaiscript
if (Statements()) {
if (m_input_pos != m_input_end) {
throw Eval_Error("Unparsed input", File_Position(m_line, m_col), t_fname);
throw exception::eval_error("Unparsed input", File_Position(m_line, m_col), t_fname);
}
else {
build_match(AST_NodePtr(new eval::File_AST_Node()), 0);
@@ -1970,5 +1972,6 @@ namespace chaiscript
}
};
}
}
#endif /* CHAISCRIPT_PARSER_HPP_ */

View File

@@ -107,14 +107,14 @@ void interactive(chaiscript::ChaiScript& chai)
catch (...) {} //If we can't, do nothing
}
}
catch (chaiscript::Eval_Error &ee) {
catch (const chaiscript::exception::eval_error &ee) {
std::cout << ee.what();
if (ee.call_stack.size() > 0) {
std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
}
std::cout << std::endl;
}
catch (std::exception &e) {
catch (const std::exception &e) {
std::cout << e.what();
std::cout << std::endl;
}
@@ -205,7 +205,7 @@ int main(int argc, char *argv[])
case eFile : val = chai.eval_file(arg); break;
}
}
catch (chaiscript::Eval_Error &ee) {
catch (const chaiscript::exception::eval_error &ee) {
std::cout << ee.what();
if (ee.call_stack.size() > 0) {
std::cout << "during evaluation at (" << *(ee.call_stack[0]->filename) << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";

View File

@@ -71,8 +71,8 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
);
CHAISCRIPT_CLASS( m,
chaiscript::ChaiScript_Parser,
(chaiscript::ChaiScript_Parser ()),
chaiscript::parser::ChaiScript_Parser,
(chaiscript::parser::ChaiScript_Parser ()),
((parse))
((ast))
);