Kea  2.3.5-git
isc::d2::D2ParserContext Class Reference

Evaluation context, an interface to the expression evaluation. More...

#include <parser_context.h>

Public Types

enum  ParserContext {
  NO_KEYWORD, CONFIG, DHCPDDNS, TSIG_KEY,
  TSIG_KEYS, ALGORITHM, DIGEST_BITS, SECRET,
  FORWARD_DDNS, REVERSE_DDNS, DDNS_DOMAIN, DDNS_DOMAINS,
  DNS_SERVER, DNS_SERVERS, CONTROL_SOCKET, LOGGERS,
  OUTPUT_OPTIONS, NCR_PROTOCOL, NCR_FORMAT, HOOKS_LIBRARIES
}
 Defines syntactic contexts for lexical tie-ins. More...
 
enum  ParserType {
  PARSER_JSON, PARSER_DHCPDDNS, PARSER_SUB_DHCPDDNS, PARSER_TSIG_KEY,
  PARSER_TSIG_KEYS, PARSER_DDNS_DOMAIN, PARSER_DDNS_DOMAINS, PARSER_DNS_SERVER,
  PARSER_DNS_SERVERS, PARSER_HOOKS_LIBRARY
}
 Defines currently supported scopes. More...
 

Public Member Functions

 D2ParserContext ()
 Default constructor. More...
 
virtual ~D2ParserContext ()
 destructor. More...
 
const std::string contextName ()
 Get the syntax context name. More...
 
void enter (const ParserContext &ctx)
 Enter a new syntactic context. More...
 
void error (const isc::d2::location &loc, const std::string &what, size_t pos=0)
 Error handler. More...
 
void error (const std::string &what)
 Error handler. More...
 
void includeFile (const std::string &filename)
 Divert input to an include file. More...
 
void leave ()
 Leave a syntactic context. More...
 
isc::data::Element::Position loc2pos (isc::d2::location &loc)
 Converts bison's position to one understood by isc::data::Element. More...
 
isc::data::ElementPtr parseFile (const std::string &filename, ParserType parser_type)
 Run the parser on the file specified. More...
 
isc::data::ElementPtr parseString (const std::string &str, ParserType parser_type)
 Run the parser on the string specified. More...
 
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. More...
 
void scanEnd ()
 Method called after the last tokens are scanned. More...
 
void scanFileBegin (FILE *f, const std::string &filename, ParserType type)
 Method called before scanning starts on a file. More...
 
void scanStringBegin (const std::string &str, ParserType type)
 Method called before scanning starts on a string. More...
 
void unique (const std::string &name, isc::data::Element::Position loc)
 Check if a parameter is already present. More...
 
void warnAboutExtraCommas (const isc::d2::location &loc)
 Warning for extra commas. More...
 
void warning (const isc::d2::location &loc, const std::string &what)
 Warning handler. More...
 

Static Public Member Functions

static void fatal (const std::string &what)
 Fatal error handler. More...
 

Public Attributes

ParserContext ctx_
 Current syntactic context. More...
 
std::string file_
 File name. More...
 
std::vector< std::string > files_
 File name stack. More...
 
isc::d2::location loc_
 Location of the current token. More...
 
std::vector< isc::d2::location > locs_
 Location stack. More...
 
FILE * sfile_
 sFile (aka FILE) More...
 
std::vector< FILE * > sfiles_
 sFile (aka FILE) stack More...
 
std::vector< isc::data::ElementPtrstack_
 JSON elements being parsed. More...
 
std::vector< struct yy_buffer_state * > states_
 Lexer state stack. More...
 

Detailed Description

Evaluation context, an interface to the expression evaluation.

Definition at line 35 of file d2/parser_context.h.

Member Enumeration Documentation

◆ ParserContext

Defines syntactic contexts for lexical tie-ins.

Enumerator
NO_KEYWORD 

This one is used in pure JSON mode.

Used while parsing top level (contains DhcpDdns).

CONFIG 

Used while parsing content of DhcpDdns.

DHCPDDNS 

Used while parsing content of a tsig-key.

