LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
parse_shims.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_parse_shims_h
2 #define fhiclcpp_parse_shims_h
3 
5 
6 #include "boost/spirit/include/qi.hpp"
7 
8 namespace shims {
9 
10  inline auto
11  lit(char arg)
12  {
14  }
15 
16  inline auto
17  lit(std::string arg)
18  {
19  if (arg[0] == '@' && shims::isSnippetMode())
20  arg[0] = '!';
21 
23  }
24 
25  BOOST_SPIRIT_TERMINAL(catchall)
26 }
27 
28 namespace boost::spirit {
29  template <>
30  struct use_terminal<qi::domain, shims::tag::catchall> : mpl::true_ {};
31 }
32 
33 namespace shims {
34 
35  inline bool
37  {
38  return !std::isgraph(ch) || ch == '#' || ch == '/' || ch == ',' ||
39  ch == ']' || ch == '}' || ch == '.' || ch == '[' || ch == ':';
40  }
41 
43  : ::boost::spirit::qi::primitive_parser<catchall_parser> {
44  template <typename Context, typename Iterator>
45  struct attribute {
46  using type = std::string;
47  };
48 
49  // do the parse:
50  template <typename Iterator,
51  typename Context,
52  typename Skipper,
53  typename Attribute>
54  bool
55  parse(Iterator& first,
56  Iterator const& last,
57  Context&,
58  Skipper const& skipper,
59  Attribute& attr) const
60  {
61  boost::spirit::qi::skip_over(first, last, skipper);
62 
63  if (!::shims::isSnippetMode())
64  return false;
65 
66  Iterator it = first;
67  while (it != last &&
68  (std::isalnum(*it) || *it == '_' || *it == ':' || *it == '@'))
69  ++it;
70 
71  if (it != last && !maximally_munched_ass(*it))
72  return false;
73 
74  Attribute result(first, it);
75  if (result.empty() || std::isdigit(result[0]))
76  return false;
77 
78  first = it;
79  boost::spirit::traits::assign_to(result, attr);
80  return true;
81  }
82 
83  template <typename Context>
84  boost::spirit::info
85  what(Context&) const
86  {
87  return boost::spirit::info("shims::catchall");
88  }
89  };
90 }
91 
92 namespace boost::spirit::qi {
93  template <typename Modifiers>
94  struct make_primitive<shims::tag::catchall, Modifiers> {
97  operator()(unused_type, unused_type) const
98  {
99  return result_type();
100  }
101  };
102 }
103 #endif /* fhiclcpp_parse_shims_h */
104 
105 // Local Variables:
106 // mode: c++
107 // End:
bool maximally_munched_ass(char ch)
Definition: parse_shims.h:36
auto lit(char arg)
Definition: parse_shims.h:11
auto lit(std::string arg)
Definition: parse_shims.h:17
bool parse(Iterator &first, Iterator const &last, Context &, Skipper const &skipper, Attribute &attr) const
Definition: parse_shims.h:55
result_type operator()(unused_type, unused_type) const
Definition: parse_shims.h:97
bool isSnippetMode(bool m=false) noexcept
boost::spirit::info what(Context &) const
Definition: parse_shims.h:85