moonscript/moonscript/dump.moon
2018-04-30 18:24:51 -07:00

19 lines
396 B
Plaintext

flat_value = (op, depth=1) ->
return '"'..op..'"' if type(op) == "string"
return tostring(op) if type(op) != "table"
items = [flat_value item, depth + 1 for item in *op]
pos = op[-1]
"{"..(pos and "["..pos.."] " or "")..table.concat(items, ", ").."}"
value = (op) ->
flat_value op
tree = (block) ->
table.concat [flat_value value for value in *block], "\n"
{ :value, :tree }