From: Francis Dupont Date: Sun, 27 Nov 2016 18:55:05 +0000 (+0100) Subject: [5014_phase2] Add Dhcp4 and DhcpDdns toplevel configs to pass all tests X-Git-Tag: trac5036_base2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a55f3fafb240c178b5a72c5a6b08b7a0e97703bd;p=thirdparty%2Fkea.git [5014_phase2] Add Dhcp4 and DhcpDdns toplevel configs to pass all tests --- diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll index b93b988ef0..d8b04064ed 100644 --- a/src/bin/dhcp6/dhcp6_lexer.ll +++ b/src/bin/dhcp6/dhcp6_lexer.ll @@ -738,6 +738,23 @@ JSONString \"{JSONStringCharacter}*\" } } +\"Dhcp4\" { + switch(driver.ctx_) { + case isc::dhcp::Parser6Context::CONFIG: + return isc::dhcp::Dhcp6Parser::make_DHCP4(loc); + default: + return isc::dhcp::Dhcp6Parser::make_STRING("Dhcp4", loc); + } +} + +\"DhcpDdns\" { + switch(driver.ctx_) { + case isc::dhcp::Parser6Context::CONFIG: + return isc::dhcp::Dhcp6Parser::make_DHCPDDNS(loc); + default: + return isc::dhcp::Dhcp6Parser::make_STRING("DhcpDdns", loc); + } +} {JSONString} { // A string has been matched. It contains the actual string and single quotes. diff --git a/src/bin/dhcp6/dhcp6_parser.yy b/src/bin/dhcp6/dhcp6_parser.yy index 24567f7c40..b0d1d1e1ae 100644 --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@ -124,6 +124,9 @@ using namespace std; ENABLE_UPDATES "enable-updates" QUALIFYING_SUFFIX "qualifying-suffix" + DHCP4 "Dhcp4" + DHCPDDNS "DhcpDdns" + // Not real tokens, just a way to signal what the parser is expected to // parse. TOPLEVEL_GENERIC_JSON @@ -256,6 +259,9 @@ global_objects: global_object // This represents a single top level entry, e.g. Dhcp6 or DhcpDdns. global_object: dhcp6_object | logging_object + | dhcp4_object + | dhcpddns_object + | unknown_map_entry ; dhcp6_object: DHCP6 { @@ -1181,6 +1187,20 @@ qualifying_suffix: QUALIFYING_SUFFIX { ctx.leave(); }; +dhcp4_object: DHCP4 { + ctx.enter(ctx.NO_KEYWORD); +} COLON value { + ctx.stack_.back()->set("Dhcp4", $4); + ctx.leave(); +}; + +dhcpddns_object: DHCPDDNS { + ctx.enter(ctx.NO_KEYWORD); +} COLON value { + ctx.stack_.back()->set("DhcpDdns", $4); + ctx.leave(); +}; + %% void diff --git a/src/bin/dhcp6/parser_context.cc b/src/bin/dhcp6/parser_context.cc index 78aa4d8c0d..db5eec4dba 100644 --- a/src/bin/dhcp6/parser_context.cc +++ b/src/bin/dhcp6/parser_context.cc @@ -115,7 +115,7 @@ Parser6Context::context_name() case NO_KEYWORD: return ("__no keyword__"); case CONFIG: - return ("__config__"); + return ("toplevel"); case DHCP6: return ("Dhcp6"); case LOGGING: diff --git a/src/bin/dhcp6/tests/parser_unittest.cc b/src/bin/dhcp6/tests/parser_unittest.cc index 1315fac84e..a974237fde 100644 --- a/src/bin/dhcp6/tests/parser_unittest.cc +++ b/src/bin/dhcp6/tests/parser_unittest.cc @@ -409,21 +409,27 @@ TEST(ParserTest, errors) { "expecting }"); testError("{ 123 }\n", Parser6Context::PARSER_DHCP6, - ":1.3-5: syntax error, unexpected integer, " - "expecting Dhcp6 or Logging"); + ":1.3-5: syntax error, unexpected integer"); testError("{ \"foo\" }\n", Parser6Context::PARSER_GENERIC_JSON, ":1.9: syntax error, unexpected }, " "expecting :"); testError("{ \"foo\" }\n", Parser6Context::PARSER_DHCP6, - ":1.3-7: syntax error, unexpected constant string, " - "expecting Dhcp6 or Logging"); + ":1.9: syntax error, unexpected }, expecting :"); + testError("{ \"foo\":null }\n", + Parser6Context::PARSER_DHCP6, + ":1.3-7: got unexpected keyword " + "\"foo\" in toplevel map."); testError("{ \"Dhcp6\" }\n", Parser6Context::PARSER_DHCP6, ":1.11: syntax error, unexpected }, " "expecting :"); - testError("{}{}", + testError("{ \"Dhcp4\":[]\n", + Parser6Context::PARSER_DHCP6, + ":2.1: syntax error, unexpected end of file, " + "expecting \",\" or }"); + testError("{}{}\n", Parser6Context::PARSER_GENERIC_JSON, ":1.3: syntax error, unexpected {, " "expecting end of file");