Bumped fennel to version 9

This commit is contained in:
Alexander Griffith 2021-04-12 19:52:31 -04:00
parent f791534c00
commit 04e00b30d0
3 changed files with 1449 additions and 805 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -24,12 +24,14 @@ local function sort_keys(_0_0, _1_0)
end end
local function table_kv_pairs(t) local function table_kv_pairs(t)
local assoc_3f = false local assoc_3f = false
local i = 1
local kv = {} local kv = {}
local insert = table.insert local insert = table.insert
for k, v in pairs(t) do for k, v in pairs(t) do
if (type(k) ~= "number") then if ((type(k) ~= "number") or (k ~= i)) then
assoc_3f = true assoc_3f = true
end end
i = (i + 1)
insert(kv, {k, v}) insert(kv, {k, v})
end end
table.sort(kv, sort_keys) table.sort(kv, sort_keys)
@ -69,21 +71,19 @@ local function save_table(t, seen)
end end
return seen0 return seen0
end end
local function detect_cycle(t, seen) local function detect_cycle(t, seen, _3fk)
local seen0 = (seen or {}) if ("table" == type(t)) then
seen0[t] = true seen[t] = true
for k, v in pairs(t) do local _2_0, _3_0 = next(t, _3fk)
if ((type(k) == "table") and (seen0[k] or detect_cycle(k, seen0))) then if ((nil ~= _2_0) and (nil ~= _3_0)) then
return true local k = _2_0
end local v = _3_0
if ((type(v) == "table") and (seen0[v] or detect_cycle(v, seen0))) then return (seen[k] or detect_cycle(k, seen) or seen[v] or detect_cycle(v, seen) or detect_cycle(t, seen, k))
return true
end end
end end
return nil
end end
local function visible_cycle_3f(t, options) local function visible_cycle_3f(t, options)
return (options["detect-cycles?"] and detect_cycle(t) and save_table(t, options.seen) and (1 < (options.appearances[t] or 0))) return (options["detect-cycles?"] and detect_cycle(t, {}) and save_table(t, options.seen) and (1 < (options.appearances[t] or 0)))
end end
local function table_indent(t, indent, id) local function table_indent(t, indent, id)
local opener_length = nil local opener_length = nil
@ -94,7 +94,7 @@ local function table_indent(t, indent, id)
end end
return (indent + opener_length) return (indent + opener_length)
end end
local pp = {} local pp = nil
local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix) local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix)
local indent_str = ("\n" .. string.rep(" ", indent)) local indent_str = ("\n" .. string.rep(" ", indent))
local open = nil local open = nil
@ -113,13 +113,7 @@ local function concat_table_lines(elements, options, multiline_3f, indent, table
close = "}" close = "}"
end end
local oneline = (open .. table.concat(elements, " ") .. close) local oneline = (open .. table.concat(elements, " ") .. close)
local _4_ if (not options["one-line?"] and (multiline_3f or ((indent + #oneline) > options["line-length"]))) then
if (table_type == "seq") then
_4_ = options["sequential-length"]
else
_4_ = options["associative-length"]
end
if (not options["one-line?"] and (multiline_3f or (#elements > _4_) or ((indent + #oneline) > options["line-length"]))) then
return (open .. table.concat(elements, indent_str) .. close) return (open .. table.concat(elements, indent_str) .. close)
else else
return oneline return oneline
@ -155,7 +149,7 @@ local function pp_associative(t, kv, options, indent, key_3f)
else else
prefix = "" prefix = ""
end end
local elements = nil local items = nil
do do
local tbl_0_ = {} local tbl_0_ = {}
for _, _6_0 in pairs(kv) do for _, _6_0 in pairs(kv) do
@ -164,16 +158,16 @@ local function pp_associative(t, kv, options, indent, key_3f)
local v = _7_[2] local v = _7_[2]
local _8_ local _8_
do do
local k0 = pp.pp(k, options, (indent0 + 1), true) local k0 = pp(k, options, (indent0 + 1), true)
local v0 = pp.pp(v, options, (indent0 + slength(k0) + 1)) local v0 = pp(v, options, (indent0 + slength(k0) + 1))
multiline_3f = (multiline_3f or k0:find("\n") or v0:find("\n")) multiline_3f = (multiline_3f or k0:find("\n") or v0:find("\n"))
_8_ = (k0 .. " " .. v0) _8_ = (k0 .. " " .. v0)
end end
tbl_0_[(#tbl_0_ + 1)] = _8_ tbl_0_[(#tbl_0_ + 1)] = _8_
end end
elements = tbl_0_ items = tbl_0_
end end
return concat_table_lines(elements, options, multiline_3f, indent0, "table", prefix) return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix)
end end
end end
local function pp_sequence(t, kv, options, indent) local function pp_sequence(t, kv, options, indent)
@ -193,7 +187,7 @@ local function pp_sequence(t, kv, options, indent)
else else
prefix = "" prefix = ""
end end
local elements = nil local items = nil
do do
local tbl_0_ = {} local tbl_0_ = {}
for _, _3_0 in pairs(kv) do for _, _3_0 in pairs(kv) do
@ -202,15 +196,15 @@ local function pp_sequence(t, kv, options, indent)
local v = _4_[2] local v = _4_[2]
local _5_ local _5_
do do
local v0 = pp.pp(v, options, indent0) local v0 = pp(v, options, indent0)
multiline_3f = (multiline_3f or v0:find("\n")) multiline_3f = (multiline_3f or v0:find("\n"))
_5_ = v0 _5_ = v0
end end
tbl_0_[(#tbl_0_ + 1)] = _5_ tbl_0_[(#tbl_0_ + 1)] = _5_
end end
elements = tbl_0_ items = tbl_0_
end end
return concat_table_lines(elements, options, multiline_3f, indent0, "seq", prefix) return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix)
end end
end end
local function concat_lines(lines, options, indent, force_multi_line_3f) local function concat_lines(lines, options, indent, force_multi_line_3f)
@ -252,7 +246,7 @@ local function pp_metamethod(t, metamethod, options, indent)
end end
options["visible-cycle?"] = _2_ options["visible-cycle?"] = _2_
_ = nil _ = nil
local lines, force_multi_line_3f = metamethod(t, pp.pp, options, indent) local lines, force_multi_line_3f = metamethod(t, pp, options, indent)
options["visible-cycle?"] = nil options["visible-cycle?"] = nil
local _3_0 = type(lines) local _3_0 = type(lines)
if (_3_0 == "string") then if (_3_0 == "string") then
@ -261,7 +255,7 @@ local function pp_metamethod(t, metamethod, options, indent)
return concat_lines(lines, options, indent, force_multi_line_3f) return concat_lines(lines, options, indent, force_multi_line_3f)
else else
local _0 = _3_0 local _0 = _3_0
return error("Error: __fennelview metamethod must return a table of lines") return error("__fennelview metamethod must return a table of lines")
end end
end end
end end
@ -313,31 +307,28 @@ local function pp_table(x, options, indent)
return x0 return x0
end end
local function number__3estring(n) local function number__3estring(n)
local _2_0, _3_0, _4_0 = math.modf(n) local _2_0 = string.gsub(tostring(n), ",", ".")
if ((nil ~= _2_0) and (_3_0 == 0)) then return _2_0
local int = _2_0
return tostring(int)
else
local _5_
do
local frac = _3_0
_5_ = (((_2_0 == 0) and (nil ~= _3_0)) and (frac < 0))
end
if _5_ then
local frac = _3_0
return ("-0." .. tostring(frac):gsub("^-?0.", ""))
elseif ((nil ~= _2_0) and (nil ~= _3_0)) then
local int = _2_0
local frac = _3_0
return (int .. "." .. tostring(frac):gsub("^-?0.", ""))
end
end
end end
local function colon_string_3f(s) local function colon_string_3f(s)
return s:find("^[-%w?\\^_!$%&*+./@:|<=>]+$") return s:find("^[-%w?^_!$%&*+./@|<=>]+$")
end
local function pp_string(str, options, indent)
local escs = nil
local _2_
if (options["escape-newlines?"] and (#str < (options["line-length"] - indent))) then
_2_ = "\\n"
else
_2_ = "\n"
end
local function _4_(_241, _242)
return ("\\%03d"):format(_242:byte())
end
escs = setmetatable({["\""] = "\\\"", ["\11"] = "\\v", ["\12"] = "\\f", ["\13"] = "\\r", ["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\\"] = "\\\\", ["\n"] = _2_}, {__index = _4_})
return ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"")
end end
local function make_options(t, options) local function make_options(t, options)
local defaults = {["associative-length"] = 4, ["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["line-length"] = 80, ["metamethod?"] = true, ["one-line?"] = false, ["sequential-length"] = 10, ["utf8?"] = true, depth = 128} local defaults = {["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["escape-newlines?"] = false, ["line-length"] = 80, ["metamethod?"] = true, ["one-line?"] = false, ["prefer-colon?"] = false, ["utf8?"] = true, depth = 128}
local overrides = {appearances = count_table_appearances(t, {}), level = 0, seen = {len = 0}} local overrides = {appearances = count_table_appearances(t, {}), level = 0, seen = {len = 0}}
for k, v in pairs((options or {})) do for k, v in pairs((options or {})) do
defaults[k] = v defaults[k] = v
@ -347,33 +338,45 @@ local function make_options(t, options)
end end
return defaults return defaults
end end
pp.pp = function(x, options, indent, key_3f) local function _2_(x, options, indent, colon_3f)
local indent0 = (indent or 0) local indent0 = (indent or 0)
local options0 = (options or make_options(x)) local options0 = (options or make_options(x))
local tv = type(x) local tv = type(x)
local function _3_() local function _4_()
local _2_0 = getmetatable(x) local _3_0 = getmetatable(x)
if _2_0 then if _3_0 then
return _2_0.__fennelview return _3_0.__fennelview
else else
return _2_0 return _3_0
end end
end end
if ((tv == "table") or ((tv == "userdata") and _3_())) then if ((tv == "table") or ((tv == "userdata") and _4_())) then
return pp_table(x, options0, indent0) return pp_table(x, options0, indent0)
elseif (tv == "number") then elseif (tv == "number") then
return number__3estring(x) return number__3estring(x)
elseif ((tv == "string") and key_3f and colon_string_3f(x)) then else
local function _5_()
if (colon_3f ~= nil) then
return colon_3f
elseif ("function" == type(options0["prefer-colon?"])) then
return options0["prefer-colon?"](x)
else
return options0["prefer-colon?"]
end
end
if ((tv == "string") and colon_string_3f(x) and _5_()) then
return (":" .. x) return (":" .. x)
elseif (tv == "string") then elseif (tv == "string") then
return string.format("%q", x) return pp_string(x, options0, indent0)
elseif ((tv == "boolean") or (tv == "nil")) then elseif ((tv == "boolean") or (tv == "nil")) then
return tostring(x) return tostring(x)
else else
return ("#<" .. tostring(x) .. ">") return ("#<" .. tostring(x) .. ">")
end end
end
end end
pp = _2_
local function view(x, options) local function view(x, options)
return pp.pp(x, make_options(x, options), 0) return pp(x, make_options(x, options), 0)
end end
return view return view