67struct std::formatter<tt::tokenizer_name_t, CharT> : std::formatter<char const *, CharT> {
68 auto format(tt::tokenizer_name_t
const &t,
auto &fc)
70 return std::formatter<char const *, CharT>::format(tt::to_const_string(t), fc);
75 tokenizer_name_t name;
81 token_t() noexcept : name(tokenizer_name_t::NotAssigned), value(), location(), is_binary(
false), precedence(0) {}
84 name(name), value(
std::move(value)), location(), is_binary(
false), precedence(0)
89 name(other.name), value(other.value), location(other.location), is_binary(other.is_binary), precedence(other.precedence)
91 tt_axiom(&other !=
this);
98 is_binary(other.is_binary),
99 precedence(other.precedence)
101 tt_axiom(&other !=
this);
106 tt_return_on_self_assignment(other);
109 location = other.location;
110 is_binary = other.is_binary;
111 precedence = other.precedence;
119 name = move(other.name);
120 value = move(other.value);
121 location = move(other.location);
122 is_binary = move(other.is_binary);
123 precedence = move(other.precedence);
127 operator bool()
const noexcept
129 return name != tokenizer_name_t::NotAssigned;
132 explicit operator long double()
const
138 throw parse_error(
"Could not convert token {} to long double", *
this);
142 explicit operator double()
const
148 throw parse_error(
"Could not convert token {} to double", *
this);
152 explicit operator float()
const
158 throw parse_error(
"Could not convert token {} to float", *
this);
162 template<std::
integral T>
163 explicit operator T()
const
166 return tt::from_string<T>(value);
169 throw parse_error(
"Could not convert token {} to {}", *
this,
typeid(T).name());
175 return utf8_to_utf8(value);
178 explicit operator decimal()
const
183 explicit operator std::chrono::year_month_day()
const
185 ttlet parts = split(value,
'-');
186 if (parts.size() != 3) {
187 throw parse_error(
"Expect date to be in the format YYYY-MM-DD");
190 ttlet year = std::chrono::year{stoi(parts[0])};
191 ttlet month = std::chrono::month{narrow_cast<unsigned int>(stoi(parts[1]))};
192 ttlet day = std::chrono::day{narrow_cast<unsigned int>(stoi(parts[2]))};
193 return {year, month, day};
199 if (value.
size() > 0) {
209 return lhs << rhs.repr();
212 [[nodiscard]]
friend bool operator==(
token_t const &lhs,
token_t const &rhs)
noexcept
214 return (lhs.name == rhs.name) && (lhs.value == rhs.value);
217 [[nodiscard]]
friend bool operator==(
token_t const &lhs, tokenizer_name_t
const &rhs)
noexcept
219 return lhs.name == rhs;
222 [[nodiscard]]
friend bool operator!=(
token_t const &lhs, tokenizer_name_t
const &rhs)
noexcept
224 return !(lhs == rhs);
227 [[nodiscard]]
friend bool operator==(
token_t const &lhs,
const char *rhs)
noexcept
229 return lhs.value == rhs;
232 [[nodiscard]]
friend bool operator!=(
token_t const &lhs,
const char *rhs)
noexcept
234 return !(lhs == rhs);
245 token_iterator next_token;
247 parse_result() noexcept : found(
false), value(), next_token() {}
249 parse_result(T
const &value, token_iterator next_token) : found(
true), value(value), next_token(next_token) {}
251 operator bool()
const noexcept
256 T
const &operator*()
const noexcept