Merge branch 'master' of https://github.com/ChaiScript/ChaiScript
This commit is contained in:
@@ -17,7 +17,7 @@ set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.txt")
|
|||||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt")
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt")
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR 3)
|
set(CPACK_PACKAGE_VERSION_MAJOR 3)
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR 0)
|
set(CPACK_PACKAGE_VERSION_MINOR 1)
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH 0)
|
set(CPACK_PACKAGE_VERSION_PATCH 0)
|
||||||
set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval")
|
set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval")
|
||||||
set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
||||||
|
@@ -140,7 +140,7 @@
|
|||||||
///
|
///
|
||||||
/// \subsubsection addingobjects Adding Objects
|
/// \subsubsection addingobjects Adding Objects
|
||||||
///
|
///
|
||||||
/// Named objects can be created with the #var function.
|
/// Named objects can be created with the chaiscript::var function.
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// using namespace chaiscript;
|
/// using namespace chaiscript;
|
||||||
@@ -300,7 +300,7 @@
|
|||||||
/// As much as possible, ChaiScript attempts to convert between &, *, const &, const *, boost::shared_ptr<T>,
|
/// As much as possible, ChaiScript attempts to convert between &, *, const &, const *, boost::shared_ptr<T>,
|
||||||
/// boost::shared_ptr<const T>, boost::reference_wrapper<T>, boost::reference_wrapper<const T> and value types automatically.
|
/// boost::shared_ptr<const T>, boost::reference_wrapper<T>, boost::reference_wrapper<const T> and value types automatically.
|
||||||
///
|
///
|
||||||
/// If a var object was created in C++ from a pointer, it cannot be convered to a shared_ptr (this would add invalid reference counting).
|
/// If a chaiscript::var object was created in C++ from a pointer, it cannot be convered to a shared_ptr (this would add invalid reference counting).
|
||||||
/// Const may be added, but never removed.
|
/// Const may be added, but never removed.
|
||||||
///
|
///
|
||||||
/// The take away is that you can pretty much expect function calls to Just Work when you need them to.
|
/// The take away is that you can pretty much expect function calls to Just Work when you need them to.
|
||||||
@@ -413,6 +413,8 @@
|
|||||||
///
|
///
|
||||||
/// \subsection exceptions Exception Handling
|
/// \subsection exceptions Exception Handling
|
||||||
///
|
///
|
||||||
|
/// \subsubsection exceptionsbasics Exception Handling Basics
|
||||||
|
///
|
||||||
/// Exceptions can be thrown in ChaiScript and caught in C++ or thrown in C++ and caught in
|
/// Exceptions can be thrown in ChaiScript and caught in C++ or thrown in C++ and caught in
|
||||||
/// ChaiScript.
|
/// ChaiScript.
|
||||||
///
|
///
|
||||||
@@ -424,10 +426,12 @@
|
|||||||
///
|
///
|
||||||
/// int main()
|
/// int main()
|
||||||
/// {
|
/// {
|
||||||
|
/// // Throw in C++, catch in ChaiScript
|
||||||
/// chaiscript::ChaiScript chai;
|
/// chaiscript::ChaiScript chai;
|
||||||
/// chai.add(chaiscript::fun(&throwexception), "throwexception");
|
/// chai.add(chaiscript::fun(&throwexception), "throwexception");
|
||||||
/// chai("try { throwexception(); } catch (e) { print(e.what()); }"); // prints "err"
|
/// chai("try { throwexception(); } catch (e) { print(e.what()); }"); // prints "err"
|
||||||
///
|
///
|
||||||
|
/// // Throw in ChaiScript, catch in C++
|
||||||
/// try {
|
/// try {
|
||||||
/// chai("throw(1)");
|
/// chai("throw(1)");
|
||||||
/// } catch (chaiscript::Boxed_Value bv) {
|
/// } catch (chaiscript::Boxed_Value bv) {
|
||||||
@@ -436,6 +440,31 @@
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// \subsubsection exceptionsautomatic Exception Handling Automatic Unboxing
|
||||||
|
///
|
||||||
|
/// As an alternative to the manual unboxing of exceptions shown above, exception specifications allow the user to tell
|
||||||
|
/// ChaiScript what possible exceptions are expected from the script being executed.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// \code
|
||||||
|
/// chaiscript::ChaiScript chai;
|
||||||
|
///
|
||||||
|
/// try {
|
||||||
|
/// chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<int, double, float, const std::string &, const std::exception &>());
|
||||||
|
/// } catch (const double e) {
|
||||||
|
/// } catch (int) {
|
||||||
|
/// } catch (float) {
|
||||||
|
/// } catch (const std::string &) {
|
||||||
|
/// } catch (const std::exception &e) {
|
||||||
|
/// // This is the one what will be called in the specific throw() above
|
||||||
|
/// }
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// \sa chaiscript::Exception_Handler for details on automatic exception unboxing
|
||||||
|
/// \sa chaiscript::exception_specification
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// \page LangObjectSystemRef ChaiScript Language Object Model Reference
|
/// \page LangObjectSystemRef ChaiScript Language Object Model Reference
|
||||||
///
|
///
|
||||||
|
176
include/chaiscript/dispatchkit/exception_specification.hpp
Normal file
176
include/chaiscript/dispatchkit/exception_specification.hpp
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
// This file is distributed under the BSD License.
|
||||||
|
// See "license.txt" for details.
|
||||||
|
// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com)
|
||||||
|
// and Jason Turner (jason@emptycrate.com)
|
||||||
|
// http://www.chaiscript.com
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_EXCEPTION_SPECIFICATION_HPP_
|
||||||
|
#define CHAISCRIPT_EXCEPTION_SPECIFICATION_HPP_
|
||||||
|
|
||||||
|
#include "boxed_cast.hpp"
|
||||||
|
|
||||||
|
namespace chaiscript
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
struct Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual void handle(const Boxed_Value &bv) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template<typename T>
|
||||||
|
void throw_type(const Boxed_Value &bv)
|
||||||
|
{
|
||||||
|
try { T t = boxed_cast<T>(bv); throw t; } catch (const exception::bad_boxed_cast &) {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T1>
|
||||||
|
struct Exception_Handler_Impl1 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual void handle(const Boxed_Value &bv)
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
struct Exception_Handler_Impl2 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual void handle(const Boxed_Value &bv)
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv);
|
||||||
|
throw_type<T2>(bv);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T1, typename T2, typename T3>
|
||||||
|
struct Exception_Handler_Impl3 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual void handle(const Boxed_Value &bv)
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv);
|
||||||
|
throw_type<T2>(bv);
|
||||||
|
throw_type<T3>(bv);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4>
|
||||||
|
struct Exception_Handler_Impl4 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual void handle(const Boxed_Value &bv)
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv);
|
||||||
|
throw_type<T2>(bv);
|
||||||
|
throw_type<T3>(bv);
|
||||||
|
throw_type<T4>(bv);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||||
|
struct Exception_Handler_Impl5 : Exception_Handler_Base
|
||||||
|
{
|
||||||
|
virtual void handle(const Boxed_Value &bv)
|
||||||
|
{
|
||||||
|
throw_type<T1>(bv);
|
||||||
|
throw_type<T2>(bv);
|
||||||
|
throw_type<T3>(bv);
|
||||||
|
throw_type<T4>(bv);
|
||||||
|
throw_type<T5>(bv);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Used in the automatic unboxing of exceptions thrown during script evaluation
|
||||||
|
///
|
||||||
|
/// Exception specifications allow the user to tell ChaiScript what possible exceptions are expected from the script
|
||||||
|
/// being executed. Exception_Handler objects are created with the chaiscript::exception_specification() function.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// \code
|
||||||
|
/// chaiscript::ChaiScript chai;
|
||||||
|
///
|
||||||
|
/// try {
|
||||||
|
/// chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<int, double, float, const std::string &, const std::exception &>());
|
||||||
|
/// } catch (const double e) {
|
||||||
|
/// } catch (int) {
|
||||||
|
/// } catch (float) {
|
||||||
|
/// } catch (const std::string &) {
|
||||||
|
/// } catch (const std::exception &e) {
|
||||||
|
/// // This is the one what will be called in the specific throw() above
|
||||||
|
/// }
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// It is recommended that if catching the generic \c std::exception& type that you specifically catch
|
||||||
|
/// the chaiscript::exception::eval_error type, so that there is no confusion.
|
||||||
|
///
|
||||||
|
/// \code
|
||||||
|
/// try {
|
||||||
|
/// chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<const std::exception &>());
|
||||||
|
/// } catch (const chaiscript::exception::eval_error &) {
|
||||||
|
/// // Error in script parsing / execution
|
||||||
|
/// } catch (const std::exception &e) {
|
||||||
|
/// // Error explicitly thrown from script
|
||||||
|
/// }
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// Similarly, if you are using the ChaiScript::eval form that unboxes the return value, then chaiscript::exception::bad_boxed_cast
|
||||||
|
/// should be handled as well.
|
||||||
|
///
|
||||||
|
/// \code
|
||||||
|
/// try {
|
||||||
|
/// chai.eval<int>("1.0", chaiscript::exception_specification<const std::exception &>());
|
||||||
|
/// } catch (const chaiscript::exception::eval_error &) {
|
||||||
|
/// // Error in script parsing / execution
|
||||||
|
/// } catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||||
|
/// // Error unboxing return value
|
||||||
|
/// } catch (const std::exception &e) {
|
||||||
|
/// // Error explicitly thrown from script
|
||||||
|
/// }
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// \sa chaiscript::exception_specification for creation of chaiscript::Exception_Handler objects
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
typedef boost::shared_ptr<detail::Exception_Handler_Base> Exception_Handler;
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles one type of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl1<T1>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles two types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl2<T1, T2>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles three types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2, typename T3>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl3<T1, T2, T3>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles four types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl4<T1, T2, T3, T4>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief creates a chaiscript::Exception_Handler which handles five types of exception unboxing
|
||||||
|
/// \sa \ref exceptions
|
||||||
|
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||||
|
Exception_Handler exception_specification()
|
||||||
|
{
|
||||||
|
return Exception_Handler(new detail::Exception_Handler_Impl5<T1, T2, T3, T4, T5>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <chaiscript/language/chaiscript_prelude.hpp>
|
#include <chaiscript/language/chaiscript_prelude.hpp>
|
||||||
#include <chaiscript/language/chaiscript_parser.hpp>
|
#include <chaiscript/language/chaiscript_parser.hpp>
|
||||||
|
#include "../dispatchkit/exception_specification.hpp"
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
@@ -598,19 +599,28 @@ namespace chaiscript
|
|||||||
/// \brief Evaluates a string. Equivalent to ChaiScript::eval.
|
/// \brief Evaluates a string. Equivalent to ChaiScript::eval.
|
||||||
///
|
///
|
||||||
/// \param[in] t_script Script to execute
|
/// \param[in] t_script Script to execute
|
||||||
|
/// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions
|
||||||
///
|
///
|
||||||
/// \return result of the script execution
|
/// \return result of the script execution
|
||||||
///
|
///
|
||||||
/// \throw exception::eval_error In the case that evaluation fails.
|
/// \throw exception::eval_error In the case that evaluation fails.
|
||||||
Boxed_Value operator()(const std::string &t_script)
|
Boxed_Value operator()(const std::string &t_script, const Exception_Handler &t_handler = Exception_Handler())
|
||||||
{
|
{
|
||||||
return do_eval(t_script);
|
try {
|
||||||
|
return do_eval(t_script);
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv);
|
||||||
|
}
|
||||||
|
throw bv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Evaluates a string and returns a typesafe result.
|
/// \brief Evaluates a string and returns a typesafe result.
|
||||||
///
|
///
|
||||||
/// \tparam T Type to extract from the result value of the script execution
|
/// \tparam T Type to extract from the result value of the script execution
|
||||||
/// \param[in] t_input Script to execute
|
/// \param[in] t_input Script to execute
|
||||||
|
/// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions
|
||||||
///
|
///
|
||||||
/// \return result of the script execution
|
/// \return result of the script execution
|
||||||
///
|
///
|
||||||
@@ -618,41 +628,72 @@ namespace chaiscript
|
|||||||
/// \throw exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted
|
/// \throw exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted
|
||||||
/// to the requested type.
|
/// to the requested type.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T eval(const std::string &t_input)
|
T eval(const std::string &t_input, const Exception_Handler &t_handler = Exception_Handler())
|
||||||
{
|
{
|
||||||
return boxed_cast<T>(do_eval(t_input));
|
try {
|
||||||
|
return boxed_cast<T>(do_eval(t_input));
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv);
|
||||||
|
}
|
||||||
|
throw bv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Evaluates a string.
|
/// \brief Evaluates a string.
|
||||||
///
|
///
|
||||||
/// \param[in] t_input Script to execute
|
/// \param[in] t_input Script to execute
|
||||||
|
/// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions
|
||||||
///
|
///
|
||||||
/// \return result of the script execution
|
/// \return result of the script execution
|
||||||
///
|
///
|
||||||
/// \throw exception::eval_error In the case that evaluation fails.
|
/// \throw exception::eval_error In the case that evaluation fails.
|
||||||
Boxed_Value eval(const std::string &t_input)
|
Boxed_Value eval(const std::string &t_input, const Exception_Handler &t_handler = Exception_Handler())
|
||||||
{
|
{
|
||||||
return do_eval(t_input);
|
try {
|
||||||
|
return do_eval(t_input);
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv);
|
||||||
|
}
|
||||||
|
throw bv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Loads the file specified by filename, evaluates it, and returns the result.
|
/// \brief Loads the file specified by filename, evaluates it, and returns the result.
|
||||||
/// \param[in] t_filename File to load and parse.
|
/// \param[in] t_filename File to load and parse.
|
||||||
|
/// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions
|
||||||
/// \return result of the script execution
|
/// \return result of the script execution
|
||||||
/// \throw exception::eval_error In the case that evaluation fails.
|
/// \throw exception::eval_error In the case that evaluation fails.
|
||||||
Boxed_Value eval_file(const std::string &t_filename) {
|
Boxed_Value eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) {
|
||||||
return do_eval(load_file(t_filename), t_filename);
|
try {
|
||||||
|
return do_eval(load_file(t_filename), t_filename);
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv);
|
||||||
|
}
|
||||||
|
throw bv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Loads the file specified by filename, evaluates it, and returns the typesafe result.
|
/// \brief Loads the file specified by filename, evaluates it, and returns the typesafe result.
|
||||||
/// \tparam T Type to extract from the result value of the script execution
|
/// \tparam T Type to extract from the result value of the script execution
|
||||||
/// \param[in] t_filename File to load and parse.
|
/// \param[in] t_filename File to load and parse.
|
||||||
|
/// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions
|
||||||
/// \return result of the script execution
|
/// \return result of the script execution
|
||||||
/// \throw exception::eval_error In the case that evaluation fails.
|
/// \throw exception::eval_error In the case that evaluation fails.
|
||||||
/// \throw exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted
|
/// \throw exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted
|
||||||
/// to the requested type.
|
/// to the requested type.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T eval_file(const std::string &t_filename) {
|
T eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) {
|
||||||
return boxed_cast<T>(do_eval(load_file(t_filename), t_filename));
|
try {
|
||||||
|
return boxed_cast<T>(do_eval(load_file(t_filename), t_filename));
|
||||||
|
} catch (Boxed_Value &bv) {
|
||||||
|
if (t_handler) {
|
||||||
|
t_handler->handle(bv);
|
||||||
|
}
|
||||||
|
throw bv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -126,13 +126,6 @@ namespace chaiscript
|
|||||||
multiplication.push_back("%");
|
multiplication.push_back("%");
|
||||||
m_operator_matches.push_back(multiplication);
|
m_operator_matches.push_back(multiplication);
|
||||||
|
|
||||||
/*
|
|
||||||
m_operators.push_back(AST_Node_Type::Dot_Access);
|
|
||||||
std::vector<std::string> dot_access;
|
|
||||||
dot_access.push_back(".");
|
|
||||||
m_operator_matches.push_back(dot_access);
|
|
||||||
*/
|
|
||||||
|
|
||||||
for ( int c = 0 ; c < detail::lengthof_alphabet ; ++c ) {
|
for ( int c = 0 ; c < detail::lengthof_alphabet ; ++c ) {
|
||||||
for ( int a = 0 ; a < detail::max_alphabet ; a ++ ) {
|
for ( int a = 0 ; a < detail::max_alphabet ; a ++ ) {
|
||||||
m_alphabet[a][c]=false;
|
m_alphabet[a][c]=false;
|
||||||
@@ -1481,7 +1474,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an dot expression(member access), then proceeds to check if it's a function or array call
|
* Reads a dot expression(member access), then proceeds to check if it's a function or array call
|
||||||
*/
|
*/
|
||||||
bool Dot_Fun_Array() {
|
bool Dot_Fun_Array() {
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
@@ -1505,7 +1498,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
build_match(AST_NodePtr(new eval::Fun_Call_AST_Node()), prev_stack_top);
|
build_match(AST_NodePtr(new eval::Fun_Call_AST_Node()), prev_stack_top);
|
||||||
//FIXME: Work around for method calls until we have a better solution
|
/// \todo Work around for method calls until we have a better solution
|
||||||
if (!m_match_stack.back()->children.empty()) {
|
if (!m_match_stack.back()->children.empty()) {
|
||||||
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) {
|
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) {
|
||||||
AST_NodePtr dot_access = m_match_stack.back()->children[0];
|
AST_NodePtr dot_access = m_match_stack.back()->children[0];
|
||||||
@@ -1700,9 +1693,7 @@ namespace chaiscript
|
|||||||
* Parses any of a group of 'value' style ast_node groups from input
|
* Parses any of a group of 'value' style ast_node groups from input
|
||||||
*/
|
*/
|
||||||
bool Value() {
|
bool Value() {
|
||||||
if (Var_Decl() || /*Lambda() ||*/ Dot_Fun_Array() || /*Num(true) ||*/ Prefix() /*||
|
if (Var_Decl() || Dot_Fun_Array() || Prefix()) {
|
||||||
Quoted_String(true) || Single_Quoted_String(true) ||
|
|
||||||
Paren_Expression() || Inline_Container()*/) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1739,11 +1730,6 @@ namespace chaiscript
|
|||||||
case(AST_Node_Type::Comparison) :
|
case(AST_Node_Type::Comparison) :
|
||||||
build_match(AST_NodePtr(new eval::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) :
|
|
||||||
build_match(AST_NodePtr(new eval::Dot_Access_AST_Node()), prev_stack_top);
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
case(AST_Node_Type::Addition) :
|
case(AST_Node_Type::Addition) :
|
||||||
oper = m_match_stack.at(m_match_stack.size()-2);
|
oper = m_match_stack.at(m_match_stack.size()-2);
|
||||||
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2,
|
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2,
|
||||||
@@ -2000,7 +1986,7 @@ namespace chaiscript
|
|||||||
while ((m_input_pos != m_input_end) && (!Eol())) {
|
while ((m_input_pos != m_input_end) && (!Eol())) {
|
||||||
++m_input_pos;
|
++m_input_pos;
|
||||||
}
|
}
|
||||||
// TODO: respect // -*- coding: utf-8 -*- on line 1 or 2 see: http://evanjones.ca/python-utf8.html)
|
/// \todo respect // -*- coding: utf-8 -*- on line 1 or 2 see: http://evanjones.ca/python-utf8.html)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Statements()) {
|
if (Statements()) {
|
||||||
|
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
#include <chaiscript/chaiscript.hpp>
|
#include <chaiscript/chaiscript.hpp>
|
||||||
|
|
||||||
|
int test_generic()
|
||||||
int main()
|
|
||||||
{
|
{
|
||||||
chaiscript::ChaiScript chai;
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
@@ -17,5 +16,107 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "test_generic failed" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_1()
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
|
try {
|
||||||
|
chai.eval("throw(1)", chaiscript::exception_specification<int>());
|
||||||
|
} catch (int e) {
|
||||||
|
if (e == 1)
|
||||||
|
{
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "test_1 failed" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_2()
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
|
try {
|
||||||
|
chai.eval("throw(1.0)", chaiscript::exception_specification<int, double>());
|
||||||
|
} catch (const double e) {
|
||||||
|
if (e == 1.0)
|
||||||
|
{
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "test_2 failed" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_5()
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
|
try {
|
||||||
|
chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification<int, double, float, const std::string &, const std::exception &>());
|
||||||
|
} catch (const double e) {
|
||||||
|
std::cout << "test_5 failed with double" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (int) {
|
||||||
|
std::cout << "test_5 failed with int" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (float) {
|
||||||
|
std::cout << "test_5 failed with float" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (const std::string &) {
|
||||||
|
std::cout << "test_5 failed with string" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "test_5 failed" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_unhandled()
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
|
||||||
|
try {
|
||||||
|
chai.eval("throw(\"error\")", chaiscript::exception_specification<int, double, float, const std::exception &>());
|
||||||
|
} catch (double) {
|
||||||
|
std::cout << "test_unhandled failed with double" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (int) {
|
||||||
|
std::cout << "test_unhandled failed with int" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (float) {
|
||||||
|
std::cout << "test_unhandled failed with float" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cout << "test_unhandled failed with std::exception" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (const chaiscript::Boxed_Value &bv) {
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "test_unhandled failed" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (test_generic() == EXIT_SUCCESS
|
||||||
|
&& test_1() == EXIT_SUCCESS
|
||||||
|
&& test_2() == EXIT_SUCCESS
|
||||||
|
&& test_5() == EXIT_SUCCESS
|
||||||
|
&& test_unhandled() == EXIT_SUCCESS)
|
||||||
|
{
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user