Kea  2.3.5-git
d2/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2021 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 <d2/d2_parser.h>
13 #include <d2/parser_context_decl.h>
14 #include <exceptions/exceptions.h>
15 
16 // Tell Flex the lexer's prototype ...
17 #define YY_DECL isc::d2::D2Parser::symbol_type d2_parser_lex (D2ParserContext& driver)
18 
19 // ... and declare it for the parser's sake.
21 
22 namespace isc {
23 namespace d2 {
24 
28 class D2ParseError : public isc::Exception {
29 public:
30  D2ParseError(const char* file, size_t line, const char* what) :
31  isc::Exception(file, line, what) { };
32 };
33 
36 {
37 public:
38 
46  typedef enum {
48  PARSER_JSON,
49 
51  PARSER_DHCPDDNS,
52 
54  PARSER_SUB_DHCPDDNS,
55 
57  PARSER_TSIG_KEY,
58 
60  PARSER_TSIG_KEYS,
61 
63  PARSER_DDNS_DOMAIN,
64 
66  PARSER_DDNS_DOMAINS,
67 
69  PARSER_DNS_SERVER,
70 
72  PARSER_DNS_SERVERS,
73 
75  PARSER_HOOKS_LIBRARY
76  } ParserType;
77 
80 
82  virtual ~D2ParserContext();
83 
85  std::vector<isc::data::ElementPtr> stack_;
86 
91  void scanStringBegin(const std::string& str, ParserType type);
92 
98  void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
99 
101  void scanEnd();
102 
106  void includeFile(const std::string& filename);
107 
118  isc::data::ElementPtr parseString(const std::string& str,
119  ParserType parser_type);
120 
131  isc::data::ElementPtr parseFile(const std::string& filename,
132  ParserType parser_type);
133 
143  void error(const isc::d2::location& loc,
144  const std::string& what,
145  size_t pos = 0);
146 
154  void error(const std::string& what);
155 
163  static void fatal(const std::string& what);
164 
172  isc::data::Element::Position loc2pos(isc::d2::location& loc);
173 
183  void require(const std::string& name,
185  isc::data::Element::Position close_loc);
186 
195  void unique(const std::string& name,
197 
204  void warning(const isc::d2::location& loc, const std::string& what);
205 
211  void warnAboutExtraCommas(const isc::d2::location& loc);
212 
214  typedef enum {
216  NO_KEYWORD,
217 
219  CONFIG,
220 
222  DHCPDDNS,
223 
225  TSIG_KEY,
226 
228  TSIG_KEYS,
229 
231  ALGORITHM,
232 
234  DIGEST_BITS,
235 
237  SECRET,
238 
240  FORWARD_DDNS,
241 
243  REVERSE_DDNS,
244 
246  DDNS_DOMAIN,
247 
249  DDNS_DOMAINS,
250 
252  DNS_SERVER,
253 
255  DNS_SERVERS,
256 
259 
262 
265 
268 
271 
273  HOOKS_LIBRARIES
274 
275  } ParserContext;
276 
278  std::string file_;
279 
281  std::vector<std::string> files_;
282 
287  isc::d2::location loc_;
288 
290  std::vector<isc::d2::location> locs_;
291 
293  std::vector<struct yy_buffer_state*> states_;
294 
296  FILE* sfile_;
297 
303  std::vector<FILE*> sfiles_;
304 
306  ParserContext ctx_;
307 
320  void enter(const ParserContext& ctx);
321 
325  void leave();
326 
330  const std::string contextName();
331 
332  private:
334  bool trace_scanning_;
335 
337  bool trace_parsing_;
338 
340  std::vector<ParserContext> cstack_;
341 
345  isc::data::ElementPtr parseCommon();
346 };
347 
348 } // end of isc::eval namespace
349 } // end of isc namespace
350 
351 #endif
Define the isc::d2::parser class.
Used while parsing DhcpDdns/loggers/output_options structures.
Evaluation context, an interface to the expression evaluation.
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
D2ParseError(const char *file, size_t line, const char *what)
std::vector< isc::d2::location > locs_
Location stack.
Used while parsing DhcpDdns/loggers structures.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
isc::d2::location loc_
Location of the current token.
Used while parsing DhcpDdns/ncr-protocol.
std::vector< std::string > files_
File name stack.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
ParserType
Defines currently supported scopes.
#define YY_DECL
Used while parsing DhcpDdns/ncr-format.
Represents the position of the data element within a configuration string.
Definition: data.h:92
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
Evaluation error exception raised when trying to parse.
FILE * sfile_
sFile (aka FILE)
Forward declaration of the ParserContext class.
ParserContext
Defines syntactic contexts for lexical tie-ins.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
ParserContext ctx_
Current syntactic context.
std::string file_
File name.