Re: Domain name parser not working
JF <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CACYgye+d+yxmeaFQbs90AFnWgGYghbv4pXExeYXhNjO0As63xQ@mail.gmail.com> |
Hi Michael,
If I understand RFC correctly, is this what you want?
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
namespace ascii = qi::ascii;
template
<
typename Iterator
>
struct grammar : qi::grammar<Iterator, std::vector<std::string>()>
{
qi::rule<Iterator, std::vector<std::string>()> domain;
qi::rule<Iterator, std::string()> label;
grammar()
: grammar::base_type(domain)
{
domain = label >> *('.' >> label);
label %= qi::raw[ascii::alpha >> *(ascii::alnum | '-')][check_label()];
}
struct check_label
{
template
<
typename Attrib, typename Context
>
void operator()(Attrib &attr, Context &context, bool &pass) const
{
auto label_length = attr.size();
auto last_char = attr[label_length - 1];
if(label_length < 64 && std::isalnum(last_char))
{
pass = true;
}
else
{
pass = false;
}
}
};
};
int main()
{
std::string input = "E-PHUMZ8G8j1KEZG26C.xx1.-";
std::vector<std::string> domain;
auto b = input.cbegin();
auto e = input.cend();
if(qi::parse(b, e, grammar<std::string::const_iterator>(), domain))
{
std::string d;
for(const auto &label : domain)
{
if(!d.empty())
{
d += '.';
}
d += label;
}
std::cout << "matched " << d << '\n';
if(b != e)
{
std::cout << "unmatched " << std::string(b, e) << '\n';
}
}
else
{
std::cout << "nothing matched\n";
}
}
?
(There may be errors... It's 1AM here.)
J
2018-01-03 0:54 GMT+01:00 Joel de Guzman <[email protected]>:
> On 03/01/2018 6:59 AM, Michael Powell wrote:
>
>> On Tue, Jan 2, 2018 at 3:24 PM, Joel de Guzman<[email protected]> wrote:
>>
>>> On 02/01/2018 11:42 PM, Michael Powell wrote:
>>>
>>>> Now after providing additional follow up, live examples, etc, any
>>>> feedback on this at all?
>>>>
>>>> This cannot be that difficult, however any of the documentation, etc,
>>>> I am scanning does not seem to work or are incomplete at best, which
>>>> isn't helping the case.
>>>>
>>>
>>> Not sure. I know you presented some code, but is it minimal enough?
>>> To me, minimal code would look like something like the code here:
>>> http://boost-spirit.com/home/feedback-and-support/
>>>
>> There is nothing I consider extraneous in the examples I presented.
>> There is a test scaffold, the grammar, and the AST. It's all pretty
>> clearly outlined in the examples. Anything more or other than that I
>> would consider NOT minimal.
>>
>
> Give it some more effort. For example, focus on one exact problem. The
> very subject of this thread does not even convey any usable information
> other than "not working". Most often than not, I could distill problematic
> code to only a few lines --one or two rules is ideal. You do not even
> have to have grammars. Also, get rid of the scaffolding, etc.
>
> Again, you'll have better luck if the essence of your question can
> be fully comprehended in one or two minutes. Do I need to study RFC
> 1034 to understand your problem? If not, then that information is
> extraneous. If yes, then your issue requires too much investment in
> time (at least for me).
>
> 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
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general