|
|
|
|
|
by spinningslate
1520 days ago
|
|
>It is no fun writing external DSLs when you're stuck with your grandfather's parser generator. Agreed. I've tried various different approaches to building external DSLs, from fully hand-written to language workbenches like xtext [0] and spoofax [1]. I always end up back at hand written, often because of error handling. Creating meaningfully helpful error handling with parser generators always seems hard. >If we had grammars that were really extensible Grammar composition is hard. Canonical BNF is top down, meaning alternate clauses are complete and closed in most parser generators. One notable exception is SF3[2] (part of Spoofax). It doesn't require alternate clauses to be grouped and so can support composable languages. It's the most flexible parser-generator I've used, and the syntax is pretty nice too. Fun fact: SDF3 and Spoofax come from Eelco Visser's group at TU-Delft - the same group that originated Scope Graphs, the basis for Github's Stack Graphs [3]. [0] http://www.eclipse.org/Xtext/
[1] https://www.spoofax.dev/
[2] https://eelcovisser.org/publications/2020/AmorimV20.pdf
[3] https://news.ycombinator.com/item?id=29500602 |
|
Composing grammars may not be possible, but it's easy to define a new grammar that provides the composition of two other grammars along with boilerplate that serves the purpose of determining whether you're in a "grammar A" context or a "grammar B" context. You just need tokens that aren't valid in grammar A or grammar B.
No statement in such a grammar would be valid in either subgrammar, because of the boilerplate, but they would all be trivially reducible to valid statements in the appropriate subgrammar.