Provide more advanced examples
I'm trying to implement a generic parser:
BinExpr<SubExpr, Op> := SubExpr (Op SubExpr)*
However I run into number of issues:
- I cannot reuse subexpr directly as parsers are effectivly non-clonable (issue #283)
- There doesn't seems to be a primitive suitable for it (for example
sepByignores separator) - Writing parser by hand is challanging:
- Many of the helper functions depend on ParseMode
- Existing implementation of
manyetc. heavily use internal macros making them non-example - There seems to be no documentation on how state in partial parsing behaves and what are the invariants
I cannot reuse subexpr directly as parsers are effectivly non-clonable (issue #283) There doesn't seems to be a primitive suitable for it (for example sepBy ignores separator)
let sub_expr = || parser;
(sub_expr(), many((op, sub_expr()))
Should work.
There are also a few chain parsers like https://docs.rs/combine/4.2.1/combine/parser/repeat/fn.chainl1.html or https://github.com/Marwes/combine-language which provides an expression parser that takes precendence into account
Writing parser by hand is challanging:
Yes, writing your own parser is largely internal now. However for a simple, custom parser you can always use https://docs.rs/combine/4.2.1/combine/fn.parser.html which is basically as efficient as you are going to get without needing to understand the whole Parser trait.
I cannot reuse subexpr directly as parsers are effectivly non-clonable (issue #283) There doesn't seems to be a primitive suitable for it (for example sepBy ignores separator)
let sub_expr = || parser; (sub_expr(), many((op, sub_expr()))
Should work.
That was my first attempt. Unfortunately this makes the size of type exponential in layers. With 15 layers it makes the size of type of order of 32768 which effectively hangs even debug build of rust.
(On second though - the clone would not help)
Writing parser by hand is challanging:
Yes, writing your own parser is largely internal now. However for a simple, custom parser you can always use https://docs.rs/combine/4.2.1/combine/fn.parser.html which is basically as efficient as you are going to get without needing to understand the whole Parser trait.
I'll take a look.
For recursive parsers there is also https://docs.rs/combine/4.2.1/combine/parser/combinator/fn.opaque.html