Go to the documentation of this file.
4 #ifndef LEXY_DSL_SCAN_HPP_INCLUDED
5 #define LEXY_DSL_SCAN_HPP_INCLUDED
16 template <
typename Production>
18 template <
typename Rule,
typename Tag>
20 template <
typename Token>
22 template <
typename T,
typename Base>
30 template <
typename Derived,
typename Reader>
50 template <
typename U = T,
typename = std::enable_if_t<std::is_constructible_v<T, U>>>
56 constexpr
explicit operator bool() const noexcept
62 return static_cast<bool>(
_value);
65 constexpr decltype(
auto)
value() const& noexcept
69 constexpr decltype(
auto)
value() && noexcept
74 template <
typename U = T>
75 constexpr decltype(
auto)
value_or(U&& fallback) const& noexcept
79 template <
typename U = T>
80 constexpr decltype(
auto)
value_or(U&& fallback) && noexcept
90 template <
typename Derived,
typename Reader>
107 constexpr
explicit operator bool() const noexcept
113 return static_cast<bool>(
_value);
121 template <
typename Derived,
typename Reader>
125 template <
typename T>
127 template <
typename T>
134 template <
typename Reader>
147 template <
typename Context,
typename Reader,
typename T>
154 template <
typename Context,
typename Reader>
163 template <
typename Derived,
typename Reader>
173 constexpr
explicit operator bool() const noexcept
183 constexpr
auto position() const noexcept -> typename Reader::iterator
194 template <
typename T,
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
207 template <
typename Production,
typename = lexy::production_rule<Production>>
208 constexpr
auto parse(Production = {})
213 typename context_t::state_type>::return_type;
220 template <
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
228 template <
typename T,
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
231 static_assert(lexy::is_branch_rule<Rule>);
235 auto& context =
static_cast<Derived&
>(*this).context();
237 if (!parser.try_parse(context.control_block,
_reader))
239 parser.cancel(context);
243 auto success = parser.template finish<lexy::_detail::scan_final_parser>(context,
_reader,
250 template <
typename Production,
typename T,
typename = lexy::production_rule<Production>>
256 template <
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
260 return branch(result, rule);
272 auto& context =
static_cast<Derived&
>(*_self).context();
279 auto& context =
static_cast<Derived&
>(*_self).context();
287 auto& context =
static_cast<Derived&
>(*_self).context();
299 return error_recovery_guard(*
this);
302 template <
typename TokenRule>
305 static_assert(lexy::is_token_rule<TokenRule>);
313 auto& context =
static_cast<Derived&
>(*this).context();
319 template <
typename Tag,
typename... Args>
320 constexpr
void error(Tag, Args&&... args)
322 auto& context =
static_cast<Derived&
>(*this).context();
326 template <
typename Tag,
typename... Args>
334 template <
typename T,
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
342 template <
typename Rule>
345 static_assert(lexy::is_rule<Rule>);
346 return branch(dsl::_peek<Rule, void>{});
349 template <
typename T,
typename Base,
typename Digits>
356 template <
typename T,
typename Digits>
364 template <
typename Rule>
367 static_assert(lexy::is_rule<Rule>);
378 template <
typename Token>
411 template <
typename Context,
typename Reader>
419 auto& cb =
_context->control_block();
420 return static_cast<std::size_t
>(cb.cur_depth);
423 constexpr
auto begin() const noexcept -> typename Reader::iterator
449 template <
typename Context,
typename Scanner,
typename StatePtr>
454 template <
typename NextParser>
457 template <
typename Scanner,
typename Context,
typename Reader,
typename... Args>
464 decltype(context.control_block->parse_state)>)
470 reader.set_position(scanner.position());
474 if constexpr (std::is_void_v<
typename decltype(result)::value_type>)
480 template <
typename Context,
typename Reader,
typename... Args>
494 template <
typename T>
500 static constexpr
auto value = lexy::forward<T>;
504 #endif // LEXY_DSL_SCAN_HPP_INCLUDED
_detail::lazy_init< void > _value
constexpr scan_result(_detail::lazy_init< void > &&value)
constexpr bool branch(scan_result< T > &result, Production={})
constexpr bool branch(Rule rule)
static constexpr auto value
constexpr bool branch(scan_result< T > &result, Rule)
constexpr scan_result(U &&value)
constexpr bool is_detected
typename Reader::encoding encoding
decltype(Context::production::scan(LEXY_DECLVAL(Scanner &), *StatePtr())) _detect_scan_state
static LEXY_PARSER_FUNC bool _parse(Scanner &scanner, Context &context, Reader &reader, Args &&... args)
constexpr scan_result(bool has_value)
constexpr auto remaining_input() const noexcept
constexpr bool peek(Rule)
typename BranchRule::template bp< Reader > branch_parser_for
constexpr auto error_recovery()
constexpr auto begin() const noexcept -> typename Reader::iterator
constexpr auto parse(Production={})
constexpr rule_scanner(Context &context, Reader reader)
typename Context::production production
scan_result(T &&) -> scan_result< std::decay_t< T >>
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr auto integer(Digits digits)
#define LEXY_PRECONDITION(Expr)
constexpr auto end(const C &c) -> decltype(c.end())
constexpr void parse(Rule rule)
constexpr struct lexy::scan_failed_t scan_failed
constexpr void parse(scan_result< T > &result, Rule)
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
constexpr T & emplace(Args &&... args)
static constexpr auto rule
constexpr LEXY_FORCE_INLINE auto try_match_token(TokenRule, Reader &reader)
constexpr bool is_at_eof() const
constexpr scan_result(scan_failed_t)
constexpr auto integer(Digits digits)
constexpr auto capture_token(Token)
constexpr scanner & operator=(const scanner &) noexcept=delete
#define LEXY_DECAY_DECLTYPE(...)
constexpr auto parse(Rule rule)
constexpr auto digits
Matches a non-empty list of digits.
error_recovery_guard(const error_recovery_guard &)=delete
constexpr scanner(const scanner &) noexcept=delete
constexpr auto capture(Rule rule) -> scan_result< lexeme< Reader >>
constexpr auto begin(const C &c) -> decltype(c.begin())
constexpr bool has_value() const noexcept
constexpr scan_result()=default
constexpr bool discard(TokenRule rule)
constexpr Context & context() noexcept
constexpr void error(Tag, Args &&... args)
constexpr void fatal_error(Tag tag, Args &&... args)
constexpr scanner(const Reader &reader) noexcept
constexpr Reader & reader() noexcept
error_recovery_guard & operator=(const error_recovery_guard &)=delete
typename Rule::template p< NextParser > parser_for
static LEXY_PARSER_FUNC bool parse(Context &, Reader &, lazy_init< T > *dest, T &&value)
constexpr void cancel() &&
constexpr decltype(auto) value_or(U &&fallback) const &noexcept
static LEXY_PARSER_FUNC bool parse(Context &, Reader &, lazy_init< void > *dest)
constexpr auto position() const noexcept -> typename Reader::iterator
constexpr std::size_t recursion_depth() const noexcept
#define LEXY_DECLVAL(...)
constexpr scan_result(_detail::lazy_init< T > &&value)
constexpr error_recovery_guard(scanner &self) noexcept
constexpr bool has_value() const noexcept
enum lexy::_detail::scanner::@5 _state
constexpr void finish() &&
constexpr auto eof
Matches EOF.
constexpr scan_result(scan_failed_t)
constexpr decltype(auto) value() const &noexcept
_detail::lazy_init< T > _value