Domain name parser not working

Michael Powell <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMEoF_G8G6CG49TdbANGvF060LEE9sB=ufKJfNRXqJDKtYc8iQ@mail.gmail.com>
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?

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.