4 #ifndef LEXY_DSL_TOKEN_HPP_INCLUDED
5 #define LEXY_DSL_TOKEN_HPP_INCLUDED
17 return "missing token";
25 template <
typename Tag,
typename Token>
27 template <auto Kind,
typename Token>
30 template <
typename ImplOrTag,
bool IsImpl = lexy::is_token_rule<ImplOrTag>>
32 template <
typename Impl>
35 template <
typename Tag>
41 template <
typename Derived,
typename ImplOrTag = branch_base>
46 template <
typename Reader>
49 typename Reader::marker
end;
51 constexpr
auto try_parse(
const void*,
const Reader& reader)
54 auto result = parser.try_parse(reader);
59 template <
typename Context>
63 template <
typename NextParser,
typename Context,
typename... Args>
66 context.on(
_ev::token{}, Derived{}, reader.position(),
end.position());
73 template <
typename Context,
typename Reader>
76 auto begin = reader.position();
79 using try_parse_result = decltype(parser.try_parse(reader));
80 if constexpr (std::is_same_v<try_parse_result, std::true_type>)
82 parser.try_parse(reader);
86 if (!parser.try_parse(reader))
89 parser.end.position());
90 parser.report_error(context, reader);
91 reader.reset(parser.end);
97 context.on(
_ev::token{},
typename Derived::token_type{},
begin, parser.end.position());
98 reader.reset(parser.end);
103 template <
typename NextParser>
106 template <
typename Context,
typename Reader,
typename... Args>
118 template <
typename Tag>
127 template <auto Kind,
typename Token>
128 struct _tokk : token_base<_tokk<Kind, Token>, Token>
131 template <
typename Tag,
typename Token>
132 struct _toke : token_base<_toke<Tag, Token>, Token>
139 template <
typename Reader,
typename Context>
147 template <
typename Reader>
153 template <
typename Context>
166 template <auto Kind,
typename Token>
167 constexpr
auto token_kind_of<lexy::dsl::_tokk<Kind, Token>> = Kind;
168 template <
typename Tag,
typename Token>
169 constexpr
auto token_kind_of<lexy::dsl::_toke<Tag, Token>> = token_kind_of<Token>;
175 template <
typename Rule>
180 static constexpr
auto name =
"<token>";
182 static constexpr
auto rule = Rule{};
185 template <
typename Reader>
188 typename Reader::marker
end;
190 constexpr
explicit tp(
const Reader& reader) :
end(reader.current()) {}
200 end = reader.current();
204 template <
typename Context>
214 template <
typename Rule>
217 if constexpr (lexy::is_token_rule<Rule>)
224 #endif // LEXY_DSL_TOKEN_HPP_INCLUDED