1 #ifndef fhiclcpp_tokens_h 2 #define fhiclcpp_tokens_h 10 #include "boost/spirit/home/support/terminal.hpp" 11 #include "boost/spirit/include/qi.hpp" 12 #include "cetlib/canonical_number.h" 30 return !std::isgraph(ch) || ch ==
'#' || ch ==
'/' || ch ==
',' ||
31 ch ==
']' || ch ==
'}';
58 BOOST_SPIRIT_TERMINAL(real)
59 BOOST_SPIRIT_TERMINAL(uint)
60 BOOST_SPIRIT_TERMINAL(hex)
61 BOOST_SPIRIT_TERMINAL(
bin)
62 BOOST_SPIRIT_TERMINAL(ass)
63 BOOST_SPIRIT_TERMINAL(dss)
64 BOOST_SPIRIT_TERMINAL(dbid)
65 BOOST_SPIRIT_TERMINAL(binding)
75 struct use_terminal<
qi::domain, fhicl::tag::real> : mpl::true_ {
79 struct use_terminal<qi::domain, fhicl::tag::uint> : mpl::true_ {
83 struct use_terminal<qi::domain, fhicl::tag::hex> : mpl::true_ {
87 struct use_terminal<qi::domain, fhicl::tag::dbid> : mpl::true_ {
95 struct use_terminal<qi::domain, fhicl::tag::ass> : mpl::true_ {
99 struct use_terminal<qi::domain, fhicl::tag::dss> : mpl::true_ {
103 struct use_terminal<qi::domain, fhicl::tag::binding> : mpl::true_ {
115 template <
typename Context,
typename Iterator>
121 template <
typename Iterator,
127 Iterator
const& last,
129 Skipper
const& skipper,
130 Attribute& attr)
const 132 boost::spirit::qi::skip_over(first, last, skipper);
134 static std::string
const allowed{
"0123456789.-+eE"};
136 while (it != last && allowed.find(*it) != std::string::npos)
142 Attribute
raw(first, it);
147 if (!cet::canonical_number(raw, result))
151 boost::spirit::traits::assign_to(result, attr);
156 template <
typename Context>
160 return boost::spirit::info{
"fhicl::real"};
165 struct uint_parser : boost::spirit::qi::primitive_parser<uint_parser> {
167 template <
typename Context,
typename Iterator>
173 template <
typename Iterator,
179 Iterator
const& last,
181 Skipper
const& skipper,
182 Attribute& attr)
const 184 boost::spirit::qi::skip_over(first, last, skipper);
187 while (it != last && std::isdigit(*it))
189 Attribute result(first, it);
197 for (std::size_t ndig = result.size(); ndig > 1 && result[0] ==
'0';
202 boost::spirit::traits::assign_to(result, attr);
207 template <
typename Context>
211 return boost::spirit::info{
"fhicl::uint"};
218 template <
typename Context,
typename Iterator>
224 template <
typename Iterator,
230 Iterator
const& last,
232 Skipper
const& skipper,
233 Attribute& attr)
const 235 boost::spirit::qi::skip_over(first, last, skipper);
237 static std::string
const allowed{
"0123456789abcdefABCDEF"};
240 if (it == last || *it !=
'0')
245 if (it == last || toupper(*it) !=
'X')
250 while (it != last && allowed.find(*it) != std::string::npos)
256 Attribute
raw(first, it);
257 if (raw.empty() || raw.size() == 2)
261 if (!cet::canonical_number(raw, result))
265 boost::spirit::traits::assign_to(result, attr);
270 template <
typename Context>
274 return boost::spirit::info{
"fhicl::hex"};
281 template <
typename Context,
typename Iterator>
287 template <
typename Iterator,
293 Iterator
const& last,
295 Skipper
const& skipper,
296 Attribute& attr)
const 298 boost::spirit::qi::skip_over(first, last, skipper);
300 static std::string
const allowed{
"0123456789abcdefABCDEF"};
306 while (it != last && allowed.find(*it) != std::string::npos)
312 Attribute result(first, it);
317 boost::spirit::traits::assign_to(result, attr);
322 template <
typename Context>
326 return boost::spirit::info{
"fhicl::dbid"};
333 template <
typename Context,
typename Iterator>
339 template <
typename Iterator,
345 Iterator
const& last,
347 Skipper
const& skipper,
348 Attribute& attr)
const 350 boost::spirit::qi::skip_over(first, last, skipper);
352 static std::string
const allowed{
"01"};
355 if (it == last || *it !=
'0')
360 if (it == last || toupper(*it) !=
'B')
365 while (it != last && allowed.find(*it) != std::string::npos)
371 Attribute
raw(first, it);
372 if (raw.empty() || raw.size() == 2)
376 if (!cet::canonical_number(raw, result))
380 boost::spirit::traits::assign_to(result, attr);
385 template <
typename Context>
389 return boost::spirit::info{
"fhicl::bin"};
396 template <
typename Context,
typename Iterator>
402 template <
typename Iterator,
408 Iterator
const& last,
410 Skipper
const& skipper,
411 Attribute& attr)
const 413 boost::spirit::qi::skip_over(first, last, skipper);
416 while (it != last && (std::isalnum(*it) || *it ==
'_'))
422 Attribute result(first, it);
423 if (result.empty() || std::isdigit(result[0]))
427 boost::spirit::traits::assign_to(result, attr);
432 template <
typename Context>
436 return boost::spirit::info{
"fhicl::ass"};
443 template <
typename Context,
typename Iterator>
449 template <
typename Iterator,
455 Iterator
const& last,
457 Skipper
const& skipper,
458 Attribute& attr)
const 460 boost::spirit::qi::skip_over(first, last, skipper);
462 bool all_digits =
true;
464 for (; it != last && (std::isalnum(*it) || *it ==
'_'); ++it)
465 all_digits = all_digits && std::isdigit(*it);
470 Attribute result(first, it);
471 if (result.empty() || all_digits || !std::isdigit(result[0]))
475 boost::spirit::traits::assign_to(result, attr);
480 template <
typename Context>
484 return boost::spirit::info{
"fhicl::dss"};
491 template <
typename Context,
typename Iterator>
497 template <
typename Iterator,
503 Iterator
const& last,
505 Skipper
const& skipper,
506 Attribute& attr)
const 509 boost::spirit::qi::skip_over(first, last, skipper);
512 boost::spirit::qi::symbols<char, binding_modifier> modifiers;
516 modifiers.add(
"@initial", binding_modifier::INITIAL);
517 modifiers.add(
"@replace", binding_modifier::REPLACE);
518 modifiers.add(
"@replace_compat", binding_modifier::REPLACE_COMPAT);
519 modifiers.add(
"@add_or_replace_compat", binding_modifier::ADD_OR_REPLACE_COMPAT);
521 if (((*first) ==
':') ||
522 (modifiers.parse(first, last, c, skipper, result) &&
528 boost::spirit::traits::assign_to(result, attr);
533 template <
typename Context>
537 return boost::spirit::info{
"fhicl::binding"};
550 template <
typename Modifiers>
551 struct make_primitive<
fhicl::tag::real, Modifiers> {
561 template <
typename Modifiers>
562 struct make_primitive<
fhicl::tag::uint, Modifiers> {
572 template <
typename Modifiers>
573 struct make_primitive<
fhicl::tag::hex, Modifiers> {
583 template <
typename Modifiers>
584 struct make_primitive<
fhicl::tag::dbid, Modifiers> {
594 template <
typename Modifiers>
605 template <
typename Modifiers>
606 struct make_primitive<
fhicl::tag::ass, Modifiers> {
616 template <
typename Modifiers>
617 struct make_primitive<
fhicl::tag::dss, Modifiers> {
627 template <
typename Modifiers>
628 struct make_primitive<
fhicl::tag::binding, Modifiers> {
result_type operator()(unused_type, unused_type) const
bool parse(Iterator &first, Iterator const &last, Context &c, Skipper const &skipper, Attribute &attr) const
result_type operator()(unused_type, unused_type) const
bool maximally_munched(char const ch)
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
boost::spirit::info what(Context &) const
boost::spirit::info what(Context &) const
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
static std::size_t max_str_size()
result_type operator()(unused_type, unused_type) const
bool maximally_munched_dss(char const ch)
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
boost::spirit::info what(Context &) const
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
result_type operator()(unused_type, unused_type) const
boost::spirit::info what(Context &) const
boost::spirit::info what(Context &) const
result_type operator()(unused_type, unused_type) const
boost::spirit::info what(Context &) const
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
bool maximally_munched_number(char const ch)
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
result_type operator()(unused_type, unused_type) const
result_type operator()(unused_type, unused_type) const
boost::spirit::info what(Context &) const
boost::spirit::info what(Context &) const
bool maximally_munched_ass(char const ch)
result_type operator()(unused_type, unused_type) const