Move around some namespaces for documentation purposes.

Fix problems with building on clang 2.8.
Remove unneeded function for get_engine() and fix functor<> calls that take a Boxed_Value
This commit is contained in:
Jason Turner
2011-03-15 17:35:14 -06:00
parent 9dd9ffec46
commit 637164e457
9 changed files with 1478 additions and 1437 deletions

View File

@@ -257,29 +257,40 @@ namespace chaiscript
}; };
namespace exception
{
/** /**
* Exception thrown in the case that a multi method dispatch fails * Exception thrown in the case that a multi method dispatch fails
* because no matching function was found * because no matching function was found
* at runtime due to either an arity_error, a guard_error or a bad_boxed_cast * at runtime due to either an arity_error, a guard_error or a bad_boxed_cast
* exception * exception
*/ */
struct reserved_word_error : std::runtime_error class reserved_word_error : public std::runtime_error
{ {
public:
reserved_word_error(const std::string &t_word) throw() reserved_word_error(const std::string &t_word) throw()
: std::runtime_error("Reserved word not allowed in object name: " + word), word(t_word) : std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word)
{ {
} }
std::string word;
virtual ~reserved_word_error() throw() {} virtual ~reserved_word_error() throw() {}
std::string word() const
{
return m_word;
}
private:
std::string m_word;
}; };
/** /**
* Exception thrown in the case that a non-const object was added as a shared object * Exception thrown in the case that a non-const object was added as a shared object
*/ */
struct global_non_const : std::runtime_error class global_non_const : public std::runtime_error
{ {
public:
global_non_const() throw() global_non_const() throw()
: std::runtime_error("a global object must be const") : std::runtime_error("a global object must be const")
{ {
@@ -287,7 +298,7 @@ namespace chaiscript
virtual ~global_non_const() throw() {} virtual ~global_non_const() throw() {}
}; };
}
/** /**
* Main class for the dispatchkit. Handles management * Main class for the dispatchkit. Handles management
@@ -377,7 +388,7 @@ namespace chaiscript
validate_object_name(name); validate_object_name(name);
if (!obj.is_const()) if (!obj.is_const())
{ {
throw global_non_const(); throw exception::global_non_const();
} }
#ifndef CHAISCRIPT_NO_THREADS #ifndef CHAISCRIPT_NO_THREADS
@@ -909,7 +920,7 @@ namespace chaiscript
if (m_state.m_reserved_words.find(name) != m_state.m_reserved_words.end()) if (m_state.m_reserved_words.find(name) != m_state.m_reserved_words.end())
{ {
throw reserved_word_error(name); throw exception::reserved_word_error(name);
} }
} }

View File

@@ -6,7 +6,7 @@
#include <boost/preprocessor.hpp> #include <boost/preprocessor.hpp>
#define addparam(z,n,text) params.push_back(boost::is_reference<Param ## n>::value?Boxed_Value(boost::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); #define addparam(z,n,text) params.push_back((boost::is_reference<Param ## n>::value&&!(boost::is_same<chaiscript::Boxed_Value, typename boost::remove_const<typename boost::remove_reference<Param ## n>::type>::type>::value))?Boxed_Value(boost::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) ));
#define curry(z,n,text) BOOST_PP_CAT(_, BOOST_PP_INC(n)) #define curry(z,n,text) BOOST_PP_CAT(_, BOOST_PP_INC(n))
@@ -25,6 +25,7 @@ namespace chaiscript
{ {
namespace detail namespace detail
{ {
/** /**
* Internal helper class for handling the return * Internal helper class for handling the return
* value of a build_function_caller * value of a build_function_caller

View File

@@ -324,7 +324,7 @@ namespace chaiscript
Bound_Function(const Const_Proxy_Function &t_f, Bound_Function(const Const_Proxy_Function &t_f,
const std::vector<Boxed_Value> &t_args) const std::vector<Boxed_Value> &t_args)
: Proxy_Function_Base(build_param_type_info(t_f, t_args)), : Proxy_Function_Base(build_param_type_info(t_f, t_args)),
m_f(t_f), m_args(t_args), m_arity(t_f->get_arity()<0?-1:get_param_types().size()-1) m_f(t_f), m_args(t_args), m_arity(t_f->get_arity()<0?-1:static_cast<int>(get_param_types().size())-1)
{ {
assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast<int>(m_args.size())); assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast<int>(m_args.size()));
} }
@@ -569,14 +569,17 @@ namespace chaiscript
T Class::* m_attr; T Class::* m_attr;
}; };
namespace exception
{
/** /**
* Exception thrown in the case that a multi method dispatch fails * Exception thrown in the case that a multi method dispatch fails
* because no matching function was found * because no matching function was found
* at runtime due to either an arity_error, a guard_error or a bad_boxed_cast * at runtime due to either an arity_error, a guard_error or a bad_boxed_cast
* exception * exception
*/ */
struct dispatch_error : std::runtime_error class dispatch_error : public std::runtime_error
{ {
public:
dispatch_error() throw() dispatch_error() throw()
: std::runtime_error("No matching function to dispatch to") : std::runtime_error("No matching function to dispatch to")
{ {
@@ -589,6 +592,7 @@ namespace chaiscript
virtual ~dispatch_error() throw() {} virtual ~dispatch_error() throw() {}
}; };
}
/** /**
* Take a vector of functions and a vector of parameters. Attempt to execute * Take a vector of functions and a vector of parameters. Attempt to execute
@@ -617,7 +621,7 @@ namespace chaiscript
++begin; ++begin;
} }
throw dispatch_error(plist.empty()?false:plist[0].is_const()); throw exception::dispatch_error(plist.empty()?false:plist[0].is_const());
} }
/** /**

View File

@@ -49,29 +49,6 @@ namespace chaiscript
}; };
} }
namespace detail
{
template<typename Ret>
struct Do_Call
{
template<typename Fun>
static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params)
{
return Handle_Return<Ret>::handle(call_func(fun, params));
}
};
template<>
struct Do_Call<void>
{
template<typename Fun>
static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params)
{
call_func(fun, params);
return Handle_Return<void>::handle();
}
};
}
} }
#define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) #define BOOST_PP_ITERATION_LIMITS ( 0, 10 )
@@ -143,3 +120,35 @@ namespace chaiscript
#undef n #undef n
#endif #endif
#ifndef BOOST_PP_IS_ITERATING
namespace chaiscript
{
namespace detail
{
template<typename Ret>
struct Do_Call
{
template<typename Fun>
static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params)
{
return Handle_Return<Ret>::handle(chaiscript::detail::call_func(fun, params));
}
};
template<>
struct Do_Call<void>
{
template<typename Fun>
static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params)
{
chaiscript::detail::call_func(fun, params);
return Handle_Return<void>::handle();
}
};
}
}
#endif

View File

@@ -298,6 +298,13 @@ namespace chaiscript
} }
} }
/**
* Returns the current evaluation m_engine
*/
Dispatch_Engine &get_eval_engine() {
return m_engine;
}
public: public:
ChaiScript(const std::vector<std::string> &t_modulepaths = std::vector<std::string>(), ChaiScript(const std::vector<std::string> &t_modulepaths = std::vector<std::string>(),
@@ -481,13 +488,6 @@ namespace chaiscript
} }
/**
* Returns the current evaluation m_engine
*/
Dispatch_Engine &get_eval_engine() {
return m_engine;
}
/** /**
* Helper function for loading a file * Helper function for loading a file
*/ */

View File

@@ -42,6 +42,8 @@ namespace chaiscript
} }
namespace eval
{
struct Binary_Operator_AST_Node : public AST_Node { struct Binary_Operator_AST_Node : public AST_Node {
public: public:
Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
@@ -62,7 +64,7 @@ namespace chaiscript
try { try {
retval = t_ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(t_ss)); retval = t_ss.call_function(this->children[i]->text, retval, this->children[i+1]->eval(t_ss));
} }
catch(const dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate '" + this->children[i]->text + "'"); throw Eval_Error("Can not find appropriate '" + this->children[i]->text + "'");
} }
catch(Eval_Error &ee) { catch(Eval_Error &ee) {
@@ -188,7 +190,7 @@ namespace chaiscript
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
return retval; return retval;
} }
catch(const dispatch_error &e){ catch(const exception::dispatch_error &e){
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
} }
@@ -237,7 +239,7 @@ namespace chaiscript
try { try {
return (*boxed_cast<Const_Proxy_Function >(fn))(plb); return (*boxed_cast<Const_Proxy_Function >(fn))(plb);
} }
catch(const dispatch_error &e){ catch(const exception::dispatch_error &e){
throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); throw Eval_Error(std::string(e.what()) + " with function '" + this->children[0]->text + "'");
} }
catch(Return_Value &rv) { catch(Return_Value &rv) {
@@ -300,11 +302,11 @@ namespace chaiscript
try { try {
retval = t_ss.call_function(this->children[i+1]->text, lhs, retval); retval = t_ss.call_function(this->children[i+1]->text, lhs, retval);
} }
catch(const dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":".")); throw Eval_Error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":"."));
} }
} }
catch(const dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not clone right hand side of equation"); throw Eval_Error("Can not clone right hand side of equation");
} }
} }
@@ -332,7 +334,7 @@ namespace chaiscript
try { try {
retval = t_ss.call_function(this->children[i+1]->text, this->children[i]->eval(t_ss), retval); retval = t_ss.call_function(this->children[i+1]->text, this->children[i]->eval(t_ss), retval);
} }
catch(const dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate '" + this->children[i+1]->text + "'"); throw Eval_Error("Can not find appropriate '" + this->children[i+1]->text + "'");
} }
catch(Eval_Error &ee) { catch(Eval_Error &ee) {
@@ -355,7 +357,7 @@ namespace chaiscript
try { try {
t_ss.add_object(this->children[0]->text, Boxed_Value()); t_ss.add_object(this->children[0]->text, Boxed_Value());
} }
catch (reserved_word_error &) { catch (const exception::reserved_word_error &) {
throw Eval_Error("Reserved word used as variable '" + this->children[0]->text + "'"); throw Eval_Error("Reserved word used as variable '" + this->children[0]->text + "'");
} }
return t_ss.get_object(this->children[0]->text); return t_ss.get_object(this->children[0]->text);
@@ -407,7 +409,7 @@ namespace chaiscript
catch(std::out_of_range &) { catch(std::out_of_range &) {
throw Eval_Error("Out of bounds exception"); throw Eval_Error("Out of bounds exception");
} }
catch(const dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate array lookup '[]' "); throw Eval_Error("Can not find appropriate array lookup '[]' ");
} }
catch(Eval_Error &ee) { catch(Eval_Error &ee) {
@@ -468,7 +470,7 @@ namespace chaiscript
retval = t_ss.call_function(fun_name, plb); retval = t_ss.call_function(fun_name, plb);
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
} }
catch(const dispatch_error &e){ catch(const exception::dispatch_error &e){
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
throw Eval_Error(std::string(e.what())); throw Eval_Error(std::string(e.what()));
} }
@@ -488,7 +490,7 @@ namespace chaiscript
catch(std::out_of_range &) { catch(std::out_of_range &) {
throw Eval_Error("Out of bounds exception"); throw Eval_Error("Out of bounds exception");
} }
catch(const dispatch_error &){ catch(const exception::dispatch_error &){
throw Eval_Error("Can not find appropriate array lookup '[]' "); throw Eval_Error("Can not find appropriate array lookup '[]' ");
} }
catch(Eval_Error &ee) { catch(Eval_Error &ee) {
@@ -641,8 +643,8 @@ namespace chaiscript
t_param_names, _1), static_cast<int>(numparams), this->children.back(), t_param_names, _1), static_cast<int>(numparams), this->children.back(),
l_annotation, guard)), l_function_name); l_annotation, guard)), l_function_name);
} }
catch (reserved_word_error &e) { catch (const exception::reserved_word_error &e) {
throw Eval_Error("Reserved word used as function name '" + e.word + "'"); throw Eval_Error("Reserved word used as function name '" + e.word() + "'");
} }
return Boxed_Value(); return Boxed_Value();
} }
@@ -930,7 +932,7 @@ namespace chaiscript
} }
return const_var(retval); return const_var(retval);
} }
catch (const dispatch_error &) { catch (const exception::dispatch_error &) {
throw Eval_Error("Can not find appropriate 'Map()'"); throw Eval_Error("Can not find appropriate 'Map()'");
} }
} }
@@ -1033,7 +1035,7 @@ namespace chaiscript
this->children[0]->children[0]->children[0]->eval(t_ss), this->children[0]->children[0]->children[0]->eval(t_ss),
this->children[0]->children[0]->children[1]->eval(t_ss)); this->children[0]->children[0]->children[1]->eval(t_ss));
} }
catch (const dispatch_error &) { catch (const exception::dispatch_error &) {
throw Eval_Error("Unable to generate range vector"); throw Eval_Error("Unable to generate range vector");
} }
catch(Eval_Error &ee) { catch(Eval_Error &ee) {
@@ -1362,8 +1364,8 @@ namespace chaiscript
} }
} }
catch (reserved_word_error &e) { catch (const exception::reserved_word_error &e) {
throw Eval_Error("Reserved word used as method name '" + e.word + "'"); throw Eval_Error("Reserved word used as method name '" + e.word() + "'");
} }
return Boxed_Value(); return Boxed_Value();
} }
@@ -1381,7 +1383,7 @@ namespace chaiscript
this->children[1]->text, _1))), this->children[1]->text); this->children[1]->text, _1))), this->children[1]->text);
} }
catch (reserved_word_error &) { catch (const exception::reserved_word_error &) {
throw Eval_Error("Reserved word used as attribute '" + this->children[1]->text + "'"); throw Eval_Error("Reserved word used as attribute '" + this->children[1]->text + "'");
} }
return Boxed_Value(); return Boxed_Value();
@@ -1509,6 +1511,7 @@ namespace chaiscript
} }
}; };
}
} }

