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 Rule>
24 template <
typename T,
typename Base>
32 template <
typename Derived,
typename Reader>
52 template <
typename U = T,
typename = std::enable_if_t<std::is_constructible_v<T, U>>>
58 constexpr
explicit operator bool() const noexcept
64 return static_cast<bool>(
_value);
67 constexpr decltype(
auto)
value() const& noexcept
71 constexpr decltype(
auto)
value() && noexcept
76 template <
typename U = T>
77 constexpr decltype(
auto)
value_or(U&& fallback) const& noexcept
81 template <
typename U = T>
82 constexpr decltype(
auto)
value_or(U&& fallback) && noexcept
92 template <
typename Derived,
typename Reader>
109 constexpr
explicit operator bool() const noexcept
115 return static_cast<bool>(
_value);
123 template <
typename Derived,
typename Reader>
127 template <
typename T>
129 template <
typename T>
136 template <
typename Reader>
149 template <
typename Context,
typename Reader,
typename T>
156 template <
typename Context,
typename Reader>
165 template <
typename Derived,
typename Reader>
175 constexpr
explicit operator bool() const noexcept
185 constexpr
auto position() const noexcept -> typename Reader::iterator
189 constexpr
auto current() const noexcept -> typename Reader::marker
200 template <
typename T,
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
213 template <
typename Production,
typename = lexy::production_rule<Production>>
214 constexpr
auto parse(Production = {})
219 typename context_t::state_type>::return_type;
226 template <
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
234 template <
typename T,
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
241 auto& context =
static_cast<Derived&
>(*this).context();
243 if (!parser.try_parse(context.control_block,
_reader))
245 parser.cancel(context);
249 auto success = parser.template finish<lexy::_detail::scan_final_parser>(context,
_reader,
256 template <
typename Production,
typename T,
typename = lexy::production_rule<Production>>
262 template <
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
266 return branch(result, rule);
278 auto& context =
static_cast<Derived&
>(*_self).context();
285 auto& context =
static_cast<Derived&
>(*_self).context();
293 auto& context =
static_cast<Derived&
>(*_self).context();
305 return error_recovery_guard(*
this);
308 template <
typename TokenRule>
311 static_assert(lexy::is_token_rule<TokenRule>);
319 auto& context =
static_cast<Derived&
>(*this).context();
325 template <
typename Tag,
typename... Args>
326 constexpr
void error(Tag, Args&&... args)
328 auto& context =
static_cast<Derived&
>(*this).context();
332 template <
typename... Args>
333 constexpr
void error(
const char* msg, Args&&... args)
335 auto& context =
static_cast<Derived&
>(*this).context();
339 template <
typename Tag,
typename... Args>
346 template <
typename... Args>
354 template <
typename T,
typename Rule,
typename = std::enable_if_t<lexy::is_rule<Rule>>>
362 template <
typename Rule>
365 static_assert(lexy::is_rule<Rule>);
366 return branch(dsl::_peek<Rule, void>{});
369 template <
typename T,
typename Base,
typename Digits>
376 template <
typename T,
typename Digits>
384 template <
typename Token>
391 template <
typename Production>
424 template <
typename Context,
typename Reader>
432 auto& cb =
_context->control_block();
433 return static_cast<std::size_t
>(cb.cur_depth);
436 constexpr
auto begin() const noexcept -> typename Reader::iterator
462 template <
typename Context,
typename Scanner,
typename StatePtr,
typename... Args>
468 template <
typename NextParser>
471 template <
typename Scanner,
typename Context,
typename Reader,
typename... Args>
478 decltype(context.control_block->parse_state), Args&&...>)
484 reader.reset(scanner.current());
488 if constexpr (std::is_void_v<
typename decltype(result)::value_type>)
494 template <
typename Context,
typename Reader,
typename... Args>
508 template <
typename T>
514 static constexpr
auto value = lexy::forward<T>;
518 #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
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()
scan_result(_detail::lazy_init< T > &&) -> scan_result< T >
constexpr auto begin() const noexcept -> typename Reader::iterator
constexpr auto parse(Production={})
constexpr void error(const char *msg, Args &&... args)
decltype(Context::production::scan(LEXY_DECLVAL(Scanner &), *StatePtr(), LEXY_DECLVAL(Args)...)) _detect_scan_state
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)
constexpr auto capture(lexyd::_prd< Production >)
#define LEXY_PRECONDITION(Expr)
constexpr auto end(const C &c) -> decltype(c.end())
constexpr void parse(Rule rule)
#define LEXY_REQUIRE_BRANCH_RULE(Rule, Name)
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.
Type erased generic failure.
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)
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 auto current() const noexcept -> typename Reader::marker
constexpr scanner(const scanner &) noexcept=delete
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 void fatal_error(const char *msg, Args &&... args)
constexpr decltype(auto) value() const &noexcept
_detail::lazy_init< T > _value