Kea 2.7.5
netconf/parser_context.h
Go to the documentation of this file.
1// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef NETCONF_PARSER_CONTEXT_H
8#define NETCONF_PARSER_CONTEXT_H
9#include <string>
10#include <map>
11#include <vector>
16
17// Tell Flex the lexer's prototype ...
18#define YY_DECL isc::netconf::NetconfParser::symbol_type netconf_lex (ParserContext& driver)
19
20// ... and declare it for the parser's sake.
22
23namespace isc {
24namespace netconf {
25
38{
39public:
40
59
62
64 virtual ~ParserContext();
65
67 std::vector<isc::data::ElementPtr> stack_;
68
73 void scanStringBegin(const std::string& str, ParserType type);
74
80 void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
81
83 void scanEnd();
84
88 void includeFile(const std::string& filename);
89
100 isc::data::ElementPtr parseString(const std::string& str,
101 ParserType parser_type);
102
114 isc::data::ElementPtr parseFile(const std::string& filename,
115 ParserType parser_type);
116
126 void error(const isc::netconf::location& loc,
127 const std::string& what,
128 size_t pos = 0);
129
137 void error(const std::string& what);
138
146 static void fatal(const std::string& what);
147
155 isc::data::Element::Position loc2pos(isc::netconf::location& loc);
156
166 void require(const std::string& name,
169
178 void unique(const std::string& name,
180
187 void warning(const isc::netconf::location& loc, const std::string& what);
188
194 void warnAboutExtraCommas(const isc::netconf::location& loc);
195
197 typedef enum {
200
202 CONFIG,
203
206
209
211 SERVER,
212
215
218
221
223 LOGGERS,
224
227
229
231 std::string file_;
232
234 std::vector<std::string> files_;
235
240 isc::netconf::location loc_;
241
243 std::vector<isc::netconf::location> locs_;
244
246 std::vector<struct yy_buffer_state*> states_;
247
249 FILE* sfile_;
250
256 std::vector<FILE*> sfiles_;
257
260
278 void enter(const LexerContext& ctx);
279
287 void leave();
288
292 const std::string contextName();
293
294 private:
296 bool trace_scanning_;
297
299 bool trace_parsing_;
300
302 std::vector<LexerContext> cstack_;
303
307 isc::data::ElementPtr parseCommon();
308}; // ParserContext
309
310} // namespace netconf
311} // namespace isc
312
313#endif
Parser context is a wrapper around flex/bison instances dedicated to Netconf-agent config file parser...
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
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.
std::vector< std::string > files_
File name stack.
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.
void includeFile(const std::string &filename)
Divert input to an include file.
std::vector< isc::netconf::location > locs_
Location stack.
static void fatal(const std::string &what)
Fatal error handler.
isc::netconf::location loc_
Location of the current token.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
ParserType
Defines currently supported scopes.
@ PARSER_NETCONF
This parser will expect the content as Netconf config wrapped in a map (that's the regular config fil...
@ PARSER_JSON
This parser will parse the content as generic JSON.
@ PARSER_SUB_NETCONF
This parser will expect only the content of Netconf.
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.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
void leave()
Leave a syntactic context.
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
void scanEnd()
Method called after the last tokens are scanned.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
Defines the logger used by the top-level component of kea-lfc.
#define YY_DECL
Forward declaration of the ParserContext class.
Define the isc::netconf::parser class.
Represents the position of the data element within a configuration string.
Definition data.h:94