Token
Represent a single lexical token in the Schematika language
Context
#include <xo/tokenizer/token.hpp>
Represent a single lexical token
Does not share any storage with original input stream (maintains a local copy).
Remembers copied input extent. Convert on demand to native untagged representation
Example
void foo() {
using namespace xo::scm;
token<char> tk = token<char>::i64_token("123");
tk.is_valid(); // -> true
tk.text(); // -> "123"s;
tk.tk_type(); // -> tokentype::tk_i64
tk.i64_value(); // -> 123
cout << tk << endl; // -> <token :type i64 :text 123>
}
Class
-
template<typename CharT>
class token Represent a Schematika lexical token.
Instance Variables
- group Token-instance-vars
Constructors
- group token constructors
Functions
-
token() = default
default ctor creates token with type
tk_invalid
-
inline token(tokentype tk_type, const std::string &text = "")
create token with type
tk_typeand input texttext
-
static inline token bool_token(const std::string &txt)
Create token representing a boolean literal from text
txttxtmust betrueorfalse
-
static inline token i64_token(const std::string &txt)
Create token representing 64-bit signed integer literal parsed from decimal
txt. The stringtxtmust be a decimal integer literal, since i64_value re-parsestxt.
-
static inline token f64_token(const std::string &txt)
create token representing 64-bit floating-point literal parsed from decimal
txtThe stringtxtmust be a decimal floating-point literal, since f64_value re-parsestxt.
-
static inline token string_token(const std::string &txt)
create token representing literal string parsed from
txt
-
token() = default
Access Methods
- group Token-access-methods
General Methods
- group Token-general-methods
Functions
-
inline bool is_valid() const
true if token understood to represent valid input i.e. any token type except
tk_invalid
-
inline bool is_invalid() const
true for sentinel token with type tk_invalid
-
inline bool has_variable_text() const
true for tokens with variable text. false for those with fixed textual representation
-
bool bool_value() const
expect input matching
trueorfalse
-
std::int64_t i64_value() const
expect input matching
[+|-][0-9][0-9]*
-
double f64_value() const
expect input matching
[+|-][0-9]*[.][0-9]*[e|E][+|-][0-9]*
-
void print(std::ostream &os) const
print human-readable token representation on stream
os
-
inline bool is_valid() const