Public Member Functions | |
definition (const ruleparser &self) | |
const rule< ScannerT > & | start () const |
Public Attributes | |
symbols< ParameterDescription > | parlist_real |
symbols< ParameterDescription > | parlist_int |
symbols< ParameterDescription > | parlist_string |
symbols< double > | unit_symbols |
stored_rule< ScannerT > | custom_comparison |
rule< ScannerT > | operators_num |
rule< ScannerT > | operators_string |
rule< ScannerT > | par_real |
rule< ScannerT > | par_int |
rule< ScannerT > | par_string |
rule< ScannerT > | value_real |
rule< ScannerT > | value_int |
rule< ScannerT > | value_string |
rule< ScannerT > | basic_lefthand_comparison |
rule< ScannerT > | basic_righthand_comparison |
rule< ScannerT > | comparison |
rule< ScannerT > | term |
rule< ScannerT > | selection |
rule< ScannerT > | expression |
rule< ScannerT > | my_grammar |
Definition at line 336 of file CreateRules.cc.
ruleparser::definition< ScannerT >::definition | ( | const ruleparser & | self | ) | [inline] |
Definition at line 338 of file CreateRules.cc.
00339 { 00340 // Load units. 00341 static unitlist sUnitlist; 00342 const unitlist::UnitList_t& ulist = sUnitlist(); 00343 unitlist::UnitList_t::const_iterator it = ulist.begin(); 00344 for( ; it != ulist.end(); ++it ){ 00345 unit_symbols.add(it->first.begin(),it->first.end(),it->second); 00346 } 00347 00348 00349 value_real 00350 = (real_p[my_do_double(self.m_store)] >> unit_symbols[my_do_unit(self.m_store)][debugprint("unit")]) 00351 [my_do_double_with_unit(self.m_store)][debugprint("realvalue-with-unit")] 00352 | (real_p[my_do_double(self.m_store)])[debugprint("realvalue")] 00353 ; 00354 00355 // Strings must be single-quoted, contain only a-z,A-Z,0-9,/,_ 00356 value_string 00357 = ch_p('\'') >> (*(alnum_p | ch_p('/') | ch_p('-')| ch_p('_')))[my_do_string(self.m_store)][debugprint("stringvalue")] >> ch_p('\'') 00358 ; 00359 00360 custom_comparison = nothing_p; 00361 00362 for(unsigned int i=0; i<self.m_pars.size(); i++) { 00363 const ParameterDescription& par = self.m_pars[i]; 00364 // change to a lowercase name so it will match with a as_lower_d directive 00365 // use the temporary stack to store an actual string location, so it is still there 00366 // when the parser runs. 00367 std::string temp = par.name(); 00368 for(std::string::iterator c = temp.begin(); c!= temp.end(); ++c) *c = tolower(*c); 00369 self.m_store.mTempStack.push(temp); 00370 std::string& parname = self.m_store.mTempStack.top(); 00371 //cout << "Setting rules for parameter " << par.name() << "\t" << parname << endl; 00372 00373 if( par.factory() ) { 00374 // It's a custom type. Set up custom rules for it. 00375 // Add one line for every operator allowed. 00376 for(unsigned int iop=0; iop < par.operators().size(); ++iop){ 00377 std::string temp = par.operators()[iop]; 00378 // change to a lowercase name so it will match with a as_lower_d directive 00379 for(std::string::iterator c = temp.begin(); c!= temp.end(); ++c) *c = tolower(*c); 00380 self.m_store.mTempStack.push(temp); 00381 std::string& op = self.m_store.mTempStack.top(); 00382 00383 // Custom floating point parameter. 00384 if(par.type() == typeid(double).name()){ 00385 custom_comparison 00386 = ( as_lower_d[parname.c_str()] 00387 >> as_lower_d[op.c_str()] 00388 >> value_real 00389 ) [my_do_custom<double>(self.m_store,par,iop,true)] // Lefthand operation 00390 00391 | ( value_real 00392 >> as_lower_d[op.c_str()] 00393 >> as_lower_d[parname.c_str()] 00394 ) [my_do_custom<double>(self.m_store,par,iop,false)] // righthand operation 00395 00396 | custom_comparison.copy() // Append. 00397 ; 00398 } 00399 00400 // Custom string-or-who-knows 00401 else { 00402 custom_comparison 00403 = ( as_lower_d[parname.c_str()] 00404 >> as_lower_d[op.c_str()] 00405 >> value_string 00406 ) [my_do_custom<string>(self.m_store,par,iop,true)] // Lefthand operation 00407 00408 | ( value_string 00409 >> as_lower_d[op.c_str()] 00410 >> as_lower_d[parname.c_str()] 00411 ) [my_do_custom<string>(self.m_store,par,iop,false)] // righthand operation 00412 00413 | custom_comparison.copy() // Append. 00414 ; 00415 } 00416 00417 00418 } 00419 00420 } else { 00421 // Not a custom type. 00422 00423 if(par.type() == typeid(double).name()) 00424 parlist_real.add(parname.begin(), parname.end(), par); 00425 else// If you dont' understand the type, treat it as a string. 00426 parlist_string.add(parname.begin(), parname.end(), par); 00427 } 00428 }; 00429 00430 // Match a name of parameter, after converting to lowercase. 00431 par_real = as_lower_d[parlist_real[my_do_param(self.m_store)]]; 00432 par_string = as_lower_d[parlist_string[my_do_param(self.m_store)]]; 00433 00434 // Valid numerical operators (int and double types) 00435 // N.B. Longer strings should go first, to ensure lazy matching doesn't screw you. 00436 operators_num 00437 = str_p("<=" ) 00438 | str_p(">=") 00439 | str_p("<" ) 00440 | str_p(">") 00441 | str_p("==") 00442 | str_p("=" ) 00443 | str_p("!=") 00444 ; 00445 00446 // Valid string operators 00447 operators_string 00448 = str_p("==" ) 00449 | str_p("=") 00450 | str_p("!=") 00451 ; 00452 00453 basic_lefthand_comparison // e.g. pdgcode<2 00454 = (par_real >> operators_num [my_do_operator(self.m_store)] >> value_real )[my_do_simple_comparison<double>(self.m_store,true)] 00455 | (par_string >> operators_string[my_do_operator(self.m_store)] >> value_string)[my_do_simple_comparison<string>(self.m_store,true)] 00456 ; 00457 00458 basic_righthand_comparison // e.g. 2>pdgcode 00459 = ( 00460 (value_real >> operators_num [my_do_operator(self.m_store)] >> par_real )[my_do_simple_comparison<double>(self.m_store,false)] 00461 | (value_string >> operators_string[my_do_operator(self.m_store)] >> par_string)[my_do_simple_comparison<string>(self.m_store,false)] 00462 ); 00463 00464 // A comparison is a basic lhs comparison, a basic rhs comparison, or a custom comparison. 00465 comparison 00466 = basic_lefthand_comparison[debugprint("lefthand-comparison")] 00467 | basic_righthand_comparison[debugprint("righthand-comparison")] 00468 | custom_comparison[debugprint("custom-comparison")] 00469 ; 00470 00471 // An expression is a term, optionally followed by AND term, or OR term 00472 expression 00473 = (term >> 00474 !( ((as_lower_d["and"]|str_p("&&")) >> term)[my_do_and(self.m_store)][debugprint("do-and")] 00475 | ((as_lower_d["or"] |str_p("||")) >> term)[my_do_or(self.m_store)][debugprint("do-or")] 00476 ) 00477 )[debugprint("expression")] 00478 ; 00479 00480 // A term is 'any', 'none', comparison, (expression), or not term 00481 term 00482 = (as_lower_d["any"] | as_lower_d["all"] )[my_do_any(self.m_store)] 00483 | ( as_lower_d["none"]| as_lower_d["nothing"])[my_do_none(self.m_store)] 00484 | comparison[debugprint("comparison-as-term")] 00485 | ('(' >> expression >> ')')[debugprint("expression-as-term")] 00486 | ((as_lower_d["not"]|str_p("!")) >> term)[my_do_not(self.m_store)][debugprint("do-not")][debugprint("not-as-term")] 00487 ; 00488 00489 00490 // Final result can be padded with whitespace. 00491 my_grammar 00492 = expression >> end_p 00493 ; 00494 }
const rule<ScannerT>& ruleparser::definition< ScannerT >::start | ( | ) | const [inline] |
symbols<ParameterDescription> ruleparser::definition< ScannerT >::parlist_real |
Definition at line 496 of file CreateRules.cc.
symbols<ParameterDescription> ruleparser::definition< ScannerT >::parlist_int |
Definition at line 497 of file CreateRules.cc.
symbols<ParameterDescription> ruleparser::definition< ScannerT >::parlist_string |
Definition at line 498 of file CreateRules.cc.
symbols<double> ruleparser::definition< ScannerT >::unit_symbols |
Definition at line 499 of file CreateRules.cc.
stored_rule<ScannerT> ruleparser::definition< ScannerT >::custom_comparison |
Definition at line 500 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::operators_num |
Definition at line 501 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::operators_string |
Definition at line 502 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::par_real |
Definition at line 503 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::par_int |
Definition at line 503 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::par_string |
Definition at line 503 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::value_real |
Definition at line 504 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::value_int |
Definition at line 504 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::value_string |
Definition at line 504 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::basic_lefthand_comparison |
Definition at line 505 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::basic_righthand_comparison |
Definition at line 505 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::comparison |
Definition at line 506 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::term |
Definition at line 506 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::selection |
Definition at line 506 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::expression |
Definition at line 506 of file CreateRules.cc.
rule<ScannerT> ruleparser::definition< ScannerT >::my_grammar |
Definition at line 507 of file CreateRules.cc.