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