GG
|
00001 // -*- C++ -*- 00002 /* GG is a GUI for SDL and OpenGL. 00003 Copyright (C) 2003-2008 T. Zachary Laine 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public License 00007 as published by the Free Software Foundation; either version 2.1 00008 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00018 02111-1307 USA 00019 00020 If you do not wish to comply with the terms of the LGPL please 00021 contact the author as other terms are available for a fee. 00022 00023 Zach Laine 00024 whatwasthataddress@gmail.com */ 00025 00028 #ifndef _GG_ExpressionParser_h_ 00029 #define _GG_ExpressionParser_h_ 00030 00031 #include <GG/Lexer.h> 00032 #include <GG/adobe/array.hpp> 00033 #include <GG/adobe/dictionary.hpp> 00034 #include <GG/adobe/implementation/token.hpp> 00035 00036 #include <boost/spirit/include/qi.hpp> 00037 #include <boost/spirit/include/phoenix.hpp> 00038 00039 00040 namespace GG { 00041 00042 namespace detail { 00043 00044 struct report_error_ 00045 { 00046 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4> 00047 struct result 00048 { typedef void type; }; 00049 00050 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4> 00051 void operator()(Arg1 first, Arg2 last, Arg3 it, Arg4 rule_name) const 00052 { 00053 std::string error_string; 00054 generate_error_string(*first, *it, rule_name, first == last, error_string); 00055 send_error_string(error_string); 00056 } 00057 00058 static boost::function<void (const std::string&)> send_error_string; 00059 static void default_send_error_string(const std::string& str); 00060 00061 private: 00062 void generate_error_string(const token_type& first, 00063 const token_type& it, 00064 const boost::spirit::info& rule_name, 00065 bool at_end, 00066 std::string& str) const; 00067 }; 00068 00069 extern GG_API const boost::phoenix::function<report_error_> report_error; 00070 00071 } 00072 00073 struct GG_API expression_parser_rules 00074 { 00075 typedef boost::spirit::qi::rule< 00076 token_iterator, 00077 adobe::name_t(), 00078 skipper_type 00079 > keyword_rule; 00080 00081 expression_parser_rules(const lexer& tok, const keyword_rule& keyword_); 00082 00083 typedef boost::spirit::qi::rule< 00084 token_iterator, 00085 void(adobe::array_t&), 00086 boost::spirit::qi::locals<adobe::array_t, adobe::array_t>, 00087 skipper_type 00088 > expression_rule; 00089 typedef boost::spirit::qi::rule< 00090 token_iterator, 00091 void(adobe::array_t&), 00092 boost::spirit::qi::locals<adobe::name_t>, 00093 skipper_type 00094 > local_name_rule; 00095 typedef boost::spirit::qi::rule< 00096 token_iterator, 00097 void(adobe::array_t&), 00098 boost::spirit::qi::locals<std::size_t>, 00099 skipper_type 00100 > local_size_rule; 00101 typedef boost::spirit::qi::rule< 00102 token_iterator, 00103 void(adobe::array_t&), 00104 boost::spirit::qi::locals<adobe::array_t>, 00105 skipper_type 00106 > local_array_rule; 00107 typedef boost::spirit::qi::rule< 00108 token_iterator, 00109 void(adobe::array_t&), 00110 skipper_type 00111 > no_locals_rule; 00112 00113 // expression grammar 00114 expression_rule expression; 00115 00116 local_array_rule or_expression; 00117 local_array_rule and_expression; 00118 local_name_rule equality_expression; 00119 local_name_rule relational_expression; 00120 local_name_rule additive_expression; 00121 local_name_rule multiplicative_expression; 00122 local_name_rule unary_expression; 00123 no_locals_rule postfix_expression; 00124 no_locals_rule primary_expression; 00125 local_name_rule variable_or_function; 00126 no_locals_rule array; 00127 no_locals_rule dictionary; 00128 no_locals_rule argument_expression_list; 00129 local_size_rule argument_list; 00130 local_size_rule named_argument_list; 00131 local_name_rule named_argument; 00132 no_locals_rule name; 00133 no_locals_rule boolean; 00134 00135 // lexical grammar 00136 boost::spirit::qi::rule< 00137 token_iterator, 00138 void(adobe::array_t&), 00139 boost::spirit::qi::locals<std::string>, 00140 skipper_type 00141 > string; 00142 keyword_rule keyword; 00143 }; 00144 00145 } 00146 00147 #endif // _GG_ExpressionParser_h_