Aesthetic tweak to generated nomsu code with colons.

This commit is contained in:
Bruce Hill 2018-07-14 15:06:03 -07:00
parent c9ff0ff04b
commit 8a44869c4a
2 changed files with 6 additions and 4 deletions

View File

@ -717,6 +717,7 @@ do
return error("Unknown type: " .. tostring(tree.type)) return error("Unknown type: " .. tostring(tree.type))
end end
end end
local MIN_COLON_LEN = 25
NomsuCompiler.tree_to_nomsu = function(self, tree, options) NomsuCompiler.tree_to_nomsu = function(self, tree, options)
options = options or { } options = options or { }
if not (options.pop_comments) then if not (options.pop_comments) then
@ -792,7 +793,7 @@ do
return nil return nil
end end
if bit.type == "Action" or bit.type == "Block" then if bit.type == "Action" or bit.type == "Block" then
if bit.type == "Action" and i == #tree then if bit.type == "Action" and i == #tree and #tostring(arg_nomsu) >= MIN_COLON_LEN then
nomsu:append(":") nomsu:append(":")
else else
arg_nomsu:parenthesize() arg_nomsu:parenthesize()
@ -827,7 +828,7 @@ do
end end
if arg_nomsu and line_len + #tostring(arg_nomsu) < MAX_LINE then if arg_nomsu and line_len + #tostring(arg_nomsu) < MAX_LINE then
if bit.type == "Action" then if bit.type == "Action" then
if can_use_colon and i > 1 then if can_use_colon and i > 1 and #tostring(arg_nomsu) >= MIN_COLON_LEN then
nomsu:append(match(next_space, "[^ ]*"), ": ", arg_nomsu) nomsu:append(match(next_space, "[^ ]*"), ": ", arg_nomsu)
next_space = "\n.." next_space = "\n.."
line_len = 2 line_len = 2

View File

@ -481,6 +481,7 @@ with NomsuCompiler
else else
error("Unknown type: #{tree.type}") error("Unknown type: #{tree.type}")
MIN_COLON_LEN = 25 -- For beautification purposes, don't bother using colon syntax for short bits
.tree_to_nomsu = (tree, options)=> .tree_to_nomsu = (tree, options)=>
options or= {} options or= {}
unless options.pop_comments unless options.pop_comments
@ -526,7 +527,7 @@ with NomsuCompiler
arg_nomsu = recurse(bit,inline:true) arg_nomsu = recurse(bit,inline:true)
return nil unless arg_nomsu return nil unless arg_nomsu
if bit.type == "Action" or bit.type == "Block" if bit.type == "Action" or bit.type == "Block"
if bit.type == "Action" and i == #tree if bit.type == "Action" and i == #tree and #tostring(arg_nomsu) >= MIN_COLON_LEN
nomsu\append ":" nomsu\append ":"
else else
arg_nomsu\parenthesize! arg_nomsu\parenthesize!
@ -550,7 +551,7 @@ with NomsuCompiler
if arg_nomsu and line_len + #tostring(arg_nomsu) < MAX_LINE if arg_nomsu and line_len + #tostring(arg_nomsu) < MAX_LINE
if bit.type == "Action" if bit.type == "Action"
if can_use_colon and i > 1 if can_use_colon and i > 1 and #tostring(arg_nomsu) >= MIN_COLON_LEN
nomsu\append match(next_space,"[^ ]*"), ": ", arg_nomsu nomsu\append match(next_space,"[^ ]*"), ": ", arg_nomsu
next_space = "\n.." next_space = "\n.."
line_len = 2 line_len = 2