Kea  1.5.0
dhcp4/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2018 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 PARSER_CONTEXT_H
8 #define PARSER_CONTEXT_H
9 #include <string>
10 #include <map>
11 #include <vector>
12 #include <dhcp4/dhcp4_parser.h>
14 #include <exceptions/exceptions.h>
15 
16 // Tell Flex the lexer's prototype ...
17 #define YY_DECL isc::dhcp::Dhcp4Parser::symbol_type parser4_lex (Parser4Context& driver)
18 
19 // ... and declare it for the parser's sake.
21 
22 namespace isc {
23 namespace dhcp {
24 
29 public:
30  Dhcp4ParseError(const char* file, size_t line, const char* what) :
31  isc::Exception(file, line, what) { };
32 };
33 
34 
37 {
38 public:
39 
50  typedef enum {
53 
57 
63 
66 
69 
72 
75 
78 
81 
84 
87 
90 
93 
96  } ParserType;
97 
100 
102  virtual ~Parser4Context();
103 
105  std::vector<isc::data::ElementPtr> stack_;
106 
111  void scanStringBegin(const std::string& str, ParserType type);
112 
118  void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
119 
121  void scanEnd();
122 
126  void includeFile(const std::string& filename);
127 
138  isc::data::ElementPtr parseString(const std::string& str,
139  ParserType parser_type);
140 
151  isc::data::ElementPtr parseFile(const std::string& filename,
152  ParserType parser_type);
153 
159  void error(const isc::dhcp::location& loc, const std::string& what);
160 
168  void error(const std::string& what);
169 
177  static void fatal(const std::string& what);
178 
186  isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
187 
197  void require(const std::string& name,
199  isc::data::Element::Position close_loc);
200 
202  typedef enum {
205 
208 
211 
212  // not yet Dhcp6, DhcpDdns,
213 
216 
219 
222 
225 
228 
231 
234 
237 
240 
243 
246 
249 
252 
255 
260 
263 
266 
269 
272 
275 
278 
281 
284 
287 
290 
293 
296 
299 
302 
305 
308 
309  } ParserContext;
310 
312  std::string file_;
313 
315  std::vector<std::string> files_;
316 
321  isc::dhcp::location loc_;
322 
324  std::vector<isc::dhcp::location> locs_;
325 
327  std::vector<struct yy_buffer_state*> states_;
328 
330  FILE* sfile_;
331 
337  std::vector<FILE*> sfiles_;
338 
341 
354  void enter(const ParserContext& ctx);
355 
359  void leave();
360 
364  const std::string contextName();
365 
366  private:
368  bool trace_scanning_;
369 
371  bool trace_parsing_;
372 
374  std::vector<ParserContext> cstack_;
375 
379  isc::data::ElementPtr parseCommon();
380 };
381 
382 }; // end of isc::eval namespace
383 }; // end of isc namespace
384 
385 #endif
Used while parsing Dhcp4/hosts-database[s] structures.
Used while parsing Dhcp4/dhcp-ddns/ncr-protocol.
This will parse the input as option data.
ParserContext
Defines syntactic contexts for lexical tie-ins.
Used while parsing Dhcp4/hooks-libraries.
void leave()
Leave a syntactic context.
Used while parsing Dhcp4/dhcp-ddns/ncr-format.
This will parse the input as option definition.
This parser will parse the content as Dhcp4 config wrapped in a map (that's the regular config file)
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Used while parsing Dhcp4/interfaces/outbound-interface structures.
Used while parsing Dhcp4/client-classes structures.
const std::string contextName()
Get the syntactic context name.
isc::data::Element::Position loc2pos(isc::dhcp::location &loc)
Converts bison's position to one understandable by isc::data::Element.
Evaluation context, an interface to the expression evaluation.
Used while parsing Dhcp4/*-database/type.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Used while parsing Dhcp4/host-reservation-identifiers.
This will parse the input as host-reservation.
This will parse the input as interfaces content.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
Used while parsing content of Logging.
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Used while parsing Dhcp4/reservations structures.
isc::dhcp::location loc_
Location of the current token.
Used while parsing Dhcp4/lease-database structures.
void scanEnd()
Method called after the last tokens are scanned.
Used while parsing Dhcp4/dhcp-ddns.
This will parse the input as config-control.
void includeFile(const std::string &filename)
Divert input to an include file.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Used while parsing Dhcp4/interfaces/dhcp-socket-type structures.
Used while parsing Dhcp4/server-id structures.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Define the isc::dhcp::parser class.
Used while parsing Dhcp4/control-socket structures.
Used while parsing Dhcp4/subnet4/pools structures.
Parser4Context()
Default constructor.
Used while parsing Dhcp4/dhcp-queue-control structures.
Used while parsing shared-networks structures.
Dhcp4ParseError(const char *file, size_t line, const char *what)
This will parse the input option definitions (for tests).
This will parse the input as hooks-library.
ParserContext ctx_
Current syntactic context.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Used while parsing Dhcp4/dhcp-ddns/replace-client-name.
This will parse the input as pool4 content.
Used while parsing Logging/loggers/output_options structures.
std::vector< isc::dhcp::location > locs_
Location stack.
std::vector< std::string > files_
File name stack.
This parser will parse the content of Dhcp4 (without outer { } and without "Dhcp4").
ParserType
Defines currently supported scopes.
This parser will parse the content as generic JSON.
Used while parsing Dhcp4/Subnet4 structures.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Evaluation error exception raised when trying to parse.
Used while parsing Dhcp4/option-def structures.
Used while parsing Dhcp4/option-data, Dhcp4/subnet4/option-data or anywhere option-data is present (c...
Used while parsing Dhcp4/interfaces structures.
Used while parsing content of Dhcp4.
Represents the position of the data element within a configuration string.
Definition: data.h:88
Used while parsing Dhcp4/subnet4relay structures.
#define YY_DECL
This is a base class for exceptions thrown from the DNS library module.
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.
Defines the logger used by the top-level component of kea-dhcp-ddns.
This will parse the input as dhcp-ddns.
This will parse the input as Subnet4 content.
Used while parsing Logging/loggers structures.
This one is used in pure JSON mode.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Forward declaration of the ParserContext class.
FILE * sfile_
sFile (aka FILE)
This will parse the content of Logging.
void error(const isc::dhcp::location &loc, const std::string &what)
Error handler.
Used while parsing Dhcp4/expired-leases-processing.
Used while parsing config-control/config-databases.
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
static void fatal(const std::string &what)
Fatal error handler.
virtual ~Parser4Context()
destructor
Used while parsing Dhcp4/config-control.
std::string file_
File name.
Used while parsing Dhcp4/reservation-mode.