Kea 2.7.6
d2/parser_context.h
Go to the documentation of this file.
1// Copyright (C) 2017-2024 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>
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
22namespace isc {
23namespace d2 {
24
29public:
30 D2ParseError(const char* file, size_t line, const char* what) :
31 isc::Exception(file, line, what) { }
32};
33
36{
37public:
38
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,
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 {
217
219 CONFIG,
220
222 DHCPDDNS,
223
225 TSIG_KEY,
226
228 TSIG_KEYS,
229
231 ALGORITHM,
232
235
237 SECRET,
238
241
244
247
250
253
256
259
262
265
267 AUTH_TYPE,
268
271
274
277
280
283
286
288
290 std::string file_;
291
293 std::vector<std::string> files_;
294
299 isc::d2::location loc_;
300
302 std::vector<isc::d2::location> locs_;
303
305 std::vector<struct yy_buffer_state*> states_;
306
308 FILE* sfile_;
309
315 std::vector<FILE*> sfiles_;
316
319
332 void enter(const ParserContext& ctx);
333
337 void leave();
338
342 const std::string contextName();
343
344 private:
346 bool trace_scanning_;
347
349 bool trace_parsing_;
350
352 std::vector<ParserContext> cstack_;
353
357 isc::data::ElementPtr parseCommon();
358};
359
360} // end of isc::eval namespace
361} // end of isc namespace
362
363#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Evaluation error exception raised when trying to parse.
D2ParseError(const char *file, size_t line, const char *what)
Evaluation context, an interface to the expression evaluation.
ParserType
Defines currently supported scopes.
@ PARSER_TSIG_KEY
Used for parsing a list of TSIG Keys.
@ PARSER_DDNS_DOMAINS
Used for parsing content of a DNS Server.
@ PARSER_DNS_SERVERS
Used for parsing content of hooks libraries.
@ PARSER_DDNS_DOMAIN
Used for parsing a list a DDNS Domains.
@ PARSER_DNS_SERVER
Used for parsing a list of DNS servers.
@ PARSER_SUB_DHCPDDNS
Used for parsing content of a TSIG key.
@ PARSER_JSON
This parser will parse the content as generic JSON.
@ PARSER_TSIG_KEYS
Used for parsing content of a DDNS Domain.
@ PARSER_DHCPDDNS
Used for parsing content of DhcpDdns.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
isc::d2::location loc_
Location of the current token.
std::string file_
File name.
void includeFile(const std::string &filename)
Divert input to an include file.
Definition d2_lexer.cc:3985
D2ParserContext()
Default constructor.
ParserContext
Defines syntactic contexts for lexical tie-ins.
@ AUTHENTICATION
Used while parsing content of an authentication type.
@ DDNS_DOMAIN
Used while parsing a list of ddns-domains.
@ DNS_SERVERS
Used while parsing content of a control-socket.
@ DDNS_DOMAINS
Used while parsing content of a dns-server.
@ AUTH_TYPE
Used while parsing content of a client.
@ NCR_FORMAT
Used while parsing DhcpDdns/ncr-format.
@ NCR_PROTOCOL
Used while parsing DhcpDdns/ncr-protocol.
@ NO_KEYWORD
This one is used in pure JSON mode.
@ DHCPDDNS
Used while parsing content of a tsig-key.
@ SECRET
Used while parsing content of DhcpDdns/forward-ddns.
@ ALGORITHM
Used while parsing content of DhcpDdns/tsig-keys/digest-bits.
@ OUTPUT_OPTIONS
Used while parsing DhcpDdns/loggers/output-options structures.
@ FORWARD_DDNS
Used while parsing content of DhcpDdns/reverse-ddns.
@ CONTROL_SOCKET_TYPE
Used while parsing content of an authentication.
@ TSIG_KEY
Used while parsing a list of tsig-keys.
@ REVERSE_DDNS
Used while parsing content of a ddns-domain.
@ LOGGERS
Used while parsing DhcpDdns/loggers structures.
@ HOOKS_LIBRARIES
Used while parsing DhcpDdns/hooks-libraries.
@ TSIG_KEYS
Used while parsing content of DhcpDdns/tsig-keys/algorithm.
@ CONTROL_SOCKET
Used while parsing content of a socket-type.
@ DIGEST_BITS
Used while parsing content of DhcpDdns/tsig-keys/secret.
@ CONFIG
Used while parsing content of DhcpDdns.
@ DNS_SERVER
Used while parsing content of list of dns-servers.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
void warning(const isc::d2::location &loc, const std::string &what)
Warning handler.
FILE * sfile_
sFile (aka FILE)
const std::string contextName()
Get the syntax context name.
void error(const isc::d2::location &loc, const std::string &what, size_t pos=0)
Error handler.
void leave()
Leave a syntactic context.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition d2_lexer.cc:3924
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
void warnAboutExtraCommas(const isc::d2::location &loc)
Warning for extra commas.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition d2_lexer.cc:3942
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
virtual ~D2ParserContext()
destructor.
std::vector< isc::d2::location > locs_
Location stack.
ParserContext ctx_
Current syntactic context.
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.
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
void enter(const ParserContext &ctx)
Enter a new syntactic context.
static void fatal(const std::string &what)
Fatal error handler.
std::vector< std::string > files_
File name stack.
void scanEnd()
Method called after the last tokens are scanned.
Definition d2_lexer.cc:3964
isc::data::Element::Position loc2pos(isc::d2::location &loc)
Converts bison's position to one understood by isc::data::Element.
#define YY_DECL
Forward declaration of the ParserContext class.
Define the isc::d2::parser class.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.
Definition data.h:94