23 : sfile_(0), ctx_(NO_KEYWORDS), trace_scanning_(false), trace_parsing_(false)
35 return (parseCommon());
40 FILE* f = fopen(filename.c_str(),
"r");
45 return (parseCommon());
49ParserContext::parseCommon() {
53 parser.set_debug_level(trace_parsing_);
55 int res = parser.parse();
67 isc_throw(ParseError,
"Expected exactly one terminal Element, found "
99 string const& file = *loc.begin.filename;
100 const uint32_t line = loc.begin.line;
101 const uint32_t pos = loc.begin.column;
113 "missing parameter '" << name <<
"' ("
114 <<
stack_.back()->getPosition() <<
") ["
116 << open_loc <<
" and " << close_loc <<
"]");
129 <<
" map (previous at " << value->getPosition() <<
")");
132 <<
" entries in JSON"
133 <<
" map (previous at " << value->getPosition() <<
")");
141 cstack_.push_back(
ctx_);
148 if (cstack_.empty()) {
149 fatal(
"unbalanced syntactic context");
151 ctx_ = cstack_.back();
160 return (
"__no keywords__");
166 return (
"managed-servers");
168 return (
"managed-servers entry");
170 return (
"control-socket");
172 return (
"socket-type");
174 return (
"hooks-libraries");
178 return (
"output-options");
180 return (
"__unknown__");
186 string const& what) {
188 msg << loc <<
": " << what;
195 warning(loc,
"Extraneous comma. A piece of configuration may have been omitted.");
Evaluation error exception raised when trying to parse.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
ParserContext()
Default constructor.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
virtual ~ParserContext()
destructor
const std::string contextName()
Get the syntactic context name.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
LexerContext ctx_
Current syntactic context.
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
void require(const std::string &name, isc::data::Element::Position open_loc, isc::data::Element::Position close_loc)
Check if a required parameter is present.
void warning(const isc::netconf::location &loc, const std::string &what)
Warning handler.
isc::data::Element::Position loc2pos(isc::netconf::location &loc)
Converts bison's position to one understandable by isc::data::Element.
void enter(const LexerContext &ctx)
Enter a new syntactic context.
LexerContext
Defines syntactic contexts for lexical tie-ins.
@ NO_KEYWORDS
This one is used in pure JSON mode.
@ HOOKS_LIBRARIES
Used while parsing Netconf/loggers structures.
@ CONFIG
Used while parsing content of Netconf.
@ MANAGED_SERVERS
Used while parsing Netconf/managed-servers.
@ SERVER
Used while parsing Netconf/manages-servers/*/control-socket.
@ LOGGERS
Used while parsing Netconf/loggers/output-options structures.
@ SOCKET_TYPE
Used while parsing Netconf/hooks-libraries.
@ CONTROL_SOCKET
Used while parsing Netconf/managed-servers/*/control-socket/socket-type.
static void fatal(const std::string &what)
Fatal error handler.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
ParserType
Defines currently supported scopes.
void warnAboutExtraCommas(const isc::netconf::location &loc)
Warning for extra commas.
void error(const isc::netconf::location &loc, const std::string &what, size_t pos=0)
Error handler.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
void leave()
Leave a syntactic context.
void scanEnd()
Method called after the last tokens are scanned.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
const isc::log::MessageID NETCONF_CONFIG_SYNTAX_WARNING
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Defines the logger used by the top-level component of kea-lfc.
Contains declarations for loggers used by the Kea netconf agent.
Define the isc::netconf::parser class.
Represents the position of the data element within a configuration string.