This commit is contained in:
Bruce Hill 2017-09-11 13:33:15 -07:00
parent 26e8ee58b3
commit e0d39996be

View File

@ -50,7 +50,7 @@ make_parser = (lingo, extra_definitions)->
defs = defs =
:wordchar, :nl, ws:whitespace, :comment :wordchar, :nl, ws:whitespace, :comment
eol: #nl + (P("")-P(1)) eol: #nl + (P("")-P(1))
word_boundary: S(" \t")^1 + B(P("..")) + B(S("\";)]")) + #S("\":([") + #P("..") + #P("/*") word_boundary: S(" \t")^1 + B(P("..")) + B(S("\";)]")) + #S("\":([") + #P("..")
indent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_indent)) indent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_indent))
dedent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_dedent)) dedent: #(nl * blank_line^0 * Cmt(whitespace^-1, check_dedent))
new_line: nl * blank_line^0 * Cmt(whitespace^-1, check_nodent) new_line: nl * blank_line^0 * Cmt(whitespace^-1, check_nodent)
@ -241,8 +241,7 @@ class Game
switch tree.type switch tree.type
when "File" when "File"
add [[ add [[return (function(game, vars)
return (function(game, vars)
local ret]] local ret]]
add to_lua(tree.value.body) add to_lua(tree.value.body)
add [[ add [[
@ -322,22 +321,8 @@ class Game
error("Unknown/unimplemented thingy: #{tree.type}") error("Unknown/unimplemented thingy: #{tree.type}")
-- TODO: make indentation clean -- TODO: make indentation clean
-- Patch the buffer together buffer = table.concat(buffer, "\n")
[=[ return buffer
for code in *buffer
if code == "<INDENT>"
indent ..= INDENT
elseif code == "<DEDENT>"
indent = indent\gsub(INDENT, "", 1)
else
first_indent,middle,last_indent = code\match("(%s*)(.*\n(%s*)[^\n]*)")
if not first_indent
error("No indent found on: [[#{code}]]")
table.insert(buffer, indent..(middle\gsub("\n"..first_indent, "\n"..indent)))
indent = last_indent
]=]
return table.concat(buffer, "\n")
@comma_separated_items: (open, items, close)=> @comma_separated_items: (open, items, close)=>
utils.accumulate "\n", -> utils.accumulate "\n", ->