3 ms·
Writing DSLs is very easy, and fun! The PEG grammars are very elegant to build up. I wrote a language for programmatic recipes (think scaling, unit conversion,
by afranchuk 2y ago
Writing DSLs is very easy, and fun! The PEG grammars are very elegant to build up. I wrote a language for programmatic recipes (think scaling, unit conversion, etc) with it and it was a delight. I'd provide an example but I haven't taken the time to write a README so I haven't published it publicly yet.
- 2pEXgD0fZ5cF 2y agoHey that's cool. Are you willing to instead share an example snippet of what the DSL itself looks like?
- afranchuk 2y agoHere's an excerpt (which is in a map passed to peg/compile) for numeric parsing: :nonzero-int (* (range "19") (any (range "09"))) :int (+ "0" :nonzero-int) :decimal (cmt (* (? (<- :int)) "." (<- (some (range "09")))) ,parse-decimal) :fraction (cmt (\* (? (\* (number :nonzero-int) :s+)) (number :nonzero-int) "/" (number :nonzero-int)) ,parse-fraction) :integer (cmt (number :nonzero-int) ,parse-integer) :num (+ :decimal :fraction :integer)