annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/numeric/int.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2001-2011 Joel de Guzman
Chris@16 3 Copyright (c) 2011 Bryce Lelbach
Chris@16 4
Chris@16 5 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 ==============================================================================*/
Chris@16 8 #if !defined(BOOST_SPIRIT_INT_APR_17_2006_0830AM)
Chris@16 9 #define BOOST_SPIRIT_INT_APR_17_2006_0830AM
Chris@16 10
Chris@16 11 #if defined(_MSC_VER)
Chris@16 12 #pragma once
Chris@16 13 #endif
Chris@16 14
Chris@16 15 #include <boost/spirit/home/qi/skip_over.hpp>
Chris@16 16 #include <boost/spirit/home/qi/detail/enable_lit.hpp>
Chris@16 17 #include <boost/spirit/home/qi/numeric/numeric_utils.hpp>
Chris@16 18 #include <boost/spirit/home/qi/meta_compiler.hpp>
Chris@16 19 #include <boost/spirit/home/qi/parser.hpp>
Chris@16 20 #include <boost/spirit/home/support/common_terminals.hpp>
Chris@16 21 #include <boost/spirit/home/support/info.hpp>
Chris@101 22 #include <boost/spirit/home/support/detail/is_spirit_tag.hpp>
Chris@16 23 #include <boost/mpl/assert.hpp>
Chris@16 24 #include <boost/type_traits/is_same.hpp>
Chris@16 25
Chris@16 26 namespace boost { namespace spirit
Chris@16 27 {
Chris@16 28 namespace tag
Chris@16 29 {
Chris@16 30 template <typename T, unsigned Radix, unsigned MinDigits
Chris@16 31 , int MaxDigits>
Chris@101 32 struct int_parser
Chris@101 33 {
Chris@101 34 BOOST_SPIRIT_IS_TAG()
Chris@101 35 };
Chris@16 36 }
Chris@16 37
Chris@16 38 namespace qi
Chris@16 39 {
Chris@16 40 ///////////////////////////////////////////////////////////////////////
Chris@16 41 // This one is the class that the user can instantiate directly in
Chris@16 42 // order to create a customized int parser
Chris@16 43 template <typename T = int, unsigned Radix = 10, unsigned MinDigits = 1
Chris@16 44 , int MaxDigits = -1>
Chris@16 45 struct int_parser
Chris@16 46 : spirit::terminal<tag::int_parser<T, Radix, MinDigits, MaxDigits> >
Chris@16 47 {};
Chris@16 48 }
Chris@16 49
Chris@16 50 ///////////////////////////////////////////////////////////////////////////
Chris@16 51 // Enablers
Chris@16 52 ///////////////////////////////////////////////////////////////////////////
Chris@16 53 //[primitive_parsers_enable_short
Chris@16 54 template <> // enables short_
Chris@16 55 struct use_terminal<qi::domain, tag::short_> : mpl::true_ {};
Chris@16 56 //]
Chris@16 57
Chris@16 58 template <typename A0> // enables lit(n)
Chris@16 59 struct use_terminal<qi::domain
Chris@16 60 , terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 61 , typename enable_if<is_same<A0, signed short> >::type>
Chris@16 62 : mpl::true_ {};
Chris@16 63
Chris@16 64 template <typename A0> // enables short_(n)
Chris@16 65 struct use_terminal<qi::domain
Chris@16 66 , terminal_ex<tag::short_, fusion::vector1<A0> > >
Chris@16 67 : is_arithmetic<A0> {};
Chris@16 68
Chris@16 69 template <> // enables *lazy* short_(n)
Chris@16 70 struct use_lazy_terminal<qi::domain, tag::short_, 1> : mpl::true_ {};
Chris@16 71
Chris@16 72 ///////////////////////////////////////////////////////////////////////////
Chris@16 73 //[primitive_parsers_enable_int
Chris@16 74 template <> // enables int_
Chris@16 75 struct use_terminal<qi::domain, tag::int_> : mpl::true_ {};
Chris@16 76 //]
Chris@16 77
Chris@16 78 template <typename A0> // enables lit(n)
Chris@16 79 struct use_terminal<qi::domain
Chris@16 80 , terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 81 , typename enable_if<is_same<A0, signed> >::type>
Chris@16 82 : mpl::true_ {};
Chris@16 83
Chris@16 84 template <typename A0> // enables int_(n)
Chris@16 85 struct use_terminal<qi::domain
Chris@16 86 , terminal_ex<tag::int_, fusion::vector1<A0> > >
Chris@16 87 : is_arithmetic<A0> {};
Chris@16 88
Chris@16 89 template <> // enables *lazy* int_(n)
Chris@16 90 struct use_lazy_terminal<qi::domain, tag::int_, 1> : mpl::true_ {};
Chris@16 91
Chris@16 92 ///////////////////////////////////////////////////////////////////////////
Chris@16 93 //[primitive_parsers_enable_long
Chris@16 94 template <> // enables long_
Chris@16 95 struct use_terminal<qi::domain, tag::long_> : mpl::true_ {};
Chris@16 96 //]
Chris@16 97
Chris@16 98 template <typename A0> // enables lit(n)
Chris@16 99 struct use_terminal<qi::domain
Chris@16 100 , terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 101 , typename enable_if<is_same<A0, signed long> >::type>
Chris@16 102 : mpl::true_ {};
Chris@16 103
Chris@16 104 template <typename A0> // enables long_(n)
Chris@16 105 struct use_terminal<qi::domain
Chris@16 106 , terminal_ex<tag::long_, fusion::vector1<A0> > >
Chris@16 107 : is_arithmetic<A0> {};
Chris@16 108
Chris@16 109 template <> // enables *lazy* long_(n)
Chris@16 110 struct use_lazy_terminal<qi::domain, tag::long_, 1> : mpl::true_ {};
Chris@16 111
Chris@16 112 ///////////////////////////////////////////////////////////////////////////
Chris@16 113 #ifdef BOOST_HAS_LONG_LONG
Chris@16 114 //[primitive_parsers_enable_long_long
Chris@16 115 template <> // enables long_long
Chris@16 116 struct use_terminal<qi::domain, tag::long_long> : mpl::true_ {};
Chris@16 117 //]
Chris@16 118
Chris@16 119 template <typename A0> // enables lit(n)
Chris@16 120 struct use_terminal<qi::domain
Chris@16 121 , terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 122 , typename enable_if<is_same<A0, boost::long_long_type> >::type>
Chris@16 123 : mpl::true_ {};
Chris@16 124
Chris@16 125 template <typename A0> // enables long_long(n)
Chris@16 126 struct use_terminal<qi::domain
Chris@16 127 , terminal_ex<tag::long_long, fusion::vector1<A0> > >
Chris@16 128 : is_arithmetic<A0> {};
Chris@16 129
Chris@16 130 template <> // enables *lazy* long_long(n)
Chris@16 131 struct use_lazy_terminal<qi::domain, tag::long_long, 1> : mpl::true_ {};
Chris@16 132 #endif
Chris@16 133
Chris@16 134 ///////////////////////////////////////////////////////////////////////////
Chris@16 135 // enables any custom int_parser
Chris@16 136 template <typename T, unsigned Radix, unsigned MinDigits
Chris@16 137 , int MaxDigits>
Chris@16 138 struct use_terminal<qi::domain
Chris@16 139 , tag::int_parser<T, Radix, MinDigits, MaxDigits> >
Chris@16 140 : mpl::true_ {};
Chris@16 141
Chris@16 142 // enables any custom int_parser(n)
Chris@16 143 template <typename T, unsigned Radix, unsigned MinDigits
Chris@16 144 , int MaxDigits, typename A0>
Chris@16 145 struct use_terminal<qi::domain
Chris@16 146 , terminal_ex<tag::int_parser<T, Radix, MinDigits, MaxDigits>
Chris@16 147 , fusion::vector1<A0> >
Chris@16 148 > : mpl::true_ {};
Chris@16 149
Chris@16 150 // enables *lazy* custom int_parser(n)
Chris@16 151 template <typename T, unsigned Radix, unsigned MinDigits
Chris@16 152 , int MaxDigits>
Chris@16 153 struct use_lazy_terminal<qi::domain
Chris@16 154 , tag::int_parser<T, Radix, MinDigits, MaxDigits>, 1
Chris@16 155 > : mpl::true_ {};
Chris@16 156 }}
Chris@16 157
Chris@16 158 namespace boost { namespace spirit { namespace qi
Chris@16 159 {
Chris@16 160 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
Chris@16 161 using spirit::short_;
Chris@16 162 using spirit::int_;
Chris@16 163 using spirit::long_;
Chris@16 164 #ifdef BOOST_HAS_LONG_LONG
Chris@16 165 using spirit::long_long;
Chris@16 166 #endif
Chris@16 167 using spirit::lit; // lit(1) is equivalent to 1
Chris@16 168 #endif
Chris@16 169 using spirit::short_type;
Chris@16 170 using spirit::int_type;
Chris@16 171 using spirit::long_type;
Chris@16 172 using spirit::lit_type;
Chris@16 173 #ifdef BOOST_HAS_LONG_LONG
Chris@16 174 using spirit::long_long_type;
Chris@16 175 #endif
Chris@16 176 using spirit::lit_type;
Chris@16 177
Chris@16 178 ///////////////////////////////////////////////////////////////////////////
Chris@16 179 // This is the actual int parser
Chris@16 180 ///////////////////////////////////////////////////////////////////////////
Chris@16 181 //[primitive_parsers_int_parser
Chris@16 182 template <
Chris@16 183 typename T
Chris@16 184 , unsigned Radix = 10
Chris@16 185 , unsigned MinDigits = 1
Chris@16 186 , int MaxDigits = -1>
Chris@16 187 struct any_int_parser
Chris@16 188 : primitive_parser<any_int_parser<T, Radix, MinDigits, MaxDigits> >
Chris@16 189 {
Chris@16 190 // check template parameter 'Radix' for validity
Chris@16 191 BOOST_SPIRIT_ASSERT_MSG(
Chris@16 192 Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,
Chris@16 193 not_supported_radix, ());
Chris@16 194
Chris@16 195 template <typename Context, typename Iterator>
Chris@16 196 struct attribute
Chris@16 197 {
Chris@16 198 typedef T type;
Chris@16 199 };
Chris@16 200
Chris@16 201 template <typename Iterator, typename Context
Chris@16 202 , typename Skipper, typename Attribute>
Chris@16 203 bool parse(Iterator& first, Iterator const& last
Chris@16 204 , Context& /*context*/, Skipper const& skipper
Chris@16 205 , Attribute& attr_) const
Chris@16 206 {
Chris@16 207 typedef extract_int<T, Radix, MinDigits, MaxDigits> extract;
Chris@16 208 qi::skip_over(first, last, skipper);
Chris@16 209 return extract::call(first, last, attr_);
Chris@16 210 }
Chris@16 211
Chris@16 212 template <typename Context>
Chris@16 213 info what(Context& /*context*/) const
Chris@16 214 {
Chris@16 215 return info("integer");
Chris@16 216 }
Chris@16 217 };
Chris@16 218 //]
Chris@16 219
Chris@16 220 template <typename T, unsigned Radix = 10, unsigned MinDigits = 1
Chris@16 221 , int MaxDigits = -1, bool no_attribute = true>
Chris@16 222 struct literal_int_parser
Chris@16 223 : primitive_parser<literal_int_parser<T, Radix, MinDigits, MaxDigits
Chris@16 224 , no_attribute> >
Chris@16 225 {
Chris@16 226 // check template parameter 'Radix' for validity
Chris@16 227 BOOST_SPIRIT_ASSERT_MSG(
Chris@16 228 Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,
Chris@16 229 not_supported_radix, ());
Chris@16 230
Chris@16 231 template <typename Value>
Chris@16 232 literal_int_parser(Value const& n) : n_(n) {}
Chris@16 233
Chris@16 234 template <typename Context, typename Iterator>
Chris@16 235 struct attribute
Chris@16 236 : mpl::if_c<no_attribute, unused_type, T>
Chris@16 237 {};
Chris@16 238
Chris@16 239 template <typename Iterator, typename Context
Chris@16 240 , typename Skipper, typename Attribute>
Chris@16 241 bool parse(Iterator& first, Iterator const& last
Chris@16 242 , Context& /*context*/, Skipper const& skipper
Chris@16 243 , Attribute& attr_param) const
Chris@16 244 {
Chris@16 245 typedef extract_int<T, Radix, MinDigits, MaxDigits> extract;
Chris@16 246 qi::skip_over(first, last, skipper);
Chris@16 247
Chris@16 248 Iterator save = first;
Chris@16 249 T attr_;
Chris@16 250
Chris@16 251 if (extract::call(first, last, attr_) && (attr_ == n_))
Chris@16 252 {
Chris@16 253 traits::assign_to(attr_, attr_param);
Chris@16 254 return true;
Chris@16 255 }
Chris@16 256
Chris@16 257 first = save;
Chris@16 258 return false;
Chris@16 259 }
Chris@16 260
Chris@16 261 template <typename Context>
Chris@16 262 info what(Context& /*context*/) const
Chris@16 263 {
Chris@16 264 return info("integer");
Chris@16 265 }
Chris@16 266
Chris@16 267 T n_;
Chris@16 268 };
Chris@16 269
Chris@16 270 ///////////////////////////////////////////////////////////////////////////
Chris@16 271 // Parser generators: make_xxx function (objects)
Chris@16 272 ///////////////////////////////////////////////////////////////////////////
Chris@16 273 //[primitive_parsers_make_int
Chris@16 274 template <
Chris@16 275 typename T
Chris@16 276 , unsigned Radix = 10
Chris@16 277 , unsigned MinDigits = 1
Chris@16 278 , int MaxDigits = -1>
Chris@16 279 struct make_int
Chris@16 280 {
Chris@16 281 typedef any_int_parser<T, Radix, MinDigits, MaxDigits> result_type;
Chris@16 282 result_type operator()(unused_type, unused_type) const
Chris@16 283 {
Chris@16 284 return result_type();
Chris@16 285 }
Chris@16 286 };
Chris@16 287 //]
Chris@16 288
Chris@16 289 template <typename T, unsigned Radix = 10, unsigned MinDigits = 1
Chris@16 290 , int MaxDigits = -1>
Chris@16 291 struct make_direct_int
Chris@16 292 {
Chris@16 293 typedef literal_int_parser<T, Radix, MinDigits, MaxDigits, false>
Chris@16 294 result_type;
Chris@16 295 template <typename Terminal>
Chris@16 296 result_type operator()(Terminal const& term, unused_type) const
Chris@16 297 {
Chris@16 298 return result_type(fusion::at_c<0>(term.args));
Chris@16 299 }
Chris@16 300 };
Chris@16 301
Chris@16 302 template <typename T, unsigned Radix = 10, unsigned MinDigits = 1
Chris@16 303 , int MaxDigits = -1>
Chris@16 304 struct make_literal_int
Chris@16 305 {
Chris@16 306 typedef literal_int_parser<T, Radix, MinDigits, MaxDigits> result_type;
Chris@16 307 template <typename Terminal>
Chris@16 308 result_type operator()(Terminal const& term, unused_type) const
Chris@16 309 {
Chris@16 310 return result_type(fusion::at_c<0>(term.args));
Chris@16 311 }
Chris@16 312 };
Chris@16 313
Chris@16 314 ///////////////////////////////////////////////////////////////////////////
Chris@16 315 template <typename Modifiers, typename A0>
Chris@16 316 struct make_primitive<
Chris@16 317 terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 318 , Modifiers, typename enable_if<is_same<A0, signed short> >::type>
Chris@16 319 : make_literal_int<signed short> {};
Chris@16 320
Chris@16 321 template <typename Modifiers, typename A0>
Chris@16 322 struct make_primitive<
Chris@16 323 terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 324 , Modifiers, typename enable_if<is_same<A0, signed> >::type>
Chris@16 325 : make_literal_int<signed> {};
Chris@16 326
Chris@16 327 template <typename Modifiers, typename A0>
Chris@16 328 struct make_primitive<
Chris@16 329 terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 330 , Modifiers, typename enable_if<is_same<A0, signed long> >::type>
Chris@16 331 : make_literal_int<signed long> {};
Chris@16 332
Chris@16 333 #ifdef BOOST_HAS_LONG_LONG
Chris@16 334 template <typename Modifiers, typename A0>
Chris@16 335 struct make_primitive<
Chris@16 336 terminal_ex<tag::lit, fusion::vector1<A0> >
Chris@16 337 , Modifiers, typename enable_if<is_same<A0, boost::long_long_type> >::type>
Chris@16 338 : make_literal_int<boost::long_long_type> {};
Chris@16 339 #endif
Chris@16 340
Chris@16 341 ///////////////////////////////////////////////////////////////////////////
Chris@16 342 template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits
Chris@16 343 , typename Modifiers>
Chris@16 344 struct make_primitive<
Chris@16 345 tag::int_parser<T, Radix, MinDigits, MaxDigits>
Chris@16 346 , Modifiers>
Chris@16 347 : make_int<T, Radix, MinDigits, MaxDigits> {};
Chris@16 348
Chris@16 349 template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits
Chris@16 350 , typename A0, typename Modifiers>
Chris@16 351 struct make_primitive<
Chris@16 352 terminal_ex<tag::int_parser<T, Radix, MinDigits, MaxDigits>
Chris@16 353 , fusion::vector1<A0> >, Modifiers>
Chris@16 354 : make_direct_int<T, Radix, MinDigits, MaxDigits> {};
Chris@16 355
Chris@16 356 ///////////////////////////////////////////////////////////////////////////
Chris@16 357 //[primitive_parsers_short_primitive
Chris@16 358 template <typename Modifiers>
Chris@16 359 struct make_primitive<tag::short_, Modifiers>
Chris@16 360 : make_int<short> {};
Chris@16 361 //]
Chris@16 362
Chris@16 363 template <typename Modifiers, typename A0>
Chris@16 364 struct make_primitive<
Chris@16 365 terminal_ex<tag::short_
Chris@16 366 , fusion::vector1<A0> > , Modifiers>
Chris@16 367 : make_direct_int<short> {};
Chris@16 368
Chris@16 369 ///////////////////////////////////////////////////////////////////////////
Chris@16 370 //[primitive_parsers_int_primitive
Chris@16 371 template <typename Modifiers>
Chris@16 372 struct make_primitive<tag::int_, Modifiers>
Chris@16 373 : make_int<int> {};
Chris@16 374 //]
Chris@16 375
Chris@16 376 template <typename Modifiers, typename A0>
Chris@16 377 struct make_primitive<
Chris@16 378 terminal_ex<tag::int_
Chris@16 379 , fusion::vector1<A0> > , Modifiers>
Chris@16 380 : make_direct_int<int> {};
Chris@16 381
Chris@16 382 ///////////////////////////////////////////////////////////////////////////
Chris@16 383 //[primitive_parsers_long_primitive
Chris@16 384 template <typename Modifiers>
Chris@16 385 struct make_primitive<tag::long_, Modifiers>
Chris@16 386 : make_int<long> {};
Chris@16 387 //]
Chris@16 388
Chris@16 389 template <typename Modifiers, typename A0>
Chris@16 390 struct make_primitive<
Chris@16 391 terminal_ex<tag::long_
Chris@16 392 , fusion::vector1<A0> > , Modifiers>
Chris@16 393 : make_direct_int<long> {};
Chris@16 394
Chris@16 395 ///////////////////////////////////////////////////////////////////////////
Chris@16 396 #ifdef BOOST_HAS_LONG_LONG
Chris@16 397 //[primitive_parsers_long_long_primitive
Chris@16 398 template <typename Modifiers>
Chris@16 399 struct make_primitive<tag::long_long, Modifiers>
Chris@16 400 : make_int<boost::long_long_type> {};
Chris@16 401 //]
Chris@16 402
Chris@16 403 template <typename Modifiers, typename A0>
Chris@16 404 struct make_primitive<
Chris@16 405 terminal_ex<tag::long_long
Chris@16 406 , fusion::vector1<A0> > , Modifiers>
Chris@16 407 : make_direct_int<boost::long_long_type> {};
Chris@16 408 #endif
Chris@16 409 }}}
Chris@16 410
Chris@16 411 #endif