1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #include "expression.hpp"
9 #include "error_handler.hpp"
10 #include "annotation.hpp"
11 #include <boost/spirit/include/phoenix_function.hpp>
12 #include <boost/spirit/include/lex_plain_token.hpp>
14 namespace client { namespace parser
16 template <typename Iterator, typename Lexer>
17 expression<Iterator, Lexer>::expression(
18 error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler
20 : expression::base_type(expr), lexer(l)
28 qi::tokenid_mask_type tokenid_mask;
33 using boost::phoenix::function;
35 typedef client::error_handler<typename Lexer::base_iterator_type, Iterator>
37 typedef function<error_handler_type> error_handler_function;
38 typedef function<client::annotation<Iterator> > annotation_function;
40 ///////////////////////////////////////////////////////////////////////
41 // Main expression grammar
44 >> *(tokenid_mask(token_ids::op_binary) > unary_expr)
49 | (tokenid_mask(token_ids::op_unary) > unary_expr)
70 argument_list = -(expr % ',');
72 identifier = lexer.identifier;
74 ///////////////////////////////////////////////////////////////////////
75 // Debugging and error handling and reporting support.
76 BOOST_SPIRIT_DEBUG_NODES(
86 ///////////////////////////////////////////////////////////////////////
87 // Error handling: on error in expr, call error_handler.
89 error_handler_function(error_handler)(
90 "Error! Expecting ", _4, _3));
92 ///////////////////////////////////////////////////////////////////////
93 // Annotation: on success in unary_expr, postfix_expr,
94 // and primary_expr call annotation.
95 on_success(unary_expr,
96 annotation_function(error_handler.iters)(_val, _1));
97 on_success(postfix_expr,
98 annotation_function(error_handler.iters)(_val, _1));
99 on_success(primary_expr,
100 annotation_function(error_handler.iters)(_val, _1));