From ee99f19d28769b528ff9997cc253cfc7c96a3855 Mon Sep 17 00:00:00 2001 From: gscalamera <graziano.scalamera@elettra.eu> Date: Thu, 23 Feb 2017 14:56:14 +0100 Subject: [PATCH] Addes support for attr_name.quality syntax --- src/Alarm.cpp | 32 +++++++++++++++++++------------- src/formula_grammar.h | 16 +++++++++++----- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Alarm.cpp b/src/Alarm.cpp index 7f3aa79..5389647 100644 --- a/src/Alarm.cpp +++ b/src/Alarm.cpp @@ -3257,11 +3257,22 @@ formula_res_t Alarm::eval_expression(iter_t const& i, string &attr_values, int e formula_res_t res; res = eval_expression(i->children.begin(), attr_values); if (*i->value.begin() == '+') + { res.value = + res.value; - if (*i->value.begin() == '-') + } + else if (*i->value.begin() == '-') + { res.value = - res.value; - if (*i->value.begin() == '!') + } + else if (*i->value.begin() == '!') + { res.value = ! res.value; + } + else + { + err << "in node unary_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends; + throw err.str(); + } return res; } else if (i->value.id() == formula_grammar::mult_exprID) @@ -3323,6 +3334,12 @@ formula_res_t Alarm::eval_expression(iter_t const& i, string &attr_values, int e } if((i->children.begin()+1)->value.id() == formula_grammar::indexID) ind = eval_expression(i->children.begin()+1, attr_values); //array index + else if(string((i->children.begin()+1)->value.begin(), (i->children.begin()+1)->value.end()) == ".quality") + { + formula_res_t res = eval_expression(i->children.begin(), attr_values, (int)ind.value); + res.value = res.quality; + return res; + } else { err << "in node event_ID(" << string(i->value.begin(), i->value.end()) << ") children2 is not an index ->" << string((i->children.begin()+1)->value.begin(), (i->children.begin()+1)->value.end()) << ends;; @@ -3665,17 +3682,6 @@ formula_res_t Alarm::eval_expression(iter_t const& i, string &attr_values, int e } else if (string(i->value.begin(), i->value.end()) == string("quality")) { - if(i->children.size() != 1) - { - err << "in node funcID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends; - throw err.str(); - } - if(i->children.begin()->value.id() != formula_grammar::nameID) - { - string name_id(i->children.begin()->value.begin(), i->children.begin()->value.end()); - err << "in node funcID(" << string(i->value.begin(), i->value.end()) << ") children is not an attribute name but " << name_id << ends; - throw err.str(); - } res.value = res.quality; return res; } diff --git a/src/formula_grammar.h b/src/formula_grammar.h index 5b0c94c..dd52a53 100644 --- a/src/formula_grammar.h +++ b/src/formula_grammar.h @@ -168,6 +168,9 @@ struct formula_grammar : public grammar<formula_grammar> symbol = (alnum_p | '.' | '_' | '-' | '+') //any alpha numeric char plus '.', '_', '-' ; + symbol_attr + = (alnum_p | '_' ) //any alpha numeric char plus '_' for attribute names + ; //------------------------------ALARM NAME-------------------------------------- name #if BOOST_VERSION < 103600 @@ -178,7 +181,7 @@ struct formula_grammar : public grammar<formula_grammar> lexeme_d[ //needed to ignore "space_p" (skip white spaces) evaluating name !("tango://" >> (+symbol) >> ':' >> uint_p >> "/") //eventually match FQDN >> (+symbol) >> '/' >> (+symbol) - >> '/' >> (+symbol) >> '/' >> (+symbol) + >> '/' >> (+symbol) >> '/' >> (+symbol_attr) ] ] // = repeat_p(3)[(+symbol) >> ch_p('/')] >> (+symbol) @@ -228,7 +231,9 @@ struct formula_grammar : public grammar<formula_grammar> event_ = name - >> !(index) + >> !( (index) + | (".quality") + ) ; /*top = ternary_if; @@ -307,7 +312,7 @@ struct formula_grammar : public grammar<formula_grammar> = ( root_node_d[str_p("abs")] >> (inner_node_d[ch_p('(') >> cond_expr >> ')']) //TODO: ? not expr_atom ? | root_node_d[str_p("cos")] >> (inner_node_d[ch_p('(') >> cond_expr >> ')']) //TODO: ? not expr_atom ? | root_node_d[str_p("sin")] >> (inner_node_d[ch_p('(') >> cond_expr >> ')']) //TODO: ? not expr_atom ? - | root_node_d[str_p("quality")] >> (inner_node_d[ch_p('(') >> name >> ')']) //TODO: ? not expr_atom ? + | root_node_d[str_p("quality")] >> (inner_node_d[ch_p('(') >> cond_expr >> ')']) //TODO: ? not expr_atom ? ) ; function_dual @@ -335,15 +340,16 @@ struct formula_grammar : public grammar<formula_grammar> //| (inner_node_d[ch_p('(') >> non_empty_expression >> ')']) | (discard_node_d[ch_p('(')] >> non_empty_expression >> discard_node_d[ch_p(')')]) ; - logical_expr_paren + /*logical_expr_paren = (discard_node_d[ch_p('(')] >> logical_expr >> discard_node_d[ch_p(')')]) | logical_expr - ; + ;*/ } rule<ScannerT> top; //rule<ScannerT> symbol; rule<typename lexeme_scanner<ScannerT>::type> symbol; //needed to use lexeme_d in rule name + rule<typename lexeme_scanner<ScannerT>::type> symbol_attr; //needed to use lexeme_d in rule name rule<ScannerT, parser_context<>, parser_tag<val_rID> > val_r; rule<ScannerT, parser_context<>, parser_tag<val_hID> > val_h; rule<ScannerT, parser_context<>, parser_tag<val_stID> > val_st; -- GitLab