Kea 2.7.6
|
Tokens for MasterLexer
.
More...
#include <master_lexer.h>
Classes | |
struct | StringRegion |
A simple representation of a range of a string. More... | |
Public Types | |
enum | ErrorCode { NOT_STARTED , UNBALANCED_PAREN , UNEXPECTED_END , UNBALANCED_QUOTES , NO_TOKEN_PRODUCED , NUMBER_OUT_OF_RANGE , BAD_NUMBER , UNEXPECTED_QUOTES , MAX_ERROR_CODE } |
Enumeration for lexer error codes. More... | |
enum | Type { END_OF_LINE , END_OF_FILE , INITIAL_WS , NOVALUE_TYPE_MAX = INITIAL_WS , STRING , QSTRING , NUMBER , ERROR } |
Enumeration for token types. More... | |
Public Member Functions | |
MasterToken (const char *str_beg, size_t str_len, bool quoted=false) | |
Constructor for string and quoted-string types of token. | |
MasterToken (ErrorCode error_code) | |
Constructor for error type of token. | |
MasterToken (Type type) | |
Constructor for non-value type of token. | |
MasterToken (uint32_t number) | |
Constructor for number type of token. | |
ErrorCode | getErrorCode () const |
Return the error code of a error type token. | |
std::string | getErrorText () const |
Return a textual description of the error of a error type token. | |
uint32_t | getNumber () const |
Return the value of a string-variant token as a string object. | |
std::string | getString () const |
Return the value of a string-variant token as a string object. | |
void | getString (std::string &ret) const |
Fill in a string with the value of a string-variant token. | |
const StringRegion & | getStringRegion () const |
Return the value of a string-variant token. | |
Type | getType () const |
Return the token type. | |
Tokens for MasterLexer
.
This is a simple value-class encapsulating a type of a lexer token and (if it has a value) its value. Essentially, the class provides constructors corresponding to different types of tokens, and corresponding getter methods. The type and value are fixed at the time of construction and will never be modified throughout the lifetime of the object. The getter methods are still provided to maximize the safety; an application cannot refer to a value that is invalid for the type of token.
This class is intentionally implemented as copyable and assignable (using the default version of copy constructor and assignment operator), but it's mainly for internal implementation convenience. Applications will simply refer to Token object as a reference via the MasterLexer
class.
Definition at line 40 of file master_lexer.h.
Enumeration for lexer error codes.
Enumerator | |
---|---|
NOT_STARTED | The lexer is just initialized and has no token. |
UNBALANCED_PAREN | Unbalanced parentheses detected. |
UNEXPECTED_END | The lexer reaches the end of line or file unexpectedly. |
UNBALANCED_QUOTES | Unbalanced quotations detected. |
NO_TOKEN_PRODUCED | No token was produced. This means programmer error and should never get out of the lexer. |
NUMBER_OUT_OF_RANGE | Number was out of range. |
BAD_NUMBER | Number is expected but not recognized. |
UNEXPECTED_QUOTES | Unexpected quotes character detected. |
MAX_ERROR_CODE | Max integer corresponding to valid error codes. (excluding this one). Mainly for internal use. |
Definition at line 64 of file master_lexer.h.
Enumeration for token types.
MasterLexer
should be represented as an unsigned 32-bit integer. If we see the need for larger integers or negative numbers, we can then extend the token types. Definition at line 48 of file master_lexer.h.
|
inlineexplicit |
Constructor for non-value type of token.
InvalidParameter | A value type token is specified. |
type | The type of the token. It must indicate a non-value type (not larger than NOVALUE_TYPE_MAX ). |
Definition at line 106 of file master_lexer.h.
References isc_throw, and NOVALUE_TYPE_MAX.
|
inline |
Constructor for string and quoted-string types of token.
The optional quoted
parameter specifies whether it's a quoted or non quoted string.
The string is specified as a pair of a pointer to the start address and its length. Any character can be contained in any position of the valid range (see StringRegion
).
When it's a quoted string, the quotation marks must be excluded from the specified range.
str_beg | The start address of the string |
str_len | The size of the string in bytes |
quoted | true if it's a quoted string; false otherwise. |
Definition at line 128 of file master_lexer.h.
|
inlineexplicit |
Constructor for number type of token.
number An unsigned 32-bit integer corresponding to the token value.
Definition at line 138 of file master_lexer.h.
|
inlineexplicit |
Constructor for error type of token.
InvalidParameter | Invalid error code value is specified. |
error_code A pre-defined constant of ErrorCode
.
Definition at line 146 of file master_lexer.h.
References isc_throw, and MAX_ERROR_CODE.
|
inline |
Return the error code of a error type token.
InvalidOperation | Called on a non error type of token. |
Definition at line 232 of file master_lexer.h.
std::string isc::dns::MasterToken::getErrorText | ( | ) | const |
Return a textual description of the error of a error type token.
The returned string would be useful to produce a log message when a zone file parser encounters an error.
InvalidOperation | Called on a non error type of token. |
std::bad_alloc | Resource allocation failure in constructing the string object. |
|
inline |
Return the value of a string-variant token as a string object.
InvalidOperation | Called on a non number type of token. |
Definition at line 220 of file master_lexer.h.
|
inline |
Return the value of a string-variant token as a string object.
Note that the underlying string may contain a nul (\0) character in the middle. The returned string object will contain all characters of the valid range of the underlying string. So some string operations such as c_str() may not work as expected.
InvalidOperation | Called on a non string-variant types of token. |
std::bad_alloc | Resource allocation failure in constructing the string object. |
Definition at line 185 of file master_lexer.h.
References getString().
Referenced by getString().
|
inline |
Fill in a string with the value of a string-variant token.
This is similar to the other version of getString()
, but the caller is supposed to pass a placeholder string object. This will be more efficient if the caller uses the same MasterLexer
repeatedly and needs to get string token in the form of a string object many times as this version could reuse the existing internal storage of the passed string.
Any existing content of the passed string will be removed.
InvalidOperation | Called on a non string-variant types of token. |
std::bad_alloc | Resource allocation failure in constructing the string object. |
ret | A string object to be filled with the token string. |
Definition at line 207 of file master_lexer.h.
|
inline |
Return the value of a string-variant token.
InvalidOperation | Called on a non string-variant types of token. |
StringRegion
corresponding to the string token value. Definition at line 166 of file master_lexer.h.
References isc_throw, QSTRING, and STRING.
Referenced by isc::dns::rdata::generic::detail::createNameFromLexer().
|
inline |
Return the token type.
none |
Definition at line 157 of file master_lexer.h.
Referenced by isc::dns::rdata::generic::Generic::Generic(), isc::dns::rdata::generic::detail::TXTLikeImpl< Type, typeCode >::TXTLikeImpl(), isc::dns::rdata::createRdata(), and isc::dns::MasterLoader::MasterLoaderImpl::loadIncremental().
ErrorCode isc::dns::MasterToken::error_code_ |
Definition at line 261 of file master_lexer.h.
uint32_t isc::dns::MasterToken::number_ |
Definition at line 260 of file master_lexer.h.
StringRegion isc::dns::MasterToken::str_region_ |
Definition at line 259 of file master_lexer.h.