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> 20 #include <boost/spirit/repository/include/qi_iter_pos.hpp> 35 namespace ph = boost::phoenix;
36 namespace qi = sp::qi;
37 namespace enc = sp::ascii;
38 namespace rep = sp::repository;
42 template <
typename Iterator>
46 comments = enc::space | rep::confix(
"/*",
"*/" )[*( qi::char_ -
"*/" )] |
47 rep::confix(
"//", ( sp::eol | sp::eoi ) )[*( qi::char_ - ( sp::eol | sp::eoi ) )];
52 template <
typename Iterator,
typename Skipper>
53 struct StringGrammar : qi::grammar<Iterator, std::string(), qi::locals<char>, Skipper> {
59 begin_quote = enc::char_(
"\"'" );
60 quote = enc::char_( qi::_r1 );
62 str = qi::lexeme[begin_quote[qi::_a = qi::_1] >>
63 *( ( enc::char_(
'\\' ) >> quote( qi::_a ) )[qi::_val += qi::_a] |
64 ( enc::char_[qi::_val += qi::_1] - quote( qi::_a ) ) ) >>
68 qi::rule<Iterator, std::string(), qi::locals<char>,
Skipper>
str;
70 qi::rule<Iterator, void( char )>
quote;
74 template <
typename Iterator,
typename Skipper>
82 rep::qi::iter_pos[op( qi::_val, qi::_1 )] >> str[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kIdentifier )];
83 str = -qi::lit(
"::" )[qi::_val +=
"::"] >> inner[qi::_val += qi::_1] >>
84 *( qi::lit(
"::" ) >> inner[qi::_val += (
"::" + qi::_1 )] );
85 inner = qi::alpha >> *( qi::alnum | qi::char_(
'_' ) );
88 qi::rule<Iterator, Node(), Skipper>
ident;
89 qi::rule<Iterator, std::string(), Skipper>
str;
90 qi::rule<Iterator, std::string()>
inner;
91 ph::function<NodeOperations>
op;
94 template <
typename Iterator,
typename Skipper>
101 boolean = enc::no_case[qi::lit(
"true" )[qi::_val =
true] | qi::lit(
"false" )[qi::_val =
false]];
107 template <
typename Iterator,
typename Skipper>
114 real = qi::raw[qi::double_][op( qi::_val, qi::_1 )][op( qi::_val,
Node::kReal )] >> -qi::char_(
'L' ) >>
115 -( -qi::char_(
'*' ) >> gunit[op( qi::_val, qi::_1 )] );
118 qi::rule<Iterator, Node(), Skipper>
real;
120 ph::function<NodeOperations>
op;
123 template <
typename Iterator,
typename Skipper>
128 units = *unit[op( qi::_val, qi::_1 )];
129 unit = rep::qi::iter_pos[op( qi::_val, qi::_1 )] >> val[op( qi::_val, qi::_1 )] >> -qi::lit(
'*' ) >>
130 gunit[op( qi::_val, qi::_1 )] >> qi::lit(
'=' ) >>
131 val[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kUnit )];
133 val = qi::raw[qi::double_][op( qi::_val, qi::_1 )][op( qi::_val,
Node::kReal )];
136 qi::rule<Iterator, Node(), Skipper> units, unit,
val;
138 ph::function<NodeOperations>
op;
141 template <
typename Iterator,
typename Skipper>
145 file = -shell[op( qi::_val, qi::_1 )] >> *( statement[op( qi::_val, qi::_1 )] )[op( qi::_val,
Node::kRoot )];
148 qi::eol )[*( qi::char_[qi::_a += qi::_1] - qi::eol )][op( qi::_val,
Node::kShell )][op( qi::_val, qi::_a )];
149 statement = rep::qi::iter_pos[qi::_a = qi::_1] >> ( include | assign | units | print_options | pragma |
150 condition )[qi::_val = qi::_1][op( qi::_val, qi::_a )];
153 property[op( qi::_val, qi::_1 )] >> ( *statement[op( qi::_a, qi::_1 )] )[op( qi::_val, qi::_a )] >>
154 -( qi::lit(
"#else" )[op( qi::_b,
Node::kElse )] >>
155 *statement[op( qi::_b, qi::_1 )] )[op( qi::_val, qi::_b )] >>
157 include = qi::lit(
"#include" ) >> gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kInclude )];
158 units = qi::lit(
"#units" ) >> gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kUnits )];
159 print_options = qi::lit(
"#printOptions" ) >> qi::lit(
"full" )[op( qi::_val,
Node::kPrintOptions )];
160 pragma = qi::lit(
"#pragma" ) >> ( pragma_print | pragma_tree | pragma_dump_file );
161 pragma_print = qi::lit(
"print" ) >> enc::no_case[qi::lit(
"on" )[op( qi::_val,
Node::kPrintOn )] |
163 pragma_tree = enc::no_case[qi::lit(
"printtree" )[op( qi::_val,
Node::kPrintTree )]];
164 pragma_dump_file = qi::lit(
"dumpfile" ) >> gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kDumpFile )];
165 assign =
property[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kAssign )] >> oper[op( qi::_val, qi::_1 )] >>
166 value[op( qi::_val, qi::_1 )] >>
';';
167 property = rep::qi::iter_pos[op( qi::_val, qi::_1 )] >>
168 ( gidentifier[op( qi::_val, qi::_1 )] %
'.' )[op( qi::_val,
Node::kProperty )];
170 oper = rep::qi::iter_pos[op( qi::_val, qi::_1 )] >>
173 value = rep::qi::iter_pos[qi::_a = qi::_1] >> ( map_value | vector_value | simple_value |
property |
174 property_ref )[qi::_val = qi::_1][op( qi::_val, qi::_a )];
176 enc::char_(
'(' )[qi::_val =
')'] | enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'];
177 end_vector = qi::char_( qi::_r1 );
178 vector_value = ( begin_vector[qi::_a = qi::_1] >> -( value[op( qi::_val, qi::_1 )] %
',' ) >>
180 map_value = ( enc::char_(
'{' ) >> -( pair[op( qi::_val, qi::_1 )] %
',' ) >>
181 enc::char_(
'}' ) )[op( qi::_val,
Node::kMap )];
183 simple_value[op( qi::_val, qi::_1 )] >>
':' >> value[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kPair )];
184 simple_value = ( gstring[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kString )] ) |
185 ( gbool[op( qi::_val, qi::_1 )][op( qi::_val,
Node::kBool )] ) | ( greal[qi::_val = qi::_1] );
187 qi::rule<Iterator, Node(), Skipper> file, include, assign,
property, property_ref, oper, map_value, pair_value,
188 simple_value, pair,
units, print_options, pragma, pragma_print, pragma_tree, pragma_dump_file;
189 qi::rule<Iterator, Node(), qi::locals<std::string>>
shell;
190 qi::rule<Iterator, Node(), qi::locals<Iterator>,
Skipper> statement,
value;
199 ph::function<NodeOperations>
op;
205 #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