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>
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.
21 
22 namespace isc {
23 namespace agent {
24 
37 {
38 public:
39 
47  typedef enum {
50 
54 
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 
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 {
153  NO_KEYWORDS,
154 
156  CONFIG,
157 
159  AGENT,
160 
162  LOGGING,
163 
166 
168  SERVER,
169 
171  SOCKET_TYPE,
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
isc::agent::ParserContext::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Definition: agent/parser_context.h:180
isc::agent::ParserContext::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition: agent_lexer.cc:3635
isc::agent::ParserContext::NO_KEYWORDS
@ NO_KEYWORDS
This one is used in pure JSON mode.
Definition: agent/parser_context.h:153
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:30
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:37
isc::agent::ParserContext::leave
void leave()
Leave a syntactic context.
Definition: agent/parser_context.cc:107
isc::agent::ParserContext::enter
void enter(const LexerContext &ctx)
Enter a new syntactic context.
Definition: agent/parser_context.cc:100
isc::agent::ParserContext::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition: agent/parser_context.h:210
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:3653
YY_DECL
#define YY_DECL
Definition: agent/parser_context.h:17
isc::agent::ParserContext::ParserContext
ParserContext()
Default constructor.
Definition: agent/parser_context.cc:20
isc::agent::ParserContext::ParserType
ParserType
Defines currently supported scopes.
Definition: agent/parser_context.h:47
isc::agent::ParserContext::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition: agent/parser_context.h:200
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:91
isc::agent::ParserContext::AGENT
@ AGENT
Used while parsing content of Logging.
Definition: agent/parser_context.h:159
isc::agent::ParserContext::contextName
const std::string contextName()
Get the syntactic context name.
Definition: agent/parser_context.cc:117
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::agent::ParserContext::loc_
isc::agent::location loc_
Location of the current token.
Definition: agent/parser_context.h:194
isc::agent::ParserContext::locs_
std::vector< isc::agent::location > locs_
Location stack.
Definition: agent/parser_context.h:197
isc::agent::ParserContext::error
void error(const isc::agent::location &loc, const std::string &what)
Error handler.
Definition: agent/parser_context.cc:73
isc::agent::ParserContext::LOGGERS
@ LOGGERS
Used while parsing Logging/loggers/output_options structures.
Definition: agent/parser_context.h:177
parser_context_decl.h
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition: data.h:88
isc::agent::ParserContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition: agent/parser_context.cc:85
isc::agent::ParserContext::SOCKET_TYPE
@ SOCKET_TYPE
Used while parsing Control-agent/hooks-libraries.
Definition: agent/parser_context.h:171
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::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
agent_parser.h
isc::agent::ParserContext::SERVER
@ SERVER
Used while parsing Control-agent/control-socket/*-server/socket-type.
Definition: agent/parser_context.h:168
isc::agent::ParserContext::sfile_
FILE * sfile_
sFile (aka FILE)
Definition: agent/parser_context.h:203
isc::agent::ParserContext::files_
std::vector< std::string > files_
File name stack.
Definition: agent/parser_context.h:188
isc::agent::ParserContext::CONFIG
@ CONFIG
Used while parsing content of Agent.
Definition: agent/parser_context.h:156
exceptions.h
isc::agent::ParserContext::file_
std::string file_
File name.
Definition: agent/parser_context.h:185
isc::agent::ParserContext::LexerContext
LexerContext
Defines syntactic contexts for lexical tie-ins.
Definition: agent/parser_context.h:151
isc::agent::ParserContext::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition: agent_lexer.cc:3675
isc::agent::ParserContext::ctx_
LexerContext ctx_
Current syntactic context.
Definition: agent/parser_context.h:213
isc::agent::ParserContext::~ParserContext
virtual ~ParserContext()
destructor
Definition: agent/parser_context.cc:25
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::agent::ParserContext::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Logging/loggers structures.
Definition: agent/parser_context.h:174
isc::agent::ParserContext
Parser context is a wrapper around flex/bison instances dedicated to Control-agent config file parser...
Definition: agent/parser_context.h:37
isc::agent::ParserContext::CONTROL_SOCKETS
@ CONTROL_SOCKETS
Used while parsing Control-agent/control-socket/*-server.
Definition: agent/parser_context.h:165
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::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition: agent_lexer.cc:3696
isc::agent::ParserContext::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition: agent/parser_context.h:66
isc::agent::ParserContext::LOGGING
@ LOGGING
Used while parsing Control-agent/control-sockets.
Definition: agent/parser_context.h:162