aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgame2.moon10
-rw-r--r--nomic_whitespace.moon41
2 files changed, 32 insertions, 19 deletions
diff --git a/game2.moon b/game2.moon
index a9de154..450437f 100755
--- a/game2.moon
+++ b/game2.moon
@@ -68,6 +68,16 @@ say both..
"hello"
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
say both..
diff --git a/nomic_whitespace.moon b/nomic_whitespace.moon
index a754c58..022cdf4 100644
--- a/nomic_whitespace.moon
+++ b/nomic_whitespace.moon
@@ -230,6 +230,23 @@ class Game
unless skip_indent
line = ind(ded(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
when "File"
@@ -267,23 +284,14 @@ class Game
for token in *tree.value
table.insert name_bits, if token.type == "Word" then token.value else "%"
name = table.concat(name_bits, " ")
- args = [a for a in *tree.value when a.type != "Word"]
-
if @macros[name]
-- TODO: figure out args
+ args = [a for a in *tree.value when a.type != "Word"]
return @macros[name][1](self, args, transform)
- if #args == 0
- lua "game:call(#{utils.repr(name, true)})"
- else
- 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 ")"
+ args = [ded(transform(a)) for a in *tree.value when a.type != "Word"]
+ table.insert args, 1, utils.repr(name, true)
+ comma_separated_items("game:call(", args, ")")
when "String"
lua utils.repr(tree.value, true)
@@ -297,12 +305,7 @@ class Game
elseif #tree.value == 1
lua "{#{transform(tree.value)}}"
else
- lua "{"
- indented ->
- for i in *tree.value
- -- I like the trailing comma
- lua transform(i)..","
- lua "}"
+ comma_separated_items("{", [ded(transform(item)) for item in *tree.value], "}")
when "Var"
lua "vars[#{utils.repr(tree.value,true)}]"