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 "
74 const std::string& what,
99 const std::string& 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__");
164 return (
"Control-agent");
166 return (
"authentication");
168 return (
"auth-type");
172 return (
"control-sockets");
174 return (
"xxx-server");
176 return (
"socket-type");
178 return (
"hooks-libraries");
182 return (
"output-options");
184 return (
"__unknown__");
190 const std::string& what) {
191 std::ostringstream msg;
192 msg << loc <<
": " << what;
199 warning(loc,
"Extraneous comma. A piece of configuration may have been omitted.");
Define the isc::agent::parser class.
Evaluation error exception raised when trying to parse.
void warning(const isc::agent::location &loc, const std::string &what)
Warning handler.
void warnAboutExtraCommas(const isc::agent::location &loc)
Warning for extra commas.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
ParserContext()
Default constructor.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
static void fatal(const std::string &what)
Fatal error handler.
virtual ~ParserContext()
destructor
const std::string contextName()
Get the syntactic context name.
isc::data::Element::Position loc2pos(isc::agent::location &loc)
Converts bison's position to one understandable by isc::data::Element.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
LexerContext ctx_
Current syntactic context.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
void leave()
Leave a syntactic context.
LexerContext
Defines syntactic contexts for lexical tie-ins.
@ CONFIG
Used while parsing content of Agent.
@ SERVER
Used while parsing Control-agent/control-socket/*-server/socket-type.
@ NO_KEYWORDS
This one is used in pure JSON mode.
@ HOOKS_LIBRARIES
Used while parsing Control-agent/loggers structures.
@ CONTROL_SOCKETS
Used while parsing Control-agent/control-socket/*-server.
@ SOCKET_TYPE
Used while parsing Control-agent/hooks-libraries.
@ AGENT
Used while parsing Control-agent/Authentication.
@ CLIENTS
Used while parsing Control-agent/control-sockets.
@ AUTHENTICATION
Used while parsing Control-agent/Authentication/type.
@ AUTH_TYPE
Used while parsing Control-agent/Authentication/clients.
@ LOGGERS
Used while parsing Control-agent/loggers/output-options structures.
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 error(const isc::agent::location &loc, const std::string &what, size_t pos=0)
Error handler.
ParserType
Defines currently supported scopes.
void enter(const LexerContext &ctx)
Enter a new 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.
const isc::log::MessageID CTRL_AGENT_CONFIG_SYNTAX_WARNING
isc::log::Logger agent_logger("ctrl-agent")
Control Agent logger.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.