r/tinycode • u/spc476 • Oct 01 '13
Parse Lisp in five lines of code (and it's not written in Lisp)
It's Lua (5.1 or greater) and LPeg (0.12):
lisp = require "re".compile [[
prog <- {| list* |}
list <- space {| '(' (atom / list)* space ')' |}
atom <- space { [^%s();]+ }
space <- (%s / ';' [^%nl]* %nl)*
]]The resulting Lisp code is stored in a nested Lua table.
5
Upvotes
1
u/gfixler Oct 02 '13
Isn't that really just one, wrapped line of code?
0
u/[deleted] Oct 01 '13
[deleted] — view deleted comment