summaryrefslogtreecommitdiff
path: root/boost/spirit/home/qi/parser.hpp
blob: ffd8bc913f0fd2b99dd9a5ba9b660f1c284356cc (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman

    Distributed under 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_PARSER_OCTOBER_16_2008_0254PM)
#define BOOST_SPIRIT_PARSER_OCTOBER_16_2008_0254PM

#if defined(_MSC_VER)
#pragma once
#endif

#include <boost/mpl/has_xxx.hpp>
#include <boost/spirit/home/qi/domain.hpp>

namespace boost { namespace spirit { namespace qi
{

    //[parser_base_parser
    template <typename Derived>
    struct parser
    {
        struct parser_id;
        typedef Derived derived_type;
        typedef qi::domain domain;

        // Requirement: p.parse(f, l, context, skip, attr) -> bool
        //
        //  p:          a parser
        //  f, l:       first/last iterator pair
        //  context:    enclosing rule context (can be unused_type)
        //  skip:       skipper (can be unused_type)
        //  attr:       attribute (can be unused_type)

        // Requirement: p.what(context) -> info
        //
        //  p:          a parser
        //  context:    enclosing rule context (can be unused_type)

        // Requirement: P::template attribute<Ctx, Iter>::type
        //
        //  P:          a parser type
        //  Ctx:        A context type (can be unused_type)
        //  Iter:       An iterator type (can be unused_type)

        Derived const& derived() const
        {
            return *static_cast<Derived const*>(this);
        }
    };
    //]

    template <typename Derived>
    struct primitive_parser : parser<Derived>
    {
        struct primitive_parser_id;
    };

    template <typename Derived>
    struct nary_parser : parser<Derived>
    {
        struct nary_parser_id;

        // Requirement: p.elements -> fusion sequence
        //
        // p:   a composite parser

        // Requirement: P::elements_type -> fusion sequence
        //
        // P:   a composite parser type
    };

    template <typename Derived>
    struct unary_parser : parser<Derived>
    {
        struct unary_parser_id;

        // Requirement: p.subject -> subject parser
        //
        // p:   a unary parser

        // Requirement: P::subject_type -> subject parser type
        //
        // P:   a unary parser type
    };

    template <typename Derived>
    struct binary_parser : parser<Derived>
    {
        struct binary_parser_id;

        // Requirement: p.left -> left parser
        //
        // p:   a binary parser

        // Requirement: P::left_type -> left parser type
        //
        // P:   a binary parser type

        // Requirement: p.right -> right parser
        //
        // p:   a binary parser

        // Requirement: P::right_type -> right parser type
        //
        // P:   a binary parser type
    };
}}}

namespace boost { namespace spirit { namespace traits // classification
{
    namespace detail
    {
        BOOST_MPL_HAS_XXX_TRAIT_DEF(parser_id)
        BOOST_MPL_HAS_XXX_TRAIT_DEF(primitive_parser_id)
        BOOST_MPL_HAS_XXX_TRAIT_DEF(nary_parser_id)
        BOOST_MPL_HAS_XXX_TRAIT_DEF(unary_parser_id)
        BOOST_MPL_HAS_XXX_TRAIT_DEF(binary_parser_id)
    }

    // parser type identification
    template <typename T>
    struct is_parser : detail::has_parser_id<T> {};

    template <typename T>
    struct is_primitive_parser : detail::has_primitive_parser_id<T> {};

    template <typename T>
    struct is_nary_parser : detail::has_nary_parser_id<T> {};

    template <typename T>
    struct is_unary_parser : detail::has_unary_parser_id<T> {};

    template <typename T>
    struct is_binary_parser : detail::has_binary_parser_id<T> {};

}}}

#endif