Updating to Fennel 7.0
This commit is contained in:
parent
229449c37b
commit
9734c46064
1028
lib/fennel
1028
lib/fennel
File diff suppressed because it is too large
Load diff
937
lib/fennel.lua
937
lib/fennel.lua
File diff suppressed because it is too large
Load diff
|
@ -21,14 +21,18 @@ local function sequence_key_3f(k, len)
|
||||||
return ((type(k) == "number") and (1 <= k) and (k <= len) and (math.floor(k) == k))
|
return ((type(k) == "number") and (1 <= k) and (k <= len) and (math.floor(k) == k))
|
||||||
end
|
end
|
||||||
local type_order = {["function"] = 5, boolean = 2, number = 1, string = 3, table = 4, thread = 7, userdata = 6}
|
local type_order = {["function"] = 5, boolean = 2, number = 1, string = 3, table = 4, thread = 7, userdata = 6}
|
||||||
local function sort_keys(a, b)
|
local function sort_keys(_0_0, _1_0)
|
||||||
|
local _1_ = _0_0
|
||||||
|
local a = _1_[1]
|
||||||
|
local _2_ = _1_0
|
||||||
|
local b = _2_[1]
|
||||||
local ta = type(a)
|
local ta = type(a)
|
||||||
local tb = type(b)
|
local tb = type(b)
|
||||||
if ((ta == tb) and (ta ~= "boolean") and ((ta == "string") or (ta == "number"))) then
|
if ((ta == tb) and ((ta == "string") or (ta == "number"))) then
|
||||||
return (a < b)
|
return (a < b)
|
||||||
else
|
else
|
||||||
local dta = type_order[a]
|
local dta = type_order[ta]
|
||||||
local dtb = type_order[b]
|
local dtb = type_order[tb]
|
||||||
if (dta and dtb) then
|
if (dta and dtb) then
|
||||||
return (dta < dtb)
|
return (dta < dtb)
|
||||||
elseif dta then
|
elseif dta then
|
||||||
|
@ -41,7 +45,7 @@ local function sort_keys(a, b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function get_sequence_length(t)
|
local function get_sequence_length(t)
|
||||||
local len = 1
|
local len = 0
|
||||||
for i in ipairs(t) do
|
for i in ipairs(t) do
|
||||||
len = i
|
len = i
|
||||||
end
|
end
|
||||||
|
@ -50,9 +54,9 @@ end
|
||||||
local function get_nonsequential_keys(t)
|
local function get_nonsequential_keys(t)
|
||||||
local keys = {}
|
local keys = {}
|
||||||
local sequence_length = get_sequence_length(t)
|
local sequence_length = get_sequence_length(t)
|
||||||
for k in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if not sequence_key_3f(k, sequence_length) then
|
if not sequence_key_3f(k, sequence_length) then
|
||||||
table.insert(keys, k)
|
table.insert(keys, {k, v})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(keys, sort_keys)
|
table.sort(keys, sort_keys)
|
||||||
|
@ -66,9 +70,7 @@ local function count_table_appearances(t, appearances)
|
||||||
count_table_appearances(k, appearances)
|
count_table_appearances(k, appearances)
|
||||||
count_table_appearances(v, appearances)
|
count_table_appearances(v, appearances)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if (t and (t == t)) then
|
|
||||||
appearances[t] = ((appearances[t] or 0) + 1)
|
appearances[t] = ((appearances[t] or 0) + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,12 +102,12 @@ end
|
||||||
local function put_sequential_table(self, t, len)
|
local function put_sequential_table(self, t, len)
|
||||||
puts(self, "[")
|
puts(self, "[")
|
||||||
self.level = (self.level + 1)
|
self.level = (self.level + 1)
|
||||||
for i = 1, len do
|
for k, v in ipairs(t) do
|
||||||
local _0_ = (1 + len)
|
local _2_ = (1 + len)
|
||||||
if ((1 < i) and (i < _0_)) then
|
if ((1 < k) and (k < _2_)) then
|
||||||
puts(self, " ")
|
puts(self, " ")
|
||||||
end
|
end
|
||||||
put_value(self, t[i])
|
put_value(self, v)
|
||||||
end
|
end
|
||||||
self.level = (self.level - 1)
|
self.level = (self.level - 1)
|
||||||
return puts(self, "]")
|
return puts(self, "]")
|
||||||
|
@ -120,13 +122,16 @@ end
|
||||||
local function put_kv_table(self, t, ordered_keys)
|
local function put_kv_table(self, t, ordered_keys)
|
||||||
puts(self, "{")
|
puts(self, "{")
|
||||||
self.level = (self.level + 1)
|
self.level = (self.level + 1)
|
||||||
for i, k in ipairs(ordered_keys) do
|
for i, _2_0 in ipairs(ordered_keys) do
|
||||||
|
local _3_ = _2_0
|
||||||
|
local k = _3_[1]
|
||||||
|
local v = _3_[2]
|
||||||
if (self["table-edges"] or (i ~= 1)) then
|
if (self["table-edges"] or (i ~= 1)) then
|
||||||
tabify(self)
|
tabify(self)
|
||||||
end
|
end
|
||||||
put_key(self, k)
|
put_key(self, k)
|
||||||
puts(self, " ")
|
puts(self, " ")
|
||||||
put_value(self, t[k])
|
put_value(self, v)
|
||||||
end
|
end
|
||||||
for i, v in ipairs(t) do
|
for i, v in ipairs(t) do
|
||||||
tabify(self)
|
tabify(self)
|
||||||
|
@ -142,22 +147,22 @@ local function put_kv_table(self, t, ordered_keys)
|
||||||
end
|
end
|
||||||
local function put_table(self, t)
|
local function put_table(self, t)
|
||||||
local metamethod = nil
|
local metamethod = nil
|
||||||
local function _1_()
|
local function _3_()
|
||||||
local _0_0 = t
|
local _2_0 = t
|
||||||
if _0_0 then
|
|
||||||
local _2_0 = getmetatable(_0_0)
|
|
||||||
if _2_0 then
|
if _2_0 then
|
||||||
return _2_0.__fennelview
|
local _4_0 = getmetatable(_2_0)
|
||||||
|
if _4_0 then
|
||||||
|
return _4_0.__fennelview
|
||||||
|
else
|
||||||
|
return _4_0
|
||||||
|
end
|
||||||
else
|
else
|
||||||
return _2_0
|
return _2_0
|
||||||
end
|
end
|
||||||
else
|
|
||||||
return _0_0
|
|
||||||
end
|
end
|
||||||
end
|
metamethod = (self["metamethod?"] and _3_())
|
||||||
metamethod = (self["metamethod?"] and _1_())
|
|
||||||
if (already_visited_3f(self, t) and self["detect-cycles?"]) then
|
if (already_visited_3f(self, t) and self["detect-cycles?"]) then
|
||||||
return puts(self, "#<table ", get_id(self, t), ">")
|
return puts(self, "#<table @", get_id(self, t), ">")
|
||||||
elseif (self.level >= self.depth) then
|
elseif (self.level >= self.depth) then
|
||||||
return puts(self, "{...}")
|
return puts(self, "{...}")
|
||||||
elseif metamethod then
|
elseif metamethod then
|
||||||
|
@ -166,16 +171,17 @@ local function put_table(self, t)
|
||||||
local non_seq_keys, len = get_nonsequential_keys(t)
|
local non_seq_keys, len = get_nonsequential_keys(t)
|
||||||
local id = get_id(self, t)
|
local id = get_id(self, t)
|
||||||
if ((1 < (self.appearances[t] or 0)) and self["detect-cycles?"]) then
|
if ((1 < (self.appearances[t] or 0)) and self["detect-cycles?"]) then
|
||||||
return puts(self, "#<table", id, ">")
|
puts(self, "@", id)
|
||||||
elseif ((#non_seq_keys == 0) and (#t == 0)) then
|
end
|
||||||
local function _2_()
|
if ((#non_seq_keys == 0) and (#t == 0)) then
|
||||||
|
local function _5_()
|
||||||
if self["empty-as-square"] then
|
if self["empty-as-square"] then
|
||||||
return "[]"
|
return "[]"
|
||||||
else
|
else
|
||||||
return "{}"
|
return "{}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return puts(self, _2_())
|
return puts(self, _5_())
|
||||||
elseif (#non_seq_keys == 0) then
|
elseif (#non_seq_keys == 0) then
|
||||||
return put_sequential_table(self, t, len)
|
return put_sequential_table(self, t, len)
|
||||||
elseif "else" then
|
elseif "else" then
|
||||||
|
@ -183,19 +189,30 @@ local function put_table(self, t)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function _0_(self, v)
|
local function _2_(self, v)
|
||||||
local tv = type(v)
|
local tv = type(v)
|
||||||
if (tv == "string") then
|
if (tv == "string") then
|
||||||
return puts(self, view_quote(escape(v)))
|
return puts(self, view_quote(escape(v)))
|
||||||
elseif ((tv == "number") or (tv == "boolean") or (tv == "nil")) then
|
elseif ((tv == "number") or (tv == "boolean") or (tv == "nil")) then
|
||||||
return puts(self, tostring(v))
|
return puts(self, tostring(v))
|
||||||
elseif (tv == "table") then
|
else
|
||||||
|
local _4_
|
||||||
|
do
|
||||||
|
local _3_0 = getmetatable(v)
|
||||||
|
if _3_0 then
|
||||||
|
_4_ = _3_0.__fennelview
|
||||||
|
else
|
||||||
|
_4_ = _3_0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if ((tv == "table") or ((tv == "userdata") and (nil ~= _4_))) then
|
||||||
return put_table(self, v)
|
return put_table(self, v)
|
||||||
elseif "else" then
|
elseif "else" then
|
||||||
return puts(self, "#<", tostring(v), ">")
|
return puts(self, "#<", tostring(v), ">")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
put_value = _0_
|
put_value = _2_
|
||||||
local function one_line(str)
|
local function one_line(str)
|
||||||
local ret = str:gsub("\n", " "):gsub("%[ ", "["):gsub(" %]", "]"):gsub("%{ ", "{"):gsub(" %}", "}"):gsub("%( ", "("):gsub(" %)", ")")
|
local ret = str:gsub("\n", " "):gsub("%[ ", "["):gsub(" %]", "]"):gsub("%{ ", "{"):gsub(" %}", "}"):gsub("%( ", "("):gsub(" %)", ")")
|
||||||
return ret
|
return ret
|
||||||
|
@ -203,17 +220,17 @@ end
|
||||||
local function fennelview(x, options)
|
local function fennelview(x, options)
|
||||||
local options0 = (options or {})
|
local options0 = (options or {})
|
||||||
local inspector = nil
|
local inspector = nil
|
||||||
local function _1_(_241)
|
local function _3_(_241)
|
||||||
return fennelview(_241, options0)
|
return fennelview(_241, options0)
|
||||||
end
|
end
|
||||||
local function _2_()
|
local function _4_()
|
||||||
if options0["one-line"] then
|
if options0["one-line"] then
|
||||||
return ""
|
return ""
|
||||||
else
|
else
|
||||||
return " "
|
return " "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
inspector = {["detect-cycles?"] = not (false == options0["detect-cycles?"]), ["empty-as-square"] = options0["empty-as-square"], ["max-ids"] = {}, ["metamethod?"] = not (false == options0["metamethod?"]), ["table-edges"] = (options0["table-edges"] ~= false), appearances = count_table_appearances(x, {}), buffer = {}, depth = (options0.depth or 128), fennelview = _1_, ids = {}, indent = (options0.indent or _2_()), level = 0}
|
inspector = {["detect-cycles?"] = not (false == options0["detect-cycles?"]), ["empty-as-square"] = options0["empty-as-square"], ["max-ids"] = {}, ["metamethod?"] = not (false == options0["metamethod?"]), ["table-edges"] = (options0["table-edges"] ~= false), appearances = count_table_appearances(x, {}), buffer = {}, depth = (options0.depth or 128), fennelview = _3_, ids = {}, indent = (options0.indent or _4_()), level = 0}
|
||||||
put_value(inspector, x)
|
put_value(inspector, x)
|
||||||
local str = table.concat(inspector.buffer)
|
local str = table.concat(inspector.buffer)
|
||||||
if options0["one-line"] then
|
if options0["one-line"] then
|
||||||
|
|
Loading…
Reference in a new issue