Re: Domain name label length
Michael Powell <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAMEoF_H0WqPRkA7aJfgvt138sMccDtA84GG5Os2extJ8JPvkQA@mail.gmail.com> |
On Sun, Dec 31, 2017 at 2:03 PM, Michael Powell <[email protected]> wrote: > On Thu, Dec 28, 2017 at 12:27 AM, Joel de Guzman <[email protected]> wrote: >> On 26/12/2017 11:38 AM, Michael Powell wrote: >>> >>> Hello, >>> >>> So, a domain name label looks something like this, in general, right? >>> >>> _label = _let >> *(_let | _dig | _hyp) >> (_let | _dig); >>> >>> However, another stipulation is that its length must be <=63 according >>> to the RFC: >>> >>> https://tools.ietf.org/html/rfc1034#section-3.5 >>> >>> So... Is there a way to constrain that using Qi? I think I am closer in the ball park if I can manage a Phoenix validation function, as I'd like to avoid the complexities of any form of Bind, Phoenix or otherwise. This at least on authority of this documentation: https://theboostcpplibraries.com/boost.phoenix, tip recommending avoiding Bind, and rather creating my own Phoenix functions. However, still running into some difficulties sorting out the bits connecting the pieces together: namespace Validation { struct label_validation { bool operator()(std::string const& l) const { return l.length() <= 63; } }; } // In my Parser struct: boost::phoenix::function<Validation::label_validation> _validate_label; // This would be perfectly sufficient and works with the bits that I absolutely require: _label = raw[_let >> -(*(_let | _dig | _hyp) >> (_let | _dig))][_pass = _validate_label(_val)]; At the moment I am defining the following: BOOST_SPIRIT_USE_PHOENIX_V3 and BOOST_RESULT_OF_USE_DECLTPYE for both library as well as test projects. // ... Severity Code Description Project File Line Suppression State Error C2516 'boost::phoenix::evaluator::impl<const Expr &,boost::phoenix::vector2<boost::mpl::true_,boost::phoenix::is_nullary>,boost::proto::envns_::empty_env>::result_type': is not a legal base class Rfc3986_Uri_RegexSyntaxVerification G:\Source\Boost.Installs\boost_1_65_1\boost\phoenix\core\is_nullary.hpp 124 Error C2039 'value': is not a member of 'boost::phoenix::result_of::is_nullary<Expr,void>' Rfc3986_Uri_RegexSyntaxVerification G:\Source\Boost.Installs\boost_1_65_1\boost\phoenix\core\actor.hpp 174 Error C2065 'value': undeclared identifier Rfc3986_Uri_RegexSyntaxVerification G:\Source\Boost.Installs\boost_1_65_1\boost\phoenix\core\actor.hpp 175 Error C2975 'C': invalid template argument for 'boost::mpl::eval_if_c', expected compile-time constant expression Rfc3986_Uri_RegexSyntaxVerification G:\Source\Boost.Installs\boost_1_65_1\boost\phoenix\core\actor.hpp 177 >> Yes, but if I were you, I'd probably avoid having too much smarts in >> the parser and have those checks post-hoc. > > Yes, of course. The rule thus far is pretty straightforward, to do > with length and length only. It would be inappropriate to embed > anything that was so application specific. > > template<typename Iterator> > struct MyParser : qi::grammar<Iterator, Ast::Address()> { > > struct validate_label_length { > template<typename Context> > void operator()(std::string& l, Context&, bool& pass) { > pass = l.length() <= 63; > } > }; > > // ... > > ... _label = raw[_let >> -(*(_let | _dig | _hyp) >> (_let | > _dig))][validate_label_length()]; > ... _address = _label % dot_; > > ... _start = _address >> eoi; > }; > > But this is yielding compiler errors. I'm not sure I need to include > something Fusion related? > > #include <boost/spirit/home/qi.hpp> > #include "ast/domain_name.hpp" > > The structure is nested, defined in the scope of my template Parser. > > Severity Code Description Project File Line Suppression State > Error C2893 Failed to specialize function template > 'action_dispatch<Subject>::fwd_storage<unknown-type,boost::spirit::traits::action_dispatch<Subject>::fwd_none>::type > boost::spirit::traits::action_dispatch<Subject>::do_call(F &&,...)' > Rfc3986_Uri_RegexSyntaxVerification > G:\Source\Boost.Installs\boost_1_65_1\boost\spirit\home\support\action_dispatch.hpp > 142 > Error C2672 'boost::spirit::traits::action_dispatch<Subject>::do_call': > no matching overloaded function found > Rfc3986_Uri_RegexSyntaxVerification > G:\Source\Boost.Installs\boost_1_65_1\boost\spirit\home\support\action_dispatch.hpp > 142 > Error C2893 Failed to specialize function template > 'action_dispatch<Subject>::fwd_storage<unknown-type,boost::spirit::traits::action_dispatch<Subject>::fwd_attrib_context_pass>::type > boost::spirit::traits::action_dispatch<Subject>::do_call(F > &&,boost::spirit::traits::action_dispatch<Subject>::fwd_tag<A>,boost::spirit::traits::action_dispatch<Subject>::fwd_tag<B>,boost::spirit::traits::action_dispatch<Subject>::fwd_tag<C>,...)' > Rfc3986_Uri_RegexSyntaxVerification > G:\Source\Boost.Installs\boost_1_65_1\boost\spirit\home\support\action_dispatch.hpp > 142 > Error C2893 Failed to specialize function template > 'action_dispatch<Subject>::fwd_storage<unknown-type,boost::spirit::traits::action_dispatch<Subject>::fwd_attrib_context>::type > boost::spirit::traits::action_dispatch<Subject>::do_call(F > &&,boost::spirit::traits::action_dispatch<Subject>::fwd_tag<A>,boost::spirit::traits::action_dispatch<Subject>::fwd_tag<B>,...)' > Rfc3986_Uri_RegexSyntaxVerification > G:\Source\Boost.Installs\boost_1_65_1\boost\spirit\home\support\action_dispatch.hpp > 142 > Error C2893 Failed to specialize function template > 'action_dispatch<Subject>::fwd_storage<unknown-type,boost::spirit::traits::action_dispatch<Subject>::fwd_attrib>::type > boost::spirit::traits::action_dispatch<Subject>::do_call(F > &&,boost::spirit::traits::action_dispatch<Subject>::fwd_tag<A>,...)' > Rfc3986_Uri_RegexSyntaxVerification > G:\Source\Boost.Installs\boost_1_65_1\boost\spirit\home\support\action_dispatch.hpp > 142 > >> Regards, >> -- >> Joel de Guzman >> http://www.ciere.com >> http://boost-spirit.com >> http://www.cycfi.com/ >> >> ------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Spirit-general mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/spirit-general ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot