Re: [Qi] Phrase parsed but iterator did not reach end

Michael Powell <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMEoF_GZha2EjuYS+EvcJuX1_9mbc2q66mt30_92NKAyF-z8eQ@mail.gmail.com>
On Fri, Nov 24, 2017 at 6:42 PM, Michael Powell <[email protected]> wrote:
> Hello,
>
> Or the iterator backtracked?
>
> Is it possible for a phrase to parse (returns true), but the iterator
> does not reach the end, or was backtracked?
>
> Depending on the rule, of course. For which I currently have:
>
> boost::spirit::qi::rule<Iterator> _port_rule;
>
> _port_rule = digit
>     | (char_('1', '5') >> repeat(1, 4)[digit])
>     | (char_('7', '9') >> repeat(1, 3)[digit])
>     | (char_('6')
>         >> ((char_('0', '4') >> repeat(0, 3)[digit])
>             | (char_('6', '9') >> repeat(0, 2)[digit])
>             | (char_('5')
>                 >> ((char_('0', '4') >> repeat(0, 2)[digit])
>                     | (char_('6', '9') >> -digit)
>                     | (char_('5')
>                         >> ((char_('0', '2') >> -digit)
>                             | char_('4', '9')
>                             | (char_('3') >> char_('0', '5'))
>                             )
>                         )
>                     )
>                 )
>             )
>         )
>     ;

I'm not sure why repeat doesn't work quite right, or perhaps the user
is failing to grasp its effects. There aren't a ton of cases, and I
was able to separate them adequately.

So instead of:

(char_('1', '5') >> repeat(1, 4)[digit])

I was able to do this type of thing:

(char_('1', '5') >> -(digit >> -(digit >> -(digit >> -digit))))

Did that throughout, and fleshed out the tree in a little better depth.

Now it works, and the iterator reports to the end as expected, whereas
before the iterator would not.

> Where Iterator is a Struct Template argument.
>
> Basically to validate all the patterns from 0-65535 (valid port range).
>
> 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.