Ocean
|
This class implements a token for the scanner. More...
Public Types | |
enum | Type : uint32_t { TOKEN_INVALID = 0u , TOKEN_CHARACTER , TOKEN_END_OF_FILE , TOKEN_IDENTIFIER , TOKEN_LINE , TOKEN_NUMBER , TOKEN_INTEGER , TOKEN_KEYWORD , TOKEN_STRING , TOKEN_SYMBOL } |
Definition of different token types. More... | |
Public Member Functions | |
Token ()=default | |
Creates an invalid token. More... | |
Token (std::string &&data, const Type type) | |
Creates a new token with given data and type. More... | |
Token (const std::string &data, const Type type) | |
Creates a new token with given data and type. More... | |
Token (std::string &&data, const uint32_t id, const Type type) | |
Creates a new token with given keyword or symbol id. More... | |
Token (const std::string &data, const uint32_t id, const Type type) | |
Creates a new token with given keyword or symbol id. More... | |
Type | type () const |
Returns the type of the token. More... | |
bool | isType (const Type type) const |
Returns whether this token is of a specific type. More... | |
bool | isCharacter () const |
Returns whether this token holds a character. More... | |
bool | isIdentifier () const |
Returns whether this token holds an identifier. More... | |
bool | isInteger () const |
Returns whether this token holds an integer. More... | |
bool | isLine () const |
Returns whether this token holds a remaining line. More... | |
bool | isNumber () const |
Returns whether this token holds a number. More... | |
bool | isIntegerOrNumber () const |
Returns whether this token holds an integer or a number. More... | |
bool | isKeyword () const |
Returns whether this token holds a keyword. More... | |
bool | isKeyword (const uint32_t keyword) const |
Returns whether this token holds a special keyword. More... | |
bool | isString () const |
Returns whether this token holds a string. More... | |
bool | isSymbol () const |
Returns whether this token holds a symbol. More... | |
bool | isSymbol (const uint32_t symbol) const |
Returns whether this token holds a special symbol. More... | |
bool | isEndOfFile () const |
Returns whether this token holds a end of file. More... | |
uint8_t | character () const |
Returns the character value of this token. More... | |
const std::string & | identifier () const |
Returns the identifier value of this token. More... | |
int | integer () const |
Returns the integer value of this token. More... | |
Scalar | number () const |
Returns the float value of this token. More... | |
Scalar | integerOrNumber () const |
Returns the integer or float value of this token. More... | |
const std::string & | line () const |
Returns the remaining line of this token. More... | |
uint32_t | keyword () const |
Returns the id of the keyword of this token. More... | |
uint32_t | symbol () const |
Returns the id of the symbol of this token. More... | |
const std::string & | string () const |
Returns the string value of this token. More... | |
std::string | moveString () |
Returns the string value of this token and invalidates the token. More... | |
const std::string & | raw () const |
Returns the raw data of the token. More... | |
operator bool () const | |
Returns whether the token is valid. More... | |
Protected Attributes | |
Type | type_ = TOKEN_INVALID |
Holds the type of the token. More... | |
uint32_t | id_ = invalidId |
Holds the id of the keyword or symbol, if any. More... | |
std::string | data_ |
Holds the data of the token. More... | |
This class implements a token for the scanner.
enum Ocean::IO::Scanner::Token::Type : uint32_t |
Definition of different token types.
Enumerator | |
---|---|
TOKEN_INVALID | Invalid token. |
TOKEN_CHARACTER | Character token. |
TOKEN_END_OF_FILE | End of file token. |
TOKEN_IDENTIFIER | Identifier token. |
TOKEN_LINE | Line token. |
TOKEN_NUMBER | Number token. |
TOKEN_INTEGER | Integer token. |
TOKEN_KEYWORD | Keyword token. |
TOKEN_STRING | String token. |
TOKEN_SYMBOL | Symbol token. |
|
default |
Creates an invalid token.
Ocean::IO::Scanner::Token::Token | ( | std::string && | data, |
const Type | type | ||
) |
Ocean::IO::Scanner::Token::Token | ( | const std::string & | data, |
const Type | type | ||
) |
Ocean::IO::Scanner::Token::Token | ( | std::string && | data, |
const uint32_t | id, | ||
const Type | type | ||
) |
Creates a new token with given keyword or symbol id.
data | Raw token data |
id | Keyword or symbol id of the token |
type | Token type |
Ocean::IO::Scanner::Token::Token | ( | const std::string & | data, |
const uint32_t | id, | ||
const Type | type | ||
) |
Creates a new token with given keyword or symbol id.
data | Raw token data |
id | Keyword or symbol id of the token |
type | Token type |
uint8_t Ocean::IO::Scanner::Token::character | ( | ) | const |
Returns the character value of this token.
const std::string& Ocean::IO::Scanner::Token::identifier | ( | ) | const |
Returns the identifier value of this token.
int Ocean::IO::Scanner::Token::integer | ( | ) | const |
Returns the integer value of this token.
Scalar Ocean::IO::Scanner::Token::integerOrNumber | ( | ) | const |
Returns the integer or float value of this token.
|
inline |
Returns whether this token holds a character.
|
inline |
Returns whether this token holds a end of file.
|
inline |
Returns whether this token holds an identifier.
|
inline |
Returns whether this token holds an integer.
|
inline |
Returns whether this token holds an integer or a number.
|
inline |
Returns whether this token holds a keyword.
bool Ocean::IO::Scanner::Token::isKeyword | ( | const uint32_t | keyword | ) | const |
Returns whether this token holds a special keyword.
keyword | The keyword id to check |
|
inline |
Returns whether this token holds a remaining line.
|
inline |
Returns whether this token holds a number.
|
inline |
Returns whether this token holds a string.
|
inline |
Returns whether this token holds a symbol.
bool Ocean::IO::Scanner::Token::isSymbol | ( | const uint32_t | symbol | ) | const |
Returns whether this token holds a special symbol.
symbol | The symbol id to check |
|
inline |
Returns whether this token is of a specific type.
type | The type to check |
uint32_t Ocean::IO::Scanner::Token::keyword | ( | ) | const |
Returns the id of the keyword of this token.
const std::string& Ocean::IO::Scanner::Token::line | ( | ) | const |
Returns the remaining line of this token.
std::string Ocean::IO::Scanner::Token::moveString | ( | ) |
Returns the string value of this token and invalidates the token.
Scalar Ocean::IO::Scanner::Token::number | ( | ) | const |
Returns the float value of this token.
|
inlineexplicit |
Returns whether the token is valid.
|
inline |
Returns the raw data of the token.
const std::string& Ocean::IO::Scanner::Token::string | ( | ) | const |
Returns the string value of this token.
uint32_t Ocean::IO::Scanner::Token::symbol | ( | ) | const |
Returns the id of the symbol of this token.
|
inline |
Returns the type of the token.
|
protected |
Holds the data of the token.
|
protected |
Holds the id of the keyword or symbol, if any.
|
protected |
Holds the type of the token.