4 #ifndef LEXY_DSL_OPERATOR_HPP_INCLUDED
5 #define LEXY_DSL_OPERATOR_HPP_INCLUDED
14 template <
typename Condition,
typename... R>
16 template <
typename... R>
23 template <
typename Literal>
27 template <
typename T, T Value>
37 template <auto Operator>
39 template <const auto& Operator>
47 template <
typename... Literals>
50 static constexpr
auto size =
sizeof...(Literals);
52 template <
typename Encoding>
57 auto value = std::size_t(0);
58 auto char_class = std::size_t(0);
59 ((result.node_value[Literals::lit_insert(result, 0, char_class)] = value++,
60 char_class += Literals::lit_char_classes.size),
65 template <
typename Encoding>
68 template <
typename... T>
75 template <
typename Reader>
78 typename Reader::marker
cur;
82 template <
typename OpList,
typename Reader>
85 using encoding =
typename Reader::encoding;
88 auto begin = reader.current();
89 auto op = op_matcher::try_match(reader);
96 template <
typename Tag,
typename Reader>
99 template <
typename Tag,
typename Reader,
typename Context>
101 = decltype(Tag(*
LEXY_DECLVAL(Context).control_block->parse_state,
104 template <
typename TagType,
typename Literal,
typename... R>
110 template <
typename NextParser,
typename Context,
typename Reader,
typename... Args>
115 context.on(
_ev::token{},
typename Literal::token_type{},
op.cur.position(),
120 if constexpr (std::is_void_v<TagType>)
126 else if constexpr (lexy::_detail::is_detected<_detect_op_tag_ctor, op_tag_type, Reader>)
133 template <
typename Reader>
138 template <
typename ControlBlock>
139 constexpr
auto try_parse(
const ControlBlock* cb,
const Reader& reader)
141 return impl.try_parse(cb, reader);
144 template <
typename Context>
147 impl.cancel(context);
150 template <
typename NextParser,
typename Context,
typename... Args>
155 if constexpr (std::is_void_v<TagType>)
156 return impl.template finish<continuation>(context, reader,
LEXY_FWD(args)...);
160 .template finish<continuation>(context, reader,
LEXY_FWD(args)...,
163 else if constexpr (lexy::_detail::is_detected<_detect_op_tag_ctor, op_tag_type, Reader>)
164 return impl.template finish<continuation>(context, reader,
LEXY_FWD(args)...,
167 return impl.template finish<continuation>(context, reader,
LEXY_FWD(args)...,
172 template <
typename NextParser>
175 template <
typename Context,
typename Reader,
typename... Args>
178 [[maybe_unused]]
auto pos = reader.position();
182 if constexpr (std::is_void_v<TagType>)
187 op_tag_type(*context.control_block->parse_state, pos));
188 else if constexpr (lexy::_detail::is_detected<_detect_op_tag_ctor, op_tag_type, Reader>)
196 template <
typename Literal>
197 constexpr
auto op(Literal)
199 static_assert(lexy::is_literal_rule<Literal>);
202 template <
typename Literal,
typename... R>
205 static_assert(lexy::is_literal_rule<Literal>,
206 "condition in the operator must be a literal rule");
210 template <
typename Tag,
typename Literal>
211 constexpr
auto op(Literal)
213 static_assert(lexy::is_literal_rule<Literal>);
216 template <
typename Tag,
typename Literal,
typename... R>
219 static_assert(lexy::is_literal_rule<Literal>,
220 "condition in the operator must be a literal rule");
221 return _op<Tag, Literal, R...>{};
224 template <auto Tag,
typename Literal>
225 constexpr
auto op(Literal)
227 static_assert(lexy::is_literal_rule<Literal>);
230 template <
auto Tag,
typename Literal,
typename... R>
231 constexpr
auto op(_br<Literal, R...>)
233 static_assert(lexy::is_literal_rule<Literal>,
234 "condition in the operator must be a literal rule");
242 template <
typename... Ops>
245 using op_literals = decltype((
typename Ops::op_literals{} + ...));
247 template <
typename NextParser,
typename Context,
typename Reader,
typename... Args>
254 auto cur_idx = std::size_t(0);
256 ? (result = Ops::template op_finish<NextParser>(context, reader,
op,
259 : (++cur_idx,
false))
265 template <
typename Reader>
269 typename Reader::marker
end;
273 op = lexy::_detail::parse_operator<op_literals>(reader);
274 end = reader.current();
278 template <
typename Context>
282 template <
typename NextParser,
typename Context,
typename... Args>
286 return op_finish<NextParser>(context, reader,
op,
LEXY_FWD(args)...);
290 template <
typename NextParser>
293 template <
typename Context,
typename Reader,
typename... Args>
297 if (!impl.try_parse(context.control_block, reader))
305 return impl.template finish<NextParser>(context, reader,
LEXY_FWD(args)...);
311 template <
typename T1,
typename L1,
typename... R1,
typename T2,
typename L2,
typename... R2>
314 return _opc<decltype(lhs), decltype(rhs)>{};
316 template <
typename... Ops,
typename T2,
typename L2,
typename... R2>
319 return _opc<Ops..., decltype(rhs)>{};
321 template <
typename T1,
typename L1,
typename... R1,
typename... Ops>
324 return _opc<decltype(lhs), Ops...>{};
326 template <
typename... O1,
typename... O2>
329 return _opc<O1..., O2...>{};
333 #endif // LEXY_DSL_OPERATOR_HPP_INCLUDED