summaryrefslogtreecommitdiff
path: root/tools/quickbook/src/grammar.hpp
blob: 73aae4a26cc10121ed365cac731e1250049b9d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*=============================================================================
    Copyright (c) 2002 2004  2006Joel de Guzman
    Copyright (c) 2004 Eric Niebler
    http://spirit.sourceforge.net/

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP)
#define BOOST_SPIRIT_QUICKBOOK_GRAMMARS_HPP

#include <boost/spirit/include/classic_core.hpp>
#include "fwd.hpp"

namespace quickbook
{
    namespace cl = boost::spirit::classic;

    // The spirit scanner for explicitly instantiating grammars. This is a
    // spirit implementation detail, but since classic is no longer under
    // development, it won't change. And spirit 2 won't require such a hack.

    typedef cl::scanner<parse_iterator, cl::scanner_policies <
        cl::iteration_policy, cl::match_policy, cl::action_policy> > scanner;

    template <typename Scanner>
    struct Scanner_must_be_the_quickbook_scanner_typedef;
    template <>
    struct Scanner_must_be_the_quickbook_scanner_typedef<scanner> {};

    struct grammar
        : public cl::grammar<grammar>
    {
        grammar(cl::rule<scanner> const& start_rule, char const* /* name */)
            : start_rule(start_rule) {}

        template <typename Scanner>
        struct definition :
            Scanner_must_be_the_quickbook_scanner_typedef<Scanner>
        {
            definition(grammar const& self) : start_rule(self.start_rule) {}
            cl::rule<scanner> const& start() const { return start_rule; }
            cl::rule<scanner> const& start_rule;
        };

        cl::rule<scanner> const& start_rule;
    };

    struct quickbook_grammar
    {
    public:
        struct impl;

    private:
        boost::scoped_ptr<impl> impl_;

    public:
        grammar command_line_macro;
        grammar inline_phrase;
        grammar phrase;
        grammar block;
        grammar doc_info;

        quickbook_grammar(quickbook::actions&);
        ~quickbook_grammar();
    };
}

#endif