Kea  1.5.0
d2/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2017 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 
34 
37 {
38 public:
39 
47  typedef enum {
50 
53 
56 
59 
62 
65 
68 
71 
74  } ParserType;
75 
78 
80  std::vector<isc::data::ElementPtr> stack_;
81 
86  void scanStringBegin(const std::string& str, ParserType type);
87 
93  void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
94 
96  void scanEnd();
97 
101  void includeFile(const std::string& filename);
102 
113  isc::data::ElementPtr parseString(const std::string& str,
114  ParserType parser_type);
115 
126  isc::data::ElementPtr parseFile(const std::string& filename,
127  ParserType parser_type);
128 
134  void error(const isc::d2::location& loc, const std::string& what);
135 
143  void error(const std::string& what);
144 
152  static void fatal(const std::string& what);
153 
161  isc::data::Element::Position loc2pos(isc::d2::location& loc);
162 
164  typedef enum {
167 
170 
173 
176 
179 
182 
185 
188 
191 
194 
197 
200 
203 
206 
209 
212 
215 
218 
221 
222  } ParserContext;
223 
225  std::string file_;
226 
228  std::vector<std::string> files_;
229 
234  isc::d2::location loc_;
235 
237  std::vector<isc::d2::location> locs_;
238 
240  std::vector<struct yy_buffer_state*> states_;
241 
243  FILE* sfile_;
244 
250  std::vector<FILE*> sfiles_;
251 
254 
267  void enter(const ParserContext& ctx);
268 
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<ParserContext> cstack_;
288 
292  isc::data::ElementPtr parseCommon();
293 };
294 
295 }; // end of isc::eval namespace
296 }; // end of isc namespace
297 
298 #endif
Used while parsing a list of tsig-keys.
Define the isc::d2::parser class.
Used for parsing a list of TSIG Keys.
Used while parsing Logging/loggers/output_options structures.
Used while parsing content of a dns-server.
Used while parsing content of DhcpDdns/tsig-keys/algorithm.
Evaluation context, an interface to the expression evaluation.
void includeFile(const std::string &filename)
Divert input to an include file.
Definition: d2_lexer.cc:3512
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Used while parsing content of DhcpDdns/forward-ddns.
This one is used in pure JSON mode.
Used for parsing a list of DNS servers.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
D2ParseError(const char *file, size_t line, const char *what)
void scanEnd()
Method called after the last tokens are scanned.
Definition: d2_lexer.cc:3491
Used while parsing content of a tsig-key.
std::vector< isc::d2::location > locs_
Location stack.
Used while parsing Logging/loggers structures.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This parser will parse the content as generic JSON.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
static void fatal(const std::string &what)
Fatal error handler.
isc::d2::location loc_
Location of the current token.
Used while parsing content of DhcpDdns/tsig-keys/secret.
Used while parsing content of a ddns-domain.
Used while parsing content of DhcpDdns/reverse-ddns.
void leave()
Leave a syntactic context.
Used while parsing content of Logging.
Used while parsing DhcpDdns/ncr-protocol.
Used for parsing content of a DNS Server.
std::vector< std::string > files_
File name stack.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Used for parsing content of a TSIG key.
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:88
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Evaluation error exception raised when trying to parse.
Used while parsing content of DhcpDdns.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition: d2_lexer.cc:3469
FILE * sfile_
sFile (aka FILE)
Forward declaration of the ParserContext class.
Used while parsing a list of ddns-domains.
ParserContext
Defines syntactic contexts for lexical tie-ins.
Used for parsing a list a DDNS Domains.
D2ParserContext()
Default constructor.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Used for parsing content of DhcpDdns.
Used while parsing content of DhcpDdns/tsig-keys/digest-bits.
Used for parsing content of a DDNS Domain.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition: d2_lexer.cc:3451
ParserContext ctx_
Current syntactic context.
Used while parsing content of list of dns-servers.
std::string file_
File name.
isc::data::Element::Position loc2pos(isc::d2::location &loc)
Converts bison's position to one understood by isc::data::Element.
void error(const isc::d2::location &loc, const std::string &what)
Error handler.
const std::string contextName()
Get the syntax context name.