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

Michael Powell <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMEoF_Fr7MXNR05pe8OR2sMgtWuMKe8S=eiADjbT5PHTLJMh9A@mail.gmail.com>
On Wed, Nov 29, 2017 at 6:40 PM, Seth <[email protected]> wrote:
> On 29-11-17 22:42, Michael Powell wrote:
>> https://wandbox.org/permlink/04tVHUZZN8j3PfAB
>>
>> But I can't fathom what. Spirit Qi -wise, I think it's fine, but I
>> could be missing something, and obviously the matched attributes are
>> telling their own story.

I appreciate the feedback.

> First, simplify

Interesting. I'd like it if there were RFC's documenting the grammar.
Not that wikipedia isn't interesting and all.

Apparently it does reject values outside the range, but I couldn't
confirm this in another attempt. It would allow edge use cases such as
256, for instance.

My goal is to parse address into a std::string. That will be important
for me when I turn the corner into IPv6 parsing. Could this approach
support that? i.e. uint_parser... into a std::string?

Which get passed into the InetPton (Windows), for instance. Or
inet_pton (Linux). If I need to parse into support struct and
translate to base 10, that would work, too; but I'd like to get there
without the extra step if possible.

Trying to minimize the footprint of Spirit in my code, if possible; as
well as supporting or intermediate structs, etc.

> https://wandbox.org/permlink/Phb2Xn3aqdbO6rhG
>
>  - Next, change the AST to be useful (storing the input string makes
> "127.00.00.1:443" different from "127.0.0.1:443".
>
>  - In fact https://en.wikipedia.org/wiki/IPv4#Address_representations
> tells me you can have "0x7f.0.0.00001:443".

Would like to see the RFC that supports that grammar.

>  - I tested this to be consistent with how `ping` parses its command
> line arguments (e.g. ping '1.000014.0x7b.003' pinged 1.12.123.3).
>
>  - Also, whitespace is not admissable after all, so let's drop the skipper.

Not a bad idea, really.

> The meat of it is in these rules:
>
>             octet_ = "0x" >> uint_parser<uint8_t, 16, 2, 2>() // 0x00 style
>                    | "0" >> uint_parser<uint8_t, 8, 1, 5>()   // 0020
> (for decimal 32) style
>                    | uint_parser<uint8_t, 10, 1, 3>();        // dot-decimal
>
>             addr_  = octet_ >> '.' >> octet_ >> '.' >> octet_ >> '.' >>
> octet_;
>             port_  = uint_parser<uint16_t, 10, 1, 5>();
>
> I've added a few to test the new capabilities and some rejections too:
>
> https://wandbox.org/permlink/Wsr1E92HWO8WrxMX
>
> Bonus tip: consider adding `>> qi::eoi` at the end of the parse
> expression so you don't need to check whether all of the input has been
> consumed (it must).
>
> AMDG

Thanks!

Cheers,

Michael

------------------------------------------------------------------------------
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.