From 9adc63737a3921fde851a70010206179b7715e98 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 23 Mar 2014 22:41:37 +0100 Subject: [PATCH] Allow rterms as object names. Refs #5846 --- lib/config/config_parser.yy | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index b8258d5d9..c3e88d125 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -157,6 +157,7 @@ using namespace icinga; %type object_inherits_list %type object_inherits_specifier %type rterm +%type rterm_scope %type lterm %type variable_decl %left T_LOGICAL_OR @@ -410,35 +411,38 @@ object: { m_Abstract = false; } - object_declaration identifier T_STRING object_inherits_specifier rterm + object_declaration identifier rterm object_inherits_specifier rterm_scope { DebugInfo di = DebugInfoRange(@2, @6); ConfigItemBuilder::Ptr item = make_shared(di); - ConfigItem::Ptr oldItem = ConfigItem::GetObject($3, $4); + AExpression::Ptr aexpr = static_cast(*$4); + delete $4; + + String name = aexpr->Evaluate(m_ModuleScope); + + ConfigItem::Ptr oldItem = ConfigItem::GetObject($3, name); if (oldItem) { std::ostringstream msgbuf; - msgbuf << "Object '" << $4 << "' of type '" << $3 << "' re-defined: " << di << "; previous definition: " << oldItem->GetDebugInfo(); + msgbuf << "Object '" << name << "' of type '" << $3 << "' re-defined: " << di << "; previous definition: " << oldItem->GetDebugInfo(); free($3); - free($4); delete $5; BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(di)); } item->SetType($3); - if (strchr($4, '!') != NULL) { + if (name.FindFirstOf("!") != String::NPos) { std::ostringstream msgbuf; - msgbuf << "Name for object '" << $4 << "' of type '" << $3 << "' is invalid: Object names may not contain '!'"; + msgbuf << "Name for object '" << name << "' of type '" << $3 << "' is invalid: Object names may not contain '!'"; free($3); BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(@4)); } free($3); - item->SetName($4); - free($4); + item->SetName(name); if ($5) { BOOST_FOREACH(const String& parent, *$5) { @@ -633,6 +637,12 @@ rbinary_op: '+' } ; +rterm_scope: '{' lterm_items '}' + { + $$ = new Value(make_shared(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @3))); + } + ; + rterm: T_STRING { $$ = new Value(make_shared(&AExpression::OpLiteral, $1, @1)); @@ -677,9 +687,9 @@ rterm: T_STRING { $$ = new Value(make_shared(&AExpression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @3))); } - | '{' lterm_items '}' + | rterm_scope { - $$ = new Value(make_shared(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @3))); + $$ = $1; } | '(' rterm ')' {