| Kea 3.0.2-git

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>
12#include <netconf/netconf_parser.h>
13#include <netconf/parser_context_decl.h>
14#include <cc/dhcp_config_error.h>
15#include <exceptions/exceptions.h>
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.
21 YY_DECL;
22
23 namespace isc {
24 namespace netconf {
25
37 class ParserContext
38{
39 public:
40
48 typedef enum {
50 PARSER_JSON,
51
54 PARSER_NETCONF,
55
57 PARSER_SUB_NETCONF
58 } ParserType;
59
61 ParserContext();
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,
167 isc::data::Element::Position open_loc,
168 isc::data::Element::Position close_loc);
169
178 void unique(const std::string& name,
179 isc::data::Element::Position loc);
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 {
199 NO_KEYWORDS,
200
202 CONFIG,
203
205 NETCONF,
206
208 MANAGED_SERVERS,
209
211 SERVER,
212
214 CONTROL_SOCKET,
215
217 SOCKET_TYPE,
218
220 HOOKS_LIBRARIES,
221
223 LOGGERS,
224
226 OUTPUT_OPTIONS
227
228 } LexerContext;
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
259 LexerContext ctx_;
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
YY_DECL
#define YY_DECL
Definition agent/parser_context.h:17
isc::netconf::ParserContext::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition netconf/parser_context.cc:39
isc::netconf::ParserContext::ParserContext
ParserContext()
Default constructor.
Definition netconf/parser_context.cc:22
isc::netconf::ParserContext::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition netconf_lexer.cc:3881
isc::netconf::ParserContext::~ParserContext
virtual ~ParserContext()
destructor
Definition netconf/parser_context.cc:27
isc::netconf::ParserContext::contextName
const std::string contextName()
Get the syntactic context name.
Definition netconf/parser_context.cc:156
isc::netconf::ParserContext::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition netconf_lexer.cc:3899
isc::netconf::ParserContext::ctx_
LexerContext ctx_
Current syntactic context.
Definition netconf/parser_context.h:259
isc::netconf::ParserContext::files_
std::vector< std::string > files_
File name stack.
Definition netconf/parser_context.h:234
isc::netconf::ParserContext::unique
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
Definition netconf/parser_context.cc:121
isc::netconf::ParserContext::require
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.
Definition netconf/parser_context.cc:106
isc::netconf::ParserContext::warning
void warning(const isc::netconf::location &loc, const std::string &what)
Warning handler.
Definition netconf/parser_context.cc:185
isc::netconf::ParserContext::loc2pos
isc::data::Element::Position loc2pos(isc::netconf::location &loc)
Converts bison's position to one understandable by isc::data::Element.
Definition netconf/parser_context.cc:97
isc::netconf::ParserContext::enter
void enter(const LexerContext &ctx)
Enter a new syntactic context.
Definition netconf/parser_context.cc:139
isc::netconf::ParserContext::LexerContext
LexerContext
Defines syntactic contexts for lexical tie-ins.
Definition netconf/parser_context.h:197
isc::netconf::ParserContext::NO_KEYWORDS
@ NO_KEYWORDS
This one is used in pure JSON mode.
Definition netconf/parser_context.h:199
isc::netconf::ParserContext::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Definition netconf/parser_context.h:226
isc::netconf::ParserContext::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Netconf/loggers structures.
Definition netconf/parser_context.h:220
isc::netconf::ParserContext::NETCONF
@ NETCONF
Definition netconf/parser_context.h:205
isc::netconf::ParserContext::CONFIG
@ CONFIG
Used while parsing content of Netconf.
Definition netconf/parser_context.h:202
isc::netconf::ParserContext::MANAGED_SERVERS
@ MANAGED_SERVERS
Used while parsing Netconf/managed-servers.
Definition netconf/parser_context.h:208
isc::netconf::ParserContext::SERVER
@ SERVER
Used while parsing Netconf/manages-servers/*‍/control-socket.
Definition netconf/parser_context.h:211
isc::netconf::ParserContext::LOGGERS
@ LOGGERS
Used while parsing Netconf/loggers/output-options structures.
Definition netconf/parser_context.h:223
isc::netconf::ParserContext::SOCKET_TYPE
@ SOCKET_TYPE
Used while parsing Netconf/hooks-libraries.
Definition netconf/parser_context.h:217
isc::netconf::ParserContext::CONTROL_SOCKET
@ CONTROL_SOCKET
Used while parsing Netconf/managed-servers/*‍/control-socket/socket-type.
Definition netconf/parser_context.h:214
isc::netconf::ParserContext::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition netconf_lexer.cc:3942
isc::netconf::ParserContext::locs_
std::vector< isc::netconf::location > locs_
Location stack.
Definition netconf/parser_context.h:243
isc::netconf::ParserContext::sfile_
FILE * sfile_
sFile (aka FILE)
Definition netconf/parser_context.h:249
isc::netconf::ParserContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition netconf/parser_context.cc:91
isc::netconf::ParserContext::loc_
isc::netconf::location loc_
Location of the current token.
Definition netconf/parser_context.h:240
isc::netconf::ParserContext::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition netconf/parser_context.h:67
isc::netconf::ParserContext::ParserType
ParserType
Defines currently supported scopes.
Definition netconf/parser_context.h:48
isc::netconf::ParserContext::PARSER_NETCONF
@ PARSER_NETCONF
This parser will expect the content as Netconf config wrapped in a map (that's the regular config fil...
Definition netconf/parser_context.h:54
isc::netconf::ParserContext::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition netconf/parser_context.h:50
isc::netconf::ParserContext::PARSER_SUB_NETCONF
@ PARSER_SUB_NETCONF
This parser will expect only the content of Netconf.
Definition netconf/parser_context.h:57
isc::netconf::ParserContext::warnAboutExtraCommas
void warnAboutExtraCommas(const isc::netconf::location &loc)
Warning for extra commas.
Definition netconf/parser_context.cc:194
isc::netconf::ParserContext::error
void error(const isc::netconf::location &loc, const std::string &what, size_t pos=0)
Error handler.
Definition netconf/parser_context.cc:73
isc::netconf::ParserContext::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition netconf/parser_context.h:256
isc::netconf::ParserContext::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition netconf/parser_context.cc:32
isc::netconf::ParserContext::leave
void leave()
Leave a syntactic context.
Definition netconf/parser_context.cc:146
isc::netconf::ParserContext::file_
std::string file_
File name.
Definition netconf/parser_context.h:231
isc::netconf::ParserContext::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition netconf/parser_context.h:246
isc::netconf::ParserContext::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition netconf_lexer.cc:3921
dhcp_config_error.h
exceptions.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
parser_context_decl.h
Forward declaration of the ParserContext class.
netconf_parser.h
Define the isc::netconf::parser class.
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition data.h:94