Kea
1.9.9-git
|
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... | |
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::ElementPtr > | stack_ |
JSON elements being parsed. More... | |
std::vector< struct yy_buffer_state * > | states_ |
Lexer state stack. More... | |
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 199 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 20 of file d2/parser_context.cc.
|
virtual |
destructor.
Definition at line 25 of file d2/parser_context.cc.
const std::string isc::d2::D2ParserContext::contextName | ( | ) |
Get the syntax context name.
Definition at line 156 of file d2/parser_context.cc.
References ALGORITHM, CONFIG, CONTROL_SOCKET, 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 138 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 when experienced a problem. |
what | string explaining the nature of the error. |
pos | optional position for in string errors. |
D2ParseError |
Definition at line 72 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 84 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 90 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 3638 of file d2_lexer.cc.
References BEGIN, isc::db::fatal, INITIAL, and YY_CURRENT_BUFFER.
void isc::d2::D2ParserContext::leave | ( | ) |
Leave a syntactic context.
isc::Unexpected | if unbalanced |
Definition at line 145 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 96 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 37 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 30 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 105 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 3617 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 3595 of file d2_lexer.cc.
References isc::db::fatal, 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 3577 of file d2_lexer.cc.
References isc::db::fatal, 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 120 of file d2/parser_context.cc.
References contextName(), ctx_, isc_throw, NO_KEYWORD, and stack_.
Referenced by isc::d2::D2Parser::parse().
ParserContext isc::d2::D2ParserContext::ctx_ |
Current syntactic context.
Definition at line 291 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 263 of file d2/parser_context.h.
std::vector<std::string> isc::d2::D2ParserContext::files_ |
File name stack.
Definition at line 266 of file d2/parser_context.h.
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 272 of file d2/parser_context.h.
std::vector<isc::d2::location> isc::d2::D2ParserContext::locs_ |
Location stack.
Definition at line 275 of file d2/parser_context.h.
FILE* isc::d2::D2ParserContext::sfile_ |
sFile (aka FILE)
Definition at line 281 of file d2/parser_context.h.
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 288 of file d2/parser_context.h.
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 278 of file d2/parser_context.h.