4 #ifndef LEXY_DSL_SUBGRAMMAR_HPP_INCLUDED
5 #define LEXY_DSL_SUBGRAMMAR_HPP_INCLUDED
12 template <
typename Production,
typename Handler,
typename State,
typename Reader>
15 template <
typename Production,
typename Action>
20 #define LEXY_DECLARE_SUBGRAMMAR(Production) \
23 template <typename ParseState> \
24 constexpr auto production_has_value_callback<Production, ParseState> = true; \
26 template <typename Handler, typename State, typename Reader> \
27 struct _subgrammar<Production, Handler, State, Reader> \
29 template <typename T> \
30 static bool parse(_detail::lazy_init<T>& value, \
31 _detail::parse_context_control_block<Handler, State>* control_block, \
36 #define LEXY_DEFINE_SUBGRAMMAR(Production) \
37 template <typename Handler, typename State, typename Reader> \
38 template <typename T> \
39 bool ::lexy::_subgrammar<Production, Handler, State, Reader>:: \
40 parse(::lexy::_detail::lazy_init<T>& value, \
41 ::lexy::_detail::parse_context_control_block<Handler, State>* control_block, \
44 lexy::_pc<Handler, State, Production> context(control_block); \
45 auto success = ::lexy::_do_action(context, reader); \
46 value = LEXY_MOV(context.value); \
50 #define LEXY_INSTANTIATE_SUBGRAMMAR(Production, ...) \
51 template bool ::lexy::_subgrammar_for<Production, __VA_ARGS__> \
52 ::parse<::lexy::_production_value_type<typename __VA_ARGS__::handler, \
53 typename __VA_ARGS__::state, Production>> \
54 (::lexy::_detail::lazy_init<::lexy::_production_value_type< \
55 typename __VA_ARGS__::handler, typename __VA_ARGS__::state, Production>>&, \
56 ::lexy::_detail::parse_context_control_block<typename __VA_ARGS__::handler, \
57 typename __VA_ARGS__::state>*, \
58 ::lexy::input_reader<typename __VA_ARGS__::input>&);
62 template <
typename Production,
typename T>
65 template <
typename NextParser>
68 template <
typename Context,
typename Reader,
typename... Args>
72 using handler_type =
typename control_block_type::handler_type;
73 using state_type =
typename control_block_type::state_type;
75 auto vars = context.control_block->vars;
76 context.control_block->vars =
nullptr;
78 constexpr
auto production_uses_void_callback = std::is_same_v<
79 typename handler_type::template value_callback<Production, state_type>,
81 using value_type = std::conditional_t<production_uses_void_callback, void, T>;
84 using subgrammar_traits
87 = subgrammar_traits::template parse<value_type>(value, context.control_block,
90 context.control_block->vars = vars;
95 if constexpr (std::is_void_v<value_type>)
105 template <
typename Production,
typename T>
109 #endif // LEXY_DSL_SUBGRAMMAR_HPP_INCLUDED