Go to the documentation of this file.
4 #ifndef LEXY_DSL_WHITESPACE_HPP_INCLUDED
5 #define LEXY_DSL_WHITESPACE_HPP_INCLUDED
16 template <
typename Rule>
24 template <
typename WhitespaceRule>
27 static constexpr
auto name =
"<whitespace>";
32 template <
typename Rule>
38 template <
typename Handler>
42 constexpr
explicit ws_handler(Handler& handler,
typename Handler::event_handler& evh)
45 template <
typename Context>
47 :
ws_handler(context.control_block->parse_handler, context.handler)
53 template <
typename Rule>
56 template <
typename Production>
59 static_assert(_detail::error<Production>,
60 "whitespace rule must not contain `dsl::p` or `dsl::recurse`;"
61 "use `dsl::inline_` instead");
64 template <
typename Error>
70 template <
typename Event,
typename... Args>
77 template <
typename Production,
typename State>
83 return rule_parse_result;
86 template <
typename Event,
typename... Args>
87 constexpr
auto real_on(Event ev, Args&&... args)
96 template <
typename Context>
102 template <
typename WhitespaceRule>
105 if constexpr (lexy::is_char_class_rule<WhitespaceRule>)
106 return WhitespaceRule::char_class_ascii().contains[int(
' ')];
111 template <
typename WhitespaceRule,
typename Handler,
typename Reader>
114 auto begin = reader.position();
116 if constexpr (lexy::is_token_rule<WhitespaceRule>)
120 if constexpr (_detail::is_swar_reader<Reader>
121 && space_is_definitely_whitespace<WhitespaceRule>())
146 return std::true_type{};
148 else if constexpr (!std::is_void_v<WhitespaceRule>)
153 auto result = lexy::do_action<production, ws_result>(
LEXY_MOV(handler),
166 return std::true_type{};
174 template <
typename NextParser>
177 template <
typename Context,
typename Reader,
typename... Args>
180 if (!std::is_base_of_v<disable_whitespace_skipping, NextParser>
181 && context.control_block->enable_whitespace_skipping)
184 typename Context::whitespace_production>;
185 if (!skip_whitespace<whitespace>(
ws_handler(context), reader))
197 template <
typename Rule>
198 struct _wsr : rule_base
200 template <
typename NextParser>
203 template <
typename Context,
typename Reader,
typename... Args>
204 constexpr
static bool parse(Context& context, Reader& reader, Args&&... args)
215 template <
typename R>
218 return _wsr<decltype(Rule{} | r)>{};
220 template <
typename R>
223 return _wsr<decltype(r | Rule{})>{};
227 template <
typename Rule>
237 template <
typename Rule>
240 template <
typename NextParser>
243 template <
typename Context,
typename Reader,
typename... Args>
247 context.control_block->enable_whitespace_skipping =
true;
254 template <
typename Reader>
259 template <
typename ControlBlock>
260 constexpr
auto try_parse(
const ControlBlock* cb,
const Reader& reader)
264 return rule.try_parse(cb, reader);
267 template <
typename Context>
270 rule.cancel(context);
273 template <
typename NextParser,
typename Context,
typename... Args>
277 context.control_block->enable_whitespace_skipping =
false;
278 return rule.template finish<_pc<NextParser>>(context, reader,
LEXY_FWD(args)...);
282 template <
typename NextParser>
285 template <
typename Context,
typename Reader,
typename... Args>
289 typename Context::whitespace_production>;
290 if constexpr (std::is_void_v<whitespace>)
299 context.control_block->enable_whitespace_skipping =
false;
308 template <
typename Rule>
311 if constexpr (lexy::is_token_rule<Rule>)
318 #endif // LEXY_DSL_WHITESPACE_HPP_INCLUDED
constexpr static bool parse(Context &context, Reader &reader, Args &&... args)
constexpr int on(ws_handler &, Event, const Args &...)
lexy::branch_parser_for< Rule, Reader > rule
string_view::value_type char_type
ws_handler(Context &context) -> ws_handler< typename Context::handler_type >
constexpr ws_handler(Context &context)
typename BranchRule::template bp< Reader > branch_parser_for
constexpr void * no_parse_state
constexpr auto no_whitespace(Rule)
Disables automatic skipping of whitespace for all tokens of the given rule.
static constexpr auto rule
constexpr friend auto operator|(R r, _wsr< Rule >)
constexpr ws_handler(Handler &handler, typename Handler::event_handler &evh)
static constexpr auto max_recursion_depth
constexpr auto loop(Rule)
Repeatedly matches the rule until a break rule matches.
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
constexpr auto try_parse(const ControlBlock *cb, const Reader &reader)
constexpr event_handler(ws_production< Rule >)
constexpr LEXY_FORCE_INLINE auto try_match_token(TokenRule, Reader &reader)
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr bool space_is_definitely_whitespace()
constexpr void cancel(Context &context)
constexpr friend auto operator|(_wsr< Rule >, R r)
constexpr bool get_result(bool rule_parse_result) &&
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr auto real_on(Event ev, Args &&... args)
decltype(_production_whitespace< Production, WhitespaceProduction >()) production_whitespace
constexpr auto begin(const C &c) -> decltype(c.begin())
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr auto break_
Exits a loop().
constexpr event_handler(Production)
Handler::event_handler * _event_handler
typename Rule::template p< NextParser > parser_for
constexpr auto whitespace(Rule)
constexpr auto skip_whitespace(ws_handler< Handler > &&handler, Reader &reader)
LEXY_PARSER_FUNC auto finish(Context &context, Reader &reader, Args &&... args)
constexpr void on(ws_handler &handler, parse_events::error ev, const Error &error)
decltype(_copy_base_impl< Rule >()) _copy_base
constexpr swar_int swar_fill(CharT _c)
static constexpr auto name