2 #ifndef GAUDIKERNEL_GRAMMARS_H
3 #define GAUDIKERNEL_GRAMMARS_H 1
6 The headers GaudiKernel/Grammars.h and GaudiKernel/Parsers.icpp are deprecated \
7 and will be removed from the next release of Gaudi. You should migrate your \
8 code the new pasers based on Boost.Spirit 2.
19 #include <boost/version.hpp>
20 #if BOOST_VERSION >= 103800
22 #if !defined(BOOST_SPIRIT_USE_OLD_NAMESPACE)
23 #define BOOST_SPIRIT_USE_OLD_NAMESPACE
25 #include <boost/spirit/include/classic.hpp>
26 #include <boost/spirit/include/phoenix1.hpp>
28 #include <boost/spirit.hpp>
29 #include <boost/spirit/phoenix.hpp>
31 #include <boost/bind.hpp>
50 using namespace boost::spirit ;
52 using namespace phoenix ;
63 struct ClosureGrammar :
public boost::spirit::closure < ClosureGrammar<T>,T >
65 typedef boost::spirit::closure<ClosureGrammar, T>
closure;
66 typename closure::member1
val;
79 template <
typename T1,
typename T2>
81 :
public boost::spirit::closure<AttributesClosureGrammar<T1,T2>,T1,T2>
83 typedef boost::spirit::closure<AttributesClosureGrammar, T1,T2>
closure;
84 typename closure::member1
val;
85 typename closure::member2
attrs;
102 ClosureGrammar<bool>::context_t
108 template <
typename ScannerT>
114 = true_literal[
self.val =
true] | false_literal[
self.val =
false];
116 = str_p(
"true" ) | str_p(
"True" ) | str_p(
"TRUE" ) | str_p(
"1");
118 = str_p(
"false") | str_p(
"False") | str_p(
"FALSE") | str_p(
"0");
121 {
return boolean_literal;}
136 template<
typename RT=
char>
139 CharGrammar<RT> , typename ClosureGrammar<RT>::context_t
145 template <
typename ScannerT>
151 = int_parser<RT>()[
self.val=arg1]
153 >> ( str_p(
"\\'")[
self.val=
'\'']
154 | (anychar_p[
self.val=arg1]-
'\'') )>>
'\'');
157 {
return char_literal; }
173 template<
typename RT=
int>
177 typename ClosureGrammar<RT>::context_t
183 template <
typename ScannerT>
188 int_literal = lexeme_d[int_parser<RT>()[
self.val=arg1]
189 >> !(ch_p(
'u') | ch_p(
'U') | ch_p(
'l') | ch_p(
'L'))];
191 rule<ScannerT>
const&
start()
const {
return int_literal; }
207 template<
typename RT=
double>
210 RealGrammar<RT>,typename ClosureGrammar<RT>::context_t
216 template <
typename ScannerT>
222 = lexeme_d[real_parser<RT,
223 real_parser_policies<RT> >()[
self.val = arg1]
224 >> !(ch_p(
'f') | ch_p(
'F') | ch_p(
'l') | ch_p(
'L'))];
227 {
return real_literal; }
248 StringGrammar, ClosureGrammar<std::string>::context_t
263 for ( std::string::iterator cur=this->val().begin();
264 cur!=this->val().end();cur++)
265 {
if(std::isspace(*cur) ) { *cur =
' '; } }
268 template <
typename ScannerT>
273 string_literal = (lexeme_d
275 (
'"' >> (*( str_p(
"\\\"")
278 [
self.val = construct_<std::string>
282 (
'\'' >> (*( str_p(
"\\'")
285 [
self.val = construct_<std::string>
289 rule<ScannerT>
const&
start()
const {
return string_literal; }
313 : m_skipnewline(skipnewline){}
318 template <
typename ScannerT>
323 if (
self.skipnewline() )
328 | comment_p(
"/*",
"*/")
336 | comment_p(
"/*",
"*/")
341 rule<ScannerT>
const&
start()
const {
return skip; }
357 template <
typename KeyGrammarT,
typename ValueGrammarT>
360 PairGrammar<KeyGrammarT,ValueGrammarT>,
361 typename ClosureGrammar<
362 std::pair<typename KeyGrammarT::ResultT,
363 typename ValueGrammarT::ResultT> >::context_t
367 typedef typename KeyGrammarT::ResultT
KeyT;
368 typedef typename ValueGrammarT::ResultT
ValueT;
382 template <
typename ScannerT>
391 >>
self.delim().c_str()
396 rule<ScannerT>
const&
start()
const {
return para; }
403 const std::string&
delim()
const {
return m_delim ; }
407 void setDelim (
const std::string& delim ) { m_delim = delim;}
423 template <
typename GrammarT>
426 VectorGrammar<GrammarT> ,
427 typename ClosureGrammar<std::vector<typename GrammarT::ResultT> >::context_t
431 typedef typename GrammarT::ResultT
ValueT;
438 template <
typename ScannerT>
447 '[' >> inner >>
']' |
448 '(' >> inner >>
')' |
449 '{' >> inner >>
'}' ;
451 rule<ScannerT>
const&
start()
const {
return vec; }
471 template <
typename KeyGrammarT,
typename ValueGrammarT>
474 MapGrammar<KeyGrammarT,ValueGrammarT>,
475 typename AttributesClosureGrammar
476 < std::map<typename KeyGrammarT::ResultT,
477 typename ValueGrammarT::ResultT>,
478 std::pair<typename KeyGrammarT::ResultT,
479 typename ValueGrammarT::ResultT> >::context_t
483 typedef typename KeyGrammarT::ResultT
KeyT;
484 typedef typename ValueGrammarT::ResultT
ValueT;
491 this->val()[this->attrs().first] = this->attrs().second ;
498 template <
typename ScannerT>
504 = (
'{'>> inner_list >>
'}') | (
'['>>inner_list>>
']');
514 >> ( ch_p(
'=') | ch_p(
':'))
519 rule<ScannerT>
const&
start()
const {
return vec; }
520 rule<ScannerT>
vec,inner, inner_list ;
529 #endif // GAUDIKERNEL_GRAMMARS_H
definition(MapGrammar const &self)
The valid represenation of boolean values are:
SkipperGrammar(const bool skipnewline=true)
Constructor.
The valid represenation of char values are:
Grammar or grammar rule which derive from this struct will have attribute of type T and name val ...
rule< ScannerT > char_literal
void matchSecond(const ValueT &second) const
callback. Action when we match second value
std::map< KeyT, ValueT > ResultT
The valid represenation of real values are:
The valid represenation of pairs are: ("abc",123) or ("abc","def") Inner types of pair depends on Key...
definition(SelfT const &self)
rule< ScannerT > const & start() const
definition(IntGrammar< RT > const &self)
KeyGrammarT::ResultT KeyT
definition(CharGrammar< RT > const &self)
std::pair< KeyT, ValueT > ResultT
VectorGrammar< GrammarT > SelfT
void setDelim(const std::string &delim)
Set delimiters for pair values.
rule< ScannerT > int_literal
PairGrammar(const std::string &delim=",")
Constructor.
The valid represenation of string values are:
rule< ScannerT > const & start() const
void matchFirst(const KeyT &value) const
call backs. Action when we match key of pair
boost::spirit::closure< AttributesClosureGrammar, T1, T2 > closure
Grammar or grammar rule which derive from this struct will have two attributes: type T1 and name val...
definition(PairGrammar const &self)
rule< ScannerT > string_literal
void matchSecond(const ValueT &value) const
call backs. Action when we match value pf pair
rule< ScannerT > const & start() const
rule< ScannerT > const & start() const
The valid representation of integers values are:
void matchFirst(const KeyT &first) const
callback. Action when we match first value
The valid represenation of vector are:
Skipping spaces and comments.
const std::string & delim() const
rule< ScannerT > const & start() const
rule< ScannerT > const & start() const
std::vector< ValueT > ResultT
The valid represenation of map are:
rule< ScannerT > const & start() const
ValueGrammarT::ResultT ValueT
void matchString() const
remove CR/LF symbols form the parsed strings
rule< ScannerT > const & start() const
definition(SkipperGrammar const &self)
void matchItem(const ValueT &value) const
callback. Action when we match inner value
rule< ScannerT > real_literal
definition(StringGrammar const &self)
KeyGrammarT::ResultT KeyT
rule< ScannerT > true_literal
rule< ScannerT > const & start() const
definition(RealGrammar const &self)
This is a number of static methods for bootstrapping the Gaudi framework.
boost::spirit::closure< ClosureGrammar, T > closure
void matchItem() const
call backs. Action when we match pair in map
ValueGrammarT::ResultT ValueT
definition(BoolGrammar const &self)