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::iterator
pos;
82 template <
typename OpList,
typename Reader>
85 using encoding =
typename Reader::encoding;
88 auto begin = reader.position();
89 auto op = op_matcher::try_match(reader);
96 template <
typename Tag,
typename Reader>
99 template <
typename TagType,
typename Literal,
typename... R>
105 template <
typename NextParser,
typename Context,
typename Reader,
typename... Args>
110 context.on(
_ev::token{},
typename Literal::token_type{},
op.pos, reader.position());
114 if constexpr (std::is_void_v<TagType>)
116 else if constexpr (lexy::_detail::is_detected<_detect_op_tag_ctor, op_tag_type, Reader>)
123 template <
typename Reader>
128 template <
typename ControlBlock>
129 constexpr
auto try_parse(
const ControlBlock* cb,
const Reader& reader)
131 return impl.try_parse(cb, reader);
134 template <
typename Context>
137 impl.cancel(context);
140 template <
typename NextParser,
typename Context,
typename... Args>
145 if constexpr (std::is_void_v<TagType>)
146 return impl.template finish<continuation>(context, reader,
LEXY_FWD(args)...);
147 else if constexpr (lexy::_detail::is_detected<_detect_op_tag_ctor, op_tag_type, Reader>)
148 return impl.template finish<continuation>(context, reader,
LEXY_FWD(args)...,
151 return impl.template finish<continuation>(context, reader,
LEXY_FWD(args)...,
156 template <
typename NextParser>
159 template <
typename Context,
typename Reader,
typename... Args>
162 [[maybe_unused]]
auto pos = reader.position();
166 if constexpr (std::is_void_v<TagType>)
168 else if constexpr (lexy::_detail::is_detected<_detect_op_tag_ctor, op_tag_type, Reader>)
176 template <
typename Literal>
177 constexpr
auto op(Literal)
179 static_assert(lexy::is_literal_rule<Literal>);
182 template <
typename Literal,
typename... R>
185 static_assert(lexy::is_literal_rule<Literal>,
186 "condition in the operator must be a literal rule");
190 template <
typename Tag,
typename Literal>
191 constexpr
auto op(Literal)
193 static_assert(lexy::is_literal_rule<Literal>);
196 template <
typename Tag,
typename Literal,
typename... R>
199 static_assert(lexy::is_literal_rule<Literal>,
200 "condition in the operator must be a literal rule");
201 return _op<Tag, Literal, R...>{};
204 template <auto Tag,
typename Literal>
205 constexpr
auto op(Literal)
207 static_assert(lexy::is_literal_rule<Literal>);
210 template <
auto Tag,
typename Literal,
typename... R>
211 constexpr
auto op(_br<Literal, R...>)
213 static_assert(lexy::is_literal_rule<Literal>,
214 "condition in the operator must be a literal rule");
222 template <
typename... Ops>
225 using op_literals = decltype((
typename Ops::op_literals{} + ...));
227 template <
typename NextParser,
typename Context,
typename Reader,
typename... Args>
234 auto cur_idx = std::size_t(0);
236 ? (result = Ops::template op_finish<NextParser>(context, reader,
op,
239 : (++cur_idx,
false))
245 template <
typename Reader>
249 typename Reader::iterator
end;
253 op = lexy::_detail::parse_operator<op_literals>(reader);
254 end = reader.position();
258 template <
typename Context>
262 template <
typename NextParser,
typename Context,
typename... Args>
265 reader.set_position(
end);
266 return op_finish<NextParser>(context, reader,
op,
LEXY_FWD(args)...);
270 template <
typename NextParser>
273 template <
typename Context,
typename Reader,
typename... Args>
277 if (!impl.try_parse(context.control_block, reader))
285 return impl.template finish<NextParser>(context, reader,
LEXY_FWD(args)...);
291 template <
typename T1,
typename L1,
typename... R1,
typename T2,
typename L2,
typename... R2>
294 return _opc<decltype(lhs), decltype(rhs)>{};
296 template <
typename... Ops,
typename T2,
typename L2,
typename... R2>
299 return _opc<Ops..., decltype(rhs)>{};
301 template <
typename T1,
typename L1,
typename... R1,
typename... Ops>
304 return _opc<decltype(lhs), Ops...>{};
306 template <
typename... O1,
typename... O2>
309 return _opc<O1..., O2...>{};
313 #endif // LEXY_DSL_OPERATOR_HPP_INCLUDED