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 
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 {
166  NO_KEYWORD,
167 
169  CONFIG,
170 
172  DHCPDDNS,
173 
175  TSIG_KEY,
176 
178  TSIG_KEYS,
179 
181  ALGORITHM,
182 
184  DIGEST_BITS,
185 
187  SECRET,
188 
190  FORWARD_DDNS,
191 
193  REVERSE_DDNS,
194 
196  DDNS_DOMAIN,
197 
199  DDNS_DOMAINS,
200 
202  DNS_SERVER,
203 
205  DNS_SERVERS,
206 
209 
212 
215 
218 
220  NCR_FORMAT
221 
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
isc::d2::D2ParserContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition: d2/parser_context.cc:81
isc::d2::D2ParserContext::PARSER_DNS_SERVERS
@ PARSER_DNS_SERVERS
Definition: d2/parser_context.h:73
isc::d2::D2ParserContext::DNS_SERVERS
@ DNS_SERVERS
Used while parsing content of Logging.
Definition: d2/parser_context.h:205
isc::d2::D2ParserContext::ParserType
ParserType
Defines currently supported scopes.
Definition: d2/parser_context.h:47
isc::d2::D2ParserContext::LOGGERS
@ LOGGERS
Used while parsing Logging/loggers structures.
Definition: d2/parser_context.h:211
isc::d2::D2ParserContext::leave
void leave()
Leave a syntactic context.
Definition: d2/parser_context.cc:103
isc::d2::D2ParserContext::ParserContext
ParserContext
Defines syntactic contexts for lexical tie-ins.
Definition: d2/parser_context.h:164
isc::d2::D2ParserContext::ALGORITHM
@ ALGORITHM
Used while parsing content of DhcpDdns/tsig-keys/digest-bits.
Definition: d2/parser_context.h:181
isc::d2::D2ParserContext::PARSER_TSIG_KEYS
@ PARSER_TSIG_KEYS
Used for parsing content of a DDNS Domain.
Definition: d2/parser_context.h:61
isc::d2::D2ParseError::D2ParseError
D2ParseError(const char *file, size_t line, const char *what)
Definition: d2/parser_context.h:30
isc::d2::D2ParserContext::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Used while parsing Logging/loggers/output_options structures.
Definition: d2/parser_context.h:214
isc::d2::D2ParserContext::NO_KEYWORD
@ NO_KEYWORD
This one is used in pure JSON mode.
Definition: d2/parser_context.h:166
isc::d2::D2ParserContext::DDNS_DOMAIN
@ DDNS_DOMAIN
Used while parsing a list of ddns-domains.
Definition: d2/parser_context.h:196
isc::d2::D2ParserContext::PARSER_DHCPDDNS
@ PARSER_DHCPDDNS
Used for parsing content of DhcpDdns.
Definition: d2/parser_context.h:52
isc::d2::D2ParserContext::REVERSE_DDNS
@ REVERSE_DDNS
Used while parsing content of a ddns-domain.
Definition: d2/parser_context.h:193
isc::d2::D2ParserContext::D2ParserContext
D2ParserContext()
Default constructor.
Definition: d2/parser_context.cc:20
isc::d2::D2ParserContext::NCR_FORMAT
@ NCR_FORMAT
Used while parsing DhcpDdns/ncr-format.
Definition: d2/parser_context.h:220
isc::d2::D2ParserContext::files_
std::vector< std::string > files_
File name stack.
Definition: d2/parser_context.h:228
isc::d2::D2ParserContext::DHCPDDNS
@ DHCPDDNS
Used while parsing content of a tsig-key.
Definition: d2/parser_context.h:172
isc::d2::D2ParserContext::PARSER_DDNS_DOMAINS
@ PARSER_DDNS_DOMAINS
Used for parsing content of a DNS Server.
Definition: d2/parser_context.h:67
isc::d2::D2ParserContext::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition: d2/parser_context.h:250
isc::d2::D2ParserContext::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition: d2/parser_context.h:80
isc::d2::D2ParserContext::sfile_
FILE * sfile_
sFile (aka FILE)
Definition: d2/parser_context.h:243
isc::d2::D2ParserContext::CONFIG
@ CONFIG
Used while parsing content of DhcpDdns.
Definition: d2/parser_context.h:169
isc::d2::D2ParserContext::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition: d2_lexer.cc:3451
isc::d2::D2ParserContext::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition: d2/parser_context.cc:33
isc::d2::D2ParserContext::contextName
const std::string contextName()
Get the syntax context name.
Definition: d2/parser_context.cc:114
isc::d2::D2ParserContext::DDNS_DOMAINS
@ DDNS_DOMAINS
Used while parsing content of a dns-server.
Definition: d2/parser_context.h:199
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
parser_context_decl.h
isc::d2::D2ParserContext::LOGGING
@ LOGGING
Definition: d2/parser_context.h:208
isc::d2::D2ParserContext::loc2pos
isc::data::Element::Position loc2pos(isc::d2::location &loc)
Converts bison's position to one understood by isc::data::Element.
Definition: d2/parser_context.cc:87
isc::d2::D2ParserContext::ctx_
ParserContext ctx_
Current syntactic context.
Definition: d2/parser_context.h:253
isc::d2::D2ParserContext::NCR_PROTOCOL
@ NCR_PROTOCOL
Used while parsing DhcpDdns/ncr-protocol.
Definition: d2/parser_context.h:217
isc::d2::D2ParserContext::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition: d2/parser_context.h:240
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition: data.h:88
isc::d2::D2ParserContext::error
void error(const isc::d2::location &loc, const std::string &what)
Error handler.
Definition: d2/parser_context.cc:69
isc::d2::D2ParserContext::file_
std::string file_
File name.
Definition: d2/parser_context.h:225
isc::d2::D2ParserContext::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition: d2_lexer.cc:3512
isc::d2::D2ParserContext::PARSER_DNS_SERVER
@ PARSER_DNS_SERVER
Used for parsing a list of DNS servers.
Definition: d2/parser_context.h:70
isc::dns::Exception
Definition: dns/exceptions.h:25
isc::d2::D2ParserContext::FORWARD_DDNS
@ FORWARD_DDNS
Used while parsing content of DhcpDdns/reverse-ddns.
Definition: d2/parser_context.h:190
d2_parser.h
isc::d2::D2ParserContext::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition: d2_lexer.cc:3491
YY_DECL
#define YY_DECL
Definition: d2/parser_context.h:17
isc::d2::D2ParserContext::locs_
std::vector< isc::d2::location > locs_
Location stack.
Definition: d2/parser_context.h:237
isc::d2::D2ParserContext::PARSER_TSIG_KEY
@ PARSER_TSIG_KEY
Used for parsing a list of TSIG Keys.
Definition: d2/parser_context.h:58
isc::d2::D2ParserContext::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition: d2/parser_context.h:49
isc::d2::D2ParserContext::DNS_SERVER
@ DNS_SERVER
Used while parsing content of list of dns-servers.
Definition: d2/parser_context.h:202
isc::d2::D2ParserContext::PARSER_DDNS_DOMAIN
@ PARSER_DDNS_DOMAIN
Used for parsing a list a DDNS Domains.
Definition: d2/parser_context.h:64
isc::d2::D2ParserContext::DIGEST_BITS
@ DIGEST_BITS
Used while parsing content of DhcpDdns/tsig-keys/secret.
Definition: d2/parser_context.h:184
isc::d2::D2ParserContext::TSIG_KEY
@ TSIG_KEY
Used while parsing a list of tsig-keys.
Definition: d2/parser_context.h:175
isc::d2::D2ParserContext::TSIG_KEYS
@ TSIG_KEYS
Used while parsing content of DhcpDdns/tsig-keys/algorithm.
Definition: d2/parser_context.h:178
exceptions.h
isc::d2::D2ParserContext
Evaluation context, an interface to the expression evaluation.
Definition: d2/parser_context.h:37
isc::d2::D2ParserContext::enter
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Definition: d2/parser_context.cc:96
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::d2::D2ParserContext::SECRET
@ SECRET
Used while parsing content of DhcpDdns/forward-ddns.
Definition: d2/parser_context.h:187
isc::d2::D2ParserContext::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition: d2_lexer.cc:3469
isc::d2::D2ParserContext::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition: d2/parser_context.cc:26
isc::d2::D2ParseError
Evaluation error exception raised when trying to parse.
Definition: d2/parser_context.h:28
isc::d2::D2ParserContext::loc_
isc::d2::location loc_
Location of the current token.
Definition: d2/parser_context.h:234
isc::d2::D2ParserContext::PARSER_SUB_DHCPDDNS
@ PARSER_SUB_DHCPDDNS
Used for parsing content of a TSIG key.
Definition: d2/parser_context.h:55