diff options
author | Francis Dupont <fdupont@isc.org> | 2019-10-07 18:37:50 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomek@isc.org> | 2019-11-25 18:23:32 +0100 |
commit | df8e28ba89b087049c20eba74df82fd0159d3275 (patch) | |
tree | c6894cf30e626d78ebb8c3e05aa3dd3a1abd4e45 | |
parent | [#850] Addressed last comment (diff) | |
download | kea-df8e28ba89b087049c20eba74df82fd0159d3275.tar.xz kea-df8e28ba89b087049c20eba74df82fd0159d3275.zip |
[274-possible-improvements-to-dhcp-queue-control-member-parsing] Updated syntax
-rw-r--r-- | src/bin/dhcp4/dhcp4_lexer.ll | 18 | ||||
-rw-r--r-- | src/bin/dhcp4/dhcp4_parser.yy | 56 | ||||
-rw-r--r-- | src/bin/dhcp6/dhcp6_lexer.ll | 20 | ||||
-rw-r--r-- | src/bin/dhcp6/dhcp6_parser.yy | 60 |
4 files changed, 97 insertions, 57 deletions
diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll index 6bca3819a9..c1d1cc89a8 100644 --- a/src/bin/dhcp4/dhcp4_lexer.ll +++ b/src/bin/dhcp4/dhcp4_lexer.ll @@ -1425,6 +1425,24 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} } } +\"enable-queue\" { + switch(driver.ctx_) { + case isc::dhcp::Parser4Context::DHCP_QUEUE_CONTROL: + return isc::dhcp::Dhcp4Parser::make_ENABLE_QUEUE(driver.loc_); + default: + return isc::dhcp::Dhcp4Parser::make_STRING("enable-queue", driver.loc_); + } +} + +\"queue-type\" { + switch(driver.ctx_) { + case isc::dhcp::Parser4Context::DHCP_QUEUE_CONTROL: + return isc::dhcp::Dhcp4Parser::make_QUEUE_TYPE(driver.loc_); + default: + return isc::dhcp::Dhcp4Parser::make_STRING("queue-type", driver.loc_); + } +} + \"dhcp-ddns\" { switch(driver.ctx_) { case isc::dhcp::Parser4Context::DHCP4: diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index 1a243d14d1..54c4307d45 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -189,6 +189,8 @@ using namespace std; SOCKET_NAME "socket-name" DHCP_QUEUE_CONTROL "dhcp-queue-control" + ENABLE_QUEUE "enable-queue" + QUEUE_TYPE "queue-type" DHCP_DDNS "dhcp-ddns" ENABLE_UPDATES "enable-updates" @@ -2019,38 +2021,38 @@ control_socket_name: SOCKET_NAME { // --- dhcp-queue-control --------------------------------------------- dhcp_queue_control: DHCP_QUEUE_CONTROL { - ctx.enter(ctx.NO_KEYWORD); -} COLON map_value { - ElementPtr qc = $4; + ElementPtr qc(new MapElement(ctx.loc2pos(@1))); ctx.stack_.back()->set("dhcp-queue-control", qc); + ctx.stack_.push_back(qc); + ctx.enter(ctx.DHCP_QUEUE_CONTROL); +} COLON LCURLY_BRACKET queue_control_params RCURLY_BRACKET { + // The enable queue parameter is required. + ctx.require("enable-queue", ctx.loc2pos(@4), ctx.loc2pos(@6)); + ctx.stack_.pop_back(); + ctx.leave(); +}; - // Doing this manually, because dhcp-queue-control - // content is otherwise arbitrary - if (!qc->contains("enable-queue")) { - std::stringstream msg; - msg << "'enable-queue' is required: "; - msg << "(" << qc->getPosition().str() << ")"; - error(@1, msg.str()); - } +queue_control_params: queue_control_param + | queue_control_params COMMA queue_control_param + ; - ConstElementPtr enable_queue = qc->get("enable-queue"); - if (enable_queue->getType() != Element::boolean) { - std::stringstream msg; - msg << "'enable-queue' must be boolean: "; - msg << "(" << qc->getPosition().str() << ")"; - error(@1, msg.str()); - } +queue_control_param: enable_queue + | queue_type + | user_context + | comment + | unknown_map_entry + ; - if (qc->contains("queue-type")) { - ConstElementPtr queue_type = qc->get("queue-type"); - if (queue_type->getType() != Element::string) { - std::stringstream msg; - msg << "'queue-type' must be a string: "; - msg << "(" << qc->getPosition().str() << ")"; - error(@1, msg.str()); - } - } +enable_queue: ENABLE_QUEUE COLON BOOLEAN { + ElementPtr b(new BoolElement($3, ctx.loc2pos(@3))); + ctx.stack_.back()->set("enable-queue", b); +}; +queue_type: QUEUE_TYPE { + ctx.enter(ctx.NO_KEYWORD); +} COLON STRING { + ElementPtr qt(new StringElement($4, ctx.loc2pos(@4))); + ctx.stack_.back()->set("queue-type", qt); ctx.leave(); }; diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll index 5b474efd25..95ac15de42 100644 --- a/src/bin/dhcp6/dhcp6_lexer.ll +++ b/src/bin/dhcp6/dhcp6_lexer.ll @@ -1125,6 +1125,7 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} case isc::dhcp::Parser6Context::POOLS: case isc::dhcp::Parser6Context::PD_POOLS: case isc::dhcp::Parser6Context::RESERVATIONS: + case isc::dhcp::Parser6Context::DHCP_QUEUE_CONTROL: case isc::dhcp::Parser6Context::LOGGERS: case isc::dhcp::Parser6Context::DHCP_DDNS: return isc::dhcp::Dhcp6Parser::make_USER_CONTEXT(driver.loc_); @@ -1146,6 +1147,7 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} case isc::dhcp::Parser6Context::CONTROL_SOCKET: case isc::dhcp::Parser6Context::POOLS: case isc::dhcp::Parser6Context::PD_POOLS: + case isc::dhcp::Parser6Context::DHCP_QUEUE_CONTROL: case isc::dhcp::Parser6Context::RESERVATIONS: case isc::dhcp::Parser6Context::LOGGERS: case isc::dhcp::Parser6Context::DHCP_DDNS: @@ -1815,6 +1817,24 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} } } +\"enable-queue\" { + switch(driver.ctx_) { + case isc::dhcp::Parser6Context::DHCP_QUEUE_CONTROL: + return isc::dhcp::Dhcp6Parser::make_ENABLE_QUEUE(driver.loc_); + default: + return isc::dhcp::Dhcp6Parser::make_STRING("enable-queue", driver.loc_); + } +} + +\"queue-type\" { + switch(driver.ctx_) { + case isc::dhcp::Parser6Context::DHCP_QUEUE_CONTROL: + return isc::dhcp::Dhcp6Parser::make_QUEUE_TYPE(driver.loc_); + default: + return isc::dhcp::Dhcp6Parser::make_STRING("queue-type", driver.loc_); + } +} + \"dhcp-ddns\" { switch(driver.ctx_) { case isc::dhcp::Parser6Context::DHCP6: diff --git a/src/bin/dhcp6/dhcp6_parser.yy b/src/bin/dhcp6/dhcp6_parser.yy index fc363c2a5a..bff7b75e2a 100644 --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@ -193,6 +193,8 @@ using namespace std; SOCKET_NAME "socket-name" DHCP_QUEUE_CONTROL "dhcp-queue-control" + ENABLE_QUEUE "enable-queue" + QUEUE_TYPE "queue-type" DHCP_DDNS "dhcp-ddns" ENABLE_UPDATES "enable-updates" @@ -2135,40 +2137,38 @@ socket_name: SOCKET_NAME { // --- dhcp-queue-control --------------------------------------------- dhcp_queue_control: DHCP_QUEUE_CONTROL { - ctx.enter(ctx.NO_KEYWORD); -} COLON map_value { - ElementPtr qc = $4; + ElementPtr qc(new MapElement(ctx.loc2pos(@1))); ctx.stack_.back()->set("dhcp-queue-control", qc); + ctx.stack_.push_back(qc); + ctx.enter(ctx.DHCP_QUEUE_CONTROL); +} COLON LCURLY_BRACKET queue_control_params RCURLY_BRACKET { + // The enable queue parameter is required. + ctx.require("enable-queue", ctx.loc2pos(@4), ctx.loc2pos(@6)); + ctx.stack_.pop_back(); + ctx.leave(); +}; - // Doing this manually, because dhcp-queue-control - // content is otherwise arbitrary - if (!qc->contains("enable-queue")) { - std::stringstream msg; - msg << "'enable-queue' is required: "; - msg << "(" << qc->getPosition().str() << ")"; - error(@1, msg.str()); - } +queue_control_params: queue_control_param + | queue_control_params COMMA queue_control_param + ; - // queue-enable is mandatory - ConstElementPtr enable_queue = qc->get("enable-queue"); - if (enable_queue->getType() != Element::boolean) { - std::stringstream msg; - msg << "'enable-queue' must be boolean: "; - msg << "(" << qc->getPosition().str() << ")"; - error(@1, msg.str()); - } - - // if queue-type is supplied make sure it's a string - if (qc->contains("queue-type")) { - ConstElementPtr queue_type = qc->get("queue-type"); - if (queue_type->getType() != Element::string) { - std::stringstream msg; - msg << "'queue-type' must be a string: "; - msg << "(" << qc->getPosition().str() << ")"; - error(@1, msg.str()); - } - } +queue_control_param: enable_queue + | queue_type + | user_context + | comment + | unknown_map_entry + ; + +enable_queue: ENABLE_QUEUE COLON BOOLEAN { + ElementPtr b(new BoolElement($3, ctx.loc2pos(@3))); + ctx.stack_.back()->set("enable-queue", b); +}; +queue_type: QUEUE_TYPE { + ctx.enter(ctx.NO_KEYWORD); +} COLON STRING { + ElementPtr qt(new StringElement($4, ctx.loc2pos(@4))); + ctx.stack_.back()->set("queue-type", qt); ctx.leave(); }; |