From: Francis Dupont Date: Sun, 17 Dec 2017 15:39:28 +0000 (+0100) Subject: [5351] Fixed syntax X-Git-Tag: trac5480_base~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55c462ceee4299e8f5cdc34cee7f68c387faa3b4;p=thirdparty%2Fkea.git [5351] Fixed syntax --- diff --git a/src/bin/dhcp4/dhcp4_parser.cc b/src/bin/dhcp4/dhcp4_parser.cc index 2872929d84..c6d3d3cd44 100644 --- a/src/bin/dhcp4/dhcp4_parser.cc +++ b/src/bin/dhcp4/dhcp4_parser.cc @@ -2340,13 +2340,15 @@ namespace isc { namespace dhcp { #line 1381 "dhcp4_parser.yy" // lalr1.cc:859 { ElementPtr parent = ctx.stack_.back(); + ElementPtr s(new StringElement(yystack_[0].value.as< std::string > ())); ConstElementPtr old = parent->get("user-context"); if (old) { - old->set("comment", yystack_[0].value.as< std::string > ()); + ElementPtr mutable_old = boost::const_pointer_cast(old); + mutable_old->set("comment", s); } else { ElementPtr e(new MapElement(ctx.loc2pos(yystack_[3].location))); - e->set("comment", yystack_[0].value.as< std::string > ()); - top->set("user-context", e); + e->set("comment", s); + parent->set("user-context", e); } ctx.leave(); } diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index 2d05b23eec..3556dcb9f2 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -1363,13 +1363,17 @@ user_context: USER_CONTEXT { ElementPtr parent = ctx.stack_.back(); ElementPtr user_context = $4; ConstElementPtr old = parent->get("user-context"); + + // Handle already existing user context if (old) { + // Check if it was a comment or a duplicate if ((old->size() != 1) || !old->contains("comment")) { std::stringstream msg; msg << "duplicate user-context entries (previous at " << old->getPosition().str() << ")"; error(@1, msg.str()); } + // Merge the comment user_context->set("comment", old->get("comment")); } parent->set("user-context", user_context); @@ -1380,13 +1384,22 @@ comment: COMMENT { ctx.enter(ctx.NO_KEYWORD); } COLON STRING { ElementPtr parent = ctx.stack_.back(); + ElementPtr e(new MapElement(ctx.loc2pos(@1))); + ElementPtr s(new StringElement($4, ctx.loc2pos(@4))); + e->set("comment", s); + + // Handle already existing user context ConstElementPtr old = parent->get("user-context"); if (old) { - old->set("comment", $4); - } else { - ElementPtr e(new MapElement(ctx.loc2pos(@1))); - e->set("comment", $4); - top->set("user-context", e); + // Check for duplicate comment + if (old->contains("comment") { + std::stringstream msg; + msg << "duplicate user-context/comment entries (previous at " + << old->getPosition().str() << ")"; + error(@1, msg.str()); + } + // Merge the user context in the comment + merge(e, old); } ctx.leave(); }; diff --git a/src/bin/dhcp6/dhcp6_parser.cc b/src/bin/dhcp6/dhcp6_parser.cc index ae3bf2472c..87498397a2 100644 --- a/src/bin/dhcp6/dhcp6_parser.cc +++ b/src/bin/dhcp6/dhcp6_parser.cc @@ -2241,13 +2241,15 @@ namespace isc { namespace dhcp { #line 1344 "dhcp6_parser.yy" // lalr1.cc:859 { ElementPtr parent = ctx.stack_.back(); + ElementPtr s(new StringElement(yystack_[0].value.as< std::string > ())); ConstElementPtr old = parent->get("user-context"); if (old) { - old->set("comment", yystack_[0].value.as< std::string > ()); + ElementPtr mutable_old = boost::const_pointer_cast(old); + mutable_old->set("comment", s); } else { ElementPtr e(new MapElement(ctx.loc2pos(yystack_[3].location))); - e->set("comment", yystack_[0].value.as< std::string > ()); - top->set("user-context", e); + e->set("comment", s); + parent->set("user-context", e); } ctx.leave(); } diff --git a/src/bin/dhcp6/dhcp6_parser.yy b/src/bin/dhcp6/dhcp6_parser.yy index ca9f3f4dab..126dab4501 100644 --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@ -1326,13 +1326,17 @@ user_context: USER_CONTEXT { ElementPtr parent = ctx.stack_.back(); ElementPtr user_context = $4; ConstElementPtr old = parent->get("user-context"); + + // Handle already existing user context if (old) { + // Check if it was a comment or a duplicate if ((old->size() != 1) || !old->contains("comment")) { std::stringstream msg; msg << "duplicate user-context entries (previous at " << old->getPosition().str() << ")"; error(@1, msg.str()); } + // Merge the comment user_context->set("comment", old->get("comment")); } parent->set("user-context", user_context); @@ -1343,13 +1347,22 @@ comment: COMMENT { ctx.enter(ctx.NO_KEYWORD); } COLON STRING { ElementPtr parent = ctx.stack_.back(); + ElementPtr e(new MapElement(ctx.loc2pos(@1))); + ElementPtr s(new StringElement($4, ctx.loc2pos(@4))); + e->set("comment", s); + + // Handle already existing user context ConstElementPtr old = parent->get("user-context"); if (old) { - old->set("comment", $4); - } else { - ElementPtr e(new MapElement(ctx.loc2pos(@1))); - e->set("comment", $4); - top->set("user-context", e); + // Check for duplicate comment + if (old->contains("comment") { + std::stringstream msg; + msg << "duplicate user-context/comment entries (previous at " + << old->getPosition().str() << ")"; + error(@1, msg.str()); + } + // Merge the user context in the comment + merge(e, old); } ctx.leave(); };