1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3 Copyright (c) 2011 Jan Frederick Eick
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_SPIRIT_X3_UINT_APR_17_2006_0901AM)
9 #define BOOST_SPIRIT_X3_UINT_APR_17_2006_0901AM
11 #include <boost/spirit/home/x3/core/parser.hpp>
12 #include <boost/spirit/home/x3/core/skip_over.hpp>
13 #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp>
16 namespace boost { namespace spirit { namespace x3
18 ///////////////////////////////////////////////////////////////////////////
22 , unsigned MinDigits = 1
24 struct uint_parser : parser<uint_parser<T, Radix, MinDigits, MaxDigits>>
26 // check template parameter 'Radix' for validity
28 (Radix >= 2 && Radix <= 36),
29 "Error Unsupported Radix");
31 typedef T attribute_type;
32 static bool const has_attribute = true;
34 template <typename Iterator, typename Context, typename Attribute>
35 bool parse(Iterator& first, Iterator const& last
36 , Context const& context, unused_type, Attribute& attr) const
38 typedef extract_uint<T, Radix, MinDigits, MaxDigits> extract;
39 x3::skip_over(first, last, context);
40 return extract::call(first, last, attr);
44 #define BOOST_SPIRIT_X3_UINT_PARSER(uint_type, name) \
45 typedef uint_parser<uint_type> name##type; \
46 name##type const name = {}; \
49 BOOST_SPIRIT_X3_UINT_PARSER(unsigned long, ulong_)
50 BOOST_SPIRIT_X3_UINT_PARSER(unsigned short, ushort_)
51 BOOST_SPIRIT_X3_UINT_PARSER(unsigned int, uint_)
52 BOOST_SPIRIT_X3_UINT_PARSER(unsigned long long, ulong_long)
54 BOOST_SPIRIT_X3_UINT_PARSER(uint8_t, uint8)
55 BOOST_SPIRIT_X3_UINT_PARSER(uint16_t, uint16)
56 BOOST_SPIRIT_X3_UINT_PARSER(uint32_t, uint32)
57 BOOST_SPIRIT_X3_UINT_PARSER(uint64_t, uint64)
59 #undef BOOST_SPIRIT_X3_UINT_PARSER
61 #define BOOST_SPIRIT_X3_UINT_PARSER(uint_type, radix, name) \
62 typedef uint_parser<uint_type, radix> name##type; \
63 name##type const name = name##type(); \
66 BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 2, bin)
67 BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 8, oct)
68 BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 16, hex)
70 #undef BOOST_SPIRIT_X3_UINT_PARSER