TSIG_KEY 

Used while parsing a list of tsig-keys.

TSIG_KEYS 

Used while parsing content of DhcpDdns/tsig-keys/algorithm.

ALGORITHM 

Used while parsing content of DhcpDdns/tsig-keys/digest-bits.

DIGEST_BITS 

Used while parsing content of DhcpDdns/tsig-keys/secret.

SECRET 

Used while parsing content of DhcpDdns/forward-ddns.

FORWARD_DDNS 

Used while parsing content of DhcpDdns/reverse-ddns.

REVERSE_DDNS 

Used while parsing content of a ddns-domain.

DDNS_DOMAIN 

Used while parsing a list of ddns-domains.

DDNS_DOMAINS 

Used while parsing content of a dns-server.

DNS_SERVER 

Used while parsing content of list of dns-servers.

DNS_SERVERS 

Used while parsing content of a control-socket.

CONTROL_SOCKET 
LOGGERS 

Used while parsing DhcpDdns/loggers structures.

OUTPUT_OPTIONS 

Used while parsing DhcpDdns/loggers/output_options structures.

NCR_PROTOCOL 

Used while parsing DhcpDdns/ncr-protocol.

NCR_FORMAT 

Used while parsing DhcpDdns/ncr-format.

HOOKS_LIBRARIES 

Used while parsing DhcpDdns/hooks-libraries.

Definition at line 214 of file d2/parser_context.h.

◆ ParserType

Defines currently supported scopes.

D2Parser may eventually support multiple levels of parsing scope. Currently it supports only the D2 module scope which expects the data to be parsed to be a map containing the DhcpDdns element and its constituents.

Enumerator
PARSER_JSON 

This parser will parse the content as generic JSON.

Used for parsing top level (contains DhcpDdns)

PARSER_DHCPDDNS 

Used for parsing content of DhcpDdns.

PARSER_SUB_DHCPDDNS 

Used for parsing content of a TSIG key.

PARSER_TSIG_KEY 

Used for parsing a list of TSIG Keys.

PARSER_TSIG_KEYS 

Used for parsing content of a DDNS Domain.

PARSER_DDNS_DOMAIN 

Used for parsing a list a DDNS Domains.

PARSER_DDNS_DOMAINS 

Used for parsing content of a DNS Server.

PARSER_DNS_SERVER 

Used for parsing a list of DNS servers.

PARSER_DNS_SERVERS 

Used for parsing content of hooks libraries.

PARSER_HOOKS_LIBRARY 

Definition at line 46 of file d2/parser_context.h.

Constructor & Destructor Documentation

◆ D2ParserContext()

isc::d2::D2ParserContext::D2ParserContext ( )

Default constructor.

Definition at line 22 of file d2/parser_context.cc.

◆ ~D2ParserContext()

isc::d2::D2ParserContext::~D2ParserContext ( )
virtual

destructor.

Definition at line 27 of file d2/parser_context.cc.

Member Function Documentation

◆ contextName()

const std::string isc::d2::D2ParserContext::contextName ( )

◆ enter()

void isc::d2::D2ParserContext::enter ( const ParserContext ctx)

Enter a new syntactic context.

