os/ossrv/ossrv_pub/boost_apis/boost/spirit/attribute/parametric.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*=============================================================================
sl@0
     2
    Copyright (c) 2001-2003 Joel de Guzman
sl@0
     3
    http://spirit.sourceforge.net/
sl@0
     4
sl@0
     5
    Use, modification and distribution is subject to the Boost Software
sl@0
     6
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
     7
    http://www.boost.org/LICENSE_1_0.txt)
sl@0
     8
=============================================================================*/
sl@0
     9
#ifndef BOOST_SPIRIT_PARAMETRIC_HPP
sl@0
    10
#define BOOST_SPIRIT_PARAMETRIC_HPP
sl@0
    11
sl@0
    12
///////////////////////////////////////////////////////////////////////////////
sl@0
    13
#include <boost/spirit/core/parser.hpp>
sl@0
    14
#include <boost/spirit/core/composite/composite.hpp>
sl@0
    15
#include <boost/spirit/core/primitives/primitives.hpp>
sl@0
    16
sl@0
    17
namespace boost { namespace spirit {
sl@0
    18
sl@0
    19
    ///////////////////////////////////////////////////////////////////////////
sl@0
    20
    //
sl@0
    21
    //  f_chlit class [ functional version of chlit ]
sl@0
    22
    //
sl@0
    23
    ///////////////////////////////////////////////////////////////////////////
sl@0
    24
    template <typename ChGenT>
sl@0
    25
    struct f_chlit : public char_parser<f_chlit<ChGenT> >
sl@0
    26
    {
sl@0
    27
        f_chlit(ChGenT chgen_)
sl@0
    28
        : chgen(chgen_) {}
sl@0
    29
sl@0
    30
        template <typename T>
sl@0
    31
        bool test(T ch) const
sl@0
    32
        { return ch == chgen(); }
sl@0
    33
sl@0
    34
        ChGenT   chgen;
sl@0
    35
    };
sl@0
    36
sl@0
    37
    template <typename ChGenT>
sl@0
    38
    inline f_chlit<ChGenT>
sl@0
    39
    f_ch_p(ChGenT chgen)
sl@0
    40
    { return f_chlit<ChGenT>(chgen); }
sl@0
    41
sl@0
    42
    ///////////////////////////////////////////////////////////////////////////
sl@0
    43
    //
sl@0
    44
    //  f_range class [ functional version of range ]
sl@0
    45
    //
sl@0
    46
    ///////////////////////////////////////////////////////////////////////////
sl@0
    47
    template <typename ChGenAT, typename ChGenBT>
sl@0
    48
    struct f_range : public char_parser<f_range<ChGenAT, ChGenBT> >
sl@0
    49
    {
sl@0
    50
        f_range(ChGenAT first_, ChGenBT last_)
sl@0
    51
        : first(first_), last(last_)
sl@0
    52
        {}
sl@0
    53
sl@0
    54
        template <typename T>
sl@0
    55
        bool test(T ch) const
sl@0
    56
        {
sl@0
    57
            BOOST_SPIRIT_ASSERT(first() <= last());
sl@0
    58
            return (ch >= first()) && (ch <= last());
sl@0
    59
        }
sl@0
    60
sl@0
    61
        ChGenAT first;
sl@0
    62
        ChGenBT last;
sl@0
    63
    };
sl@0
    64
sl@0
    65
    template <typename ChGenAT, typename ChGenBT>
sl@0
    66
    inline f_range<ChGenAT, ChGenBT>
sl@0
    67
    f_range_p(ChGenAT first, ChGenBT last)
sl@0
    68
    { return f_range<ChGenAT, ChGenBT>(first, last); }
sl@0
    69
sl@0
    70
    ///////////////////////////////////////////////////////////////////////////
sl@0
    71
    //
sl@0
    72
    //  f_chseq class [ functional version of chseq ]
sl@0
    73
    //
sl@0
    74
    ///////////////////////////////////////////////////////////////////////////
sl@0
    75
    template <typename IterGenAT, typename IterGenBT>
sl@0
    76
    class f_chseq : public parser<f_chseq<IterGenAT, IterGenBT> >
sl@0
    77
    {
sl@0
    78
    public:
sl@0
    79
sl@0
    80
        typedef f_chseq<IterGenAT, IterGenBT> self_t;
sl@0
    81
sl@0
    82
        f_chseq(IterGenAT first_, IterGenBT last_)
sl@0
    83
        : first(first_), last(last_) {}
sl@0
    84
sl@0
    85
        template <typename ScannerT>
sl@0
    86
        typename parser_result<self_t, ScannerT>::type
sl@0
    87
        parse(ScannerT const& scan) const
sl@0
    88
        {
sl@0
    89
            typedef typename parser_result<self_t, ScannerT>::type result_t;
sl@0
    90
            return impl::string_parser_parse<result_t>(first(), last(), scan);
sl@0
    91
        }
sl@0
    92
sl@0
    93
    private:
sl@0
    94
sl@0
    95
        IterGenAT first;
sl@0
    96
        IterGenBT last;
sl@0
    97
    };
sl@0
    98
sl@0
    99
    template <typename IterGenAT, typename IterGenBT>
sl@0
   100
    inline f_chseq<IterGenAT, IterGenBT>
sl@0
   101
    f_chseq_p(IterGenAT first, IterGenBT last)
sl@0
   102
    { return f_chseq<IterGenAT, IterGenBT>(first, last); }
sl@0
   103
sl@0
   104
    ///////////////////////////////////////////////////////////////////////////
sl@0
   105
    //
sl@0
   106
    //  f_strlit class [ functional version of strlit ]
sl@0
   107
    //
sl@0
   108
    ///////////////////////////////////////////////////////////////////////////
sl@0
   109
    template <typename IterGenAT, typename IterGenBT>
sl@0
   110
    class f_strlit : public parser<f_strlit<IterGenAT, IterGenBT> >
sl@0
   111
    {
sl@0
   112
    public:
sl@0
   113
sl@0
   114
        typedef f_strlit<IterGenAT, IterGenBT> self_t;
sl@0
   115
sl@0
   116
        f_strlit(IterGenAT first, IterGenBT last)
sl@0
   117
        : seq(first, last) {}
sl@0
   118
sl@0
   119
        template <typename ScannerT>
sl@0
   120
        typename parser_result<self_t, ScannerT>::type
sl@0
   121
        parse(ScannerT const& scan) const
sl@0
   122
        {
sl@0
   123
            typedef typename parser_result<self_t, ScannerT>::type result_t;
sl@0
   124
            return impl::contiguous_parser_parse<result_t>
sl@0
   125
                (seq, scan, scan);
sl@0
   126
        }
sl@0
   127
sl@0
   128
    private:
sl@0
   129
sl@0
   130
        f_chseq<IterGenAT, IterGenBT> seq;
sl@0
   131
    };
sl@0
   132
sl@0
   133
    template <typename IterGenAT, typename IterGenBT>
sl@0
   134
    inline f_strlit<IterGenAT, IterGenBT>
sl@0
   135
    f_str_p(IterGenAT first, IterGenBT last)
sl@0
   136
    { return f_strlit<IterGenAT, IterGenBT>(first, last); }
sl@0
   137
sl@0
   138
}} // namespace boost::spirit
sl@0
   139
sl@0
   140
#endif