Kea  1.9.9-git
agent/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2020 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 
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,
167  isc::data::Element::Position close_loc);
168 
177  void unique(const std::string& name,
179 
181  typedef enum {
184 
187 
190 
193 
196 
199 
202 
205 
208 
211 
214 
217  } LexerContext;
218 
220  std::string file_;
221 
223  std::vector<std::string> files_;
224 
229  isc::agent::location loc_;
230 
232  std::vector<isc::agent::location> locs_;
233 
235  std::vector<struct yy_buffer_state*> states_;
236 
238  FILE* sfile_;
239 
245  std::vector<FILE*> sfiles_;
246 
249 
267  void enter(const LexerContext& ctx);
268 
276  void leave();
277 
281  const std::string contextName();
282 
283  private:
285  bool trace_scanning_;
286 
288  bool trace_parsing_;
289 
291  std::vector<LexerContext> cstack_;
292 
296  isc::data::ElementPtr parseCommon();
297 };
298 
299 } // end of isc::eval namespace
300 } // end of isc namespace
301 
302 #endif
Used while parsing Control-agent/Authentication/type.
Used while parsing content of Agent.
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
static void fatal(const std::string &what)
Fatal error handler.
#define YY_DECL
void enter(const LexerContext &ctx)
Enter a new syntactic context.
ParserType
Defines currently supported scopes.
LexerContext ctx_
Current syntactic context.
Used while parsing Control-agent/control-socket/*-server/socket-type.
This parser will parse the content as generic JSON.
void includeFile(const std::string &filename)
Divert input to an include file.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::agent::location loc_
Location of the current token.
FILE * sfile_
sFile (aka FILE)
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Used while parsing Control-agent/loggers structures.
ParserContext()
Default constructor.
LexerContext
Defines syntactic contexts for lexical tie-ins.
Forward declaration of the ParserContext class.
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.
isc::data::Element::Position loc2pos(isc::agent::location &loc)
Converts bison's position to one understandable by isc::data::Element.
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
const std::string contextName()
Get the syntactic context name.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
void leave()
Leave a syntactic context.
Used while parsing Control-agent/loggers/output_options structures.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Represents the position of the data element within a configuration string.
Definition: data.h:88
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
This one is used in pure JSON mode.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::vector< std::string > files_
File name stack.
Define the isc::agent::parser class.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
std::string file_
File name.
void scanEnd()
Method called after the last tokens are scanned.
This parser will expect only the content of Control-agent.
This parser will expect the content as Control-agent config wrapped in a map (that's the regular conf...
Used while parsing Control-agent/hooks-libraries.
std::vector< isc::agent::location > locs_
Location stack.
Used while parsing Control-agent/control-sockets.
Used while parsing Control-agent/Authentication.
Used while parsing Control-agent/Authentication/clients.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Parser context is a wrapper around flex/bison instances dedicated to Control-agent config file parser...
Used while parsing Control-agent/control-socket/*-server.
virtual ~ParserContext()
destructor
void error(const isc::agent::location &loc, const std::string &what, size_t pos=0)
Error handler.