63 tokenizer_name_t name;
70 name(tokenizer_name_t::NotAssigned), value(), location(), is_binary(
false), precedence(0) {}
73 name(name), value(
std::move(value)), location(), is_binary(
false), precedence(0) {}
76 name(other.name), value(other.value), location(other.location), is_binary(other.is_binary), precedence(other.precedence) {}
79 name(other.name), value(
std::move(other.value)), location(
std::move(other.location)), is_binary(other.is_binary), precedence(other.precedence) {}
85 location = other.location;
86 is_binary = other.is_binary;
87 precedence = other.precedence;
94 name = move(other.name);
95 value = move(other.value);
96 location = move(other.location);
97 is_binary = move(other.is_binary);
98 precedence = move(other.precedence);
102 operator bool ()
const noexcept {
103 return name != tokenizer_name_t::NotAssigned;
106 explicit operator long double ()
const {
110 TTAURI_THROW(
parse_error(
"Could not convert token {} to long double", *
this));
114 explicit operator double ()
const {
118 TTAURI_THROW(
parse_error(
"Could not convert token {} to double", *
this));
122 explicit operator float ()
const {
126 TTAURI_THROW(
parse_error(
"Could not convert token {} to float", *
this));
130 explicit operator signed long long ()
const {
134 TTAURI_THROW(
parse_error(
"Could not convert token {} to signed long long", *
this));
138 explicit operator signed long ()
const {
139 auto v =
static_cast<signed long long>(*this);
141 TTAURI_THROW(
parse_error(
"Could not convert token {} to signed long", *
this))
143 return static_cast<signed long>(v);
146 explicit operator signed int ()
const {
147 auto v =
static_cast<signed long long>(*this);
149 TTAURI_THROW(
parse_error(
"Could not convert token {} to signed int", *
this))
151 return static_cast<signed int>(v);
154 explicit operator signed short ()
const {
155 auto v =
static_cast<signed long long>(*this);
157 TTAURI_THROW(
parse_error(
"Could not convert token {} to signed short", *
this))
159 return static_cast<signed short>(v);
162 explicit operator signed char ()
const {
163 auto v =
static_cast<signed long long>(*this);
165 TTAURI_THROW(
parse_error(
"Could not convert token {} to signed char", *
this))
167 return static_cast<signed char>(v);
170 explicit operator unsigned long long ()
const {
171 auto v =
static_cast<signed long long>(*this);
173 TTAURI_THROW(
parse_error(
"Could not convert token {} to unsigned long long", *
this))
175 return static_cast<unsigned long long>(v);
178 explicit operator unsigned long ()
const {
179 auto v =
static_cast<signed long long>(*this);
181 TTAURI_THROW(
parse_error(
"Could not convert token {} to unsigned long", *
this))
183 return static_cast<unsigned long>(v);
186 explicit operator unsigned int ()
const {
187 auto v =
static_cast<signed long long>(*this);
189 TTAURI_THROW(
parse_error(
"Could not convert token {} to unsigned int", *
this))
191 return static_cast<unsigned int>(v);
194 explicit operator unsigned short ()
const {
195 auto v =
static_cast<signed long long>(*this);
197 TTAURI_THROW(
parse_error(
"Could not convert token {} to unsigned short", *
this))
199 return static_cast<unsigned short>(v);
202 explicit operator unsigned char ()
const {
203 auto v =
static_cast<signed long long>(*this);
205 TTAURI_THROW(
parse_error(
"Could not convert token {} to unsigned char", *
this))
207 return static_cast<unsigned char>(v);
214 explicit operator decimal ()
const {
218 explicit operator date::year_month_day ()
const {
219 ttlet parts = split(value,
"-");
220 if (parts.size() != 3) {
221 TTAURI_THROW(
parse_error(
"Expect date to be in the format YYYY-MM-DD"));
224 ttlet year = date::year{stoi(parts[0])};
225 ttlet month = date::month{numeric_cast<unsigned int>(stoi(parts[1]))};
226 ttlet day = date::day{numeric_cast<unsigned int>(stoi(parts[2]))};
227 return {year, month, day};
232 if (value.
size() > 0) {
242 return lhs << rhs.repr();
245 [[nodiscard]]
friend tt_force_inline
bool operator==(
token_t const &lhs,
token_t const &rhs)
noexcept {
246 return (lhs.name == rhs.name) && (lhs.value == rhs.value);
249 [[nodiscard]]
friend tt_force_inline
bool operator==(
token_t const &lhs, tokenizer_name_t
const &rhs)
noexcept {
250 return lhs.name == rhs;
253 [[nodiscard]]
friend tt_force_inline
bool operator!=(
token_t const &lhs, tokenizer_name_t
const &rhs)
noexcept {
254 return !(lhs == rhs);
257 [[nodiscard]]
friend tt_force_inline
bool operator==(
token_t const &lhs,
const char *rhs)
noexcept {
258 return lhs.value == rhs;
261 [[nodiscard]]
friend tt_force_inline
bool operator!=(
token_t const &lhs,
const char *rhs)
noexcept {
262 return !(lhs == rhs);
274 token_iterator next_token;
277 found(
false), value(), next_token() {}
279 parse_result(T
const &value, token_iterator next_token) :
280 found(
true), value(value), next_token(next_token) {}
282 operator bool ()
const noexcept {
286 T
const &operator*()
const noexcept {