ohmjs / ohm

A library and language for building parsers, interpreters, compilers, etc.
MIT License
5.01k stars 217 forks source link

Implement Throw and Label operations #387

Open DavidSouther opened 2 years ago

DavidSouther commented 2 years ago

https://arxiv.org/pdf/1806.11150.pdf with proof of concept in https://github.com/sqmedeiros/lpeglabel

We propose a conservative extension, based on PEGs with labeled failures, that adds a syntax error recovery mechanism for PEGs. Œis extension associates recovery expressions to labels, where a label now not only reports a syntax error but also uses this recovery expression to reach a synchronization point in the input and resume parsing.

The syntax using ^ as the synchronization operator feels fairly clean? I'm not sure whether throw should be %{l} or, better, Throw to make it obvious. One would require special casing syntax; the other, special casing a function. ListOf sort of does that? but IIRC the semantics phase, not in the grammar.

Some overlap with #302 here, and I don't know if this would affect #158 if one were to try to resynchronize to the proposed @rules.