| Kea 3.0.2-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 , 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.

## Detailed Description

Evaluation context, an interface to the expression evaluation.

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

## Member Enumeration Documentation

## ◆ ParserContext

enum isc::d2::D2ParserContext::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 | Used while parsing content of a socket-type.
CONTROL_SOCKET_TYPE | Used while parsing content of an authentication.
AUTHENTICATION | Used while parsing content of an authentication type.
AUTH_TYPE | Used while parsing content of a client.
CLIENTS |
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

enum isc::d2::D2ParserContext::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.

References ctx_, NO_KEYWORD, and sfile_.

## ◆ ~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 | ( |  | ) |

Get the syntax context name.

Returns
  printable name of the context.

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 require(), and unique().

## ◆ 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

  ctx | the syntactic context to enter into

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

References ctx_.

## ◆ 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

  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.

Exceptions

  D2ParseError |

Definition at line 73 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

  what | string explaining the nature of the error.

Exceptions

  D2ParseError |

Definition at line 85 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

  what | string explaining the nature of the error.

Exceptions

  D2ParseError |

Definition at line 91 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

  filename | file to be included

Definition at line 3987 of file d2_lexer.cc.

References BEGIN, isc::db::fatal, file_, files_, INITIAL, loc_, locs_, sfile_, sfiles_, states_, and YY_CURRENT_BUFFER.

## ◆ leave()

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

Leave a syntactic context.

Exceptions

  isc::Unexpected | if unbalanced

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

References ctx_, and fatal().

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

  loc | location in bison format

Returns
  Position in format accepted by Element

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

## ◆ 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

  filename | file to be parsed
  parser_type | specifies expected content

Returns
  Element structure representing parsed text.

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

References isc_throw, and scanFileBegin().

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

  str | string to be parsed
  parser_type | specifies 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

  name | name of the parameter to check
  open_loc | location of the opening curly bracket
  close_loc | location of the closing curly bracket

Exceptions

  D2ParseError |

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

References contextName(), isc_throw, and stack_.

Here is the call graph for this function:

## ◆ scanEnd()

void D2ParserContext::scanEnd | ( |  | ) |

Method called after the last tokens are scanned.

Definition at line 3966 of file d2_lexer.cc.

References sfile_, sfiles_, and states_.

## ◆ scanFileBegin()

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

Method called before scanning starts on a file.

Parameters

  f | stdio FILE pointer
  filename | file to be parsed
  type | specifies expected content

Definition at line 3944 of file d2_lexer.cc.

References isc::db::fatal, file_, loc_, sfile_, 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

  str | string to be parsed
  type | specifies expected content

Definition at line 3926 of file d2_lexer.cc.

References isc::db::fatal, file_, loc_, sfile_, 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

  name | name of the parameter to check
  loc | location of the current parameter

Exceptions

  D2ParseError |

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

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

Here is the call graph for this function:

## ◆ warnAboutExtraCommas()

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

Warning for extra commas.

Parameters

  loc | location within the parsed file of the extra comma

Exceptions

  ParseError |

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

References warning().

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

  loc | location within the parsed file where the problem was experienced
  what | string explaining the nature of the error

Exceptions

  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().

## Member Data Documentation

## ◆ ctx_

ParserContext isc::d2::D2ParserContext::ctx_

Current syntactic context.

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

Referenced by D2ParserContext(), contextName(), enter(), leave(), and unique().

## ◆ file_

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

File name.

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

Referenced by includeFile(), scanFileBegin(), and scanStringBegin().

## ◆ files_

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

File name stack.

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

Referenced by includeFile().

## ◆ 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 299 of file d2/parser_context.h.

Referenced by includeFile(), scanFileBegin(), and scanStringBegin().

## ◆ locs_

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

Location stack.

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

Referenced by includeFile().

## ◆ sfile_

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

sFile (aka FILE)

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

Referenced by D2ParserContext(), includeFile(), scanEnd(), scanFileBegin(), and scanStringBegin().

## ◆ 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 315 of file d2/parser_context.h.

Referenced by includeFile(), and scanEnd().

## ◆ 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 require(), and unique().

## ◆ states_

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().

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

- d2/parser_context.h
- d2_lexer.cc
- d2/parser_context.cc