LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 {
29  namespace spirit {
30  template <>
31  struct use_terminal<::boost::spirit::qi::domain, shims::tag::catchall>
32  : mpl::true_ {
33  };
34  }
35 }
36 
37 namespace shims {
38 
39  inline bool
41  {
42  return !std::isgraph(ch) || ch == '#' || ch == '/' || ch == ',' ||
43  ch == ']' || ch == '}' || ch == '.' || ch == '[' || ch == ':';
44  }
45 
47  : ::boost::spirit::qi::primitive_parser<catchall_parser> {
48  template <typename Context, typename Iterator>
49  struct attribute {
50  typedef std::string type;
51  };
52 
53  // do the parse:
54  template <typename Iterator,
55  typename Context,
56  typename Skipper,
57  typename Attribute>
58  bool
59  parse(Iterator& first,
60  Iterator const& last,
61  Context&,
62  Skipper const& skipper,
63  Attribute& attr) const
64  {
65  boost::spirit::qi::skip_over(first, last, skipper);
66 
67  if (!::shims::isSnippetMode())
68  return false;
69 
70  Iterator it = first;
71  while (it != last &&
72  (std::isalnum(*it) || *it == '_' || *it == ':' || *it == '@'))
73  ++it;
74 
75  if (it != last && !maximally_munched_ass(*it))
76  return false;
77 
78  Attribute result(first, it);
79  if (result.empty() || std::isdigit(result[0]))
80  return false;
81 
82  first = it;
83  boost::spirit::traits::assign_to(result, attr);
84  return true;
85  }
86 
87  template <typename Context>
88  boost::spirit::info
89  what(Context&) const
90  {
91  return boost::spirit::info("shims::catchall");
92  }
93  };
94 }
95 
96 namespace boost {
97  namespace spirit {
98  namespace qi {
99  template <typename Modifiers>
100  struct make_primitive<shims::tag::catchall, Modifiers> {
102  result_type operator()(unused_type, unused_type) const
103  {
104  return result_type();
105  }
106  };
107  }
108  }
109 }
110 #endif /* fhiclcpp_parse_shims_h */
bool maximally_munched_ass(char ch)
Definition: parse_shims.h:40
bool isSnippetMode(bool m)
Definition: parse_shims.cc:9
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:59
result_type operator()(unused_type, unused_type) const
Definition: parse_shims.h:102
boost::spirit::info what(Context &) const
Definition: parse_shims.h:89