|
|
|
|
|
by PaulHoule
1520 days ago
|
|
It is no fun writing external DSLs when you're stuck with your grandfather's parser generator. If we had grammars that were really extensible (add "unless(X)" equivalent to "if(!X)" in Java's grammar with a few lines of code) and composable (stick a SQL statement into a Java program with just a few lines of code if you have the SQL and Java grammars) and reversible (turn the AST tree back to source code) it would be a lot more fun writing external DSLs. Every so often a revolution gets promised, like PEG parsers for Python, but then people get worried about how fast the parser is again and it isn't like Heinlein's Moon is a Harsh Mistress but more like Haldeman's Worlds (as Pete Townsend puts it "We won't get fooled again".) If parsers were easier to use people might use them 10x as often as they do today. |
|
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