rust-bakery / nom

Rust parser combinator framework
MIT License
9.18k stars 792 forks source link

Any other approach to handle left recursion #1708

Open Chiichen opened 7 months ago

Chiichen commented 7 months ago

Knowing that I can handle left recursion cases by rewriting the grammar. But I am wondering if there is any other approach (since rewriting might greatly reduce the code readability beacause we can not easily infer the usage of a single combinator literraly) in some simple cases like recursively parsing an arithmetic grammar(I believe threre is no a general method to handle left recursion without rewriting grammar at current version).

Here is an example:

We have a left recuesive grammar :

We rewrite it into:

Before we rewrite it,each production can be clearly and easily described by a single combinator.But after rewriting the grammar, each production is coupling with E' which greatly reduces the self-explanation of combinators

445 is a previous issue