4 #ifndef LEXY_GRAMMAR_HPP_INCLUDED
5 #define LEXY_GRAMMAR_HPP_INCLUDED
43 namespace dsl =
lexyd;
46 constexpr
bool is_rule = std::is_base_of_v<dsl::rule_base, T>;
64 constexpr
auto is_separator = std::is_base_of_v<lexy::dsl::_sep_base, T>;
67 constexpr
auto is_operation = std::is_base_of_v<lexy::dsl::_operation_base, T>;
69 template <
typename... T>
73 #define LEXY_REQUIRE_BRANCH_RULE(Rule, Name) \
74 static_assert(lexy::_require_branch_rule<Rule>, Name \
75 " requires a branch condition." \
76 " You may need to use `>>` to specify the condition that is used for dispatch." \
77 " See https://lexy.foonathan.net/learn/branching/ for more information.")
100 template <
typename T>
113 return "error token";
136 template <
typename TokenRule>
139 template <
typename TokenRule>
146 template <
typename Production>
149 template <
typename Production>
150 constexpr
bool is_production = _detail::is_detected<production_rule, Production>;
159 template <
typename Production>
168 template <
typename Production>
171 template <
typename Production>
174 return _detail::type_name<Production>();
177 template <
typename Production>
180 template <
typename EntryProduction>
183 if constexpr (_detail::is_detected<_detect_max_recursion_depth, EntryProduction>)
189 template <
typename T>
194 const char*
const*
id;
199 template <
typename Production,
typename = _enable_production_or_operation<Production>>
208 return lhs.
id == rhs.
id;
212 return !(lhs == rhs);
219 template <
typename Production>
222 template <
typename Production>
224 = lexy::_detail::is_detected<_detect_whitespace, Production>;
226 template <
typename Production,
typename WhitespaceProduction>
229 if constexpr (_production_defines_whitespace<Production>)
234 else if constexpr (_production_defines_whitespace<WhitespaceProduction>)
242 template <
typename Production,
typename WhitespaceProduction>
248 template <
typename To,
typename... Args>
250 template <
typename To,
typename Arg>
255 template <
typename ParseState,
typename Production>
259 typename decltype(
LEXY_DECLVAL(ParseState&).value_of(Production{}))::return_type;
261 template <
typename Production>
264 template <
typename Production,
typename Sink>
273 template <
typename... Args>
276 if constexpr (!is_sink_callback_for<Sink, Args&&...>)
279 static_assert(_detail::error<Production, Args...>,
280 "missing value sink callback overload for production");
290 template <
typename Production,
typename ParseState =
void>
292 = lexy::_detail::is_detected<_detect_value_of, ParseState, Production>
293 || lexy::_detail::is_detected<_detect_value, Production>;
295 template <
typename Production,
typename ParseState =
void>
298 static constexpr
auto _get_value([[maybe_unused]] ParseState* state)
300 if constexpr (lexy::_detail::is_detected<_detect_value_of, ParseState, Production>)
301 return state->value_of(Production{});
309 if constexpr (lexy::is_callback<_type>)
320 template <
typename State = ParseState,
typename = std::enable_if_t<std::is_
void_v<State>>>
323 template <
typename State = ParseState,
324 typename = std::enable_if_t<std::is_same_v<State, ParseState>>>
340 static_assert(lexy::is_sink<_type>,
"missing value sink for production");
345 template <
typename... Args>
348 if constexpr (lexy::is_callback_with_state_for<_type, ParseState, Args&&...>
349 && !std::is_void_v<ParseState>)
353 else if constexpr (lexy::is_callback_for<_type, Args&&...>)
357 else if constexpr ((lexy::is_sink<_type>
359 &&_is_convertible<return_type, Args&&...>)
371 static_assert(_detail::error<Production, Args...>,
372 "missing value callback overload for production");
381 #endif // LEXY_GRAMMAR_HPP_INCLUDED