6#include "text_phrasing.hpp"
8namespace hi::inline v1 {
11template<
typename It,
typename ItEnd,
char... Terminator>
16 for (; it != last; ++it) {
17 hilet c =
static_cast<char>(*it);
19 if (((c == Terminator) or ...)) {
26 throw parse_error(
"Unexpected end-of-text.");
29template<
typename It,
typename ItEnd>
30[[nodiscard]]
constexpr generator<attributes_grapheme> parse_aux_text(It first, ItEnd last)
32 auto phrasing = text_phrasing::regular;
33 auto language = language_tag{};
34 auto style = text_style{};
37 for (
auto it = first; it != last;);
38 hilet attribute = text_attribute{style, phrasing, language};
39 if (
hilet g = *it++; g !=
'[') {
40 co_yield {g, attribute};
45 hilet [s, c] = detail::parse_aux_name<'[', ':', '@', ']'>(it, last);
48 case 'a': phrasing = text_phrasing::abbreviation;
break;
49 case 'b': phrasing = text_phrasing::bold;
break;
50 case 'c': phrasing = text_phrasing::code;
break;
51 case 'e': phrasing = text_phrasing::emphesis;
break;
52 case 'h': phrasing = text_phrasing::help;
break;
53 case 'i': phrasing = text_phrasing::italic;
break;
54 case 'k': phrasing = text_phrasing::key;
break;
55 case 'l': phrasing = text_phrasing::link;
break;
56 case 'm': phrasing = text_phrasing::math;
break;
57 case 'q': phrasing = text_phrasing::quote;
break;
58 case 'r': phrasing = text_phrasing::regular;
break;
59 case 's': phrasing = text_phrasing::strong;
break;
60 case 'u': phrasing = text_phrasing::underline;
break;
61 default:
throw parse_error(std::format(
"Unknown phrasing '{}'.", s));
63 }
else if (s.size() > 1) {
64 language = language_tag{s};
68 co_yield {
'[', attribute};
69 }
else if (c ==
':') {
71 }
else if (c ==
'@') {
72 hilet [s2, c2] = detail::parse_aux_name<']'>(it, last);
73 style = theme_book.get_text_style(s2);
89 constexpr void reset()
noexcept
91 state = state_type::idle;
94 constexpr void operator()(
char32_t c)
noexcept
96 return this->*(state)(c);
100 enum class state_type {
104 [[nodiscard]]
constexpr state_type open_bracket(
grapheme c)
noexcept
108 return state_type::idle;
114 [[nodiscard]]
constexpr state_type idle(
grapheme c)
noexcept
117 return state_type::open_bracket;
118 }
else if (c ==
']') {
119 return state_type::close_bracket;
122 return state_type::idle;
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
Definition aux_text.hpp:80
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41