Go to the documentation of this file.
4 #ifndef LEXY_DSL_DIGIT_HPP_INCLUDED
5 #define LEXY_DSL_DIGIT_HPP_INCLUDED
26 return "digit.binary";
36 static constexpr
unsigned digit_radix = 2;
38 template <
typename CharT>
41 return static_cast<unsigned>(c) -
'0';
44 template <
typename CharT>
51 return (c & mask) == expected && ((c + offset) & mask) == expected;
71 static constexpr
unsigned digit_radix = 8;
73 template <
typename CharT>
76 return static_cast<unsigned>(c) -
'0';
79 template <
typename CharT>
86 return (c & mask) == expected && ((c + offset) & mask) == expected;
96 return "digit.decimal";
106 static constexpr
unsigned digit_radix = 10;
108 template <
typename CharT>
111 return static_cast<unsigned>(c) -
'0';
114 template <
typename CharT>
121 return (c & mask) == expected && ((c + offset) & mask) == expected;
130 return "digit.hex-lower";
143 template <
typename CharT>
147 return static_cast<unsigned>(c) -
'a' + 10;
149 return static_cast<unsigned>(c) -
'0';
154 template <
typename CharT>
166 return "digit.hex-upper";
179 template <
typename CharT>
183 return static_cast<unsigned>(c) -
'A' + 10;
185 return static_cast<unsigned>(c) -
'0';
190 template <
typename CharT>
215 static constexpr
unsigned digit_radix = 16;
217 template <
typename CharT>
221 return static_cast<unsigned>(c) -
'a' + 10;
223 return static_cast<unsigned>(c) -
'A' + 10;
225 return static_cast<unsigned>(c) -
'0';
230 template <
typename CharT>
262 template <
typename Base = decimal,
int = Base::digit_radix>
286 return "forbidden leading zero";
293 template <
typename Base,
typename Reader>
304 if constexpr (lexy::_detail::is_swar_reader<Reader>)
307 while (Base::template swar_matches<char_type>(reader.peek_swar()))
317 template <
typename Base,
typename Sep,
typename Reader>
336 if constexpr (lexy::_detail::is_swar_reader<Reader>)
339 while (Base::template swar_matches<char_type>(reader.peek_swar()))
352 template <
typename Base,
typename Sep>
355 template <
typename Reader>
358 typename Reader::iterator
end;
361 constexpr
explicit tp(
const Reader& reader)
368 auto begin = reader.position();
369 auto result = _match_digits_sep<Base, Sep>(reader);
370 end = reader.position();
373 && *
begin == lexy::_detail::transcode_char<char_type>(
'0'))
383 template <
typename Context>
402 template <
typename Base,
typename Sep>
405 template <
typename Reader>
408 typename Reader::iterator
end;
414 auto result = _match_digits_sep<Base, Sep>(reader);
415 end = reader.position();
419 template <
typename Context>
433 template <
typename Base>
436 template <
typename Reader>
439 typename Reader::iterator
end;
442 constexpr
explicit tp(
const Reader& reader)
449 auto begin = reader.position();
450 auto result = _match_digits<Base>(reader);
451 end = reader.position();
454 && *
begin == lexy::_detail::transcode_char<char_type>(
'0'))
464 template <
typename Context>
476 Base::char_class_name());
482 template <
typename Token>
483 constexpr
auto sep(Token)
const
485 static_assert(lexy::is_token_rule<Token>);
490 template <
typename Base>
493 template <
typename Reader>
496 typename Reader::iterator
end;
502 auto result = _match_digits<Base>(reader);
503 end = reader.position();
507 template <
typename Context>
511 Base::char_class_name());
516 template <
typename Token>
517 constexpr
auto sep(Token)
const
519 static_assert(lexy::is_token_rule<Token>);
530 template <
typename Base = decimal>
539 template <
typename Base>
541 template <
typename Base>
543 template <
typename Base,
typename Sep>
545 template <
typename Base,
typename Sep>
552 template <std::
size_t N,
typename Base,
typename Sep>
557 template <
typename Reader, std::size_t... Idx>
560 typename Reader::iterator
end;
569 end = reader.position();
577 end = reader.position();
581 template <
typename Context>
590 template <std::
size_t N,
typename Base>
593 static_assert(N > 1);
595 template <
typename Reader,
typename Indices = lexy::_detail::make_index_sequence<N>>
597 template <
typename Reader, std::size_t... Idx>
600 typename Reader::iterator
end;
608 end = reader.position();
612 template <
typename Context>
620 template <
typename Token>
621 constexpr
auto sep(Token)
const
623 static_assert(lexy::is_token_rule<Token>);
629 template <std::
size_t N,
typename Base = decimal>
635 template <std::
size_t N,
typename Base>
637 template <std::
size_t N,
typename Base,
typename Sep>
641 #endif // LEXY_DSL_DIGIT_HPP_INCLUDED
static constexpr unsigned digit_value(CharT c)
constexpr auto position
Produces an iterator to the current reader position without parsing anything.
constexpr bool try_parse(Reader reader)
static constexpr bool swar_matches(lexy::_detail::swar_int c)
integer_sequence< std::size_t, Indices... > index_sequence
static constexpr unsigned digit_value(CharT c)
constexpr tp(const Reader &reader)
string_view::value_type char_type
constexpr tp(const Reader &reader)
static LEXY_CONSTEVAL auto char_class_ascii()
static constexpr unsigned digit_value(CharT c)
constexpr auto n_digits
Matches exactly N digits.
static constexpr unsigned digit_value(CharT c)
constexpr auto no_leading_zero() const
static LEXY_CONSTEVAL auto char_class_ascii()
constexpr bool try_parse(Reader reader)
constexpr Iterator next(Iterator iter)
constexpr void report_error(Context &context, const Reader &)
constexpr bool try_parse(Reader reader)
static LEXY_CONSTEVAL auto char_class_name()
static LEXY_CONSTEVAL auto char_class_name()
static LEXY_CONSTEVAL auto char_class_name()
constexpr void insert(int c)
constexpr bool try_parse(Reader reader)
static LEXY_CONSTEVAL auto char_class_name()
static LEXY_CONSTEVAL auto char_class_ascii()
static LEXY_CONSTEVAL auto name()
typename _make_index_sequence< Size >::type make_index_sequence
constexpr auto end(const C &c) -> decltype(c.end())
constexpr void report_error(Context &context, const Reader &)
static LEXY_CONSTEVAL auto char_class_name()
constexpr tp(const Reader &reader)
bool forbidden_leading_zero
constexpr LEXY_FORCE_INLINE auto try_match_token(TokenRule, Reader &reader)
constexpr auto digit_sep_underscore
constexpr tp(const Reader &reader)
static constexpr bool swar_matches(lexy::_detail::swar_int c)
static constexpr bool swar_matches(lexy::_detail::swar_int c)
constexpr void report_error(Context &context, const Reader &reader)
constexpr void report_error(Context &context, const Reader &)
constexpr bool try_parse(Reader reader)
static LEXY_CONSTEVAL auto char_class_ascii()
constexpr auto digits
Matches a non-empty list of digits.
constexpr tp(const Reader &reader)
constexpr bool _match_digits_sep(Reader &reader)
constexpr void report_error(Context &context, const Reader &reader)
static LEXY_CONSTEVAL auto char_class_name()
static constexpr bool swar_matches(lexy::_detail::swar_int c)
constexpr auto begin(const C &c) -> decltype(c.begin())
bool forbidden_leading_zero
constexpr auto digit
Matches a single digit.
constexpr auto digit_sep_tick
static LEXY_CONSTEVAL auto char_class_ascii()
static LEXY_CONSTEVAL auto char_class_name()
constexpr tp(const Reader &reader)
constexpr bool _match_digits(Reader &reader)
constexpr auto sep(Token) const
constexpr auto sep(Token) const
static LEXY_CONSTEVAL auto char_class_ascii()
static constexpr bool swar_matches(lexy::_detail::swar_int c)
static constexpr unsigned digit_radix
static LEXY_CONSTEVAL auto char_class_ascii()
constexpr auto sep(Token) const
constexpr auto zero
Matches the zero digit.
static constexpr bool swar_matches(lexy::_detail::swar_int c)
static constexpr unsigned digit_value(CharT c)
static constexpr unsigned digit_value(CharT c)
constexpr bool try_parse(Reader reader)
constexpr swar_int swar_fill_compl(CharT _c)
static constexpr unsigned digit_radix
constexpr auto no_leading_zero() const
constexpr void report_error(Context &context, const Reader &reader)
constexpr swar_int swar_fill(CharT _c)