function_def.hpp 2.1 KB

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