From ba679187064b4dc9d80194c19e4c75a118c0d060 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Mon, 21 Nov 2022 12:18:11 +0100 Subject: [PATCH] Test properties in DDDigi --- DDCore/include/DD4hep/GrammarParsed.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/DDCore/include/DD4hep/GrammarParsed.h b/DDCore/include/DD4hep/GrammarParsed.h index 553ef2265..d348bf60e 100644 --- a/DDCore/include/DD4hep/GrammarParsed.h +++ b/DDCore/include/DD4hep/GrammarParsed.h @@ -84,7 +84,8 @@ namespace dd4hep { } /// Item evaluator - template <typename T> inline int eval_item(T* ptr, std::string val) { + template <typename T> inline int eval_item(T* ptr, const std::string& val) { + /// First try to parse the value with spirit. try { T temp; int sc = ::dd4hep::Parsers::parse(temp,val); @@ -95,16 +96,18 @@ namespace dd4hep { } catch (...) { } + /// If this failed: try to evaluate it with the expression parser auto result = grammar_evaluate_item(val); - if (result.first != tools::Evaluator::OK) { - return 0; + if (result.first == tools::Evaluator::OK) { + *ptr = (T)result.second; + return 1; } - *ptr = (T)result.second; - return 1; + /// This also failed: Return error. + return 0; } - /// String evaluator - template <> inline int eval_item<std::string>(std::string* ptr, std::string val) { + /// String evaluator: Nothing to do! + template <> inline int eval_item<std::string>(std::string* ptr, const std::string& val) { *ptr = val; return 1; } @@ -280,18 +283,19 @@ namespace dd4hep { #define DD4HEP_DEFINE_PARSER_GRAMMAR_EVAL(xx,func) \ namespace dd4hep { namespace detail { \ - template<> int grammar_eval<xx>(const BasicGrammar&, void* _p, const std::string& _v) { return func ((xx*)_p,_v); }}} + template<> int grammar_eval<xx>(const BasicGrammar&, void* _p, const std::string& _v) {\ + return func ((xx*)_p,_v); \ + }}} #define DD4HEP_DEFINE_PARSER_GRAMMAR_INSTANCE(serial,xx) \ namespace dd4hep { \ template class Grammar< xx >; \ template BasicGrammar const& BasicGrammar::instance< xx >(); \ - template const GrammarRegistry& GrammarRegistry::pre_note<xx>(); \ template const GrammarRegistry& GrammarRegistry::pre_note<xx>(int); \ } \ namespace DD4HEP_PARSER_GRAMMAR_CNAME(serial,0) { \ - static auto s_reg = ::dd4hep::GrammarRegistry::pre_note< xx >(); \ + static auto s_reg = ::dd4hep::GrammarRegistry::pre_note< xx >(1); \ } #define DD4HEP_DEFINE_PARSER_GRAMMAR_SERIAL(serial,ctxt,xx,func) \ -- GitLab