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_ {};
78 struct use_terminal<qi::domain, fhicl::tag::uint> : mpl::true_ {};
81 struct use_terminal<qi::domain, fhicl::tag::hex> : mpl::true_ {};
84 struct use_terminal<qi::domain, fhicl::tag::dbid> : mpl::true_ {};
90 struct use_terminal<qi::domain, fhicl::tag::ass> : mpl::true_ {};
93 struct use_terminal<qi::domain, fhicl::tag::dss> : mpl::true_ {};
96 struct use_terminal<qi::domain, fhicl::tag::binding> : mpl::true_ {};
107 template <
typename Context,
typename Iterator>
113 template <
typename Iterator,
119 Iterator
const& last,
121 Skipper
const& skipper,
122 Attribute& attr)
const 124 boost::spirit::qi::skip_over(first, last, skipper);
126 static std::string
const allowed{
"0123456789.-+eE"};
128 while (it != last && allowed.find(*it) != std::string::npos)
134 Attribute
raw(first, it);
139 if (!cet::canonical_number(raw, result))
143 boost::spirit::traits::assign_to(result, attr);
148 template <
typename Context>
152 return boost::spirit::info{
"fhicl::real"};
157 struct uint_parser : boost::spirit::qi::primitive_parser<uint_parser> {
159 template <
typename Context,
typename Iterator>
165 template <
typename Iterator,
171 Iterator
const& last,
173 Skipper
const& skipper,
174 Attribute& attr)
const 176 boost::spirit::qi::skip_over(first, last, skipper);
179 while (it != last && std::isdigit(*it))
181 Attribute result(first, it);
189 for (std::size_t ndig = result.size(); ndig > 1 && result[0] ==
'0';
194 boost::spirit::traits::assign_to(result, attr);
199 template <
typename Context>
203 return boost::spirit::info{
"fhicl::uint"};
210 template <
typename Context,
typename Iterator>
216 template <
typename Iterator,
222 Iterator
const& last,
224 Skipper
const& skipper,
225 Attribute& attr)
const 227 boost::spirit::qi::skip_over(first, last, skipper);
229 static std::string
const allowed{
"0123456789abcdefABCDEF"};
232 if (it == last || *it !=
'0')
237 if (it == last || toupper(*it) !=
'X')
242 while (it != last && allowed.find(*it) != std::string::npos)
248 Attribute
raw(first, it);
249 if (raw.empty() || raw.size() == 2)
253 if (!cet::canonical_number(raw, result))
257 boost::spirit::traits::assign_to(result, attr);
262 template <
typename Context>
266 return boost::spirit::info{
"fhicl::hex"};
273 template <
typename Context,
typename Iterator>
279 template <
typename Iterator,
285 Iterator
const& last,
287 Skipper
const& skipper,
288 Attribute& attr)
const 290 boost::spirit::qi::skip_over(first, last, skipper);
292 static std::string
const allowed{
"0123456789abcdefABCDEF"};
298 while (it != last && allowed.find(*it) != std::string::npos)
304 Attribute result(first, it);
309 boost::spirit::traits::assign_to(result, attr);
314 template <
typename Context>
318 return boost::spirit::info{
"fhicl::dbid"};
325 template <
typename Context,
typename Iterator>
331 template <
typename Iterator,
337 Iterator
const& last,
339 Skipper
const& skipper,
340 Attribute& attr)
const 342 boost::spirit::qi::skip_over(first, last, skipper);
344 static std::string
const allowed{
"01"};
347 if (it == last || *it !=
'0')
352 if (it == last || toupper(*it) !=
'B')
357 while (it != last && allowed.find(*it) != std::string::npos)
363 Attribute
raw(first, it);
364 if (raw.empty() || raw.size() == 2)
368 if (!cet::canonical_number(raw, result))
372 boost::spirit::traits::assign_to(result, attr);
377 template <
typename Context>
381 return boost::spirit::info{
"fhicl::bin"};
388 template <
typename Context,
typename Iterator>
394 template <
typename Iterator,
400 Iterator
const& last,
402 Skipper
const& skipper,
403 Attribute& attr)
const 405 boost::spirit::qi::skip_over(first, last, skipper);
408 while (it != last && (std::isalnum(*it) || *it ==
'_'))
414 Attribute result(first, it);
415 if (result.empty() || std::isdigit(result[0]))
419 boost::spirit::traits::assign_to(result, attr);
424 template <
typename Context>
428 return boost::spirit::info{
"fhicl::ass"};
435 template <
typename Context,
typename Iterator>
441 template <
typename Iterator,
447 Iterator
const& last,
449 Skipper
const& skipper,
450 Attribute& attr)
const 452 boost::spirit::qi::skip_over(first, last, skipper);
454 bool all_digits =
true;
456 for (; it != last && (std::isalnum(*it) || *it ==
'_'); ++it)
457 all_digits = all_digits && std::isdigit(*it);
462 Attribute result(first, it);
463 if (result.empty() || all_digits || !std::isdigit(result[0]))
467 boost::spirit::traits::assign_to(result, attr);
472 template <
typename Context>
476 return boost::spirit::info{
"fhicl::dss"};
483 template <
typename Context,
typename Iterator>
489 template <
typename Iterator,
495 Iterator
const& last,
497 Skipper
const& skipper,
498 Attribute& attr)
const 501 boost::spirit::qi::skip_over(first, last, skipper);
504 boost::spirit::qi::symbols<char, binding_modifier> modifiers;
508 modifiers.add(
"@initial", binding_modifier::INITIAL);
509 modifiers.add(
"@replace", binding_modifier::REPLACE);
510 modifiers.add(
"@replace_compat", binding_modifier::REPLACE_COMPAT);
511 modifiers.add(
"@add_or_replace_compat", binding_modifier::ADD_OR_REPLACE_COMPAT);
513 if (((*first) ==
':') ||
514 (modifiers.parse(first, last, c, skipper, result) &&
520 boost::spirit::traits::assign_to(result, attr);
525 template <
typename Context>
529 return boost::spirit::info{
"fhicl::binding"};
542 template <
typename Modifiers>
543 struct make_primitive<
fhicl::tag::real, Modifiers> {
554 template <
typename Modifiers>
555 struct make_primitive<
fhicl::tag::uint, Modifiers> {
566 template <
typename Modifiers>
567 struct make_primitive<
fhicl::tag::hex, Modifiers> {
578 template <
typename Modifiers>
579 struct make_primitive<
fhicl::tag::dbid, Modifiers> {
590 template <
typename Modifiers>
602 template <
typename Modifiers>
603 struct make_primitive<
fhicl::tag::ass, Modifiers> {
614 template <
typename Modifiers>
615 struct make_primitive<
fhicl::tag::dss, Modifiers> {
626 template <
typename Modifiers>
627 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
result_type operator()(unused_type, unused_type) const
static constexpr std::size_t max_str_size() noexcept
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