| Kea 3.0.2-git

agent/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 <agent/agent_parser.h>
13#include <agent/parser_context_decl.h>
14#include <exceptions/exceptions.h>
15
16// Tell Flex the lexer's prototype ...
17#define YY_DECL isc::agent::AgentParser::symbol_type agent_lex (ParserContext& driver)
18
19// ... and declare it for the parser's sake.
20 YY_DECL;
21
22 namespace isc {
23 namespace agent {
24
36 class ParserContext
37{
38 public:
39
47 typedef enum {
49 PARSER_JSON,
50
53 PARSER_AGENT,
54
56 PARSER_SUB_AGENT
57 } ParserType;
58
60 ParserContext();
61
63 virtual ~ParserContext();
64
66 std::vector<isc::data::ElementPtr> stack_;
67
72 void scanStringBegin(const std::string& str, ParserType type);
73
79 void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
80
82 void scanEnd();
83
87 void includeFile(const std::string& filename);
88
99 isc::data::ElementPtr parseString(const std::string& str,
100 ParserType parser_type);
101
113 isc::data::ElementPtr parseFile(const std::string& filename,
114 ParserType parser_type);
115
125 void error(const isc::agent::location& loc,
126 const std::string& what,
127 size_t pos = 0);
128
136 void error(const std::string& what);
137
145 static void fatal(const std::string& what);
146
154 isc::data::Element::Position loc2pos(isc::agent::location& loc);
155
165 void require(const std::string& name,
166 isc::data::Element::Position open_loc,
167 isc::data::Element::Position close_loc);
168
177 void unique(const std::string& name,
178 isc::data::Element::Position loc);
179
186 void warning(const isc::agent::location& loc, const std::string& what);
187
193 void warnAboutExtraCommas(const isc::agent::location& loc);
194
196 typedef enum {
198 NO_KEYWORDS,
199
201 CONFIG,
202
204 AGENT,
205
207 HTTP_HEADERS,
208
210 AUTHENTICATION,
211
213 AUTH_TYPE,
214
216 CLIENTS,
217
219 CONTROL_SOCKETS,
220
222 SERVER,
223
225 SOCKET_TYPE,
226
228 HOOKS_LIBRARIES,
229
231 LOGGERS,
232
234 OUTPUT_OPTIONS
235 } LexerContext;
236
238 std::string file_;
239
241 std::vector<std::string> files_;
242
247 isc::agent::location loc_;
248
250 std::vector<isc::agent::location> locs_;
251
253 std::vector<struct yy_buffer_state*> states_;
254
256 FILE* sfile_;
257
263 std::vector<FILE*> sfiles_;
264
266 LexerContext ctx_;
267
285 void enter(const LexerContext& ctx);
286
294 void leave();
295
299 const std::string contextName();
300
301 private:
303 bool trace_scanning_;
304
306 bool trace_parsing_;
307
309 std::vector<LexerContext> cstack_;
310
314 isc::data::ElementPtr parseCommon();
315};
316
317} // end of isc::eval namespace
318} // end of isc namespace
319
320#endif
YY_DECL
#define YY_DECL
Definition agent/parser_context.h:17
parser_context_decl.h
Forward declaration of the ParserContext class.
agent_parser.h
Define the isc::agent::parser class.
isc::agent::ParserContext::warning
void warning(const isc::agent::location &loc, const std::string &what)
Warning handler.
Definition agent/parser_context.cc:191
isc::agent::ParserContext::locs_
std::vector< isc::agent::location > locs_
Location stack.
Definition agent/parser_context.h:250
isc::agent::ParserContext::warnAboutExtraCommas
void warnAboutExtraCommas(const isc::agent::location &loc)
Warning for extra commas.
Definition agent/parser_context.cc:200
isc::agent::ParserContext::files_
std::vector< std::string > files_
File name stack.
Definition agent/parser_context.h:241
isc::agent::ParserContext::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition agent_lexer.cc:4096
isc::agent::ParserContext::ParserContext
ParserContext()
Default constructor.
Definition agent/parser_context.cc:22
isc::agent::ParserContext::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition agent_lexer.cc:4114
isc::agent::ParserContext::unique
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
Definition agent/parser_context.cc:121
isc::agent::ParserContext::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition agent/parser_context.h:66
isc::agent::ParserContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition agent/parser_context.cc:91
isc::agent::ParserContext::~ParserContext
virtual ~ParserContext()
destructor
Definition agent/parser_context.cc:27
isc::agent::ParserContext::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition agent/parser_context.h:253
isc::agent::ParserContext::loc_
isc::agent::location loc_
Location of the current token.
Definition agent/parser_context.h:247
isc::agent::ParserContext::contextName
const std::string contextName()
Get the syntactic context name.
Definition agent/parser_context.cc:156
isc::agent::ParserContext::file_
std::string file_
File name.
Definition agent/parser_context.h:238
isc::agent::ParserContext::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition agent_lexer.cc:4157
isc::agent::ParserContext::loc2pos
isc::data::Element::Position loc2pos(isc::agent::location &loc)
Converts bison's position to one understandable by isc::data::Element.
Definition agent/parser_context.cc:97
isc::agent::ParserContext::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition agent/parser_context.cc:39
isc::agent::ParserContext::ctx_
LexerContext ctx_
Current syntactic context.
Definition agent/parser_context.h:266
isc::agent::ParserContext::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition agent/parser_context.cc:32
isc::agent::ParserContext::leave
void leave()
Leave a syntactic context.
Definition agent/parser_context.cc:146
isc::agent::ParserContext::LexerContext
LexerContext
Defines syntactic contexts for lexical tie-ins.
Definition agent/parser_context.h:196
isc::agent::ParserContext::CONFIG
@ CONFIG
Used while parsing content of Agent.
Definition agent/parser_context.h:201
isc::agent::ParserContext::SERVER
@ SERVER
Used while parsing Control-agent/control-socket/*-server/socket-type.
Definition agent/parser_context.h:222
isc::agent::ParserContext::NO_KEYWORDS
@ NO_KEYWORDS
This one is used in pure JSON mode.
Definition agent/parser_context.h:198
isc::agent::ParserContext::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Control-agent/loggers structures.
Definition agent/parser_context.h:228
isc::agent::ParserContext::CONTROL_SOCKETS
@ CONTROL_SOCKETS
Used while parsing Control-agent/control-socket/*-server.
Definition agent/parser_context.h:219
isc::agent::ParserContext::HTTP_HEADERS
@ HTTP_HEADERS
Used while parsing Control-agent/Authentication.
Definition agent/parser_context.h:207
isc::agent::ParserContext::SOCKET_TYPE
@ SOCKET_TYPE
Used while parsing Control-agent/hooks-libraries.
Definition agent/parser_context.h:225
isc::agent::ParserContext::AGENT
@ AGENT
Used while parsing HTTP headers.
Definition agent/parser_context.h:204
isc::agent::ParserContext::CLIENTS
@ CLIENTS
Used while parsing Control-agent/control-sockets.
Definition agent/parser_context.h:216
isc::agent::ParserContext::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Definition agent/parser_context.h:234
isc::agent::ParserContext::AUTHENTICATION
@ AUTHENTICATION
Used while parsing Control-agent/Authentication/type.
Definition agent/parser_context.h:210
isc::agent::ParserContext::AUTH_TYPE
@ AUTH_TYPE
Used while parsing Control-agent/Authentication/clients.
Definition agent/parser_context.h:213
isc::agent::ParserContext::LOGGERS
@ LOGGERS
Used while parsing Control-agent/loggers/output-options structures.
Definition agent/parser_context.h:231
isc::agent::ParserContext::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition agent/parser_context.h:263
isc::agent::ParserContext::require
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.
Definition agent/parser_context.cc:106
isc::agent::ParserContext::error
void error(const isc::agent::location &loc, const std::string &what, size_t pos=0)
Error handler.
Definition agent/parser_context.cc:73
isc::agent::ParserContext::ParserType
ParserType
Defines currently supported scopes.
Definition agent/parser_context.h:47
isc::agent::ParserContext::PARSER_AGENT
@ PARSER_AGENT
This parser will expect the content as Control-agent config wrapped in a map (that's the regular conf...
Definition agent/parser_context.h:53
isc::agent::ParserContext::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition agent/parser_context.h:49
isc::agent::ParserContext::PARSER_SUB_AGENT
@ PARSER_SUB_AGENT
This parser will expect only the content of Control-agent.
Definition agent/parser_context.h:56
isc::agent::ParserContext::enter
void enter(const LexerContext &ctx)
Enter a new syntactic context.
Definition agent/parser_context.cc:139
isc::agent::ParserContext::sfile_
FILE * sfile_
sFile (aka FILE)
Definition agent/parser_context.h:256
isc::agent::ParserContext::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition agent_lexer.cc:4136
exceptions.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition data.h:94