1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include "expression.hpp"
8 #include "error_handler.hpp"
9 #include "annotation.hpp"
10 #include <boost/spirit/include/phoenix_function.hpp>
12 namespace client { namespace parser
14 template <typename Iterator>
15 expression<Iterator>::expression(error_handler<Iterator>& error_handler)
16 : expression::base_type(expr)
27 qi::lexeme_type lexeme;
35 using boost::phoenix::function;
37 typedef function<client::error_handler<Iterator> > error_handler_function;
38 typedef function<client::annotation<Iterator> > annotation_function;
40 ///////////////////////////////////////////////////////////////////////
52 ("!=", ast::op_not_equal)
57 ("<=", ast::op_less_equal)
58 (">", ast::op_greater)
59 (">=", ast::op_greater_equal)
73 ("+", ast::op_positive)
74 ("-", ast::op_negative)
89 ///////////////////////////////////////////////////////////////////////
90 // Main expression grammar
92 logical_or_expr.alias()
97 >> *(logical_or_op > logical_and_expr)
102 >> *(logical_and_op > equality_expr)
107 >> *(equality_op > relational_expr)
112 >> *(relational_op > additive_expr)
117 >> *(additive_op > multiplicative_expr)
120 multiplicative_expr =
122 >> *(multiplicative_op > unary_expr)
127 | (unary_op > unary_expr)
144 argument_list = -(expr % ',');
147 !lexeme[keywords >> !(alnum | '_')]
148 >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]]
151 ///////////////////////////////////////////////////////////////////////
152 // Debugging and error handling and reporting support.
153 BOOST_SPIRIT_DEBUG_NODES(
160 (multiplicative_expr)
168 ///////////////////////////////////////////////////////////////////////
169 // Error handling: on error in expr, call error_handler.
171 error_handler_function(error_handler)(
172 "Error! Expecting ", _4, _3));
174 ///////////////////////////////////////////////////////////////////////
175 // Annotation: on success in primary_expr, call annotation.
176 on_success(primary_expr,
177 annotation_function(error_handler.iters)(_val, _1));