1 /*============================================================================= 2 Copyright (c) 2002 2004 2006Joel de Guzman 3 Copyright (c) 2004 Eric Niebler 4 http://spirit.sourceforge.net/ 5 6 Use, modification and distribution is subject to the Boost Software 7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 http://www.boost.org/LICENSE_1_0.txt) 9 =============================================================================*/ 10 #if !defined(BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP) 11 #define BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP 12 13 #include <boost/spirit/include/classic_core.hpp> 14 #include "fwd.hpp" 15 #include "iterator.hpp" 16 17 namespace quickbook 18 { 19 namespace cl = boost::spirit::classic; 20 21 // The spirit scanner for explicitly instantiating grammars. This is a 22 // spirit implementation detail, but since classic is no longer under 23 // development, it won't change. And spirit 2 won't require such a hack. 24 25 typedef cl::scanner< 26 parse_iterator, 27 cl::scanner_policies< 28 cl::iteration_policy, 29 cl::match_policy, 30 cl::action_policy> > 31 scanner; 32 33 template <typename Scanner> 34 struct Scanner_must_be_the_quickbook_scanner_typedef; 35 template <> struct Scanner_must_be_the_quickbook_scanner_typedef<scanner> 36 { 37 }; 38 39 struct grammar : public cl::grammar<grammar> 40 { grammarquickbook::grammar41 grammar(cl::rule<scanner> const& start_rule_, char const* /* name */) 42 : start_rule(start_rule_) 43 { 44 } 45 46 template <typename Scanner> 47 struct definition 48 : Scanner_must_be_the_quickbook_scanner_typedef<Scanner> 49 { definitionquickbook::grammar::definition50 definition(grammar const& self) : start_rule(self.start_rule) {} startquickbook::grammar::definition51 cl::rule<scanner> const& start() const { return start_rule; } 52 cl::rule<scanner> const& start_rule; 53 }; 54 55 cl::rule<scanner> const& start_rule; 56 }; 57 58 struct quickbook_grammar 59 { 60 public: 61 struct impl; 62 63 private: 64 boost::scoped_ptr<impl> impl_; 65 66 public: 67 grammar command_line_macro; 68 grammar inline_phrase; 69 grammar phrase_start; 70 grammar block_start; 71 grammar attribute_template_body; 72 grammar doc_info; 73 74 quickbook_grammar(quickbook::state&); 75 ~quickbook_grammar(); 76 }; 77 } 78 79 #endif 80