Kea 1.5.0
agent/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 <agent/agent_parser.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.
21
22namespace isc {
23namespace agent {
24
37{
38public:
39
47 typedef enum {
50
54
58
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
121 void error(const isc::agent::location& loc, const std::string& what);
122
130 void error(const std::string& what);
131
139 static void fatal(const std::string& what);
140
148 isc::data::Element::Position loc2pos(isc::agent::location& loc);
149
151 typedef enum {
154
156 CONFIG,
157
159 AGENT,
160
162 LOGGING,
163
166
168 SERVER,
169
172
175
177 LOGGERS,
178
181
183
185 std::string file_;
186
188 std::vector<std::string> files_;
189
194 isc::agent::location loc_;
195
197 std::vector<isc::agent::location> locs_;
198
200 std::vector<struct yy_buffer_state*> states_;
201
203 FILE* sfile_;
204
210 std::vector<FILE*> sfiles_;
211
214
232 void enter(const LexerContext& ctx);
233
241 void leave();
242
246 const std::string contextName();
247
248 private:
250 bool trace_scanning_;
251
253 bool trace_parsing_;
254
256 std::vector<LexerContext> cstack_;
257
261 isc::data::ElementPtr parseCommon();
262};
263
264}; // end of isc::eval namespace
265}; // end of isc namespace
266
267#endif
#define YY_DECL
Forward declaration of the ParserContext class.
Define the isc::agent::parser class.
Parser context is a wrapper around flex/bison instances dedicated to Control-agent config file parser...
std::vector< isc::agent::location > locs_
Location stack.
std::vector< std::string > files_
File name stack.
void error(const isc::agent::location &loc, const std::string &what)
Error handler.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
ParserContext()
Default constructor.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
static void fatal(const std::string &what)
Fatal error handler.
virtual ~ParserContext()
destructor
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
isc::agent::location loc_
Location of the current token.
const std::string contextName()
Get the syntactic context name.
std::string file_
File name.
void includeFile(const std::string &filename)
Divert input to an include file.
isc::data::Element::Position loc2pos(isc::agent::location &loc)
Converts bison's position to one understandable by isc::data::Element.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
LexerContext ctx_
Current syntactic context.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
void leave()
Leave a syntactic context.
LexerContext
Defines syntactic contexts for lexical tie-ins.
@ CONFIG
Used while parsing content of Agent.
@ SERVER
Used while parsing Control-agent/control-socket/*-server/socket-type.
@ NO_KEYWORDS
This one is used in pure JSON mode.
@ HOOKS_LIBRARIES
Used while parsing Logging/loggers structures.
@ CONTROL_SOCKETS
Used while parsing Control-agent/control-socket/*-server.
@ SOCKET_TYPE
Used while parsing Control-agent/hooks-libraries.
@ AGENT
Used while parsing content of Logging.
@ LOGGING
Used while parsing Control-agent/control-sockets.
@ LOGGERS
Used while parsing Logging/loggers/output_options structures.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
ParserType
Defines currently supported scopes.
@ PARSER_AGENT
This parser will expect the content as Control-agent config wrapped in a map (that's the regular conf...
@ PARSER_JSON
This parser will parse the content as generic JSON.
@ PARSER_SUB_AGENT
This parser will expect only the content of Control-agent.
void enter(const LexerContext &ctx)
Enter a new syntactic context.
FILE * sfile_
sFile (aka FILE)
void scanEnd()
Method called after the last tokens are scanned.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
Defines the logger used by the top-level component of kea-dhcp-ddns.
Represents the position of the data element within a configuration string.
Definition: data.h:88