1 #ifndef JOBOPTIONSVC_GRAMMAR_H_ 2 #define JOBOPTIONSVC_GRAMMAR_H_ 14 #include <boost/spirit/include/phoenix_core.hpp> 15 #include <boost/spirit/include/phoenix_fusion.hpp> 16 #include <boost/spirit/include/phoenix_operator.hpp> 17 #include <boost/spirit/include/phoenix_stl.hpp> 18 #include <boost/spirit/include/qi.hpp> 19 #include <boost/spirit/repository/include/qi_confix.hpp> 21 #if BOOST_VERSION <= 104400 24 #include <boost/spirit/repository/include/qi_iter_pos.hpp> 40 namespace ph = boost::phoenix;
41 namespace qi = sp::qi;
42 namespace enc = sp::ascii;
43 namespace rep = sp::repository;
47 template <
typename Iterator>
51 comments = enc::space | rep::confix(
"/*",
"*/" )[*( qi::char_ -
"*/" )] |
52 rep::confix(
"//", ( sp::eol | sp::eoi ) )[*( qi::char_ - ( sp::eol | sp::eoi ) )];
57 template <
typename Iterator,
typename Skipper>
58 struct StringGrammar : qi::grammar<Iterator, std::string(), qi::locals<char>, Skipper> {
64 begin_quote = enc::char_(
"\"'" );
65 quote = enc::char_( qi::_r1 );
67 str = qi::lexeme[begin_quote[qi::_a = qi::_1] >>
68 *( ( enc::char_(
'\\' ) >> quote( qi::_a ) )[qi::_val += qi::_a] |
69 ( enc::char_[qi::_val += qi::_1] - quote( qi::_a ) ) ) >>
73 qi::rule<Iterator, std::string(), qi::locals<char>,
Skipper>
str;
75 qi::rule<Iterator, void( char )>
quote;
79 template <
typename Iterator,
typename Skipper>
87 rep::qi::iter_pos[op( qi::_val, qi::_1 )] >> str[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kIdentifier )];
88 str = -qi::lit(
"::" )[qi::_val +=
"::"] >> inner[qi::_val += qi::_1] >>
89 *( qi::lit(
"::" ) >> inner[qi::_val += (
"::" + qi::_1 )] );
90 inner = qi::alpha >> *( qi::alnum | qi::char_(
'_' ) );
93 qi::rule<Iterator, Node(), Skipper>
ident;
94 qi::rule<Iterator, std::string(), Skipper>
str;
95 qi::rule<Iterator, std::string()>
inner;
96 ph::function<NodeOperations>
op;
99 template <
typename Iterator,
typename Skipper>
106 boolean = enc::no_case[qi::lit(
"true" )[qi::_val =
true] | qi::lit(
"false" )[qi::_val =
false]];
112 template <
typename Iterator,
typename Skipper>
119 real = qi::raw[qi::double_][op( qi::_val, qi::_1 )][op( qi::_val,
Node::kReal )] >> -qi::char_(
'L' ) >>
120 -( -qi::char_(
'*' ) >> gunit[op( qi::_val, qi::_1 )] );
123 qi::rule<Iterator, Node(), Skipper>
real;
125 ph::function<NodeOperations>
op;
128 template <
typename Iterator,
typename Skipper>
133 units = *unit[op( qi::_val, qi::_1 )];
134 unit = rep::qi::iter_pos[op( qi::_val, qi::_1 )] >> val[op( qi::_val, qi::_1 )] >> -qi::lit(
'*' ) >>
135 gunit[op( qi::_val, qi::_1 )] >> qi::lit(
'=' ) >>
136 val[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kUnit )];
138 val = qi::raw[qi::double_][op( qi::_val, qi::_1 )][op( qi::_val,
Node::kReal )];
141 qi::rule<Iterator, Node(), Skipper> units, unit,
val;
143 ph::function<NodeOperations>
op;
146 template <
typename Iterator,
typename Skipper>
150 file = -shell[op( qi::_val, qi::_1 )] >> *( statement[op( qi::_val, qi::_1 )] )[op( qi::_val,
Node::kRoot )];
153 qi::eol )[*( qi::char_[qi::_a += qi::_1] - qi::eol )][op( qi::_val,
Node::kShell )][op( qi::_val, qi::_a )];
154 statement = rep::qi::iter_pos[qi::_a = qi::_1] >> ( include | assign | units | print_options | pragma |
155 condition )[qi::_val = qi::_1][op( qi::_val, qi::_a )];
158 property[op( qi::_val, qi::_1 )] >> ( *statement[op( qi::_a, qi::_1 )] )[op( qi::_val, qi::_a )] >>
159 -( qi::lit(
"#else" )[op( qi::_b,
Node::kElse )] >>
160 *statement[op( qi::_b, qi::_1 )] )[op( qi::_val, qi::_b )] >>
162 include = qi::lit(
"#include" ) >> gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kInclude )];
163 units = qi::lit(
"#units" ) >> gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kUnits )];
164 print_options = qi::lit(
"#printOptions" ) >> qi::lit(
"full" )[op( qi::_val,
Node::kPrintOptions )];
165 pragma = qi::lit(
"#pragma" ) >> ( pragma_print | pragma_tree | pragma_dump_file );
166 pragma_print = qi::lit(
"print" ) >> enc::no_case[qi::lit(
"on" )[op( qi::_val,
Node::kPrintOn )] |
168 pragma_tree = enc::no_case[qi::lit(
"printtree" )[op( qi::_val,
Node::kPrintTree )]];
169 pragma_dump_file = qi::lit(
"dumpfile" ) >> gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kDumpFile )];
170 assign =
property[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kAssign )] >> oper[op( qi::_val, qi::_1 )] >>
171 value[op( qi::_val, qi::_1 )] >>
';';
172 property = rep::qi::iter_pos[op( qi::_val, qi::_1 )] >>
173 ( gidentifier[op( qi::_val, qi::_1 )] %
'.' )[op( qi::_val,
Node::kProperty )];
175 oper = rep::qi::iter_pos[op( qi::_val, qi::_1 )] >>
178 value = rep::qi::iter_pos[qi::_a = qi::_1] >> ( map_value | vector_value | simple_value |
property |
179 property_ref )[qi::_val = qi::_1][op( qi::_val, qi::_a )];
181 enc::char_(
'(' )[qi::_val =
')'] | enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'];
182 end_vector = qi::char_( qi::_r1 );
183 vector_value = ( begin_vector[qi::_a = qi::_1] >> -( value[op( qi::_val, qi::_1 )] %
',' ) >>
185 map_value = ( enc::char_(
'{' ) >> -( pair[op( qi::_val, qi::_1 )] %
',' ) >>
186 enc::char_(
'}' ) )[op( qi::_val,
Node::kMap )];
188 simple_value[op( qi::_val, qi::_1 )] >>
':' >> value[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kPair )];
189 simple_value = ( gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kString )] ) |
190 ( gbool[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kBool )] ) | ( greal[qi::_val = qi::_1] );
192 qi::rule<Iterator, Node(), Skipper> file, include, assign,
property, property_ref, oper, map_value, pair_value,
193 simple_value, pair,
units, print_options, pragma, pragma_print, pragma_tree, pragma_dump_file;
194 qi::rule<Iterator, Node(), qi::locals<std::string>>
shell;
195 qi::rule<Iterator, Node(), qi::locals<Iterator>,
Skipper> statement,
value;
204 ph::function<NodeOperations>
op;
210 #endif // JOBOPTIONSVC_GRAMMAR_H_
qi::rule< Iterator, Node(), qi::locals< std::string > > shell
qi::rule< Iterator, void(char)> end_vector
qi::rule< Iterator, Node(), qi::locals< Node, Node >, Skipper > condition
qi::rule< Iterator > comments
qi::rule< Iterator, std::string(), Skipper > str
IdentifierGrammar< Iterator, Skipper > gidentifier
Gaudi::Details::PropertyBase * property(const std::string &name) const
RealGrammar< Iterator, Skipper > greal
qi::rule< Iterator, void(char)> quote
IdentifierGrammar< Iterator, Skipper > gunit
qi::rule< Iterator, Node(), qi::locals< Iterator >, Skipper > value
ph::function< NodeOperations > op
qi::rule< Iterator, Node(), Skipper > real
BoolGrammar< Iterator, Skipper > gbool
qi::rule< Iterator, Node(), Skipper > val
ph::function< NodeOperations > op
qi::rule< Iterator, char()> begin_vector
qi::rule< Iterator, Node(), qi::locals< char >, Skipper > vector_value
qi::rule< Iterator, Node(), Skipper > units
qi::rule< Iterator, Node(), Skipper > ident
IdentifierGrammar< Iterator, Skipper > gunit
qi::rule< Iterator, std::string()> inner
qi::rule< Iterator, bool(), Skipper > boolean
qi::rule< Iterator, std::string(), qi::locals< char >, Skipper > str
StringGrammar< Iterator, Skipper > gstring
ph::function< NodeOperations > op
ph::function< NodeOperations > op
Helper functions to set/get the application return code.
qi::rule< Iterator, char()> begin_quote