reusing partial parsed and not matched prefix in the next alternative extended parser

Marian Klein <[email protected]> Wed, 13 Jun 2018 08:39:06 +0100
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAA0DKYqC46b1Z_jEpOjWbB6LOhhEM5qBXejeVKYbX3rASBthEg@mail.gmail.com>
Hi Spirit X3

I am using your x3 spirit library for my little project.

I would like to know if there is a way to pass an attribute from failed ,
but partially parsed text to the next alternative parser.

Example:

auto  parser=P1|P2;

some parsed text matches P2 fully, but only prefix of parsed text matches
P1 . Once P1 is parsed , it will fail, backtrack and goes onto trying to
parse P2 from the beginning redundantly
repeating parsing of  P1 prefix.
It is suboptimal and unneccesarilly waste of CPU cycles.
If parser P2  parse function had signature like

P2::parse(P1_Attr&& parsed_attr,Iterator It_begin,Iterator It_end,Attr&
attr)

It could reused already parsed text prefix.

Is it difficult to implement such extension in  a generic way to the
framework?

I understand you can achieve similar effect by optional suffix,but it is
less elegant,
as this is not meant to express logical grammar, it is rather technical
optimization so it should be hidden and visible.

Another example:
I want to pass any number real or integer.
auto parser=int_ | double_;
parse text is 1234567.890

It would be great if double_ parser could reuse value parsed in int_
1234567 which was not match.
double_::parse(int prefix,Iterator it_beg,Iterator it_end,double& val)

Thanks

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