Re: Domain name parser not working
Michael Powell <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAMEoF_EzyajpBsiVXLc-HpLA05m4C9oE57EAk-4hfKMojtdt7g@mail.gmail.com> |
On Mon, Jan 1, 2018 at 6:49 PM, Michael Powell <[email protected]> wrote: > Hello, > > // Where Let is char_(/*upper/lower-case chars*/), Dig is > char_("0123456789"), Hyp is char_('.'), and dot_ is '.'. > > template<typename It> > struct DomainNameParser : boost::spirit::qi::grammar<It, Ast::Address()> { > > DomainNameParser() { > > _hyp = char_('-'); > _dig = char_(DOMAIN_NAME_PARSER_DIGITS); > _let = char_(DOMAIN_NAME_PARSER_LOWERCASE DOMAIN_NAME_PARSER_UPPERCASE); > > // A straight interpretation of the Domain Name grammar leads me to this: > /*qi::rule<It, std::string()>*/ _label = raw[_let >> -(*(_let | > _dig | _hyp) >> (_let | _dig))]; > /*qi::rule<It, Ast::Address()>*/ _start = (_label % dot_) >> eoi; > // ... > > } > }; > > Assuming, > > struct Address { > std::vector<std::string> _labels; > }; > > BOOST_FUSION_ADAPT_STRUCT(Ast::Address, > (std::vector<std::string>, _labels) > ) > > However, this is failing to match: "E-PHUMZ8G8j1KEZG26C" in spite of > the fact this matches the expected pattern. No skippers involved, just > the iterator (std::string::const_iterator), and the AST, of course. > > For now, dropping the semantic action until I can get the parser to > work properly. However, eventually I want to incorporate the > validation rule: > > struct label_validation { > // Notwithstanding Qi/Fusion bits that glue it together. > bool operator()(std::string const& l) const { > return l.length() <= 63; > } > }; > > Once again I am suspicious whether Optional is working properly, never > minding Kleene Star productions. I ended up needing to separate out > Alternative phrases instead of the Optional before in order to make it > work properly. > > Perhaps I need to capture each phrase in a rule of its own focused > solely on std::string or char, respectively, as contrasted with the > entire std::string? Here's an MRP: https://wandbox.org/permlink/cbpUPMnQ4APZeDdw More or less based on RFC 1034: https://tools.ietf.org/html/rfc1034#section-3.5 Thoughts? Cheers, Michael > Cheers, > > Michael Powell ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot