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