rust-bakery / nom

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

Question - Recipe to parse in look-ahead manner #1672

Open tisonkun opened 1 year ago

tisonkun commented 1 year ago

Hi developers,

I'm writing a SQL parser with nom and encounter some issues that the order of alt is significant and even when nested rules the code can be hard to debug.

One of the most subtle case is the I often try to "find" the possible longest branch and push it in the very beginning. With parser combinations the longest branch in one call graph may not retain from another call graph.

Parsers like ANTLR and Bison use LALR(1) or LL(*) algorithm to look-ahead characters so that it always try to make a longest match. I used to write parsers in this theory and I find nom supports peek / condition / etc.. Thus, I wonder if there is existing recipes or projects follow the same flavor and can show as an example to learn from.