| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | Copyright (c) 2001-2011 Hartmut Kaiser |
| 4 | |
| 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 "function.hpp" |
| 9 | #include "error_handler.hpp" |
| 10 | #include "annotation.hpp" |
| 11 | |
| 12 | namespace client { namespace parser |
| 13 | { |
| 14 | template <typename Iterator, typename Lexer> |
| 15 | function<Iterator, Lexer>::function( |
| 16 | error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler |
| 17 | , Lexer const& l) |
| 18 | : function::base_type(start), body(error_handler, l) |
| 19 | { |
| 20 | qi::_1_type _1; |
| 21 | qi::_2_type _2; |
| 22 | qi::_3_type _3; |
| 23 | qi::_4_type _4; |
| 24 | |
| 25 | qi::_val_type _val; |
| 26 | |
| 27 | using qi::on_error; |
| 28 | using qi::on_success; |
| 29 | using qi::fail; |
| 30 | using boost::phoenix::function; |
| 31 | |
| 32 | typedef client::error_handler<typename Lexer::base_iterator_type, Iterator> |
| 33 | error_handler_type; |
| 34 | typedef function<error_handler_type> error_handler_function; |
| 35 | typedef function<client::annotation<Iterator> > annotation_function; |
| 36 | |
| 37 | identifier = body.expr.identifier; |
| 38 | argument_list = -(identifier % ','); |
| 39 | |
| 40 | start = (l.token("void" ) | l.token("int" )) |
| 41 | > identifier |
| 42 | > '(' > argument_list > ')' |
| 43 | > (';' | '{' > body > '}') |
| 44 | ; |
| 45 | |
| 46 | // Debugging and error handling and reporting support. |
| 47 | BOOST_SPIRIT_DEBUG_NODES( |
| 48 | (identifier) |
| 49 | (argument_list) |
| 50 | (start) |
| 51 | ); |
| 52 | |
| 53 | // Error handling: on error in start, call error_handler. |
| 54 | on_error<fail>(start, |
| 55 | error_handler_function(error_handler)( |
| 56 | "Error! Expecting " , _4, _3)); |
| 57 | |
| 58 | // Annotation: on success in start, call annotation. |
| 59 | on_success(identifier, |
| 60 | annotation_function(error_handler.iters)(_val, _1)); |
| 61 | } |
| 62 | }} |
| 63 | |
| 64 | |
| 65 | |