2 #ifndef GAUDIKERNEL_GRAMMARSV2_H 3 #define GAUDIKERNEL_GRAMMARSV2_H 1 5 #pragma GCC system_header 17 #include <unordered_map> 18 #include <unordered_set> 23 #include <boost/fusion/include/std_pair.hpp> 24 #include <boost/fusion/include/unused.hpp> 25 #include <boost/spirit/include/qi.hpp> 27 #include <boost/spirit/include/phoenix_core.hpp> 28 #include <boost/spirit/include/phoenix_operator.hpp> 30 #include <boost/type_traits.hpp> 31 #include <boost/utility/enable_if.hpp> 33 #include <boost/spirit/repository/include/qi_confix.hpp> 52 namespace ph = boost::phoenix;
53 namespace qi = sp::qi;
54 namespace enc = sp::ascii;
55 namespace rep = sp::repository;
62 template <
typename Iterator,
typename T,
typename Skipper,
class Enable =
void>
73 #define REGISTER_GRAMMAR( ResultType, GrammarName ) \ 74 template <typename Iterator, typename Skipper> \ 75 struct Grammar_<Iterator, ResultType, Skipper> { \ 76 typedef GrammarName<Iterator, Skipper> Grammar; \ 79 template <
typename Iterator>
80 struct SkipperGrammar : qi::grammar<Iterator> {
83 comments = enc::space | rep::confix(
"/*",
"*/" )[*( qi::char_ -
"*/" )] |
84 rep::confix(
"//", ( sp::eol | sp::eoi ) )[*( qi::char_ - ( sp::eol | sp::eoi ) )];
86 qi::rule<Iterator> comments;
89 template <
typename Iterator,
typename Skipper>
90 struct StringGrammar : qi::grammar<Iterator, std::string(), qi::locals<char>, Skipper> {
96 begin_quote = enc::char_(
"\"'" );
97 quote = enc::char_( qi::_r1 );
99 str = qi::lexeme[begin_quote[qi::_a = qi::_1] >
100 *( ( enc::char_(
'\\' ) >> quote( qi::_a ) )[qi::_val += qi::_a] |
101 ( enc::char_[qi::_val += qi::_1] - quote( qi::_a ) ) ) > quote( qi::_a )];
104 qi::rule<Iterator, std::string(), qi::locals<char>,
Skipper> str;
105 qi::rule<Iterator, char()> begin_quote;
106 qi::rule<Iterator, void( char )> quote;
112 template <
typename Iterator,
typename Skipper>
117 ch = qi::int_parser<char>() |
'\'' >> ( qi::char_ -
'\'' ) >>
'\'';
119 qi::rule<Iterator, char(), Skipper>
ch;
123 template <
typename Iterator,
typename Skipper>
124 struct BoolGrammar : qi::grammar<Iterator, bool(), Skipper> {
128 boolean_literal = ( qi::lit(
"true" ) |
"True" |
"TRUE" |
"1" )[qi::_val =
true] |
129 ( qi::lit(
"false" ) |
"False" |
"FALSE" |
"0" )[qi::_val =
false];
135 template <
typename Iterator,
typename RT,
typename Skipper>
140 integer = qi::int_parser<RT>()[qi::_val = qi::_1] >> -qi::no_case[qi::char_(
'L' )];
147 template <
typename Iterator,
typename T,
typename Skipper>
152 template <
typename Iterator,
typename RT,
typename Skipper>
153 struct RealGrammar : qi::grammar<Iterator, RT(), Skipper> {
156 qi::rule<Iterator, RT(), Skipper>
real;
161 template <
typename Iterator,
typename T,
typename Skipper>
168 template <
typename T>
172 template <
typename T>
176 template <
typename T,
typename... Ts>
181 template <
typename T,
typename... Ts>
188 template <
typename Iterator,
typename TupleT, std::
size_t N,
typename Skipper>
190 : qi::grammar<Iterator, TupleT(), qi::locals<typename tuple_get_first_type<TupleT>::type>, Skipper> {
199 void operator()( ResultT& res, HeadT& head, TailT& tail )
const 208 tup = grHead[qi::_a = qi::_1] >>
',' >> grLast[op( qi::_val, qi::_a, qi::_1 )];
214 qi::rule<Iterator, ResultT(), qi::locals<HeadT>,
Skipper>
tup;
215 ph::function<Operations>
op;
218 template <
typename Iterator,
typename TupleT,
typename Skipper>
229 std::get<0>( res ) = val;
238 qi::rule<Iterator, ResultT(), Skipper>
tup;
239 ph::function<Operations>
op;
243 template <
typename Iterator,
typename TupleT, std::
size_t N,
typename Skipper>
244 struct TupleGrammar : qi::grammar<Iterator, TupleT(), qi::locals<char>, Skipper> {
248 begin = enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'(' )[qi::_val =
')'];
249 end = enc::char_( qi::_r1 );
251 tup =
begin[qi::_a = qi::_1] >> grTuple[qi::_val = qi::_1] >>
end( qi::_a );
255 qi::rule<Iterator, void( char )>
end;
256 qi::rule<Iterator, ResultT(), qi::locals<char>,
Skipper>
tup;
268 template <
typename Iterator,
typename VectorT,
typename Skipper>
269 struct VectorGrammar : qi::grammar<Iterator, VectorT(), qi::locals<char>, Skipper> {
276 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
277 end = enc::char_( qi::_r1 );
278 list = elementGrammar %
',';
279 vec =
begin[qi::_a = qi::_1] >> -list[qi::_val = qi::_1] >>
end( qi::_a );
284 qi::rule<Iterator, void( char )>
end;
286 qi::rule<Iterator, ResultT(), qi::locals<char>, Skipper>
vec;
287 qi::rule<Iterator, ResultT(), Skipper>
list;
293 template <
typename Iterator,
typename InnerT,
typename AllocatorT,
typename Skipper>
300 template <
typename Iterator,
typename InnerT,
typename AllocatorT,
typename Skipper>
307 template <
typename Iterator,
typename InnerT,
typename CompareT,
typename AllocatorT,
typename Skipper>
314 template <
typename Iterator,
typename InnerT,
typename HashT,
typename CompareT,
typename AllocatorT,
321 template <
typename Iterator,
typename PairT,
typename Skipper>
322 struct PairGrammar : qi::grammar<Iterator, PairT(), qi::locals<char>, Skipper> {
336 begin = enc::char_(
'(' )[qi::_val =
')'] | enc::char_(
'[' )[qi::_val =
']'];
337 end = qi::char_( qi::_r1 );
338 pair =
begin[qi::_a = qi::_1] >> pair_in[qi::_val = qi::_1] >>
end( qi::_a );
339 pair_in = key >> qi::lit( delimeter ) >> value;
345 qi::rule<Iterator, void( char )>
end;
346 qi::rule<Iterator, ResultT(), qi::locals<char>, Skipper>
pair;
347 qi::rule<Iterator, ResultT(), Skipper>
pair_in;
354 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename Skipper>
359 template <
typename Iterator,
typename MapT,
typename Skipper>
363 typedef typename MapT::key_type
KeyT;
375 void operator()( ResultT& res,
const VectorPairT& vec )
const 377 for (
auto cur = vec.
begin(); cur != vec.
end(); ++cur ) {
388 pair = key[op( qi::_val, qi::_1,
tag_key() )] > ( qi::lit(
':' ) |
'=' ) >
390 list = -( pair % enc::char_(
',' ) );
391 map = ( (
'[' >> list >>
']' ) | (
'{' >> list >>
'}' ) )[op( qi::_val, qi::_1 )];
396 qi::rule<Iterator, PairT(), Skipper>
pair;
397 qi::rule<Iterator, VectorPairT(), Skipper>
list;
398 qi::rule<Iterator, ResultT(), Skipper>
map;
399 ph::function<Operations>
op;
405 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename KeyCompareT,
typename AllocatorT,
413 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename HashT,
typename KeyCompareT,
414 typename AllocatorT,
typename Skipper>
421 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename KeyCompareT,
typename AllocatorT,
427 template <
typename Iterator,
typename Po
intT,
typename Skipper>
433 void operator()( ResultT& res,
const Scalar& scalar,
const char xyz )
const 453 point = list | (
'(' >> list >>
')' ) | (
'[' >> list >>
']' );
454 list = -( enc::no_case[qi::lit(
"x" ) | qi::lit(
"px" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'x' )] >>
455 ',' >> -( enc::no_case[qi::lit(
"y" ) | qi::lit(
"py" )] >>
':' ) >>
456 scalar[op( qi::_val, qi::_1,
'y' )] >>
',' >>
457 -( enc::no_case[qi::lit(
"z" ) | qi::lit(
"pz" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'z' )];
460 qi::rule<Iterator, ResultT(), Skipper>
point, list;
462 ph::function<Operations>
op;
468 template <
typename Iterator,
typename T1,
typename T2,
typename Skipper>
475 template <
typename Iterator,
typename T1,
typename T2,
typename Skipper>
480 template <
typename Iterator,
typename Po
intT,
typename Skipper>
487 void operator()( ResultT& res,
const ScalarT& scalar,
const char xyz )
const 508 res.SetPx( xyz.Px() );
509 res.SetPy( xyz.Py() );
510 res.SetPz( xyz.Pz() );
516 point4d = list4d | (
'(' >> list4d >>
')' ) | (
'[' >> list4d >>
']' );
517 list4d = ( point3d[op( qi::_val, qi::_1 )] >> enc::char_(
";," ) >> e[op( qi::_val, qi::_1,
'e' )] ) |
518 ( e[op( qi::_val, qi::_1,
'e' )] >> enc::char_(
";," ) >> point3d[op( qi::_val, qi::_1 )] );
519 e = -( enc::no_case[enc::char_(
"te" )] >>
':' ) >> scalar[qi::_val = qi::_1];
521 point3d = list3d | (
'(' >> list3d >>
')' ) | (
'[' >> list3d >>
']' );
522 list3d = -( enc::no_case[qi::lit(
"x" ) | qi::lit(
"px" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'x' )] >>
523 ',' >> -( enc::no_case[qi::lit(
"y" ) | qi::lit(
"py" )] >>
':' ) >>
524 scalar[op( qi::_val, qi::_1,
'y' )] >>
',' >>
525 -( enc::no_case[qi::lit(
"z" ) | qi::lit(
"pz" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'z' )];
528 qi::rule<Iterator, ResultT(), Skipper> point3d,
point4d, list3d, list4d;
529 qi::rule<Iterator, ScalarT(), Skipper>
e;
531 ph::function<Operations>
op;
537 template <
typename Iterator,
typename T1,
typename Skipper>
542 template <
typename Iterator,
typename Skipper>
543 struct Histo1DGrammar : qi::grammar<Iterator, Gaudi::Histo1DDef(), qi::locals<char>, Skipper> {
548 void operator()( ResultT& res,
const double& val,
const char lh )
const 552 res.setLowEdge( val );
555 res.setHighEdge( val );
561 void operator()( ResultT& res,
int val )
const { res.setBins( val ); }
567 val1 = title[op( qi::_val, qi::_1 )] >>
',' >> qi::double_[op( qi::_val, qi::_1,
'l' )] >>
',' >>
568 qi::double_[op( qi::_val, qi::_1,
'h' )] >> -(
',' >> qi::int_[op( qi::_val, qi::_1 )] );
569 val2 = qi::double_[op( qi::_val, qi::_1,
'l' )] >>
',' >> qi::double_[op( qi::_val, qi::_1,
'h' )] >>
',' >>
570 title[op( qi::_val, qi::_1 )] >> -(
',' >> qi::int_[op( qi::_val, qi::_1 )] );
571 val3 = qi::double_[op( qi::_val, qi::_1,
'l' )] >>
',' >> qi::double_[op( qi::_val, qi::_1,
'h' )] >>
572 -(
',' >> title[op( qi::_val, qi::_1 )] ) >> -(
',' >> qi::int_[op( qi::_val, qi::_1 )] );
573 begin = enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'(' )[qi::_val =
')'];
574 end = enc::char_( qi::_r1 );
575 hist = begin[qi::_a = qi::_1] >> ( val1 | val2 | val3 )[qi::_val = qi::_1] >>
end( qi::_a );
578 qi::rule<Iterator, ResultT(), qi::locals<char>, Skipper>
hist;
579 qi::rule<Iterator, ResultT(), Skipper> val1, val2,
val3;
581 qi::rule<Iterator, void( char )>
end;
583 ph::function<Operations>
op;
589 template <
typename Iterator,
typename Skipper>
590 struct KeyValueGrammar : qi::grammar<Iterator, std::pair<std::string, std::string>(), Skipper> {
602 pair = gstring >>
":" >> +enc::char_;
606 qi::rule<Iterator, ResultT(), Skipper>
pair;
qi::rule< Iterator, char()> begin
qi::rule< Iterator, ResultT(), Skipper > pair
VectorGrammar< Iterator, std::vector< InnerT, AllocatorT >, Skipper > Grammar
qi::rule< Iterator, ResultT(), Skipper > val3
qi::rule< Iterator, VectorPairT(), Skipper > list
StringGrammar< Iterator, Skipper > gstring
MapGrammar< Iterator, std::map< KeyT, ValueT, KeyCompareT, AllocatorT >, Skipper > Grammar
void operator()(ResultT &res, const ScalarT &scalar, const char xyz) const
void operator()(ResultT &res, const std::string &title) const
Grammar_< Iterator, ScalarT, Skipper >::Grammar scalar
PairT::second_type second_type
Grammar_< Iterator, typename PairT::first_type, Skipper >::Grammar key
qi::rule< Iterator, ResultT(), Skipper > point
RealGrammar< Iterator, T, Skipper > Grammar
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > pair
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > tup
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > vec
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
void operator()(ResultT &res, const typename std::tuple_element< 0, ResultT >::type &val) const
SkipperGrammar< IteratorT > Skipper
qi::rule< Iterator, ResultT(), qi::locals< HeadT >, Skipper > tup
ph::function< Operations > op
MapT::mapped_type MappedT
StringGrammar< Iterator, Skipper > title
qi::rule< Iterator, ResultT(), Skipper > map
TupleInnerGrammar< Iterator, TailT, N-1, Skipper > grLast
void operator()(ResultT &res) const
BOOST_MPL_ASSERT_MSG(false, GRAMMAR_FOR_TYPE_DOES_NOT_EXISTS,(T))
VectorGrammar< Iterator, std::unordered_set< InnerT, HashT, CompareT, AllocatorT >, Skipper > Grammar
The helper class to represent the efficient "key" for access.
qi::rule< Iterator, ScalarT(), Skipper > e
PairGrammar(const std::string &delimeter)
Grammar_< Iterator, typename VectorT::value_type, Skipper >::Grammar elementGrammar
Grammar_< Iterator, HeadT, Skipper >::Grammar grHead
void operator()(ResultT &res, const double &val, const char lh) const
qi::rule< Iterator, char()> begin
struct GAUDI_API map
Parametrisation class for map-like implementation.
qi::rule< Iterator, void(char)> end
std::pair< KeyT, MappedT > PairT
ph::function< Operations > op
Pnt3DGrammar< Iterator, ROOT::Math::DisplacementVector3D< T1, T2 >, Skipper > Grammar
VectorGrammar< Iterator, std::list< InnerT, AllocatorT >, Skipper > Grammar
Grammar_< Iterator, typename PairT::second_type, Skipper >::Grammar value
void operator()(ResultT &res, const Scalar &scalar, const char xyz) const
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > hist
qi::rule< Iterator, ResultT(), Skipper > pair_in
PairT::first_type first_type
tuple_get_first_type< TupleT >::type HeadT
qi::rule< Iterator, ResultT(), Skipper > point4d
qi::rule< Iterator, PairT(), Skipper > pair
MapGrammar< Iterator, GaudiUtils::VectorMap< KeyT, ValueT, KeyCompareT, AllocatorT >, Skipper > Grammar
qi::rule< Iterator, ResultT(), Skipper > list
MapGrammar< Iterator, std::unordered_map< KeyT, ValueT, HashT, KeyCompareT, AllocatorT >, Skipper > Grammar
std::string::const_iterator DefaultIterator
IntGrammar< Iterator, T, Skipper > Grammar
void operator()(PairT &res, const KeyT &key, tag_key) const
Pnt4DGrammar< Iterator, ROOT::Math::LorentzVector< T1 >, Skipper > Grammar
Grammar_< Iterator, typename MapT::key_type, Skipper >::Grammar key
void operator()(ResultT &res, int val) const
enc::space_type DefaultSkipper
std::vector< PairT > VectorPairT
qi::rule< Iterator, void(char)> end
qi::rule< Iterator, bool(), Skipper > boolean_literal
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
PairGrammar< Iterator, std::pair< KeyT, ValueT >, Skipper > Grammar
void operator()(ResultT &res, const VectorPairT &vec) const
ph::function< Operations > op
void operator()(ResultT &res, const ResultT &xyz) const
Forward declarations for the functions in SerializeSTL.h.
tuple_remove_first_type< TupleT >::type TailT
qi::rule< Iterator, char(), Skipper > ch
TupleInnerGrammar< Iterator, TupleT, N, Skipper > grTuple
qi::rule< Iterator, void(char)> end
Grammar_< Iterator, typename std::tuple_element< 0, ResultT >::type, Skipper >::Grammar grFirst
qi::rule< Iterator, char()> begin
ph::function< Operations > op
Pnt3DGrammar< Iterator, ROOT::Math::PositionVector3D< T1, T2 >, Skipper > Grammar
VectorGrammar< Iterator, std::set< InnerT, CompareT, AllocatorT >, Skipper > Grammar
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Grammar_< Iterator, typename MapT::mapped_type, Skipper >::Grammar value
qi::rule< Iterator, RT(), Skipper > real
qi::rule< Iterator, RT(), Skipper > integer
void operator()(ResultT &res, HeadT &head, TailT &tail) const
qi::rule< Iterator, char()> begin
qi::rule< Iterator, void(char)> end
void operator()(PairT &res, const MappedT &value, tag_mapped) const
Helper functions to set/get the application return code.
Gaudi::Histo1DDef ResultT
std::pair< std::string, std::string > ResultT
ph::function< Operations > op
qi::rule< Iterator, ResultT(), Skipper > tup
Grammar_< Iterator, Scalar, Skipper >::Grammar scalar
ph::function< Operations > op
REGISTER_GRAMMAR(GaudiMath::Interpolation::Type, InterpolGrammar)