six grammars in under nine hundred lines
summary: an audit of every peg grammar shipped under std/. the small line count is evidence for grammars-as-values.
Core idea: small parser implementations were evidence that first-class grammars removed the usual boundary between DSL syntax and host-language execution.
Six PEG grammars under std/, eight hundred and eighty-two lines:
| file | lines | rules |
|---|---|---|
xml.o | 16 | 13 |
markdown.o | 49 | 36 |
lit.o | 85 | 16 |
urllib.o | 140 | 11 |
prolog.o | 142 | 12 |
sql.o | 450 | 43 |
That count is the receipt for the grammars-as-values design. The reason it fits is not that O is concise; it is concise, but not by that factor. The reason is that there is no boundary between the grammar, the reaction that fires on its output, and the kernel that runs the result. The grammar's action body and the surrounding application code are the same lambda surface; the runtime cost is the same kernel everyone else uses.
If we add a seventh grammar and the average line count holds, that is the strongest argument for the design I have.