Re: reusing partial parsed and not matched prefix in the next alternative extended parser
Joel de Guzman <[email protected]> Sun, 17 Jun 2018 04:31:58 +0800
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 13/06/2018 3:39 PM, Marian Klein wrote:
> 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
Before anything else, allow me to ask a question:
How are you supposed to know what "fully" means in the context of P1? End of
line? End of input?
> 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)
Well, you can do something like that using the sequence operator for the
common parts. E.g.
auto parser = int_ >> -('.' >> uint_);
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