Compare commits
3 Commits
level_pars
...
5634fcf4a4
Author | SHA1 | Date | |
---|---|---|---|
5634fcf4a4
|
|||
447a1bedd0
|
|||
0f7c7a810b
|
@ -1,61 +0,0 @@
|
|||||||
pico-8 cartridge // http://www.pico-8.com
|
|
||||||
version 41
|
|
||||||
__lua__
|
|
||||||
-- the parser
|
|
||||||
|
|
||||||
parser = {}
|
|
||||||
mknew(parser)
|
|
||||||
|
|
||||||
-- calls parse_into with a nop
|
|
||||||
-- emit function.
|
|
||||||
function parser:parse(str)
|
|
||||||
self:parse_into(str, function() end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- read a file of commands and
|
|
||||||
-- execute them, emitting the
|
|
||||||
-- results from each call into
|
|
||||||
-- `emit` as a table per row.
|
|
||||||
--
|
|
||||||
-- a "command" is a method on
|
|
||||||
-- self. a row alternates
|
|
||||||
-- commands with args. when
|
|
||||||
-- calling a command, it also
|
|
||||||
-- gets a table of previous
|
|
||||||
-- results as the first arg.
|
|
||||||
-- args are split on ','.
|
|
||||||
function parser:parse_into(str, emit)
|
|
||||||
for row in all(split(str, "\n")) do
|
|
||||||
local prev = {}
|
|
||||||
local sectors = split(row, ":")
|
|
||||||
for i=1,#sectors,2 do
|
|
||||||
local x = self[sectors[i]](self, prev, usplit(sectors[i+1]))
|
|
||||||
if (x) add(prev, x)
|
|
||||||
end
|
|
||||||
emit(prev)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- saves prev[sel] as self.name.
|
|
||||||
-- if sel is unspecified, saves
|
|
||||||
-- all of prev (as a table).
|
|
||||||
function parser:saveas(prev, name, sel)
|
|
||||||
self[name] = sel and prev[sel] or prev
|
|
||||||
end
|
|
||||||
|
|
||||||
-- returns its args, ignoring
|
|
||||||
-- prev. Used to stuff things
|
|
||||||
-- into prev. args are packed
|
|
||||||
-- if there's multiple.
|
|
||||||
function parser:val(_, ...)
|
|
||||||
local ret := pack(...)
|
|
||||||
if (#ret == 1) return ret[1]
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
function parser:bind(_, fn, ...)
|
|
||||||
local f = self[fn]
|
|
||||||
return function()
|
|
||||||
f(...)
|
|
||||||
end
|
|
||||||
end
|
|
1189
updatedshmup.p8
1189
updatedshmup.p8
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user