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
261 void matchString()
const
264 cur!=this->val().end();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>
287 '\'')])[boost::bind(&StringGrammar::matchString,&
self)];
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>
390 >> (grkey[boost::bind(&PairGrammar::matchFirst,&
self,_1)])
391 >>
self.delim().c_str()
392 >> (grvalue[boost::bind(&PairGrammar::matchSecond,&
self,_1)])
396 rule<ScannerT>
const&
start()
const {
return para; }
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>
444 !(gr[boost::bind(&VectorGrammar::matchItem,&
self,_1)]
445 >> *(
','>>gr[boost::bind(&VectorGrammar::matchItem,&
self,_1)]));
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;
488 void matchItem ()
const
491 this->val()[this->attrs().first] = this->attrs().second ;
498 template <
typename ScannerT>
504 = (
'{'>> inner_list >>
'}') | (
'['>>inner_list>>
']');
507 !( inner[boost::bind(&MapGrammar::matchItem,&
self)]
509 inner[boost::bind(&MapGrammar::matchItem,&
self)] )
513 grKey[boost ::bind(&MapGrammar::matchFirst,&
self,_1)]
514 >> ( ch_p(
'=') | ch_p(
':'))
515 >> grValue[boost::bind(&MapGrammar::matchSecond,&
self,_1)] ;
519 rule<ScannerT>
const&
start()
const {
return vec; }
520 rule<ScannerT>
vec,inner, inner_list ;
529 #endif // GAUDIKERNEL_GRAMMARS_H