From 2cff44d27a7ed9c1526c0805c1f04623106d13ea Mon Sep 17 00:00:00 2001 From: Myun2 Date: Sun, 9 Jan 2011 04:07:40 +0900 Subject: [PATCH] =?utf8?q?lexical/exception.hpp=20=E3=81=B8=E3=81=AE?= =?utf8?q?=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/lexical/exception.hpp | 120 ++++++++++++++++++++++++++++++ roast/include/roast/lexical/rule.hpp | 97 +----------------------- 2 files changed, 121 insertions(+), 96 deletions(-) create mode 100644 roast/include/roast/lexical/exception.hpp diff --git a/roast/include/roast/lexical/exception.hpp b/roast/include/roast/lexical/exception.hpp new file mode 100644 index 00000000..a61c7406 --- /dev/null +++ b/roast/include/roast/lexical/exception.hpp @@ -0,0 +1,120 @@ +// Roast+ License +/* +*/ +#ifndef __SFJP_ROAST__lexical__exception_HPP__ +#define __SFJP_ROAST__lexical__exception_HPP__ + +namespace roast +{ + namespace lexical + { + class lexical_exception : public ::std::string + { + public: + lexical_exception(const char* msg) : ::std::string(msg) {} + }; + + namespace rule + { + class lexical_rule_exception : public lexical_exception + { + public: + lexical_rule_exception(const char* msg) : lexical_exception(msg) {} + }; + + class illegal_terminated : public lexical_exception + { + public: + illegal_terminated() : lexical_exception("illegal terminated.") {} + }; + + class end_of_iterator_exception : public lexical_exception + { + public: + end_of_iterator_exception(const char* msg="End of iterator") : lexical_exception(msg) {} + }; + typedef end_of_iterator_exception iterator_term_exception, eoi_exception; + + ////////////////////////////////////////////////////////////////////////////// + + template + class on_true; + + template + class on_false; + + template + class _false_ret_to_exception_proc + { + public: + template + bool operator ()(_It&, _Param&) + { + throw _Exception(); + return true; + } + }; + + template + class false_ret_to_exception : public on_false< T, _false_ret_to_exception_proc<_Exception> > {}; + + /// + template class send_normal_event; + template class send_error_event; + + class Exception_is_send_normal_event; + class Exception_is_send_error_event; + + template + class false_ret_to_exception > : public _true_analyze { + Exception_is_send_normal_event _; }; + template + class false_ret_to_exception > : public _true_analyze{ + Exception_is_send_normal_event _; }; + + ////////// + + template + class exception_to_false : public T + { + public: + template + bool analyze(_It &it, _Param& param) + { + try + { + T t; + return t.analyze(it, param); + } + catch(_CatchException &) + { + return false; + } + } + }; + + template + class exception_to_exception : public T + { + public: + template + bool analyze(_It &it, _Param& param) + { + try + { + T t; + return t.analyze(it, param); + } + catch(_CatchException &) + { + throw _NewException(); + } + } + }; + } + + ////////////////////////////////////////////////// + } +} + +#endif//__SFJP_ROAST__lexical__exception_HPP__ diff --git a/roast/include/roast/lexical/rule.hpp b/roast/include/roast/lexical/rule.hpp index 7f69e8a0..3d7d002a 100644 --- a/roast/include/roast/lexical/rule.hpp +++ b/roast/include/roast/lexical/rule.hpp @@ -8,33 +8,15 @@ #include "roast/memory/sized_ptr.hpp" #include "roast/type_traits/is_derived.hpp" // for length_of +#include "roast/lexical/exception.hpp" #include namespace roast { namespace lexical { - class lexical_exception : public ::std::string - { - public: - lexical_exception(const char* msg) : ::std::string(msg) {} - }; - namespace rule { - class lexical_rule_exception : public ::std::string - { - public: - lexical_rule_exception(const char* msg) : ::std::string(msg) {} - }; - - class end_of_iterator_exception : public ::std::string - { - public: - end_of_iterator_exception(const char* msg="End of iterator") : ::std::string(msg) {} - }; - typedef end_of_iterator_exception iterator_term_exception, eoi_exception; - ////////////////////////////////////////////////////////////////////////////////// struct lengthable {}; @@ -241,83 +223,6 @@ namespace roast } }; - ////////// - - class illegal_terminated : public lexical_exception - { - public: - illegal_terminated() : lexical_exception("illegal terminated.") {} - }; - - template - class _false_ret_to_exception_proc - { - public: - template - bool operator ()(_It&, _Param&) - { - throw _Exception(); - return true; - } - }; - - template - class false_ret_to_exception : public on_false< T, _false_ret_to_exception_proc<_Exception> > {}; - - /// - template class send_normal_event; - template class send_error_event; - - class Exception_is_send_normal_event; - class Exception_is_send_error_event; - - template - class false_ret_to_exception > : public _true_analyze { - Exception_is_send_normal_event _; }; - template - class false_ret_to_exception > : public _true_analyze{ - Exception_is_send_normal_event _; }; - - ////////// - - template - class exception_to_false : public T - { - public: - template - bool analyze(_It &it, _Param& param) - { - try - { - T t; - return t.analyze(it, param); - } - catch(_CatchException &) - { - return false; - } - } - }; - - template - class exception_to_exception : public T - { - public: - template - bool analyze(_It &it, _Param& param) - { - try - { - T t; - return t.analyze(it, param); - } - catch(_CatchException &) - { - throw _NewException(); - } - } - }; - //////////////////////////////////////////////////////////////// template -- 2.11.0