Cleaned up code output. More concise now.

This commit is contained in:
Bruce Hill 2017-08-20 02:02:15 -07:00
parent c5c014864e
commit ecc4e82919
2 changed files with 32 additions and 19 deletions

View File

@ -68,6 +68,16 @@ say both..
"hello" "hello"
and "world" and "world"
say [..]
"this is a stupidly long list", "the items go way past the 80 character", "limit that older consoles"
"had.", "It just keeps going and going"
rule "dumbfunc %a %b %c %d %e":
say "doop"
dumbfunc..
"this is a stupidly long list" "the items go way past the 80 character" "limit that older consoles"
"had." "It just keeps going and going"
rule "four": return 4 rule "four": return 4
say both.. say both..

View File

@ -231,6 +231,23 @@ class Game
line = ind(ded(line)) line = ind(ded(line))
table.insert ret_lines, line table.insert ret_lines, line
comma_separated_items = (open, items, close)->
buffer = open
so_far = indent_level*2
indented ->
export buffer,so_far
for i,item in ipairs(items)
if i < #items then item ..= ", "
if so_far + #item >= 80 and #buffer > 0
lua buffer
so_far -= #buffer
buffer = item
else
so_far += #item
buffer ..= item
buffer ..= close
lua buffer
switch tree.type switch tree.type
when "File" when "File"
if tree.value.errors and #tree.value.errors.value > 1 if tree.value.errors and #tree.value.errors.value > 1
@ -267,23 +284,14 @@ class Game
for token in *tree.value for token in *tree.value
table.insert name_bits, if token.type == "Word" then token.value else "%" table.insert name_bits, if token.type == "Word" then token.value else "%"
name = table.concat(name_bits, " ") name = table.concat(name_bits, " ")
args = [a for a in *tree.value when a.type != "Word"]
if @macros[name] if @macros[name]
-- TODO: figure out args -- TODO: figure out args
args = [a for a in *tree.value when a.type != "Word"]
return @macros[name][1](self, args, transform) return @macros[name][1](self, args, transform)
if #args == 0 args = [ded(transform(a)) for a in *tree.value when a.type != "Word"]
lua "game:call(#{utils.repr(name, true)})" table.insert args, 1, utils.repr(name, true)
else comma_separated_items("game:call(", args, ")")
lua "game:call(#{utils.repr(name, true)},"
indented ->
for i,a in ipairs(args)
if a.type != "Word"
line = transform(a)
if i != #args then line ..=","
lua line
lua ")"
when "String" when "String"
lua utils.repr(tree.value, true) lua utils.repr(tree.value, true)
@ -297,12 +305,7 @@ class Game
elseif #tree.value == 1 elseif #tree.value == 1
lua "{#{transform(tree.value)}}" lua "{#{transform(tree.value)}}"
else else
lua "{" comma_separated_items("{", [ded(transform(item)) for item in *tree.value], "}")
indented ->
for i in *tree.value
-- I like the trailing comma
lua transform(i)..","
lua "}"
when "Var" when "Var"
lua "vars[#{utils.repr(tree.value,true)}]" lua "vars[#{utils.repr(tree.value,true)}]"