Entering a new syntactic context is useful in several ways. First, it allows the parser to avoid conflicts. Second, it allows the lexer to return different tokens depending on context (e.g. if "name" string is detected, the lexer will return STRING token if in JSON mode or NAME if in TSIG_KEY mode. Finally, the syntactic context allows the error message to be more descriptive if the input string does not parse properly.

Parameters
ctxthe syntactic context to enter into

Definition at line 140 of file d2/parser_context.cc.

References ctx_.

Referenced by isc::d2::D2Parser::parse().

◆ error() [1/2]

void isc::d2::D2ParserContext::error ( const isc::d2::location &  loc,
const std::string &  what,
size_t  pos = 0 
)

Error handler.

Note
The optional position for an error in a string begins by 1 so the caller should add 1 to the position of the C++ string.
Parameters
loclocation within the parsed file where the problem was experienced.
whatstring explaining the nature of the error.
posoptional position for in string errors.
Exceptions
D2ParseError

Definition at line 74 of file d2/parser_context.cc.

References isc_throw.

◆ error() [2/2]

void isc::d2::D2ParserContext::error ( const std::string &  what)

Error handler.

This is a simplified error reporting tool for reporting parsing errors.

Parameters
whatstring explaining the nature of the error.
Exceptions
D2ParseError

Definition at line 86 of file d2/parser_context.cc.

References isc_throw.

◆ fatal()

void isc::d2::D2ParserContext::fatal ( const std::string &  what)
static

Fatal error handler.

This is for should not happen but fatal errors. Used by YY_FATAL_ERROR macro so required to be static.

Parameters
whatstring explaining the nature of the error.
Exceptions
D2ParseError

Definition at line 92 of file d2/parser_context.cc.

References isc_throw.

Referenced by leave().

◆ includeFile()

void D2ParserContext::includeFile ( const std::string &  filename)

Divert input to an include file.

Parameters
filenamefile to be included

Definition at line 3640 of file d2_lexer.cc.

References BEGIN, isc::db::fatal, INITIAL, and YY_CURRENT_BUFFER.

◆ leave()

void isc::d2::D2ParserContext::leave ( )

Leave a syntactic context.

Exceptions
isc::Unexpectedif unbalanced

Definition at line 147 of file d2/parser_context.cc.

References ctx_, and fatal().

Referenced by isc::d2::D2Parser::parse().

+ Here is the call graph for this function:

◆ loc2pos()

isc::data::Element::Position isc::d2::D2ParserContext::loc2pos ( isc::d2::location &  loc)

Converts bison's position to one understood by isc::data::Element.

Convert a bison location into an element position (take the begin, the end is lost)

Parameters
loclocation in bison format
Returns
Position in format accepted by Element

Definition at line 98 of file d2/parser_context.cc.

Referenced by isc::d2::D2Parser::parse().

◆ parseFile()

isc::data::ElementPtr isc::d2::D2ParserContext::parseFile ( const std::string &  filename,
ParserType  parser_type 
)

Run the parser on the file specified.

This method parses specified file. Depending on the value of parser_type, parser may either check only that the input is valid JSON, or may do more specific syntax checking. See ParserType for supported syntax checkers.

Parameters
filenamefile to be parsed
parser_typespecifies expected content
Returns
Element structure representing parsed text.

Definition at line 39 of file d2/parser_context.cc.

References isc_throw, isc::d2::D2Parser::parse(), scanEnd(), scanFileBegin(), isc::d2::D2Parser::set_debug_level(), and stack_.

+ Here is the call graph for this function:

◆ parseString()

isc::data::ElementPtr isc::d2::D2ParserContext::parseString ( const std::string &  str,
ParserType  parser_type 
)

Run the parser on the string specified.

This method parses specified string. Depending on the value of parser_type, parser may either check only that the input is valid JSON, or may do more specific syntax checking. See ParserType for supported syntax checkers.

Parameters
strstring to be parsed
parser_typespecifies expected content
Returns
Element structure representing parsed text.

Definition at line 32 of file d2/parser_context.cc.

References scanStringBegin().

+ Here is the call graph for this function:

◆ require()

void isc::d2::D2ParserContext::require ( const std::string &  name,
isc::data::Element::Position  open_loc,
isc::data::Element::Position  close_loc 
)

Check if a required parameter is present.

Check if a required parameter is present in the map at the top of the stack and raise an error when it is not.

Parameters
namename of the parameter to check
open_loclocation of the opening curly bracket
close_loclocation of the closing curly bracket
Exceptions
D2ParseError

Definition at line 107 of file d2/parser_context.cc.

References contextName(), isc_throw, and stack_.

Referenced by isc::d2::D2Parser::parse().

+ Here is the call graph for this function:

◆ scanEnd()

void D2ParserContext::scanEnd ( )

Method called after the last tokens are scanned.

Definition at line 3619 of file d2_lexer.cc.

Referenced by parseFile().

◆ scanFileBegin()

void D2ParserContext::scanFileBegin ( FILE *  f,
const std::string &  filename,
ParserType  type 
)

Method called before scanning starts on a file.

Parameters
fstdio FILE pointer
filenamefile to be parsed
typespecifies expected content

Definition at line 3597 of file d2_lexer.cc.

References isc::db::fatal, and yy_flex_debug.

Referenced by parseFile().

◆ scanStringBegin()

void D2ParserContext::scanStringBegin ( const std::string &  str,
ParserType  type 
)

Method called before scanning starts on a string.

Parameters
strstring to be parsed
typespecifies expected content

Definition at line 3579 of file d2_lexer.cc.

References isc::db::fatal, and yy_flex_debug.

Referenced by parseString().

◆ unique()

void isc::d2::D2ParserContext::unique ( const std::string &  name,
isc::data::Element::Position  loc 
)

Check if a parameter is already present.

Check if a parameter is already present in the map at the top of the stack and raise an error when it is.

Parameters
namename of the parameter to check
loclocation of the current parameter
Exceptions
D2ParseError

Definition at line 122 of file d2/parser_context.cc.

References contextName(), ctx_, isc_throw, NO_KEYWORD, and stack_.

Referenced by isc::d2::D2Parser::parse().

+ Here is the call graph for this function:

◆ warnAboutExtraCommas()

void isc::d2::D2ParserContext::warnAboutExtraCommas ( const isc::d2::location &  loc)

Warning for extra commas.

Parameters
loclocation within the parsed file of the extra comma
Exceptions
ParseError

Definition at line 216 of file d2/parser_context.cc.

References warning().

Referenced by isc::d2::D2Parser::parse().

+ Here is the call graph for this function:

◆ warning()

void isc::d2::D2ParserContext::warning ( const isc::d2::location &  loc,
const std::string &  what 
)

Warning handler.

Parameters
loclocation within the parsed file where the problem was experienced
whatstring explaining the nature of the error
Exceptions
ParseError

Definition at line 207 of file d2/parser_context.cc.

References isc::d2::d2_to_dns_logger, isc::d2::DHCP_DDNS_CONFIG_SYNTAX_WARNING, and LOG_WARN.

Referenced by warnAboutExtraCommas().

Member Data Documentation

◆ ctx_

ParserContext isc::d2::D2ParserContext::ctx_

Current syntactic context.

Definition at line 306 of file d2/parser_context.h.

Referenced by contextName(), enter(), leave(), isc::d2::D2Parser::parse(), and unique().

◆ file_

std::string isc::d2::D2ParserContext::file_

File name.

Definition at line 278 of file d2/parser_context.h.

◆ files_

std::vector<std::string> isc::d2::D2ParserContext::files_

File name stack.

Definition at line 281 of file d2/parser_context.h.

◆ loc_

isc::d2::location isc::d2::D2ParserContext::loc_

Location of the current token.

The lexer will keep updating it. This variable will be useful for logging errors.

Definition at line 287 of file d2/parser_context.h.

◆ locs_

std::vector<isc::d2::location> isc::d2::D2ParserContext::locs_

Location stack.

Definition at line 290 of file d2/parser_context.h.

◆ sfile_

FILE* isc::d2::D2ParserContext::sfile_

sFile (aka FILE)

Definition at line 296 of file d2/parser_context.h.

◆ sfiles_

std::vector<FILE*> isc::d2::D2ParserContext::sfiles_

sFile (aka FILE) stack

This is a stack of files. Typically there's only one file (the one being currently parsed), but there may be more if one file includes another.

Definition at line 303 of file d2/parser_context.h.

◆ stack_

std::vector<isc::data::ElementPtr> isc::d2::D2ParserContext::stack_

JSON elements being parsed.

Definition at line 85 of file d2/parser_context.h.

Referenced by isc::d2::D2Parser::parse(), parseFile(), require(), and unique().

◆ states_

std::vector<struct yy_buffer_state*> isc::d2::D2ParserContext::states_

Lexer state stack.

Definition at line 293 of file d2/parser_context.h.


The documentation for this class was generated from the following files: