Kea 2.7.5
isc::dns::MasterToken Class Reference

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 StringRegiongetStringRegion () const
 Return the value of a string-variant token.
 
Type getType () const
 Return the token type.
 

Detailed Description

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.

Member Enumeration Documentation

◆ ErrorCode

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.

◆ Type

Enumeration for token types.

Note
At the time of initial implementation, all numeric tokens that would be extracted from 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.
Enumerator
END_OF_LINE 

End of line detected.

END_OF_FILE 

End of file detected.

INITIAL_WS 

White spaces at the beginning of a line after an end of line or at the beginning of file (if asked.

NOVALUE_TYPE_MAX 

Max integer corresponding to no-value (type only) types.

Mainly for internal use.

STRING 

A single string.

QSTRING 

A single string quoted by double-quotes (").

NUMBER 

A decimal number (unsigned 32-bit)

ERROR 

Error detected in getting a token.

Definition at line 48 of file master_lexer.h.

Constructor & Destructor Documentation

◆ MasterToken() [1/4]

isc::dns::MasterToken::MasterToken ( Type type)
inlineexplicit

Constructor for non-value type of token.

Exceptions
InvalidParameterA value type token is specified.
Parameters
typeThe 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.

◆ MasterToken() [2/4]

isc::dns::MasterToken::MasterToken ( const char * str_beg,
size_t str_len,
bool quoted = false )
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.

Parameters
str_begThe start address of the string
str_lenThe size of the string in bytes
quotedtrue if it's a quoted string; false otherwise.

Definition at line 128 of file master_lexer.h.

◆ MasterToken() [3/4]

isc::dns::MasterToken::MasterToken ( uint32_t number)
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.

◆ MasterToken() [4/4]

isc::dns::MasterToken::MasterToken ( ErrorCode error_code)
inlineexplicit

Constructor for error type of token.

Exceptions
InvalidParameterInvalid 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.

Member Function Documentation

◆ getErrorCode()

ErrorCode isc::dns::MasterToken::getErrorCode ( ) const
inline

Return the error code of a error type token.

Exceptions
InvalidOperationCalled on a non error type of token.
Returns
The error code of the token.

Definition at line 232 of file master_lexer.h.

References ERROR, and isc_throw.

◆ getErrorText()

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.

Exceptions
InvalidOperationCalled on a non error type of token.
std::bad_allocResource allocation failure in constructing the string object.
Returns
A string object that describes the meaning of the error.

◆ getNumber()

uint32_t isc::dns::MasterToken::getNumber ( ) const
inline

Return the value of a string-variant token as a string object.

Exceptions
InvalidOperationCalled on a non number type of token.
Returns
The integer corresponding to the number token value.

Definition at line 220 of file master_lexer.h.

References isc_throw, and NUMBER.

◆ getString() [1/2]

std::string isc::dns::MasterToken::getString ( ) const
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.

Exceptions
InvalidOperationCalled on a non string-variant types of token.
std::bad_allocResource allocation failure in constructing the string object.
Returns
A std::string object corresponding to the string token value.

Definition at line 185 of file master_lexer.h.

References getString().

Referenced by getString().

+ Here is the call graph for this function:

◆ getString() [2/2]

void isc::dns::MasterToken::getString ( std::string & ret) const
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.

Exceptions
InvalidOperationCalled on a non string-variant types of token.
std::bad_allocResource allocation failure in constructing the string object.
Parameters
retA string object to be filled with the token string.

Definition at line 207 of file master_lexer.h.

References isc_throw, QSTRING, and STRING.

◆ getStringRegion()

const StringRegion & isc::dns::MasterToken::getStringRegion ( ) const
inline

Return the value of a string-variant token.

Exceptions
InvalidOperationCalled on a non string-variant types of token.
Returns
A reference to StringRegion corresponding to the string token value.

Definition at line 166 of file master_lexer.h.

References isc_throw, QSTRING, and STRING.

◆ getType()

Type isc::dns::MasterToken::getType ( ) const
inline

Return the token type.

Exceptions
none

Definition at line 157 of file master_lexer.h.

Referenced by isc::dns::rdata::createRdata().

Member Data Documentation

◆ error_code_

ErrorCode isc::dns::MasterToken::error_code_

Definition at line 261 of file master_lexer.h.

◆ number_

uint32_t isc::dns::MasterToken::number_

Definition at line 260 of file master_lexer.h.

◆ str_region_

StringRegion isc::dns::MasterToken::str_region_

Definition at line 259 of file master_lexer.h.


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