// // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/url // #ifndef BOOST_URL_GRAMMAR_OPTIONAL_RULE_HPP #define BOOST_URL_GRAMMAR_OPTIONAL_RULE_HPP #include #include #include #include #include #include #include namespace boost { namespace urls { namespace grammar { namespace implementation_defined { template struct optional_rule_t : private empty_value { using value_type = boost::optional< typename Rule::value_type>; system::result parse( char const*& it, char const* end) const; constexpr optional_rule_t( Rule const& r) noexcept : empty_value( empty_init, r) { } }; } // implementation_defined /** Match a rule, or the empty string Optional BNF elements are denoted with square brackets. If the specified rule returns any error it is treated as if the rule did not match. @par Value Type @code using value_type = optional< typename Rule::value_type >; @endcode @par Example Rules are used with the function @ref grammar::parse. @code system::result< optional< core::string_view > > rv = parse( "", optional_rule( token_rule( alpha_chars ) ) ); @endcode @par BNF @code optional = [ rule ] @endcode @par Specification @li 3.8. Optional Sequence (rfc5234) @param r The rule to match @return The adapted rule @see @ref alpha_chars, @ref parse, @ref optional, @ref token_rule. */ template auto constexpr optional_rule( R const& r) -> implementation_defined::optional_rule_t { BOOST_CORE_STATIC_ASSERT(grammar::is_rule::value); return { r }; } } // grammar } // urls } // boost #include #endif