Kea  1.9.9-git
netconf/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 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>
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.
22 
23 namespace isc {
24 namespace netconf {
25 
38 {
39 public:
40 
48  typedef enum {
51 
55 
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,
168  isc::data::Element::Position close_loc);
169 
178  void unique(const std::string& name,
180 
182  typedef enum {
185 
188 
191 
194 
197 
200 
203 
206 
209 
212 
213  } LexerContext;
214 
216  std::string file_;
217 
219  std::vector<std::string> files_;
220 
225  isc::netconf::location loc_;
226 
228  std::vector<isc::netconf::location> locs_;
229 
231  std::vector<struct yy_buffer_state*> states_;
232 
234  FILE* sfile_;
235 
241  std::vector<FILE*> sfiles_;
242 
245 
263  void enter(const LexerContext& ctx);
264 
272  void leave();
273 
277  const std::string contextName();
278 
279  private:
281  bool trace_scanning_;
282 
284  bool trace_parsing_;
285 
287  std::vector<LexerContext> cstack_;
288 
292  isc::data::ElementPtr parseCommon();
293 };
294 
295 } // end of isc::netconf namespace
296 } // end of isc namespace
297 
298 #endif
ParserContext()
Default constructor.
static void fatal(const std::string &what)
Fatal error handler.
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Used while parsing Netconf/loggers/output_options structures.
Used while parsing Netconf/managed-servers/*/control-socket/socket-type.
void includeFile(const std::string &filename)
Divert input to an include file.
LexerContext
Defines syntactic contexts for lexical tie-ins.
void scanEnd()
Method called after the last tokens are scanned.
void leave()
Leave a syntactic context.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
LexerContext ctx_
Current syntactic context.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Forward declaration of the ParserContext class.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
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.
isc::netconf::location loc_
Location of the current token.
This parser will expect the content as Netconf config wrapped in a map (that's the regular config fil...
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
#define YY_DECL
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
std::vector< std::string > files_
File name stack.
std::vector< isc::netconf::location > locs_
Location stack.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Used while parsing Netconf/hooks-libraries.
This parser will parse the content as generic JSON.
isc::data::Element::Position loc2pos(isc::netconf::location &loc)
Converts bison's position to one understandable by isc::data::Element.
void error(const isc::netconf::location &loc, const std::string &what, size_t pos=0)
Error handler.
Used while parsing Netconf/loggers structures.
Used while parsing Netconf/manages-servers/*/control-socket.
Represents the position of the data element within a configuration string.
Definition: data.h:88
Defines the logger used by the top-level component of kea-dhcp-ddns.
Used while parsing content of Netconf.
This one is used in pure JSON mode.
Define the isc::netconf::parser class.
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
Parser context is a wrapper around flex/bison instances dedicated to Netconf-agent config file parser...
void enter(const LexerContext &ctx)
Enter a new syntactic context.
ParserType
Defines currently supported scopes.
This parser will expect only the content of Netconf.
Used while parsing Netconf/managed-servers.
FILE * sfile_
sFile (aka FILE)
const std::string contextName()
Get the syntactic context name.