View File

@@ -15,6 +15,8 @@
#include "chaiscript_common.hpp" #include "chaiscript_common.hpp"
namespace chaiscript namespace chaiscript
{
namespace detail
{ {
enum Alphabet enum Alphabet
{ symbol_alphabet = 0 { symbol_alphabet = 0
@@ -30,6 +32,7 @@ namespace chaiscript
, max_alphabet , max_alphabet
, lengthof_alphabet = 256 , lengthof_alphabet = 256
}; };
}
class ChaiScript_Parser { class ChaiScript_Parser {
@@ -40,7 +43,7 @@ namespace chaiscript
std::string m_singleline_comment; std::string m_singleline_comment;
boost::shared_ptr<std::string> m_filename; boost::shared_ptr<std::string> m_filename;
std::vector<AST_NodePtr> m_match_stack; std::vector<AST_NodePtr> m_match_stack;
bool m_alphabet[max_alphabet][lengthof_alphabet]; bool m_alphabet[detail::max_alphabet][detail::lengthof_alphabet];
std::vector<std::vector<std::string> > m_operator_matches; std::vector<std::vector<std::string> > m_operator_matches;
std::vector<AST_Node_Type::Type> m_operators; std::vector<AST_Node_Type::Type> m_operators;
@@ -122,55 +125,55 @@ namespace chaiscript
dot_access.push_back("."); dot_access.push_back(".");
m_operator_matches.push_back(dot_access); m_operator_matches.push_back(dot_access);
for ( int c = 0 ; c < lengthof_alphabet ; ++c ) { for ( int c = 0 ; c < detail::lengthof_alphabet ; ++c ) {
for ( int a = 0 ; a < max_alphabet ; a ++ ) { for ( int a = 0 ; a < detail::max_alphabet ; a ++ ) {
m_alphabet[a][c]=false; m_alphabet[a][c]=false;
} }
} }
m_alphabet[symbol_alphabet]['+']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('+')]=true;
m_alphabet[symbol_alphabet]['-']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('-')]=true;
m_alphabet[symbol_alphabet]['*']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('*')]=true;
m_alphabet[symbol_alphabet]['/']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('/')]=true;
m_alphabet[symbol_alphabet]['|']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('|')]=true;
m_alphabet[symbol_alphabet]['&']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('&')]=true;
m_alphabet[symbol_alphabet]['^']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('^')]=true;
m_alphabet[symbol_alphabet]['=']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('=')]=true;
m_alphabet[symbol_alphabet]['.']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('.')]=true;
m_alphabet[symbol_alphabet]['<']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('<')]=true;
m_alphabet[symbol_alphabet]['>']=true; m_alphabet[detail::symbol_alphabet][static_cast<int>('>')]=true;
for ( int c = 'a' ; c <= 'z' ; ++c ) { m_alphabet[keyword_alphabet][c]=true; } for ( int c = 'a' ; c <= 'z' ; ++c ) { m_alphabet[detail::keyword_alphabet][c]=true; }
for ( int c = 'A' ; c <= 'Z' ; ++c ) { m_alphabet[keyword_alphabet][c]=true; } for ( int c = 'A' ; c <= 'Z' ; ++c ) { m_alphabet[detail::keyword_alphabet][c]=true; }
for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[keyword_alphabet][c]=true; } for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[detail::keyword_alphabet][c]=true; }
m_alphabet[keyword_alphabet]['_']=true; m_alphabet[detail::keyword_alphabet][static_cast<int>('_')]=true;
for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[int_alphabet][c]=true; } for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[detail::int_alphabet][c]=true; }
for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[float_alphabet][c]=true; } for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[detail::float_alphabet][c]=true; }
m_alphabet[float_alphabet]['.']=true; m_alphabet[detail::float_alphabet][static_cast<int>('.')]=true;
for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[hex_alphabet][c]=true; } for ( int c = '0' ; c <= '9' ; ++c ) { m_alphabet[detail::hex_alphabet][c]=true; }
for ( int c = 'a' ; c <= 'f' ; ++c ) { m_alphabet[hex_alphabet][c]=true; } for ( int c = 'a' ; c <= 'f' ; ++c ) { m_alphabet[detail::hex_alphabet][c]=true; }
for ( int c = 'A' ; c <= 'F' ; ++c ) { m_alphabet[hex_alphabet][c]=true; } for ( int c = 'A' ; c <= 'F' ; ++c ) { m_alphabet[detail::hex_alphabet][c]=true; }
m_alphabet[x_alphabet]['x']=true; m_alphabet[detail::x_alphabet][static_cast<int>('x')]=true;
m_alphabet[x_alphabet]['X']=true; m_alphabet[detail::x_alphabet][static_cast<int>('X')]=true;
for ( int c = '0' ; c <= '1' ; ++c ) { m_alphabet[bin_alphabet][c]=true; } for ( int c = '0' ; c <= '1' ; ++c ) { m_alphabet[detail::bin_alphabet][c]=true; }
m_alphabet[b_alphabet]['b']=true; m_alphabet[detail::b_alphabet][static_cast<int>('b')]=true;
m_alphabet[b_alphabet]['B']=true; m_alphabet[detail::b_alphabet][static_cast<int>('B')]=true;
for ( int c = 'a' ; c <= 'z' ; ++c ) { m_alphabet[id_alphabet][c]=true; } for ( int c = 'a' ; c <= 'z' ; ++c ) { m_alphabet[detail::id_alphabet][c]=true; }
for ( int c = 'A' ; c <= 'Z' ; ++c ) { m_alphabet[id_alphabet][c]=true; } for ( int c = 'A' ; c <= 'Z' ; ++c ) { m_alphabet[detail::id_alphabet][c]=true; }
m_alphabet[id_alphabet]['_'] = true; m_alphabet[detail::id_alphabet][static_cast<int>('_')] = true;
m_alphabet[white_alphabet][' ']=true; m_alphabet[detail::white_alphabet][static_cast<int>(' ')]=true;
m_alphabet[white_alphabet]['\t']=true; m_alphabet[detail::white_alphabet][static_cast<int>('\t')]=true;
} }
/** /**
* test a char in an m_alphabet * test a char in an m_alphabet
*/ */
bool char_in_alphabet(unsigned char c,Alphabet a) { return m_alphabet[a][c]; } bool char_in_alphabet(unsigned char c, detail::Alphabet a) { return m_alphabet[a][c]; }
/** /**
* Prints the parsed ast_nodes as a tree * Prints the parsed ast_nodes as a tree
@@ -298,7 +301,7 @@ namespace chaiscript
bool SkipWS() { bool SkipWS() {
bool retval = false; bool retval = false;
while (has_more_input()) { while (has_more_input()) {
if ( char_in_alphabet(*m_input_pos,white_alphabet) ) { if ( char_in_alphabet(*m_input_pos,detail::white_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
retval = true; retval = true;
@@ -320,17 +323,17 @@ namespace chaiscript
bool retval = false; bool retval = false;
std::string::const_iterator start = m_input_pos; std::string::const_iterator start = m_input_pos;
if (has_more_input() && char_in_alphabet(*m_input_pos,float_alphabet) ) { if (has_more_input() && char_in_alphabet(*m_input_pos,detail::float_alphabet) ) {
while (has_more_input() && char_in_alphabet(*m_input_pos,int_alphabet) ) { while (has_more_input() && char_in_alphabet(*m_input_pos,detail::int_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
} }
if (has_more_input() && (*m_input_pos == '.')) { if (has_more_input() && (*m_input_pos == '.')) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
if (has_more_input() && char_in_alphabet(*m_input_pos,int_alphabet)) { if (has_more_input() && char_in_alphabet(*m_input_pos,detail::int_alphabet)) {
retval = true; retval = true;
while (has_more_input() && char_in_alphabet(*m_input_pos,int_alphabet) ) { while (has_more_input() && char_in_alphabet(*m_input_pos,detail::int_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
} }
@@ -353,12 +356,12 @@ namespace chaiscript
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
if (has_more_input() && char_in_alphabet(*m_input_pos,x_alphabet) ) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::x_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
if (has_more_input() && char_in_alphabet(*m_input_pos,hex_alphabet)) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::hex_alphabet)) {
retval = true; retval = true;
while (has_more_input() && char_in_alphabet(*m_input_pos,hex_alphabet) ) { while (has_more_input() && char_in_alphabet(*m_input_pos, detail::hex_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
} }
@@ -386,12 +389,12 @@ namespace chaiscript
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
if (has_more_input() && char_in_alphabet(*m_input_pos,b_alphabet) ) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::b_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
if (has_more_input() && char_in_alphabet(*m_input_pos,bin_alphabet) ) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::bin_alphabet) ) {
retval = true; retval = true;
while (has_more_input() && char_in_alphabet(*m_input_pos,bin_alphabet) ) { while (has_more_input() && char_in_alphabet(*m_input_pos, detail::bin_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
} }
@@ -423,7 +426,7 @@ namespace chaiscript
std::string::const_iterator start = m_input_pos; std::string::const_iterator start = m_input_pos;
int prev_col = m_col; int prev_col = m_col;
int prev_line = m_line; int prev_line = m_line;
if (has_more_input() && char_in_alphabet(*m_input_pos,float_alphabet) ) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) {
if (Hex_()) { if (Hex_()) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
std::stringstream ss(match); std::stringstream ss(match);
@@ -432,7 +435,7 @@ namespace chaiscript
std::ostringstream out_int; std::ostringstream out_int;
out_int << static_cast<int>(temp_int); out_int << static_cast<int>(temp_int);
AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -451,13 +454,13 @@ namespace chaiscript
std::ostringstream out_int; std::ostringstream out_int;
out_int << temp_int; out_int << temp_int;
AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
if (Float_()) { if (Float_()) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Float_AST_Node(match, AST_Node_Type::Float, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Float_AST_Node(match, AST_Node_Type::Float, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -470,11 +473,11 @@ namespace chaiscript
std::ostringstream out_int; std::ostringstream out_int;
out_int << int(temp_int); out_int << int(temp_int);
AST_NodePtr t(new Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Int_AST_Node(out_int.str(), AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
} }
else { else {
AST_NodePtr t(new Int_AST_Node(match, AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Int_AST_Node(match, AST_Node_Type::Int, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
} }
return true; return true;
@@ -491,9 +494,9 @@ namespace chaiscript
*/ */
bool Id_() { bool Id_() {
bool retval = false; bool retval = false;
if (has_more_input() && char_in_alphabet(*m_input_pos,id_alphabet)) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::id_alphabet)) {
retval = true; retval = true;
while (has_more_input() && char_in_alphabet(*m_input_pos,keyword_alphabet) ) { while (has_more_input() && char_in_alphabet(*m_input_pos, detail::keyword_alphabet) ) {
++m_input_pos; ++m_input_pos;
++m_col; ++m_col;
} }
@@ -544,13 +547,13 @@ namespace chaiscript
if (*start == '`') { if (*start == '`') {
//Id Literal //Id Literal
std::string match(start+1, m_input_pos-1); std::string match(start+1, m_input_pos-1);
AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Id_AST_Node(match, AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
else { else {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Id_AST_Node(match, AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Id_AST_Node(match, AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -583,7 +586,7 @@ namespace chaiscript
} while (Symbol("#")); } while (Symbol("#"));
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Annotation_AST_Node(match, AST_Node_Type::Annotation, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Annotation_AST_Node(match, AST_Node_Type::Annotation, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -658,23 +661,23 @@ namespace chaiscript
if (is_interpolated) { if (is_interpolated) {
//If we've seen previous interpolation, add on instead of making a new one //If we've seen previous interpolation, add on instead of making a new one
AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr plus(new eval::Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(plus); m_match_stack.push_back(plus);
AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Additive_AST_Node()), prev_stack_top);
} }
else { else {
AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
} }
//We've finished with the part of the string up to this point, so clear it //We've finished with the part of the string up to this point, so clear it
match = ""; match = "";
AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr plus(new eval::Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(plus); m_match_stack.push_back(plus);
std::string eval_match; std::string eval_match;
@@ -690,28 +693,28 @@ namespace chaiscript
size_t tostr_stack_top = m_match_stack.size(); size_t tostr_stack_top = m_match_stack.size();
AST_NodePtr tostr(new Id_AST_Node("to_string", AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr tostr(new eval::Id_AST_Node("to_string", AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(tostr); m_match_stack.push_back(tostr);
size_t ev_stack_top = m_match_stack.size(); size_t ev_stack_top = m_match_stack.size();
AST_NodePtr ev(new Id_AST_Node("eval", AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr ev(new eval::Id_AST_Node("eval", AST_Node_Type::Id, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(ev); m_match_stack.push_back(ev);
size_t arg_stack_top = m_match_stack.size(); size_t arg_stack_top = m_match_stack.size();
AST_NodePtr t(new Quoted_String_AST_Node(eval_match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Quoted_String_AST_Node(eval_match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
build_match(AST_NodePtr(new Arg_List_AST_Node()), arg_stack_top); build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), arg_stack_top);
build_match(AST_NodePtr(new Inplace_Fun_Call_AST_Node()), ev_stack_top); build_match(AST_NodePtr(new eval::Inplace_Fun_Call_AST_Node()), ev_stack_top);
build_match(AST_NodePtr(new Arg_List_AST_Node()), ev_stack_top); build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), ev_stack_top);
build_match(AST_NodePtr(new Fun_Call_AST_Node()), tostr_stack_top); build_match(AST_NodePtr(new eval::Fun_Call_AST_Node()), tostr_stack_top);
build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Additive_AST_Node()), prev_stack_top);
} }
else { else {
throw Eval_Error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename); throw Eval_Error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename);
@@ -758,16 +761,16 @@ namespace chaiscript
} }
} }
if (is_interpolated) { if (is_interpolated) {
AST_NodePtr plus(new Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr plus(new eval::Str_AST_Node("+", AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(plus); m_match_stack.push_back(plus);
AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Additive_AST_Node()), prev_stack_top);
} }
else { else {
AST_NodePtr t(new Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Quoted_String_AST_Node(match, AST_Node_Type::Quoted_String, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
} }
return true; return true;
@@ -859,7 +862,7 @@ namespace chaiscript
is_escaped = false; is_escaped = false;
} }
} }
AST_NodePtr t(new Single_Quoted_String_AST_Node(match, AST_Node_Type::Single_Quoted_String, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Single_Quoted_String_AST_Node(match, AST_Node_Type::Single_Quoted_String, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -898,7 +901,7 @@ namespace chaiscript
int prev_line = m_line; int prev_line = m_line;
if (Char_(t_c)) { if (Char_(t_c)) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Char_AST_Node(match, AST_Node_Type::Char, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Char_AST_Node(match, AST_Node_Type::Char, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -941,7 +944,7 @@ namespace chaiscript
int prev_line = m_line; int prev_line = m_line;
bool retval = Keyword_(t_s); bool retval = Keyword_(t_s);
// ignore substring matches // ignore substring matches
if ( retval && has_more_input() && char_in_alphabet(*m_input_pos,keyword_alphabet) ) { if ( retval && has_more_input() && char_in_alphabet(*m_input_pos, detail::keyword_alphabet) ) {
m_input_pos = start; m_input_pos = start;
m_col = prev_col; m_col = prev_col;
m_line = prev_line; m_line = prev_line;
@@ -950,7 +953,7 @@ namespace chaiscript
if ( t_capture && retval ) { if ( t_capture && retval ) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Str_AST_Node(match, AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
} }
return retval; return retval;
@@ -989,7 +992,7 @@ namespace chaiscript
int prev_line = m_line; int prev_line = m_line;
bool retval = Symbol_(t_s); bool retval = Symbol_(t_s);
// ignore substring matches // ignore substring matches
if (retval && has_more_input() && (t_disallow_prevention == false) && char_in_alphabet(*m_input_pos,symbol_alphabet)) { if (retval && has_more_input() && (t_disallow_prevention == false) && char_in_alphabet(*m_input_pos,detail::symbol_alphabet)) {
m_input_pos = start; m_input_pos = start;
m_col = prev_col; m_col = prev_col;
m_line = prev_line; m_line = prev_line;
@@ -998,7 +1001,7 @@ namespace chaiscript
if ( t_capture && retval ) { if ( t_capture && retval ) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Str_AST_Node(match, AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Str_AST_Node(match, AST_Node_Type::Str, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
} }
@@ -1038,7 +1041,7 @@ namespace chaiscript
int prev_line = m_line; int prev_line = m_line;
if (Eol_()) { if (Eol_()) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
AST_NodePtr t(new Eol_AST_Node(match, AST_Node_Type::Eol, m_filename, prev_line, prev_col, m_line, m_col)); AST_NodePtr t(new eval::Eol_AST_Node(match, AST_Node_Type::Eol, m_filename, prev_line, prev_col, m_line, m_col));
m_match_stack.push_back(t); m_match_stack.push_back(t);
return true; return true;
} }
@@ -1067,7 +1070,7 @@ namespace chaiscript
} }
} while (retval && Char(',')); } while (retval && Char(','));
} }
build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1083,7 +1086,7 @@ namespace chaiscript
if (Value_Range()) { if (Value_Range()) {
retval = true; retval = true;
build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top);
} }
else if (Map_Pair()) { else if (Map_Pair()) {
retval = true; retval = true;
@@ -1096,7 +1099,7 @@ namespace chaiscript
} }
} while (retval && Char(',')); } while (retval && Char(','));
} }
build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top);
} }
else if (Operator()) { else if (Operator()) {
retval = true; retval = true;
@@ -1109,7 +1112,7 @@ namespace chaiscript
} }
} while (retval && Char(',')); } while (retval && Char(','));
} }
build_match(AST_NodePtr(new Arg_List_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1140,7 +1143,7 @@ namespace chaiscript
throw Eval_Error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Lambda_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Lambda_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1201,10 +1204,10 @@ namespace chaiscript
} }
if (is_method) { if (is_method) {
build_match(AST_NodePtr(new Method_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Method_AST_Node()), prev_stack_top);
} }
else { else {
build_match(AST_NodePtr(new Def_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Def_AST_Node()), prev_stack_top);
} }
if (is_annotated) { if (is_annotated) {
@@ -1254,7 +1257,7 @@ namespace chaiscript
if (!Block()) { if (!Block()) {
throw Eval_Error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Catch_AST_Node()), catch_stack_top); build_match(AST_NodePtr(new eval::Catch_AST_Node()), catch_stack_top);
has_matches = true; has_matches = true;
} }
} }
@@ -1267,10 +1270,10 @@ namespace chaiscript
if (!Block()) { if (!Block()) {
throw Eval_Error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Finally_AST_Node()), finally_stack_top); build_match(AST_NodePtr(new eval::Finally_AST_Node()), finally_stack_top);
} }
build_match(AST_NodePtr(new Try_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Try_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1334,7 +1337,7 @@ namespace chaiscript
} }
} }
build_match(AST_NodePtr(new If_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::If_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1365,7 +1368,7 @@ namespace chaiscript
throw Eval_Error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new While_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::While_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1410,7 +1413,7 @@ namespace chaiscript
throw Eval_Error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new For_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::For_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1432,7 +1435,7 @@ namespace chaiscript
throw Eval_Error("Incomplete block", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete block", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Block_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Block_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1450,7 +1453,7 @@ namespace chaiscript
retval = true; retval = true;
Operator(); Operator();
build_match(AST_NodePtr(new Return_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Return_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1467,7 +1470,7 @@ namespace chaiscript
if (Keyword("break")) { if (Keyword("break")) {
retval = true; retval = true;
build_match(AST_NodePtr(new Break_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Break_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1496,7 +1499,7 @@ namespace chaiscript
throw Eval_Error("Incomplete function call", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete function call", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Fun_Call_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Fun_Call_AST_Node()), prev_stack_top);
} }
else if (Char('[')) { else if (Char('[')) {
has_more = true; has_more = true;
@@ -1505,7 +1508,7 @@ namespace chaiscript
throw Eval_Error("Incomplete array access", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Array_Call_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Array_Call_AST_Node()), prev_stack_top);
} }
} }
} }
@@ -1528,7 +1531,7 @@ namespace chaiscript
throw Eval_Error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Var_Decl_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Var_Decl_AST_Node()), prev_stack_top);
} }
else if (Keyword("attr")) { else if (Keyword("attr")) {
retval = true; retval = true;
@@ -1544,7 +1547,7 @@ namespace chaiscript
} }
build_match(AST_NodePtr(new Attr_Decl_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Attr_Decl_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1584,17 +1587,17 @@ namespace chaiscript
} }
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { 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) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
build_match(AST_NodePtr(new Inline_Range_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Inline_Range_AST_Node()), prev_stack_top);
} }
else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) { else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) {
build_match(AST_NodePtr(new Inline_Map_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Inline_Map_AST_Node()), prev_stack_top);
} }
else { else {
build_match(AST_NodePtr(new Inline_Array_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Inline_Array_AST_Node()), prev_stack_top);
} }
} }
else { else {
build_match(AST_NodePtr(new Inline_Array_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Inline_Array_AST_Node()), prev_stack_top);
} }
} }
@@ -1616,7 +1619,7 @@ namespace chaiscript
throw Eval_Error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete '++' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
} }
else if (Symbol("--", true)) { else if (Symbol("--", true)) {
retval = true; retval = true;
@@ -1625,7 +1628,7 @@ namespace chaiscript
throw Eval_Error("Incomplete '--' expression", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete '--' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
} }
else if (Char('-', true)) { else if (Char('-', true)) {
retval = true; retval = true;
@@ -1634,7 +1637,7 @@ namespace chaiscript
throw Eval_Error("Incomplete unary '-' expression", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete unary '-' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
} }
else if (Char('+', true)) { else if (Char('+', true)) {
retval = true; retval = true;
@@ -1643,7 +1646,7 @@ namespace chaiscript
throw Eval_Error("Incomplete unary '+' expression", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete unary '+' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
} }
else if (Char('!', true)) { else if (Char('!', true)) {
retval = true; retval = true;
@@ -1652,7 +1655,7 @@ namespace chaiscript
throw Eval_Error("Incomplete '!' expression", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete '!' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
} }
else if (Char('~', true)) { else if (Char('~', true)) {
retval = true; retval = true;
@@ -1661,7 +1664,7 @@ namespace chaiscript
throw Eval_Error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Prefix_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top);
} }
return retval; return retval;
@@ -1708,37 +1711,37 @@ namespace chaiscript
switch (m_operators[t_precedence]) { switch (m_operators[t_precedence]) {
case(AST_Node_Type::Comparison) : case(AST_Node_Type::Comparison) :
build_match(AST_NodePtr(new Comparison_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Comparison_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Dot_Access) : case(AST_Node_Type::Dot_Access) :
build_match(AST_NodePtr(new Dot_Access_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Dot_Access_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Additive) : case(AST_Node_Type::Additive) :
build_match(AST_NodePtr(new Additive_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Additive_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Multiplicative) : case(AST_Node_Type::Multiplicative) :
build_match(AST_NodePtr(new Multiplicative_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Multiplicative_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Shift) : case(AST_Node_Type::Shift) :
build_match(AST_NodePtr(new Shift_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Shift_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Equality) : case(AST_Node_Type::Equality) :
build_match(AST_NodePtr(new Equality_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Equality_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Bitwise_And) : case(AST_Node_Type::Bitwise_And) :
build_match(AST_NodePtr(new Bitwise_And_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Bitwise_And_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Bitwise_Xor) : case(AST_Node_Type::Bitwise_Xor) :
build_match(AST_NodePtr(new Bitwise_Xor_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Bitwise_Xor_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Bitwise_Or) : case(AST_Node_Type::Bitwise_Or) :
build_match(AST_NodePtr(new Bitwise_Or_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Bitwise_Or_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Logical_And) : case(AST_Node_Type::Logical_And) :
build_match(AST_NodePtr(new Logical_And_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Logical_And_AST_Node()), prev_stack_top);
break; break;
case(AST_Node_Type::Logical_Or) : case(AST_Node_Type::Logical_Or) :
build_match(AST_NodePtr(new Logical_Or_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Logical_Or_AST_Node()), prev_stack_top);
break; break;
default: default:
throw Eval_Error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename);
@@ -1770,7 +1773,7 @@ namespace chaiscript
throw Eval_Error("Incomplete map pair", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete map pair", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Map_Pair_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Map_Pair_AST_Node()), prev_stack_top);
} }
else { else {
m_input_pos = prev_pos; m_input_pos = prev_pos;
@@ -1801,7 +1804,7 @@ namespace chaiscript
throw Eval_Error("Incomplete value range", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete value range", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Value_Range_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Value_Range_AST_Node()), prev_stack_top);
} }
else { else {
m_input_pos = prev_pos; m_input_pos = prev_pos;
@@ -1833,7 +1836,7 @@ namespace chaiscript
throw Eval_Error("Incomplete equation", File_Position(m_line, m_col), *m_filename); throw Eval_Error("Incomplete equation", File_Position(m_line, m_col), *m_filename);
} }
build_match(AST_NodePtr(new Equation_AST_Node()), prev_stack_top); build_match(AST_NodePtr(new eval::Equation_AST_Node()), prev_stack_top);
} }
} }
@@ -1957,7 +1960,7 @@ namespace chaiscript
throw Eval_Error("Unparsed input", File_Position(m_line, m_col), t_fname); throw Eval_Error("Unparsed input", File_Position(m_line, m_col), t_fname);
} }
else { else {
build_match(AST_NodePtr(new File_AST_Node()), 0); build_match(AST_NodePtr(new eval::File_AST_Node()), 0);
return true; return true;
} }
} }

View File

@@ -102,7 +102,7 @@ void interactive(chaiscript::ChaiScript& chai)
//Then, we try to print the result of the evaluation to the user //Then, we try to print the result of the evaluation to the user
if (!val.get_type_info().bare_equal(chaiscript::user_type<void>())) { if (!val.get_type_info().bare_equal(chaiscript::user_type<void>())) {
try { try {
chaiscript::dispatch(chai.get_eval_engine().get_function("print"), chaiscript::Param_List_Builder() << val); std::cout << chai.functor<std::string (const chaiscript::Boxed_Value &bv)>("to_string")(val) << std::endl;
} }
catch (...) {} //If we can't, do nothing catch (...) {} //If we can't, do nothing
} }

View File

@@ -8,9 +8,19 @@ int main()
chai.eval("def func() { print(\"Hello World\"); } "); chai.eval("def func() { print(\"Hello World\"); } ");
boost::function<void ()> f = chai.functor<void ()>("func"); boost::function<void ()> f = chai.functor<void ()>("func");
f(); f();
if (chai.functor<std::string (int)>("to_string")(6) != "6")
{
return EXIT_FAILURE;
}
if (chai.functor<std::string (const chaiscript::Boxed_Value &)>("to_string")(chaiscript::var(6)) == "6")
{
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
} }