Chris@102
|
1 /*=============================================================================
|
Chris@102
|
2 Copyright (c) 2001-2014 Joel de Guzman
|
Chris@102
|
3
|
Chris@102
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@102
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
6 ==============================================================================*/
|
Chris@102
|
7 #if !defined(BOOST_SPIRIT_X3_INT_APR_17_2006_0830AM)
|
Chris@102
|
8 #define BOOST_SPIRIT_X3_INT_APR_17_2006_0830AM
|
Chris@102
|
9
|
Chris@102
|
10 #if defined(_MSC_VER)
|
Chris@102
|
11 #pragma once
|
Chris@102
|
12 #endif
|
Chris@102
|
13
|
Chris@102
|
14 #include <boost/spirit/home/x3/core/parser.hpp>
|
Chris@102
|
15 #include <boost/spirit/home/x3/core/skip_over.hpp>
|
Chris@102
|
16 #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp>
|
Chris@102
|
17 #include <cstdint>
|
Chris@102
|
18
|
Chris@102
|
19 namespace boost { namespace spirit { namespace x3
|
Chris@102
|
20 {
|
Chris@102
|
21 ///////////////////////////////////////////////////////////////////////////
|
Chris@102
|
22 template <
|
Chris@102
|
23 typename T
|
Chris@102
|
24 , unsigned Radix = 10
|
Chris@102
|
25 , unsigned MinDigits = 1
|
Chris@102
|
26 , int MaxDigits = -1>
|
Chris@102
|
27 struct int_parser : parser<int_parser<T, Radix, MinDigits, MaxDigits>>
|
Chris@102
|
28 {
|
Chris@102
|
29 // check template parameter 'Radix' for validity
|
Chris@102
|
30 static_assert(
|
Chris@102
|
31 (Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16),
|
Chris@102
|
32 "Error Unsupported Radix");
|
Chris@102
|
33
|
Chris@102
|
34 typedef T attribute_type;
|
Chris@102
|
35 static bool const has_attribute = true;
|
Chris@102
|
36
|
Chris@102
|
37 template <typename Iterator, typename Context, typename Attribute>
|
Chris@102
|
38 bool parse(Iterator& first, Iterator const& last
|
Chris@102
|
39 , Context const& context, unused_type, Attribute& attr) const
|
Chris@102
|
40 {
|
Chris@102
|
41 typedef extract_int<T, Radix, MinDigits, MaxDigits> extract;
|
Chris@102
|
42 x3::skip_over(first, last, context);
|
Chris@102
|
43 return extract::call(first, last, attr);
|
Chris@102
|
44 }
|
Chris@102
|
45 };
|
Chris@102
|
46
|
Chris@102
|
47 #define BOOST_SPIRIT_X3_INT_PARSER(int_type, name) \
|
Chris@102
|
48 typedef int_parser<int_type> name##type; \
|
Chris@102
|
49 name##type const name = {}; \
|
Chris@102
|
50 /***/
|
Chris@102
|
51
|
Chris@102
|
52 BOOST_SPIRIT_X3_INT_PARSER(long, long_)
|
Chris@102
|
53 BOOST_SPIRIT_X3_INT_PARSER(short, short_)
|
Chris@102
|
54 BOOST_SPIRIT_X3_INT_PARSER(int, int_)
|
Chris@102
|
55 BOOST_SPIRIT_X3_INT_PARSER(long long, long_long)
|
Chris@102
|
56
|
Chris@102
|
57 BOOST_SPIRIT_X3_INT_PARSER(int8_t, int8)
|
Chris@102
|
58 BOOST_SPIRIT_X3_INT_PARSER(int16_t, int16)
|
Chris@102
|
59 BOOST_SPIRIT_X3_INT_PARSER(int32_t, int32)
|
Chris@102
|
60 BOOST_SPIRIT_X3_INT_PARSER(int64_t, int64)
|
Chris@102
|
61
|
Chris@102
|
62 #undef BOOST_SPIRIT_X3_INT_PARSER
|
Chris@102
|
63
|
Chris@102
|
64 }}}
|
Chris@102
|
65
|
Chris@102
|
66 #endif
|