afranchuk 21 hours 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.

1
2pEXgD0fZ5cF 20 hours ago

Hey that's cool. Are you willing to instead share an example snippet of what the DSL itself looks like?

afranchuk 14 hours ago

Here'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)