16 enum class kind_type : uint8_t {
18 error_unexepected_character,
20 error_incomplete_exponent,
21 error_incomplete_string,
22 error_incomplete_comment,
40 kind_type::none,
"none",
41 kind_type::error_unexepected_character,
"error:unexpected character",
42 kind_type::error_invalid_digit,
"error:invalid digit",
43 kind_type::error_incomplete_exponent,
"error:incomplete exponent",
44 kind_type::error_incomplete_string,
"error:incomplete string",
45 kind_type::error_incomplete_comment,
"error:incomplete comment",
46 kind_type::error_after_lt_bang,
"error:after_lt_bang",
47 kind_type::integer,
"integer",
48 kind_type::real,
"read",
49 kind_type::sstr,
"single-quote string",
50 kind_type::dstr,
"double-quote string",
51 kind_type::bstr,
"back-quote string",
52 kind_type::istr,
"ini string",
53 kind_type::color,
"color",
54 kind_type::lcomment,
"line comment",
55 kind_type::bcomment,
"block comment",
58 kind_type::other,
"other"
62 constexpr static auto none = kind_type::none;
63 constexpr static auto error_unexepected_character = kind_type::error_unexepected_character;
64 constexpr static auto error_invalid_digit = kind_type::error_invalid_digit;
65 constexpr static auto error_incomplete_exponent = kind_type::error_incomplete_exponent;
66 constexpr static auto error_incomplete_string = kind_type::error_incomplete_string;
67 constexpr static auto error_incomplete_comment = kind_type::error_incomplete_comment;
68 constexpr static auto error_after_lt_bang = kind_type::error_after_lt_bang;
69 constexpr static auto integer = kind_type::integer;
70 constexpr static auto real = kind_type::real;
71 constexpr static auto sstr = kind_type::sstr;
72 constexpr static auto dstr = kind_type::dstr;
73 constexpr static auto bstr = kind_type::bstr;
74 constexpr static auto istr = kind_type::istr;
75 constexpr static auto color = kind_type::color;
76 constexpr static auto lcomment = kind_type::lcomment;
77 constexpr static auto bcomment = kind_type::bcomment;
78 constexpr static auto ws = kind_type::ws;
79 constexpr static auto id = kind_type::id;
80 constexpr static auto other = kind_type::other;
85 kind_type kind = kind_type::none;
87 constexpr token()
noexcept =
default;
88 constexpr token(
token const&)
noexcept =
default;
90 constexpr token& operator=(
token const&)
noexcept =
default;
91 constexpr token& operator=(
token&&)
noexcept =
default;
93 constexpr token(kind_type kind, std::string_view capture,
size_t column_nr)
noexcept :
94 kind(kind), capture(), line_nr(0), column_nr(column_nr)
99 constexpr token(kind_type kind, std::string_view capture,
size_t line_nr,
size_t column_nr)
noexcept :
100 kind(kind), capture(), line_nr(line_nr), column_nr(column_nr)
105 [[
nodiscard]]
constexpr friend bool operator==(
token const&,
token const&)
noexcept =
default;
107 [[
nodiscard]]
constexpr bool operator==(kind_type rhs)
const noexcept
112 [[
nodiscard]]
constexpr bool operator==(std::string_view rhs)
const noexcept
114 return static_cast<std::string_view
>(*this) == rhs;
117 [[
nodiscard]]
constexpr bool operator==(
char rhs)
const noexcept
119 return kind == kind_type::other
and capture.
size() == 1
and capture.
front() == rhs;
127 template<std::
integral T>
128 constexpr operator T()
const
133 template<std::
floating_po
int T>
139 operator color()
const
141 hi_axiom(kind == kind_type::color);
146 constexpr operator std::string_view()
const noexcept
148 return std::string_view{capture.
data(), capture.
size()};
178struct std::formatter<
hi::token, CharT> : std::formatter<std::string, CharT> {
179 auto format(
hi::token const& t,
auto& fc)
const
181 return std::formatter<std::string, CharT>::format(
183 "{} \"{}\" {}:{}", hi::token::kind_type_metadata[t.kind],
static_cast<std::string>(t), t.line_nr, t.column_nr),
color color_from_sRGB(float r, float g, float b, float a) noexcept
Convert gama corrected sRGB color to the linear color.
Definition sRGB.hpp:142
hi_export constexpr std::string token_location(It &it, ItEnd last, std::string_view path) noexcept
Create a location string for error messages.
Definition token.hpp:160