zhangmeng
2021-07-02 056f71f24cefaf88f2a93714c6678c03ed5f1e0e
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
//  Copyright (c) 2001 Daniel C. Nuffer
//  Copyright (c) 2001-2011 Hartmut Kaiser
// 
//  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_ITERATOR_LEX_INPUT_POLICY_MAR_16_2007_1205PM)
#define BOOST_SPIRIT_ITERATOR_LEX_INPUT_POLICY_MAR_16_2007_1205PM
 
#include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
#include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
 
namespace boost { namespace spirit { namespace iterator_policies
{
    ///////////////////////////////////////////////////////////////////////////////
    //  class lex_input
    //  Implementation of the InputPolicy used by multi_pass
    // 
    //  The lex_input class gets tokens (integers) from yylex()
    ///////////////////////////////////////////////////////////////////////////
    struct lex_input
    {
        typedef int value_type;
 
        ///////////////////////////////////////////////////////////////////////
        template <typename T>
        class unique : public detail::default_input_policy
        {
        public:
            typedef std::ptrdiff_t difference_type;
            typedef std::ptrdiff_t distance_type;
            typedef int* pointer;
            typedef int& reference;
 
        protected:
            unique() {}
            explicit unique(T) {}
 
        public:
            template <typename MultiPass>
            static typename MultiPass::reference get_input(MultiPass& mp)
            {
                value_type& curtok = mp.shared()->curtok;
                if (-1 == curtok)
                {
                    extern int yylex();
                    curtok = yylex();
                }
                return curtok;
            }
 
            template <typename MultiPass>
            static void advance_input(MultiPass& mp)
            {
                extern int yylex();
                mp.shared()->curtok = yylex();
            }
 
            // test, whether we reached the end of the underlying stream
            template <typename MultiPass>
            static bool input_at_eof(MultiPass const& mp) 
            {
                return mp.shared()->curtok == 0;
            }
 
            template <typename MultiPass>
            static bool input_is_valid(MultiPass const&, value_type const& t) 
            {
                return -1 != t;
            }
        };
 
        ///////////////////////////////////////////////////////////////////////
        template <typename T>
        struct shared
        {
            explicit shared(T) : curtok(-1) {}
 
            value_type curtok;
        };
    };
 
}}}
 
#endif