mix_and_match_trees.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Copyright (c) 2006 Joao Abecasis
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. ////////////////////////////////////////////////////////////////////////////////
  9. //
  10. // As reported by Jascha Wetzel, in
  11. // http://article.gmane.org/gmane.comp.parsers.spirit.general/9013, the
  12. // directives gen_ast_node_d and gen_pt_node_d were not working for lack of
  13. // appropriate conversion constructors in the underlying tree match policies.
  14. //
  15. ////////////////////////////////////////////////////////////////////////////////
  16. #include <boost/spirit/include/classic_core.hpp>
  17. #include <boost/spirit/include/classic_ast.hpp>
  18. #include <boost/spirit/include/classic_parse_tree.hpp>
  19. using namespace BOOST_SPIRIT_CLASSIC_NS;
  20. struct my_grammar : grammar<my_grammar>
  21. {
  22. template <class Scanner>
  23. struct definition
  24. {
  25. typedef
  26. scanner<
  27. typename Scanner::iterator_t,
  28. scanner_policies<
  29. typename Scanner::iteration_policy_t,
  30. ast_match_policy<
  31. typename Scanner::match_policy_t::iterator_t,
  32. typename Scanner::match_policy_t::factory_t
  33. >,
  34. typename Scanner::action_policy_t
  35. >
  36. > ast_scanner;
  37. typedef
  38. scanner<
  39. typename Scanner::iterator_t,
  40. scanner_policies<
  41. typename Scanner::iteration_policy_t,
  42. pt_match_policy<
  43. typename Scanner::match_policy_t::iterator_t,
  44. typename Scanner::match_policy_t::factory_t
  45. >,
  46. typename Scanner::action_policy_t
  47. >
  48. > pt_scanner;
  49. typedef rule<ast_scanner> ast_rule;
  50. typedef rule<pt_scanner> pt_rule;
  51. typedef rule<Scanner> rule_;
  52. definition(my_grammar const & /* self */)
  53. {
  54. start_ = gen_ast_node_d[ ast_rule_ ];
  55. start_ = gen_pt_node_d[ pt_rule_ ];
  56. }
  57. rule_ const & start() const
  58. {
  59. return start_;
  60. }
  61. rule_ start_;
  62. ast_rule ast_rule_;
  63. pt_rule pt_rule_;
  64. };
  65. };
  66. int main()
  67. {
  68. const char * begin = NULL, * end = NULL;
  69. pt_parse(begin, end, my_grammar());
  70. ast_parse(begin, end, my_grammar());
  71. }