-/* Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+/* Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
}
}
-\"Logging\" {
- switch(driver.ctx_) {
- case ParserContext::CONFIG:
- return AgentParser::make_LOGGING(driver.loc_);
- default:
- return AgentParser::make_STRING("Logging", driver.loc_);
- }
-}
-
\"loggers\" {
switch(driver.ctx_) {
case ParserContext::AGENT:
- case ParserContext::LOGGING:
return AgentParser::make_LOGGERS(driver.loc_);
default:
return AgentParser::make_STRING("loggers", driver.loc_);
}
}
-\"Dhcp4\" {
- switch(driver.ctx_) {
- case ParserContext::CONFIG:
- return AgentParser::make_DHCP4(driver.loc_);
- default:
- return AgentParser::make_STRING("Dhcp4", driver.loc_);
- }
-}
-
-\"Dhcp6\" {
- switch(driver.ctx_) {
- case ParserContext::CONFIG:
- return AgentParser::make_DHCP6(driver.loc_);
- default:
- return AgentParser::make_STRING("Dhcp6", driver.loc_);
- }
-}
-
-\"DhcpDdns\" {
- switch(driver.ctx_) {
- case ParserContext::CONFIG:
- return AgentParser::make_DHCPDDNS(driver.loc_);
- default:
- return AgentParser::make_STRING("DhcpDdns", driver.loc_);
- }
-}
-
{JSONString} {
/* A string has been matched. It contains the actual string and single quotes.
We need to get those quotes out of the way and just use its content, e.g.
-/* Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+/* Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
LIBRARY "library"
PARAMETERS "parameters"
- LOGGING "Logging"
LOGGERS "loggers"
NAME "name"
OUTPUT_OPTIONS "output_options"
MAXVER "maxver"
PATTERN "pattern"
- DHCP4 "Dhcp4"
- DHCP6 "Dhcp6"
- DHCPDDNS "DhcpDdns"
-
// Not real tokens, just a way to signal what the parser is expected to
// parse. This define the starting point. It either can be full grammar
// (START_AGENT), part of the grammar related to control-agent (START_SUB_AGENT)
%%
// The whole grammar starts with a map, because the config file
-// consists of Control-Agent, DhcpX, Logger and DhcpDdns entries in one big { }.
+// consists of only Control-Agent entry in one big { }.
%start start;
// The starting token can be one of those listed below. Note these are
"got unexpected keyword \"" + keyword + "\" in " + where + " map.");
};
-// This defines the top-level { } that holds Control-agent, Dhcp6, Dhcp4,
-// DhcpDdns or Logging objects.
+// This defines the top-level { } that holds only Control-agent object.
agent_syntax_map: LCURLY_BRACKET {
// This code is executed when we're about to start parsing
// the content of the map
// for it.
};
-// This represents top-level entries: Control-agent, Logging, possibly others
+// This represents top-level entries: Control-agent.
global_objects: global_object
- | global_objects COMMA global_object
;
-// This represents a single top level entry, e.g. Control-agent, Dhcp6 or DhcpDdns.
+// This represents a single top level entry, e.g. Control-agent.
global_object: agent_object
- | logging_object
- | dhcp4_json_object
- | dhcp6_json_object
- | dhcpddns_json_object
- | unknown_map_entry
;
// This define the Control-agent object.
// --- control-sockets end here ------------------------------------------------
-// JSON entries for other global objects (Dhcp4,Dhcp6 and DhcpDdns)
-dhcp4_json_object: DHCP4 {
- ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
- ctx.stack_.back()->set("Dhcp4", $4);
- ctx.leave();
-};
-
-dhcp6_json_object: DHCP6 {
- ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
- ctx.stack_.back()->set("Dhcp6", $4);
- ctx.leave();
-};
-
-dhcpddns_json_object: DHCPDDNS {
- ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
- ctx.stack_.back()->set("DhcpDdns", $4);
- ctx.leave();
-};
-
-// --- Logging starts here -----------------------------------------------------
-
-// This defines the top level "Logging" object. It parses
-// the following "Logging": { ... }. The ... is defined
-// by logging_params
-logging_object: LOGGING {
- ElementPtr m(new MapElement(ctx.loc2pos(@1)));
- ctx.stack_.back()->set("Logging", m);
- ctx.stack_.push_back(m);
- ctx.enter(ctx.LOGGING);
-} COLON LCURLY_BRACKET logging_params RCURLY_BRACKET {
- ctx.stack_.pop_back();
- ctx.leave();
-};
-
-// This defines the list of allowed parameters that may appear
-// in the top-level Logging object. It can either be a single
-// parameter or several parameters separated by commas.
-logging_params: logging_param
- | logging_params COMMA logging_param
- ;
-
-// There's currently only one parameter defined, which is "loggers".
-logging_param: loggers;
+// --- Loggers starts here -----------------------------------------------------
-// "loggers", the only parameter currently defined in "Logging" object,
-// is "Loggers": [ ... ].
loggers: LOGGERS {
ElementPtr l(new ListElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("loggers", l);
| loggers_entries COMMA logger_entry
;
-// This defines a single entry defined in loggers in Logging.
+// This defines a single entry defined in loggers.
logger_entry: LCURLY_BRACKET {
ElementPtr l(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->add(l);
-// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
return ("toplevel");
case AGENT:
return ("Control-agent");
- case LOGGING:
- return ("Logging");
case CONTROL_SOCKETS:
return ("control-sockets");
case SERVER:
-// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
///< This one is used in pure JSON mode.
NO_KEYWORDS,
- ///< Used while parsing top level (that contains Control-agent, Logging and others)
+ ///< Used while parsing top level (that contains Control-agent)
CONFIG,
///< Used while parsing content of Agent.
AGENT,
- ///< Used while parsing content of Logging.
- LOGGING,
-
///< Used while parsing Control-agent/control-sockets.
CONTROL_SOCKETS,
-/* Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+/* Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
}
}
-
-\"Logging\" {
- switch(driver.ctx_) {
- case isc::d2::D2ParserContext::CONFIG:
- return isc::d2::D2Parser::make_LOGGING(driver.loc_);
- default:
- return isc::d2::D2Parser::make_STRING("Logging", driver.loc_);
- }
-}
-
\"loggers\" {
switch(driver.ctx_) {
case isc::d2::D2ParserContext::DHCPDDNS:
- case isc::d2::D2ParserContext::LOGGING:
return isc::d2::D2Parser::make_LOGGERS(driver.loc_);
default:
return isc::d2::D2Parser::make_STRING("loggers", driver.loc_);
}
}
-\"Dhcp4\" {
- switch(driver.ctx_) {
- case isc::d2::D2ParserContext::CONFIG:
- return isc::d2::D2Parser::make_DHCP4(driver.loc_);
- default:
- return isc::d2::D2Parser::make_STRING("Dhcp4", driver.loc_);
- }
-}
-
-\"Dhcp6\" {
- switch(driver.ctx_) {
- case isc::d2::D2ParserContext::CONFIG:
- return isc::d2::D2Parser::make_DHCP6(driver.loc_);
- default:
- return isc::d2::D2Parser::make_STRING("Dhcp6", driver.loc_);
- }
-}
-
-\"Control-agent\" {
- switch(driver.ctx_) {
- case isc::d2::D2ParserContext::CONFIG:
- return isc::d2::D2Parser::make_CONTROL_AGENT(driver.loc_);
- default:
- return isc::d2::D2Parser::make_STRING("Control-agent", driver.loc_);
- }
-}
-
-
{JSONString} {
/* A string has been matched. It contains the actual string and single quotes.
We need to get those quotes out of the way and just use its content, e.g.
-/* Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+/* Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
RCURLY_BRACKET "}"
NULL_TYPE "null"
- DHCP6 "Dhcp6"
- DHCP4 "Dhcp4"
- CONTROL_AGENT "Control-agent"
-
DHCPDDNS "DhcpDdns"
IP_ADDRESS "ip-address"
PORT "port"
SOCKET_TYPE "socket-type"
SOCKET_NAME "socket-name"
- LOGGING "Logging"
LOGGERS "loggers"
NAME "name"
OUTPUT_OPTIONS "output_options"
};
-// This defines the top-level { } that holds Control-agent, Dhcp6, Dhcp4,
-// DhcpDdns or Logging objects.
+// This defines the top-level { } that holds only DhcpDdns object.
syntax_map: LCURLY_BRACKET {
// This code is executed when we're about to start parsing
// the content of the map
// for it.
};
-// This represents top-level entries: Dhcp6, Dhcp4, DhcpDdns, Logging
+// This represents top-level entries: DhcpDdns.
global_objects: global_object
- | global_objects COMMA global_object
;
-// This represents a single top level entry, e.g. Dhcp6 or DhcpDdns.
-global_object: dhcp6_json_object
- | logging_object
- | dhcp4_json_object
- | dhcpddns_object
- | control_agent_json_object
- | unknown_map_entry
+// This represents a single top level entry, e.g. DhcpDdns.
+global_object: dhcpddns_object
;
// --- dhcp ddns ---------------------------------------------
ctx.leave();
};
-// ----------------------------------------------------------------
-
-dhcp6_json_object: DHCP6 {
- ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
- ctx.stack_.back()->set("Dhcp6", $4);
- ctx.leave();
-};
-
-dhcp4_json_object: DHCP4 {
- ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
- ctx.stack_.back()->set("Dhcp4", $4);
- ctx.leave();
-};
-
-control_agent_json_object: CONTROL_AGENT {
- ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
- ctx.stack_.back()->set("Control-agent", $4);
- ctx.leave();
-};
-
-// --- logging entry -----------------------------------------
-
-// This defines the top level "Logging" object. It parses
-// the following "Logging": { ... }. The ... is defined
-// by logging_params
-logging_object: LOGGING {
- ElementPtr m(new MapElement(ctx.loc2pos(@1)));
- ctx.stack_.back()->set("Logging", m);
- ctx.stack_.push_back(m);
- ctx.enter(ctx.LOGGING);
-} COLON LCURLY_BRACKET logging_params RCURLY_BRACKET {
- ctx.stack_.pop_back();
- ctx.leave();
-};
-
-// This defines the list of allowed parameters that may appear
-// in the top-level Logging object. It can either be a single
-// parameter or several parameters separated by commas.
-logging_params: logging_param
- | logging_params COMMA logging_param
- ;
-
-// There's currently only one parameter defined, which is "loggers".
-logging_param: loggers;
+// --- loggers entry -----------------------------------------
-// "loggers", the only parameter currently defined in "Logging" object,
// is "Loggers": [ ... ].
loggers: LOGGERS {
ElementPtr l(new ListElement(ctx.loc2pos(@1)));
| loggers_entries COMMA logger_entry
;
-// This defines a single entry defined in loggers in Logging.
+// This defines a single entry defined in loggers.
logger_entry: LCURLY_BRACKET {
ElementPtr l(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->add(l);
-// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
return("dns-servers");
case CONTROL_SOCKET:
return("control-socket");
- case LOGGING:
- return ("Logging");
case LOGGERS:
return ("loggers");
case OUTPUT_OPTIONS:
-// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// This parser will parse the content as generic JSON.
PARSER_JSON,
- ///< Used for parsing top level (contains DhcpDdns, Logging, others)
+ ///< Used for parsing top level (contains DhcpDdns)
PARSER_DHCPDDNS,
///< Used for parsing content of DhcpDdns.
///< This one is used in pure JSON mode.
NO_KEYWORD,
- ///< Used while parsing top level (contains DhcpDdns, Logging, ...)
+ ///< Used while parsing top level (contains DhcpDdns).
CONFIG,
///< Used while parsing content of DhcpDdns.
///< Used while parsing content of a control-socket
CONTROL_SOCKET,
- ///< Used while parsing content of Logging
- LOGGING,
-
/// Used while parsing DhcpDdns/loggers structures.
LOGGERS,
-/* Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+/* Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
}
}
-\"Logging\" {
- switch(driver.ctx_) {
- case ParserContext::CONFIG:
- return NetconfParser::make_LOGGING(driver.loc_);
- default:
- return NetconfParser::make_STRING("Logging", driver.loc_);
- }
-}
-
\"loggers\" {
switch(driver.ctx_) {
case ParserContext::NETCONF:
- case ParserContext::LOGGING:
return NetconfParser::make_LOGGERS(driver.loc_);
default:
return NetconfParser::make_STRING("loggers", driver.loc_);
-/* Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+/* Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
LIBRARY "library"
PARAMETERS "parameters"
- LOGGING "Logging"
LOGGERS "loggers"
NAME "name"
OUTPUT_OPTIONS "output_options"
"got unexpected keyword \"" + keyword + "\" in " + where + " map.");
};
-// This defines the top-level { } that holds Netconf or Logging objects.
+// This defines the top-level { } that holds Netconf object.
netconf_syntax_map: LCURLY_BRACKET {
// This code is executed when we're about to start parsing
// the content of the map
// for it.
};
-// This represents top-level entries: Netconf, Logging, possibly others
+// This represents top-level entries: Netconf.
global_objects: global_object
| global_objects COMMA global_object
;
-// This represents a single top level entry, e.g. Netconf or Logging.
+// This represents a single top level entry, e.g. Netconf.
global_object: netconf_object
- | logging_object
;
// This define the Netconf object.
// top level map (that's already on the stack) and put the new map
// on the stack as well, so child elements will be able to add
// themselves to it.
+
+ // Prevent against duplicate.
+ ctx.unique("Netconf, ctx.loc2pos(@1));
ElementPtr m(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("Netconf", m);
ctx.stack_.push_back(m);
// --- managed-servers end here ------------------------------------------------
-// --- Logging starts here -----------------------------------------------------
-
-// This defines the top level "Logging" object. It parses
-// the following "Logging": { ... }. The ... is defined
-// by logging_params
-logging_object: LOGGING {
- ElementPtr m(new MapElement(ctx.loc2pos(@1)));
- ctx.stack_.back()->set("Logging", m);
- ctx.stack_.push_back(m);
- ctx.enter(ctx.LOGGING);
-} COLON LCURLY_BRACKET logging_params RCURLY_BRACKET {
- ctx.stack_.pop_back();
- ctx.leave();
-};
-
-// This defines the list of allowed parameters that may appear
-// in the top-level Logging object. It can either be a single
-// parameter or several parameters separated by commas.
-logging_params: logging_param
- | logging_params COMMA logging_param
- ;
-
-// There's currently only one parameter defined, which is "loggers".
-logging_param: loggers;
+// --- Loggers starts here -----------------------------------------------------
-// "loggers", the only parameter currently defined in "Logging" object,
-// is "Loggers": [ ... ].
loggers: LOGGERS {
ElementPtr l(new ListElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("loggers", l);
| loggers_entries COMMA logger_entry
;
-// This defines a single entry defined in loggers in Logging.
+// This defines a single entry defined in loggers.
logger_entry: LCURLY_BRACKET {
ElementPtr l(new MapElement(ctx.loc2pos(@1)));
ctx.stack_.back()->add(l);
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
}
}
+void
+ParserContext::unique(const std::string& name,
+ isc::data::Element::Position loc)
+{
+ ConstElementPtr value = stack_.back()->get(name);
+ if (value) {
+ isc_throw(ParseError, loc << ": duplicate " << name
+ << " entries in " << contextName()
+ << " map (previous at " << value->getPosition() << ")");
+ }
+}
+
void
ParserContext::enter(const LexerContext& ctx)
{
return ("toplevel");
case NETCONF:
return ("Netconf");
- case LOGGING:
- return ("Logging");
case MANAGED_SERVERS:
return ("managed-servers");
case SERVER:
-// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
isc::data::Element::Position open_loc,
isc::data::Element::Position close_loc);
+ /// @brief Check if a parameter is already present
+ ///
+ /// Check if a parameter is already present in the map at the top
+ /// of the stack and raise an error when it is.
+ ///
+ /// @param name name of the parameter to check
+ /// @param loc location of the current parameter
+ /// @throw ParseError
+ void unique(const std::string& name,
+ isc::data::Element::Position loc);
+
/// @brief Defines syntactic contexts for lexical tie-ins
typedef enum {
///< This one is used in pure JSON mode.
NO_KEYWORDS,
- ///< Used while parsing top level (that contains Netconf, Logging and others)
+ ///< Used while parsing top level (that contains Netconf)
CONFIG,
///< Used while parsing content of Netconf.
NETCONF,
- ///< Used while parsing content of Logging.
- LOGGING,
-
/// Used while parsing Netconf/managed-servers.
MANAGED_SERVERS,