Kea  1.5.0
netconf/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2018 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 NETCONF_PARSER_CONTEXT_H
8 #define NETCONF_PARSER_CONTEXT_H
9 #include <string>
10 #include <map>
11 #include <vector>
12 #include <netconf/netconf_parser.h>
14 #include <cc/dhcp_config_error.h>
15 #include <exceptions/exceptions.h>
16 
17 // Tell Flex the lexer's prototype ...
18 #define YY_DECL isc::netconf::NetconfParser::symbol_type netconf_lex (ParserContext& driver)
19 
20 // ... and declare it for the parser's sake.
22 
23 namespace isc {
24 namespace netconf {
25 
38 {
39 public:
40 
48  typedef enum {
51 
55 
59 
61  ParserContext();
62 
64  virtual ~ParserContext();
65 
67  std::vector<isc::data::ElementPtr> stack_;
68 
73  void scanStringBegin(const std::string& str, ParserType type);
74 
80  void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
81 
83  void scanEnd();
84 
88  void includeFile(const std::string& filename);
89 
100  isc::data::ElementPtr parseString(const std::string& str,
101  ParserType parser_type);
102 
114  isc::data::ElementPtr parseFile(const std::string& filename,
115  ParserType parser_type);
116 
122  void error(const isc::netconf::location& loc, const std::string& what);
123 
131  void error(const std::string& what);
132 
140  static void fatal(const std::string& what);
141 
149  isc::data::Element::Position loc2pos(isc::netconf::location& loc);
150 
160  void require(const std::string& name,
162  isc::data::Element::Position close_loc);
163 
165  typedef enum {
167  NO_KEYWORDS,
168 
170  CONFIG,
171 
173  NETCONF,
174 
177 
180 
182  SERVER,
183 
186 
188  SOCKET_TYPE,
189 
192 
194  LOGGERS,
195 
198 
200 
202  std::string file_;
203 
205  std::vector<std::string> files_;
206 
211  isc::netconf::location loc_;
212 
214  std::vector<isc::netconf::location> locs_;
215 
217  std::vector<struct yy_buffer_state*> states_;
218 
220  FILE* sfile_;
221 
227  std::vector<FILE*> sfiles_;
228 
231 
249  void enter(const LexerContext& ctx);
250 
258  void leave();
259 
263  const std::string contextName();
264 
265  private:
267  bool trace_scanning_;
268 
270  bool trace_parsing_;
271 
273  std::vector<LexerContext> cstack_;
274 
278  isc::data::ElementPtr parseCommon();
279 };
280 
281 }; // end of isc::netconf namespace
282 }; // end of isc namespace
283 
284 #endif
isc::netconf::ParserContext::enter
void enter(const LexerContext &ctx)
Enter a new syntactic context.
Definition: netconf/parser_context.cc:115
isc::netconf::ParserContext::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition: netconf/parser_context.cc:30
isc::netconf::ParserContext::sfile_
FILE * sfile_
sFile (aka FILE)
Definition: netconf/parser_context.h:220
isc::netconf::ParserContext::MANAGED_SERVERS
@ MANAGED_SERVERS
Used while parsing Netconf/managed-servers.
Definition: netconf/parser_context.h:179
isc::netconf::ParserContext::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition: netconf/parser_context.h:67
isc::netconf::ParserContext::LOGGING
@ LOGGING
Definition: netconf/parser_context.h:176
isc::netconf::ParserContext::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition: netconf_lexer.cc:3846
isc::netconf::ParserContext::LexerContext
LexerContext
Defines syntactic contexts for lexical tie-ins.
Definition: netconf/parser_context.h:165
isc::netconf::ParserContext::NETCONF
@ NETCONF
Used while parsing content of Logging.
Definition: netconf/parser_context.h:173
dhcp_config_error.h
isc::netconf::ParserContext::ParserType
ParserType
Defines currently supported scopes.
Definition: netconf/parser_context.h:48
isc::netconf::ParserContext::SERVER
@ SERVER
Used while parsing Netconf/manages-servers/*‍/control-socket.
Definition: netconf/parser_context.h:182
isc::netconf::ParserContext
Parser context is a wrapper around flex/bison instances dedicated to Netconf-agent config file parser...
Definition: netconf/parser_context.h:38
isc::netconf::ParserContext::SOCKET_TYPE
@ SOCKET_TYPE
Used while parsing Netconf/hooks-libraries.
Definition: netconf/parser_context.h:188
isc::netconf::ParserContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition: netconf/parser_context.cc:85
isc::netconf::ParserContext::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Logging/loggers structures.
Definition: netconf/parser_context.h:191
parser_context_decl.h
isc::netconf::ParserContext::PARSER_NETCONF
@ PARSER_NETCONF
This parser will expect the content as Netconf config wrapped in a map (that's the regular config fil...
Definition: netconf/parser_context.h:54
isc::netconf::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: netconf/parser_context.cc:100
isc::netconf::ParserContext::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition: netconf/parser_context.h:50
isc::netconf::ParserContext::~ParserContext
virtual ~ParserContext()
destructor
Definition: netconf/parser_context.cc:25
isc::netconf::ParserContext::ParserContext
ParserContext()
Default constructor.
Definition: netconf/parser_context.cc:20
isc::netconf::ParserContext::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition: netconf/parser_context.h:217
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::netconf::ParserContext::NO_KEYWORDS
@ NO_KEYWORDS
This one is used in pure JSON mode.
Definition: netconf/parser_context.h:167
isc::netconf::ParserContext::error
void error(const isc::netconf::location &loc, const std::string &what)
Error handler.
Definition: netconf/parser_context.cc:73
isc::netconf::ParserContext::PARSER_SUB_NETCONF
@ PARSER_SUB_NETCONF
This parser will expect only the content of Netconf.
Definition: netconf/parser_context.h:57
isc::netconf::ParserContext::ctx_
LexerContext ctx_
Current syntactic context.
Definition: netconf/parser_context.h:230
isc::netconf::ParserContext::files_
std::vector< std::string > files_
File name stack.
Definition: netconf/parser_context.h:205
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition: data.h:88
isc::netconf::ParserContext::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition: netconf_lexer.cc:3803
isc::netconf::ParserContext::contextName
const std::string contextName()
Get the syntactic context name.
Definition: netconf/parser_context.cc:132
isc::netconf::ParserContext::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition: netconf_lexer.cc:3785
isc::netconf::ParserContext::loc_
isc::netconf::location loc_
Location of the current token.
Definition: netconf/parser_context.h:211
YY_DECL
#define YY_DECL
Definition: netconf/parser_context.h:18
isc::netconf::ParserContext::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Definition: netconf/parser_context.h:197
isc::netconf::ParserContext::CONTROL_SOCKET
@ CONTROL_SOCKET
Used while parsing Netconf/managed-servers/*‍/control-socket/socket-type.
Definition: netconf/parser_context.h:185
isc::netconf::ParserContext::loc2pos
isc::data::Element::Position loc2pos(isc::netconf::location &loc)
Converts bison's position to one understandable by isc::data::Element.
Definition: netconf/parser_context.cc:91
isc::netconf::ParserContext::locs_
std::vector< isc::netconf::location > locs_
Location stack.
Definition: netconf/parser_context.h:214
exceptions.h
isc::netconf::ParserContext::file_
std::string file_
File name.
Definition: netconf/parser_context.h:202
isc::netconf::ParserContext::LOGGERS
@ LOGGERS
Used while parsing Logging/loggers/output_options structures.
Definition: netconf/parser_context.h:194
netconf_parser.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::netconf::ParserContext::CONFIG
@ CONFIG
Used while parsing content of Netconf.
Definition: netconf/parser_context.h:170
isc::netconf::ParserContext::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition: netconf_lexer.cc:3825
isc::netconf::ParserContext::leave
void leave()
Leave a syntactic context.
Definition: netconf/parser_context.cc:122
isc::netconf::ParserContext::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition: netconf/parser_context.cc:37
isc::netconf::ParserContext::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition: netconf/parser_context.h:227