Circus 0.0.1-alpha
C++ Serialization Framework
Loading...
Searching...
No Matches
circus::tokens__ Struct Reference

Represents a lexical token with type, literal value, and source location. More...

#include <token.hpp>

Public Types

enum  TYPE : unsigned char { TOKEN_DEFs }
using literal_variant_t = std::variant<char, std::string, int, float, double>
 Variant type to hold possible literal values of tokens.
using location_t = std::pair<std::size_t, std::size_t>
 Type representing the token location as (row, column)

Public Member Functions

void print_token () const noexcept
 Prints the token details to standard output.
 tokens__ (TYPE type, std::string embedded, literal_variant_t lit, location_t loc)
 Constructor to create a token instance.

Static Public Member Functions

static constexpr const char * to_string (TYPE type) noexcept
 Get string representation of token enum name.
static constexpr const char * to_stringized (TYPE type) noexcept
 Get string representation of token literal value.
static constexpr std::string to_literal (TYPE type) noexcept
 Convert the token literal to a std::string without surrounding quotes.

Public Attributes

TYPE _token_type
 The type of the token.
std::string embedded
 The embedded string representing the token as read from the source.
literal_variant_t literal
 The literal value held by the token.
location_t location
 The location of the token in source as (row, column)

Detailed Description

Represents a lexical token with type, literal value, and source location.

This struct defines the set of token types (using an enum), and stores the literal value associated with the token, its embedded string form, and its source location (row, column).

Constructor & Destructor Documentation

◆ tokens__()

circus::tokens__::tokens__ ( TYPE type,
std::string embedded,
literal_variant_t lit,
location_t loc )
inline

Constructor to create a token instance.

Parameters
typeToken type enum
embeddedString representing the token
litLiteral value of the token
locSource location as (row, column)

Member Function Documentation

◆ to_literal()

constexpr std::string circus::tokens__::to_literal ( TYPE type)
inlinestaticconstexprnoexcept

Convert the token literal to a std::string without surrounding quotes.

Parameters
typeToken type enum value
Returns
std::string Token literal without quotes

◆ to_string()

constexpr const char * circus::tokens__::to_string ( TYPE type)
inlinestaticconstexprnoexcept

Get string representation of token enum name.

Parameters
typeToken type enum value
Returns
const char* Token name as string

◆ to_stringized()

constexpr const char * circus::tokens__::to_stringized ( TYPE type)
inlinestaticconstexprnoexcept

Get string representation of token literal value.

Parameters
typeToken type enum value
Returns
const char* Token literal as string

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