67 tokenizer_name_t name;
73 token_t() noexcept : name(tokenizer_name_t::NotAssigned), value(), location(), is_binary(
false), precedence(0) {}
76 name(name), value(
std::move(value)), location(), is_binary(
false), precedence(0)
81 name(other.name), value(other.value), location(other.location), is_binary(other.is_binary), precedence(other.precedence)
89 is_binary(other.is_binary),
90 precedence(other.precedence)
99 location = other.location;
100 is_binary = other.is_binary;
101 precedence = other.precedence;
109 name = move(other.name);
110 value = move(other.value);
111 location = move(other.location);
112 is_binary = move(other.is_binary);
113 precedence = move(other.precedence);
117 operator bool()
const noexcept
119 return name != tokenizer_name_t::NotAssigned;
122 explicit operator long double()
const
128 throw parse_error(
"Could not convert token {} to long double", *
this);
132 explicit operator double()
const
138 throw parse_error(
"Could not convert token {} to double", *
this);
142 explicit operator float()
const
148 throw parse_error(
"Could not convert token {} to float", *
this);
152 template<std::
integral T>
153 explicit operator T()
const
156 return tt::from_string<T>(value);
159 throw parse_error(
"Could not convert token {} to {}", *
this,
typeid(T).name());
168 explicit operator std::u8string()
const noexcept
170 return sanitize_u8string(make_u8string(value));
173 explicit operator decimal()
const
178 explicit operator date::year_month_day()
const
180 ttlet parts = split(value,
'-');
181 if (parts.size() != 3) {
182 throw parse_error(
"Expect date to be in the format YYYY-MM-DD");
185 ttlet year = date::year{stoi(parts[0])};
186 ttlet month = date::month{narrow_cast<unsigned int>(stoi(parts[1]))};
187 ttlet day = date::day{narrow_cast<unsigned int>(stoi(parts[2]))};
188 return {year, month, day};
194 if (value.
size() > 0) {
204 return lhs << rhs.repr();
207 [[nodiscard]]
friend bool operator==(
token_t const &lhs,
token_t const &rhs)
noexcept
209 return (lhs.name == rhs.name) && (lhs.value == rhs.value);
212 [[nodiscard]]
friend bool operator==(
token_t const &lhs, tokenizer_name_t
const &rhs)
noexcept
214 return lhs.name == rhs;
217 [[nodiscard]]
friend bool operator!=(
token_t const &lhs, tokenizer_name_t
const &rhs)
noexcept
219 return !(lhs == rhs);
222 [[nodiscard]]
friend bool operator==(
token_t const &lhs,
const char *rhs)
noexcept
224 return lhs.value == rhs;
227 [[nodiscard]]
friend bool operator!=(
token_t const &lhs,
const char *rhs)
noexcept
229 return !(lhs == rhs);
240 token_iterator next_token;
242 parse_result() noexcept : found(
false), value(), next_token() {}
244 parse_result(T
const &value, token_iterator next_token) : found(
true), value(value), next_token(next_token) {}
246 operator bool()
const noexcept
251 T
const &operator*()
const noexcept