Kea 2.7.4
|
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 , CONTROL_SOCKET_TYPE , AUTHENTICATION , AUTH_TYPE , CLIENTS , 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. | |
virtual | ~D2ParserContext () |
destructor. | |
const std::string | contextName () |
Get the syntax context name. | |
void | enter (const ParserContext &ctx) |
Enter a new syntactic context. | |
void | error (const isc::d2::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::d2::location &loc) |
Converts bison's position to one understood 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::d2::location &loc) |
Warning for extra commas. | |
void | warning (const isc::d2::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::d2::location | loc_ |
Location of the current token. | |
std::vector< isc::d2::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 d2/parser_context.h.
Defines syntactic contexts for lexical tie-ins.
Definition at line 214 of file d2/parser_context.h.
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.
Definition at line 46 of file d2/parser_context.h.
isc::d2::D2ParserContext::D2ParserContext | ( | ) |
Default constructor.
Definition at line 22 of file d2/parser_context.cc.
|
virtual |
destructor.
Definition at line 27 of file d2/parser_context.cc.
const std::string isc::d2::D2ParserContext::contextName | ( | ) |
Get the syntax context name.
Definition at line 157 of file d2/parser_context.cc.
References ALGORITHM, AUTH_TYPE, AUTHENTICATION, CLIENTS, CONFIG, CONTROL_SOCKET, CONTROL_SOCKET_TYPE, ctx_, DDNS_DOMAIN, DDNS_DOMAINS, DHCPDDNS, DIGEST_BITS, DNS_SERVER, DNS_SERVERS, FORWARD_DDNS, HOOKS_LIBRARIES, LOGGERS, NCR_FORMAT, NCR_PROTOCOL, NO_KEYWORD, OUTPUT_OPTIONS, REVERSE_DDNS, SECRET, TSIG_KEY, and TSIG_KEYS.
Referenced by isc::d2::D2Parser::parse(), require(), and unique().
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.
ctx | the syntactic context to enter into |
Definition at line 139 of file d2/parser_context.cc.
References ctx_.
Referenced by isc::d2::D2Parser::parse().
void isc::d2::D2ParserContext::error | ( | const isc::d2::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. |
D2ParseError |
Definition at line 73 of file d2/parser_context.cc.
References isc_throw.
void isc::d2::D2ParserContext::error | ( | const std::string & | what | ) |
Error handler.
This is a simplified error reporting tool for reporting parsing errors.
what | string explaining the nature of the error. |
D2ParseError |
Definition at line 85 of file d2/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. |
D2ParseError |
Definition at line 91 of file d2/parser_context.cc.
References isc_throw.
Referenced by leave().
void D2ParserContext::includeFile | ( | const std::string & | filename | ) |
Divert input to an include file.
filename | file to be included |
Definition at line 3985 of file d2_lexer.cc.
References BEGIN, isc::db::fatal, file_, files_, INITIAL, loc_, locs_, sfile_, sfiles_, states_, and YY_CURRENT_BUFFER.
void isc::d2::D2ParserContext::leave | ( | ) |
Leave a syntactic context.
isc::Unexpected | if unbalanced |
Definition at line 146 of file d2/parser_context.cc.
Referenced by isc::d2::D2Parser::parse().
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)
loc | location in bison format |
Definition at line 97 of file d2/parser_context.cc.
Referenced by isc::d2::D2Parser::parse().
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.
filename | file to be parsed |
parser_type | specifies expected content |
Definition at line 39 of file d2/parser_context.cc.
References isc_throw, and scanFileBegin().
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.
str | string to be parsed |
parser_type | specifies expected content |
Definition at line 32 of file d2/parser_context.cc.
References scanStringBegin().
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.
name | name of the parameter to check |
open_loc | location of the opening curly bracket |
close_loc | location of the closing curly bracket |
D2ParseError |
Definition at line 106 of file d2/parser_context.cc.
References contextName(), isc_throw, and stack_.
Referenced by isc::d2::D2Parser::parse().
void D2ParserContext::scanEnd | ( | ) |
Method called after the last tokens are scanned.
Definition at line 3964 of file d2_lexer.cc.
void D2ParserContext::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 3942 of file d2_lexer.cc.
References isc::db::fatal, file_, loc_, sfile_, and yy_flex_debug.
Referenced by parseFile().
void D2ParserContext::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 3924 of file d2_lexer.cc.
References isc::db::fatal, file_, loc_, sfile_, and yy_flex_debug.
Referenced by parseString().
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.
name | name of the parameter to check |
loc | location of the current parameter |
D2ParseError |
Definition at line 121 of file d2/parser_context.cc.
References contextName(), ctx_, isc_throw, NO_KEYWORD, and stack_.
Referenced by isc::d2::D2Parser::parse().
void isc::d2::D2ParserContext::warnAboutExtraCommas | ( | const isc::d2::location & | loc | ) |
Warning for extra commas.
loc | location within the parsed file of the extra comma |
ParseError |
Definition at line 223 of file d2/parser_context.cc.
References warning().
Referenced by isc::d2::D2Parser::parse().
void isc::d2::D2ParserContext::warning | ( | const isc::d2::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 214 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().
ParserContext isc::d2::D2ParserContext::ctx_ |
Current syntactic context.
Definition at line 318 of file d2/parser_context.h.
Referenced by contextName(), enter(), leave(), isc::d2::D2Parser::parse(), and unique().
std::string isc::d2::D2ParserContext::file_ |
File name.
Definition at line 290 of file d2/parser_context.h.
Referenced by includeFile(), scanFileBegin(), and scanStringBegin().
std::vector<std::string> isc::d2::D2ParserContext::files_ |
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 299 of file d2/parser_context.h.
Referenced by includeFile(), scanFileBegin(), and scanStringBegin().
std::vector<isc::d2::location> isc::d2::D2ParserContext::locs_ |
FILE* isc::d2::D2ParserContext::sfile_ |
sFile (aka FILE)
Definition at line 308 of file d2/parser_context.h.
Referenced by includeFile(), scanEnd(), scanFileBegin(), and scanStringBegin().
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 315 of file d2/parser_context.h.
Referenced by includeFile(), and scanEnd().
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(), require(), and unique().
std::vector<struct yy_buffer_state*> isc::d2::D2ParserContext::states_ |
Lexer state stack.
Definition at line 305 of file d2/parser_context.h.
Referenced by includeFile(), and scanEnd().