Kea 2.7.5
|
Evaluation context, an interface to the expression evaluation. More...
#include <parser_context.h>
Public Member Functions | |
Parser6Context () | |
Default constructor. | |
virtual | ~Parser6Context () |
destructor | |
const std::string | contextName () |
Get the syntactic context name. | |
void | enter (const ParserContext &ctx) |
Enter a new syntactic context. | |
void | error (const isc::dhcp::location &loc, const std::string &what, size_t pos=0) |
Error handler. | |
void | error (const std::string &what) |
Error handler. | |
void | includeFile (const std::string &filename) |
Divert input to an include file. | |
void | leave () |
Leave a syntactic context. | |
isc::data::Element::Position | loc2pos (isc::dhcp::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. | |
isc::data::ElementPtr | parseString (const std::string &str, ParserType parser_type) |
Run the parser on the string specified. | |
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. | |
void | scanEnd () |
Method called after the last tokens are scanned. | |
void | scanFileBegin (FILE *f, const std::string &filename, ParserType type) |
Method called before scanning starts on a file. | |
void | scanStringBegin (const std::string &str, ParserType type) |
Method called before scanning starts on a string. | |
void | unique (const std::string &name, isc::data::Element::Position loc) |
Check if a parameter is already present. | |
void | warnAboutExtraCommas (const isc::dhcp::location &loc) |
Warning for extra commas. | |
void | warning (const isc::dhcp::location &loc, const std::string &what) |
Warning handler. | |
Static Public Member Functions | |
static void | fatal (const std::string &what) |
Fatal error handler. | |
Public Attributes | |
ParserContext | ctx_ |
Current syntactic context. | |
std::string | file_ |
File name. | |
std::vector< std::string > | files_ |
File name stack. | |
isc::dhcp::location | loc_ |
Location of the current token. | |
std::vector< isc::dhcp::location > | locs_ |
Location stack. | |
FILE * | sfile_ |
sFile (aka FILE) | |
std::vector< FILE * > | sfiles_ |
sFile (aka FILE) stack | |
std::vector< isc::data::ElementPtr > | stack_ |
JSON elements being parsed. | |
std::vector< struct yy_buffer_state * > | states_ |
Lexer state stack. | |
Evaluation context, an interface to the expression evaluation.
Definition at line 35 of file dhcp6/parser_context.h.
Defines syntactic contexts for lexical tie-ins.
Definition at line 233 of file dhcp6/parser_context.h.
Defines currently supported scopes.
Dhcp6Parser is able to parse several types of scope. Usually, when it parses a config file, it expects the data to have a map with Dhcp6 in it and all the parameters within that Dhcp6 map. However, sometimes the parser is expected to parse only a subset of that information. For example, it may be asked to parse a structure that is host-reservation only, without the global 'Dhcp6' or 'reservations' around it. In such case the parser is being told to start parsing as PARSER_HOST_RESERVATION6.
Enumerator | |
---|---|
PARSER_JSON | This parser will parse the content as generic JSON. |
PARSER_DHCP6 | This parser will parse the content as Dhcp6 config wrapped in a map (that's the regular config file) |
SUBPARSER_DHCP6 | This parser will parse the content of Dhcp6 (without outer { } and without "Dhcp6"). It is mostly used in unit-tests as most of the unit-tests do not define the outer map and Dhcp6 entity, just the contents of it. |
PARSER_INTERFACES | This will parse the input as interfaces content. |
PARSER_SUBNET6 | This will parse the input as Subnet6 content. |
PARSER_POOL6 | This will parse the input as pool6 content. |
PARSER_PD_POOL | This will parse the input as pd-pool content. |
PARSER_HOST_RESERVATION | This will parse the input as host-reservation. |
PARSER_OPTION_DEFS | This will parse the input option definitions (for tests). |
PARSER_OPTION_DEF | This will parse the input as option definition. |
PARSER_OPTION_DATA | This will parse the input as option data. |
PARSER_HOOKS_LIBRARY | This will parse the input as hooks-library. |
PARSER_DHCP_DDNS | This will parse the input as dhcp-ddns. (D2 client config) |
PARSER_CONFIG_CONTROL | This will parse the input as config-control. |
Definition at line 49 of file dhcp6/parser_context.h.
isc::dhcp::Parser6Context::Parser6Context | ( | ) |
Default constructor.
Definition at line 22 of file dhcp6/parser_context.cc.
|
virtual |
destructor
Definition at line 27 of file dhcp6/parser_context.cc.
const std::string isc::dhcp::Parser6Context::contextName | ( | ) |
Get the syntactic context name.
Definition at line 148 of file dhcp6/parser_context.cc.
References AUTH_TYPE, AUTHENTICATION, CLIENT_CLASSES, CLIENTS, COMPATIBILITY, CONFIG, CONFIG_CONTROL, CONFIG_DATABASE, CONTROL_SOCKET, CONTROL_SOCKET_TYPE, ctx_, DATABASE_ON_FAIL, DDNS_CONFLICT_RESOLUTION_MODE, DHCP6, DHCP_DDNS, DHCP_MULTI_THREADING, DHCP_QUEUE_CONTROL, DUID_TYPE, EXPIRED_LEASES_PROCESSING, HOOKS_LIBRARIES, HOST_RESERVATION_IDENTIFIERS, HOSTS_DATABASE, HTTP_HEADERS, INTERFACES_CONFIG, LEASE_DATABASE, LOGGERS, MAC_SOURCES, NCR_FORMAT, NCR_PROTOCOL, NO_KEYWORD, OPTION_DATA, OPTION_DEF, OUTPUT_OPTIONS, PD_POOLS, POOLS, RELAY, REPLACE_CLIENT_NAME, RESERVATIONS, SANITY_CHECKS, SERVER_ID, SHARED_NETWORK, and SUBNET6.
Referenced by isc::dhcp::Dhcp6Parser::parse(), require(), and unique().
void isc::dhcp::Parser6Context::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 "renew-timer" string is detected, the lexer will return STRING token if in JSON mode or RENEW_TIMER if in DHCP6 mode. Finally, the syntactic context allows the error message to be more descriptive if the input string does not parse properly.
ctx | the syntactic context to enter into |
Definition at line 131 of file dhcp6/parser_context.cc.
References ctx_.
Referenced by isc::dhcp::Dhcp6Parser::parse().
void isc::dhcp::Parser6Context::error | ( | const isc::dhcp::location & | loc, |
const std::string & | what, | ||
size_t | pos = 0 ) |
Error handler.
loc | location within the parsed file where the problem was experienced. |
what | string explaining the nature of the error. |
pos | optional position for in string errors. |
Dhcp6ParseError |
Definition at line 71 of file dhcp6/parser_context.cc.
References isc_throw.
void isc::dhcp::Parser6Context::error | ( | const std::string & | what | ) |
Error handler.
This is a simplified error reporting tool for possible future cases when the Dhcp6Parser is not able to handle the packet.
what | string explaining the nature of the error. |
Dhcp6ParseError |
Definition at line 82 of file dhcp6/parser_context.cc.
References isc_throw.
|
static |
Fatal error handler.
This is for should not happen but fatal errors. Used by YY_FATAL_ERROR macro so required to be static.
what | string explaining the nature of the error. |
Dhcp6ParseError |
Definition at line 87 of file dhcp6/parser_context.cc.
References isc_throw.
void Parser6Context::includeFile | ( | const std::string & | filename | ) |
Divert input to an include file.
filename | file to be included |
Definition at line 7016 of file dhcp6_lexer.cc.
References BEGIN, isc::db::fatal, file_, files_, INITIAL, loc_, locs_, sfile_, sfiles_, states_, and YY_CURRENT_BUFFER.
void isc::dhcp::Parser6Context::leave | ( | ) |
Leave a syntactic context.
isc::Unexpected | if unbalanced |
Definition at line 137 of file dhcp6/parser_context.cc.
References ctx_, and isc::db::fatal.
Referenced by isc::dhcp::Dhcp6Parser::parse().
isc::data::Element::Position isc::dhcp::Parser6Context::loc2pos | ( | isc::dhcp::location & | loc | ) |
Converts bison's position to one understandable by isc::data::Element.
Convert a bison location into an element position (take the begin, the end is lost)
loc | location in bison format |
Definition at line 92 of file dhcp6/parser_context.cc.
Referenced by isc::dhcp::Dhcp6Parser::parse().
isc::data::ElementPtr isc::dhcp::Parser6Context::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.
filename | file to be parsed |
parser_type | specifies expected content (usually DHCP6 or generic JSON) |
Definition at line 37 of file dhcp6/parser_context.cc.
References isc_throw, and scanFileBegin().
Referenced by isc::dhcp::ControlledDhcpv6Srv::loadConfigFile(), and main().
isc::data::ElementPtr isc::dhcp::Parser6Context::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.
str | string to be parsed |
parser_type | specifies expected content (usually DHCP6 or generic JSON) |
Definition at line 31 of file dhcp6/parser_context.cc.
References scanStringBegin().
void isc::dhcp::Parser6Context::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.
name | name of the parameter expected to be present |
open_loc | location of the opening curly bracket |
close_loc | location of the closing curly bracket |
Dhcp6ParseError |
Definition at line 100 of file dhcp6/parser_context.cc.
References contextName(), isc_throw, and stack_.
Referenced by isc::dhcp::Dhcp6Parser::parse().
void Parser6Context::scanEnd | ( | ) |
Method called after the last tokens are scanned.
Definition at line 6995 of file dhcp6_lexer.cc.
void Parser6Context::scanFileBegin | ( | FILE * | f, |
const std::string & | filename, | ||
ParserType | type ) |
Method called before scanning starts on a file.
f | stdio FILE pointer |
filename | file to be parsed |
type | specifies expected content |
Definition at line 6973 of file dhcp6_lexer.cc.
References isc::db::fatal, file_, loc_, sfile_, and yy_flex_debug.
Referenced by parseFile().
void Parser6Context::scanStringBegin | ( | const std::string & | str, |
ParserType | type ) |
Method called before scanning starts on a string.
str | string to be parsed |
type | specifies expected content |
Definition at line 6955 of file dhcp6_lexer.cc.
References isc::db::fatal, file_, loc_, sfile_, and yy_flex_debug.
Referenced by parseString().
void isc::dhcp::Parser6Context::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.
name | name of the parameter to check |
loc | location of the current parameter |
Dhcp6ParseError |
Definition at line 114 of file dhcp6/parser_context.cc.
References contextName(), ctx_, isc_throw, NO_KEYWORD, and stack_.
Referenced by isc::dhcp::Dhcp6Parser::parse().
void isc::dhcp::Parser6Context::warnAboutExtraCommas | ( | const isc::dhcp::location & | loc | ) |
Warning for extra commas.
loc | location within the parsed file of the extra comma |
ParseError |
Definition at line 247 of file dhcp6/parser_context.cc.
References warning().
Referenced by isc::dhcp::Dhcp6Parser::parse().
void isc::dhcp::Parser6Context::warning | ( | const isc::dhcp::location & | loc, |
const std::string & | what ) |
Warning handler.
loc | location within the parsed file where the problem was experienced |
what | string explaining the nature of the error |
ParseError |
Definition at line 238 of file dhcp6/parser_context.cc.
References isc::dhcp::DHCP6_CONFIG_SYNTAX_WARNING, isc::dhcp::dhcp6_logger, and LOG_WARN.
Referenced by isc::dhcp::Dhcp6Parser::parse(), and warnAboutExtraCommas().
ParserContext isc::dhcp::Parser6Context::ctx_ |
Current syntactic context.
Definition at line 391 of file dhcp6/parser_context.h.
Referenced by contextName(), enter(), leave(), isc::dhcp::Dhcp6Parser::parse(), and unique().
std::string isc::dhcp::Parser6Context::file_ |
File name.
Definition at line 363 of file dhcp6/parser_context.h.
Referenced by includeFile(), scanFileBegin(), and scanStringBegin().
std::vector<std::string> isc::dhcp::Parser6Context::files_ |
File name stack.
Definition at line 366 of file dhcp6/parser_context.h.
Referenced by includeFile().
isc::dhcp::location isc::dhcp::Parser6Context::loc_ |
Location of the current token.
The lexer will keep updating it. This variable will be useful for logging errors.
Definition at line 372 of file dhcp6/parser_context.h.
Referenced by includeFile(), scanFileBegin(), and scanStringBegin().
std::vector<isc::dhcp::location> isc::dhcp::Parser6Context::locs_ |
FILE* isc::dhcp::Parser6Context::sfile_ |
sFile (aka FILE)
Definition at line 381 of file dhcp6/parser_context.h.
Referenced by includeFile(), scanEnd(), scanFileBegin(), and scanStringBegin().
std::vector<FILE*> isc::dhcp::Parser6Context::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 388 of file dhcp6/parser_context.h.
Referenced by includeFile(), and scanEnd().
std::vector<isc::data::ElementPtr> isc::dhcp::Parser6Context::stack_ |
JSON elements being parsed.
Definition at line 104 of file dhcp6/parser_context.h.
Referenced by isc::dhcp::Dhcp6Parser::parse(), require(), and unique().
std::vector<struct yy_buffer_state*> isc::dhcp::Parser6Context::states_ |
Lexer state stack.
Definition at line 378 of file dhcp6/parser_context.h.
Referenced by includeFile(), and scanEnd().