19 enum class kind_type : uint8_t {
21 error_unexepected_character,
23 error_incomplete_exponent,
24 error_incomplete_string,
25 error_incomplete_comment,
43 kind_type::none,
"none",
44 kind_type::error_unexepected_character,
"error:unexpected character",
45 kind_type::error_invalid_digit,
"error:invalid digit",
46 kind_type::error_incomplete_exponent,
"error:incomplete exponent",
47 kind_type::error_incomplete_string,
"error:incomplete string",
48 kind_type::error_incomplete_comment,
"error:incomplete comment",
49 kind_type::error_after_lt_bang,
"error:after_lt_bang",
50 kind_type::integer,
"integer",
51 kind_type::real,
"read",
52 kind_type::sstr,
"single-quote string",
53 kind_type::dstr,
"double-quote string",
54 kind_type::bstr,
"back-quote string",
55 kind_type::istr,
"ini string",
56 kind_type::color,
"color",
57 kind_type::lcomment,
"line comment",
58 kind_type::bcomment,
"block comment",
61 kind_type::other,
"other"
65 constexpr static auto none = kind_type::none;
66 constexpr static auto error_unexepected_character = kind_type::error_unexepected_character;
67 constexpr static auto error_invalid_digit = kind_type::error_invalid_digit;
68 constexpr static auto error_incomplete_exponent = kind_type::error_incomplete_exponent;
69 constexpr static auto error_incomplete_string = kind_type::error_incomplete_string;
70 constexpr static auto error_incomplete_comment = kind_type::error_incomplete_comment;
71 constexpr static auto error_after_lt_bang = kind_type::error_after_lt_bang;
72 constexpr static auto integer = kind_type::integer;
73 constexpr static auto real = kind_type::real;
74 constexpr static auto sstr = kind_type::sstr;
75 constexpr static auto dstr = kind_type::dstr;
76 constexpr static auto bstr = kind_type::bstr;
77 constexpr static auto istr = kind_type::istr;
78 constexpr static auto color = kind_type::color;
79 constexpr static auto lcomment = kind_type::lcomment;
80 constexpr static auto bcomment = kind_type::bcomment;
81 constexpr static auto ws = kind_type::ws;
82 constexpr static auto id = kind_type::id;
83 constexpr static auto other = kind_type::other;
88 kind_type kind = kind_type::none;
90 constexpr token()
noexcept =
default;
91 constexpr token(
token const&)
noexcept =
default;
93 constexpr token& operator=(
token const&)
noexcept =
default;
94 constexpr token& operator=(
token&&)
noexcept =
default;
96 constexpr token(kind_type kind, std::string_view capture,
size_t column_nr) noexcept :
97 kind(kind), capture(), line_nr(0), column_nr(column_nr)
102 constexpr token(kind_type kind, std::string_view capture,
size_t line_nr,
size_t column_nr) noexcept :
103 kind(kind), capture(), line_nr(line_nr), column_nr(column_nr)
108 [[nodiscard]]
constexpr friend bool operator==(
token const&,
token const&)
noexcept =
default;
110 [[nodiscard]]
constexpr bool operator==(kind_type rhs)
const noexcept
115 [[nodiscard]]
constexpr bool operator==(std::string_view rhs)
const noexcept
117 return static_cast<std::string_view
>(*this) == rhs;
120 [[nodiscard]]
constexpr bool operator==(
char rhs)
const noexcept
122 return kind == kind_type::other and capture.
size() == 1 and capture.
front() == rhs;
130 template<std::
integral T>
131 constexpr operator T()
const
133 return from_string<T>(
static_cast<std::string_view
>(*
this));
136 template<std::
floating_po
int T>
139 return from_string<T>(
static_cast<std::string_view
>(*
this));
142 operator ::hi::color()
const
144 hi_axiom(kind == kind_type::color);
149 constexpr operator std::string_view()
const noexcept
151 return std::string_view{capture.
data(), capture.
size()};
182struct std::formatter<
hi::token, char> : std::formatter<std::string, char> {
183 auto format(
hi::token const& t,
auto& fc)
const
185 return std::formatter<std::string, char>::format(
187 "{} \"{}\" {}:{}", 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:149
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:163