diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-28 15:25:12 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-28 15:25:31 -0700 |
| commit | d13a945b5f8924c1416ea2bd72212efdb3bebc20 (patch) | |
| tree | 9b750c94008a49020b8d76a4e0a73fd67e619dac /nomsu_tree.moon | |
| parent | 23022dc88c5a2df0cb3415720a8f3a8c479d6b92 (diff) | |
Removed LFS dependency in favor of just using `find`
Diffstat (limited to 'nomsu_tree.moon')
| -rw-r--r-- | nomsu_tree.moon | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/nomsu_tree.moon b/nomsu_tree.moon index e2b2c74..5a505d0 100644 --- a/nomsu_tree.moon +++ b/nomsu_tree.moon @@ -55,9 +55,11 @@ Tree "File", return nil if inline nomsu = Nomsu(@source) for i, line in ipairs @value - line = assert(line\as_nomsu!, "Could not convert line to nomsu") + line = assert(line\as_nomsu(nil,true), "Could not convert line to nomsu") nomsu\append line if i < #@value + if tostring(line)\match("\n") + nomsu\append "\n" nomsu\append "\n" return nomsu @@ -95,7 +97,7 @@ Tree "Block", return nomsu nomsu = Nomsu(@source) for i, line in ipairs @value - line = assert(line\as_nomsu!, "Could not convert line to nomsu") + line = assert(line\as_nomsu(nil, true), "Could not convert line to nomsu") nomsu\append line if i < #@value nomsu\append "\n" @@ -163,7 +165,7 @@ Tree "Action", else [(t.type == "Word" and t.value or "%") for t in *@value] return concat(bits, " ") - as_nomsu: (inline=false)=> + as_nomsu: (inline=false, can_use_colon=false)=> if inline nomsu = Nomsu(@source) for i,bit in ipairs @value @@ -181,32 +183,42 @@ Tree "Action", nomsu\append arg_nomsu return nomsu else - inline_version = @as_nomsu(true) - if inline_version and #inline_version <= MAX_LINE - return inline_version nomsu = Nomsu(@source) - spacer = nil + next_space = "" + -- TODO: track line length as we go and use 80-that instead of 80 for wrapping + last_colon = nil for i,bit in ipairs @value if bit.type == "Word" - if spacer then nomsu\append spacer - nomsu\append bit.value - spacer = " " + nomsu\append next_space, bit.value + next_space = " " else - arg_nomsu = bit\as_nomsu(true) + arg_nomsu = bit.type != "Block" and bit\as_nomsu(true) if arg_nomsu and #arg_nomsu < MAX_LINE - if spacer then nomsu\append spacer - if bit.type == "Action" or bit.type == "Block" - arg_nomsu\parenthesize! - spacer = " " + if bit.type == "Action" + if can_use_colon and i > 1 + nomsu\append next_space\match("[^ ]*"), ": ", arg_nomsu + next_space = "\n.." + last_colon = i + else + nomsu\append next_space, "(", arg_nomsu, ")" + next_space = " " + else + nomsu\append next_space, arg_nomsu + next_space = " " else - arg_nomsu = bit\as_nomsu! + arg_nomsu = bit\as_nomsu(nil, true) return nil unless nomsu - if bit.type == "Action" or bit.type == "Block" - nomsu\append "\n " - else - if spacer then nomsu\append spacer - spacer = "\n.." - nomsu\append arg_nomsu + -- These types carry their own indentation + if bit.type != "List" and bit.type != "Dict" and bit.type != "Text" + if i == 1 + arg_nomsu = Nomsu(bit.source, "(..)\n ", arg_nomsu) + else + arg_nomsu = Nomsu(bit.source, "\n ", arg_nomsu) + + if last_colon == i-1 and (bit.type == "Action" or bit.type == "Block") + next_space = "" + nomsu\append next_space, arg_nomsu + next_space = "\n.." return nomsu @@ -244,9 +256,7 @@ Tree "Text", nomsu = Nomsu(@source, '"') for bit in *@value if type(bit) == 'string' - -- Force indented text - return nil if bit\find("\n") - -- TODO: unescape better + -- TODO: unescape better? nomsu\append (bit\gsub("\\","\\\\")\gsub("\n","\\n")) else interp_nomsu = bit\as_nomsu(true) |
