annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/numeric/int.hpp @ 73:e9d2ba7cce95 emscripten

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