diff --git a/fnl/nvim-tree-docs/collector.fnl b/fnl/nvim-tree-docs/collector.fnl index defa62d..4752f3d 100644 --- a/fnl/nvim-tree-docs/collector.fnl +++ b/fnl/nvim-tree-docs/collector.fnl @@ -41,7 +41,7 @@ (when (not (. entry key)) (tset entry key (new-collector))) (-> (. entry key) - (add-fn key _match collect))) + (add-fn key _match collect_))) (not (. entry key)) (tset entry key _match) (and (= key :start_point) _match.node) diff --git a/fnl/nvim-tree-docs/internal.fnl b/fnl/nvim-tree-docs/internal.fnl index 67d8a96..9603069 100644 --- a/fnl/nvim-tree-docs/internal.fnl +++ b/fnl/nvim-tree-docs/internal.fnl @@ -65,7 +65,7 @@ :end {:line (+ node-er 1) :character 0}}}) (vim.list_extend marks result.marks) (set line-offset (- (+ line-offset (length result.content)) replaced-count)))) - (vim.lsp.util.apply_text_edits edits bufnr))) + (vim.lsp.util.apply_text_edits edits bufnr :utf-16))) ; Uncomment to test marks ;(utils.highlight-marks marks bufnr))) diff --git a/lua/nvim-tree-docs/aniseed/autoload.lua b/lua/nvim-tree-docs/aniseed/autoload.lua index 3817719..1ff4f3c 100644 --- a/lua/nvim-tree-docs/aniseed/autoload.lua +++ b/lua/nvim-tree-docs/aniseed/autoload.lua @@ -1,78 +1,37 @@ local _2afile_2a = "fnl/aniseed/autoload.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.autoload" +local _2amodule_2a +do + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] +end +local _2amodule_locals_2a do - local name_0_ = "nvim-tree-docs.aniseed.autoload" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local function autoload(name) + local res = {["aniseed/autoload-enabled?"] = true, ["aniseed/autoload-module"] = false} + local function ensure() + if res["aniseed/autoload-module"] then + return res["aniseed/autoload-module"] else - module_0_ = {} + local m = require(name) + do end (res)["aniseed/autoload-module"] = m + return m end end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} + local function _2_(t, ...) + return ensure()(...) end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {} - return val_0_ - else - return print(val_0_) + local function _3_(t, k) + return ensure()[k] end -end -local _local_0_ = _2_(...) -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.autoload" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local autoload0 -do - local v_0_ - do - local v_0_0 - local function autoload1(name) - local res = {["aniseed/autoload-enabled?"] = true, ["aniseed/autoload-module"] = false} - local function ensure() - if res["aniseed/autoload-module"] then - return res["aniseed/autoload-module"] - else - local m = require(name) - do end (res)["aniseed/autoload-module"] = m - return m - end - end - local function _3_(t, ...) - return ensure()(...) - end - local function _4_(t, k) - return ensure()[k] - end - local function _5_(t, k, v) - ensure()[k] = v - return nil - end - return setmetatable(res, {__call = _3_, __index = _4_, __newindex = _5_}) - end - v_0_0 = autoload1 - _0_["autoload"] = v_0_0 - v_0_ = v_0_0 + local function _4_(t, k, v) + ensure()[k] = v + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["autoload"] = v_0_ - autoload0 = v_0_ + return setmetatable(res, {__call = _2_, __index = _3_, __newindex = _4_}) end -return nil +_2amodule_2a["autoload"] = autoload +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/compile.lua b/lua/nvim-tree-docs/aniseed/compile.lua index d061df8..a18141c 100644 --- a/lua/nvim-tree-docs/aniseed/compile.lua +++ b/lua/nvim-tree-docs/aniseed/compile.lua @@ -1,146 +1,83 @@ local _2afile_2a = "fnl/aniseed/compile.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.compile" +local _2amodule_2a +do + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] +end +local _2amodule_locals_2a do - local name_0_ = "nvim-tree-docs.aniseed.compile" - local module_0_ + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a, fennel, fs, nvim = autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.fennel"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim") +do end (_2amodule_locals_2a)["a"] = a +_2amodule_locals_2a["fennel"] = fennel +_2amodule_locals_2a["fs"] = fs +_2amodule_locals_2a["nvim"] = nvim +local function wrap_macros(code, opts) + local macros_module = "nvim-tree-docs.aniseed.macros" + local filename do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ + local _1_ = a.get(opts, "filename") + if (nil ~= _1_) then + filename = string.gsub(_1_, (nvim.fn.getcwd() .. fs["path-sep"]), "") else - module_0_ = {} + filename = _1_ end end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.fennel"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "nvim-tree-docs.aniseed.core", fennel = "nvim-tree-docs.aniseed.fennel", fs = "nvim-tree-docs.aniseed.fs", nvim = "nvim-tree-docs.aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local fennel = _local_0_[2] -local fs = _local_0_[3] -local nvim = _local_0_[4] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.compile" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local macros_prefix -do - local v_0_ - do - local v_0_0 - local function macros_prefix0(code, opts) - local macros_module = "nvim-tree-docs.aniseed.macros" - local filename - do - local _3_ = a.get(opts, "filename") - if _3_ then - filename = string.gsub(_3_, (nvim.fn.getcwd() .. fs["path-sep"]), "") - else - filename = _3_ - end - end - local _4_ - if filename then - _4_ = ("\"" .. string.gsub(filename, "\\", "\\\\") .. "\"") - else - _4_ = "nil" - end - return ("(local *file* " .. _4_ .. ")" .. "(require-macros \"" .. macros_module .. "\")\n" .. code) + local function _3_() + if filename then + return ("\"" .. string.gsub(filename, "\\", "\\\\") .. "\"") + else + return "nil" end - v_0_0 = macros_prefix0 - _0_["macros-prefix"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["macros-prefix"] = v_0_ - macros_prefix = v_0_ + return ("(local *file* " .. _3_() .. ")" .. "(require-macros \"" .. macros_module .. "\")\n" .. "(wrap-module-body " .. (code or "") .. ")") end -local str -do - local v_0_ - do - local v_0_0 - local function str0(code, opts) - local fnl = fennel.impl() - local function _3_() - return fnl.compileString(macros_prefix(code, opts), a.merge({allowedGlobals = false}, opts)) - end - return xpcall(_3_, fnl.traceback) - end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["wrap-macros"] = wrap_macros +local marker_prefix = "ANISEED_" +_2amodule_2a["marker-prefix"] = marker_prefix +local delete_marker = (marker_prefix .. "DELETE_ME") +do end (_2amodule_2a)["delete-marker"] = delete_marker +local delete_marker_pat = ("\n[^\n]-\"" .. delete_marker .. "\".-") +do end (_2amodule_locals_2a)["delete-marker-pat"] = delete_marker_pat +local function str(code, opts) + ANISEED_STATIC_MODULES = (true == a.get(opts, "static?")) + local fnl = fennel.impl() + local function _4_() + return string.gsub(string.gsub(fnl.compileString(wrap_macros(code, opts), a["merge!"]({compilerEnv = _G, allowedGlobals = false}, opts)), (delete_marker_pat .. "\n"), "\n"), (delete_marker_pat .. "$"), "") end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + return xpcall(_4_, fnl.traceback) end -local file -do - local v_0_ - do - local v_0_0 - local function file0(src, dest) - local code = a.slurp(src) - local _3_, _4_ = str(code, {filename = src}) - if ((_3_ == false) and (nil ~= _4_)) then - local err = _4_ - return nvim.err_writeln(err) - elseif ((_3_ == true) and (nil ~= _4_)) then - local result = _4_ - fs.mkdirp(fs.basename(dest)) - return a.spit(dest, result) - end - end - v_0_0 = file0 - _0_["file"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["str"] = str +local function file(src, dest, opts) + local code = a.slurp(src) + local _5_, _6_ = str(code, a["merge!"]({filename = src, ["static?"] = true}, opts)) + if ((_5_ == false) and (nil ~= _6_)) then + local err = _6_ + return nvim.err_writeln(err) + elseif ((_5_ == true) and (nil ~= _6_)) then + local result = _6_ + fs.mkdirp(fs.basename(dest)) + return a.spit(dest, result) + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["file"] = v_0_ - file = v_0_ end -local glob -do - local v_0_ - do - local v_0_0 - local function glob0(src_expr, src_dir, dest_dir) - for _, path in ipairs(fs.relglob(src_dir, src_expr)) do - if fs["macro-file-path?"](path) then - a.spit((dest_dir .. path), a.slurp((src_dir .. path))) - else - file((src_dir .. path), string.gsub((dest_dir .. path), ".fnl$", ".lua")) - end - end - return nil +_2amodule_2a["file"] = file +local function glob(src_expr, src_dir, dest_dir, opts) + for _, path in ipairs(fs.relglob(src_dir, src_expr)) do + if fs["macro-file-path?"](path) then + local dest = (dest_dir .. path) + fs.mkdirp(fs.basename(dest)) + a.spit(dest, a.slurp((src_dir .. path))) + else + file((src_dir .. path), string.gsub((dest_dir .. path), ".fnl$", ".lua"), opts) end - v_0_0 = glob0 - _0_["glob"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["glob"] = v_0_ - glob = v_0_ + return nil end -return nil +_2amodule_2a["glob"] = glob +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/core.lua b/lua/nvim-tree-docs/aniseed/core.lua index 397d4e4..a835491 100644 --- a/lua/nvim-tree-docs/aniseed/core.lua +++ b/lua/nvim-tree-docs/aniseed/core.lua @@ -1,957 +1,469 @@ local _2afile_2a = "fnl/aniseed/core.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.aniseed.core" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.view")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {view = "nvim-tree-docs.aniseed.view"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local view = _local_0_[1] -local _2amodule_2a = _0_ local _2amodule_name_2a = "nvim-tree-docs.aniseed.core" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -math.randomseed(os.time()) -local rand +local _2amodule_2a do - local v_0_ - do - local v_0_0 - local function rand0(n) - return (math.random() * (n or 1)) - end - v_0_0 = rand0 - _0_["rand"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["rand"] = v_0_ - rand = v_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local string_3f +local _2amodule_locals_2a do - local v_0_ - do - local v_0_0 - local function string_3f0(x) - return ("string" == type(x)) - end - v_0_0 = string_3f0 - _0_["string?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["string?"] = v_0_ - string_3f = v_0_ + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -local nil_3f -do - local v_0_ - do - local v_0_0 - local function nil_3f0(x) - return (nil == x) - end - v_0_0 = nil_3f0 - _0_["nil?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["nil?"] = v_0_ - nil_3f = v_0_ +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local view = autoload("nvim-tree-docs.aniseed.view") +do end (_2amodule_locals_2a)["view"] = view +math.randomseed(os.time()) +local function rand(n) + return (math.random() * (n or 1)) end -local table_3f -do - local v_0_ - do - local v_0_0 - local function table_3f0(x) - return ("table" == type(x)) - end - v_0_0 = table_3f0 - _0_["table?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["table?"] = v_0_ - table_3f = v_0_ +_2amodule_2a["rand"] = rand +local function nil_3f(x) + return (nil == x) end -local count -do - local v_0_ - do - local v_0_0 - local function count0(xs) - if table_3f(xs) then - return table.maxn(xs) - elseif not xs then - return 0 - else - return #xs - end - end - v_0_0 = count0 - _0_["count"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["count"] = v_0_ - count = v_0_ +_2amodule_2a["nil?"] = nil_3f +local function number_3f(x) + return ("number" == type(x)) end -local empty_3f -do - local v_0_ - do - local v_0_0 - local function empty_3f0(xs) - return (0 == count(xs)) - end - v_0_0 = empty_3f0 - _0_["empty?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["empty?"] = v_0_ - empty_3f = v_0_ +_2amodule_2a["number?"] = number_3f +local function boolean_3f(x) + return ("boolean" == type(x)) end -local first -do - local v_0_ - do - local v_0_0 - local function first0(xs) - if xs then - return xs[1] - end - end - v_0_0 = first0 - _0_["first"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["first"] = v_0_ - first = v_0_ +_2amodule_2a["boolean?"] = boolean_3f +local function string_3f(x) + return ("string" == type(x)) end -local second -do - local v_0_ - do - local v_0_0 - local function second0(xs) - if xs then - return xs[2] - end - end - v_0_0 = second0 - _0_["second"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["second"] = v_0_ - second = v_0_ +_2amodule_2a["string?"] = string_3f +local function table_3f(x) + return ("table" == type(x)) end -local last -do - local v_0_ - do - local v_0_0 - local function last0(xs) - if xs then - return xs[count(xs)] - end - end - v_0_0 = last0 - _0_["last"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["last"] = v_0_ - last = v_0_ +_2amodule_2a["table?"] = table_3f +local function function_3f(value) + return ("function" == type(value)) end -local inc -do - local v_0_ - do - local v_0_0 - local function inc0(n) - return (n + 1) +_2amodule_2a["function?"] = function_3f +local function keys(t) + local result = {} + if t then + for k, _ in pairs(t) do + table.insert(result, k) end - v_0_0 = inc0 - _0_["inc"] = v_0_0 - v_0_ = v_0_0 + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["inc"] = v_0_ - inc = v_0_ + return result end -local dec -do - local v_0_ - do - local v_0_0 - local function dec0(n) - return (n - 1) +_2amodule_2a["keys"] = keys +local function count(xs) + if table_3f(xs) then + local maxn = table.maxn(xs) + if (0 == maxn) then + return table.maxn(keys(xs)) + else + return maxn end - v_0_0 = dec0 - _0_["dec"] = v_0_0 - v_0_ = v_0_0 + elseif not xs then + return 0 + else + return #xs end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["dec"] = v_0_ - dec = v_0_ end -local even_3f -do - local v_0_ - do - local v_0_0 - local function even_3f0(n) - return ((n % 2) == 0) - end - v_0_0 = even_3f0 - _0_["even?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["even?"] = v_0_ - even_3f = v_0_ +_2amodule_2a["count"] = count +local function empty_3f(xs) + return (0 == count(xs)) end -local odd_3f -do - local v_0_ - do - local v_0_0 - local function odd_3f0(n) - return not even_3f(n) - end - v_0_0 = odd_3f0 - _0_["odd?"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["empty?"] = empty_3f +local function first(xs) + if xs then + return xs[1] + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["odd?"] = v_0_ - odd_3f = v_0_ end -local keys -do - local v_0_ - do - local v_0_0 - local function keys0(t) - local result = {} - if t then - for k, _ in pairs(t) do - table.insert(result, k) - end - end - return result - end - v_0_0 = keys0 - _0_["keys"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["first"] = first +local function second(xs) + if xs then + return xs[2] + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["keys"] = v_0_ - keys = v_0_ end -local vals -do - local v_0_ - do - local v_0_0 - local function vals0(t) - local result = {} - if t then - for _, v in pairs(t) do - table.insert(result, v) - end - end - return result - end - v_0_0 = vals0 - _0_["vals"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["second"] = second +local function last(xs) + if xs then + return xs[count(xs)] + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["vals"] = v_0_ - vals = v_0_ end -local kv_pairs -do - local v_0_ - do - local v_0_0 - local function kv_pairs0(t) - local result = {} - if t then - for k, v in pairs(t) do - table.insert(result, {k, v}) - end - end - return result - end - v_0_0 = kv_pairs0 - _0_["kv-pairs"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["kv-pairs"] = v_0_ - kv_pairs = v_0_ +_2amodule_2a["last"] = last +local function inc(n) + return (n + 1) end -local run_21 -do - local v_0_ - do - local v_0_0 - local function run_210(f, xs) - if xs then - local nxs = count(xs) - if (nxs > 0) then - for i = 1, nxs do - f(xs[i]) - end - return nil - end - end +_2amodule_2a["inc"] = inc +local function dec(n) + return (n - 1) +end +_2amodule_2a["dec"] = dec +local function even_3f(n) + return ((n % 2) == 0) +end +_2amodule_2a["even?"] = even_3f +local function odd_3f(n) + return not even_3f(n) +end +_2amodule_2a["odd?"] = odd_3f +local function vals(t) + local result = {} + if t then + for _, v in pairs(t) do + table.insert(result, v) end - v_0_0 = run_210 - _0_["run!"] = v_0_0 - v_0_ = v_0_0 + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["run!"] = v_0_ - run_21 = v_0_ + return result end -local filter -do - local v_0_ - do - local v_0_0 - local function filter0(f, xs) - local result = {} - local function _3_(x) - if f(x) then - return table.insert(result, x) - end - end - run_21(_3_, xs) - return result +_2amodule_2a["vals"] = vals +local function kv_pairs(t) + local result = {} + if t then + for k, v in pairs(t) do + table.insert(result, {k, v}) end - v_0_0 = filter0 - _0_["filter"] = v_0_0 - v_0_ = v_0_0 + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["filter"] = v_0_ - filter = v_0_ + return result end -local map -do - local v_0_ - do - local v_0_0 - local function map0(f, xs) - local result = {} - local function _3_(x) - local mapped = f(x) - local function _4_() - if (0 == select("#", mapped)) then - return nil - else - return mapped - end - end - return table.insert(result, _4_()) +_2amodule_2a["kv-pairs"] = kv_pairs +local function run_21(f, xs) + if xs then + local nxs = count(xs) + if (nxs > 0) then + for i = 1, nxs do + f(xs[i]) end - run_21(_3_, xs) - return result + return nil + else + return nil end - v_0_0 = map0 - _0_["map"] = v_0_0 - v_0_ = v_0_0 + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["map"] = v_0_ - map = v_0_ end -local map_indexed -do - local v_0_ - do - local v_0_0 - local function map_indexed0(f, xs) - return map(f, kv_pairs(xs)) - end - v_0_0 = map_indexed0 - _0_["map-indexed"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["run!"] = run_21 +local function complement(f) + local function _11_(...) + return not f(...) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["map-indexed"] = v_0_ - map_indexed = v_0_ + return _11_ end -local identity -do - local v_0_ - do - local v_0_0 - local function identity0(x) - return x +_2amodule_2a["complement"] = complement +local function filter(f, xs) + local result = {} + local function _12_(x) + if f(x) then + return table.insert(result, x) + else + return nil end - v_0_0 = identity0 - _0_["identity"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["identity"] = v_0_ - identity = v_0_ + run_21(_12_, xs) + return result end -local reduce -do - local v_0_ - do - local v_0_0 - local function reduce0(f, init, xs) - local result = init - local function _3_(x) - result = f(result, x) +_2amodule_2a["filter"] = filter +local function remove(f, xs) + return filter(complement(f), xs) +end +_2amodule_2a["remove"] = remove +local function map(f, xs) + local result = {} + local function _14_(x) + local mapped = f(x) + local function _15_() + if (0 == select("#", mapped)) then return nil + else + return mapped end - run_21(_3_, xs) - return result end - v_0_0 = reduce0 - _0_["reduce"] = v_0_0 - v_0_ = v_0_0 + return table.insert(result, _15_()) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["reduce"] = v_0_ - reduce = v_0_ + run_21(_14_, xs) + return result end -local some -do - local v_0_ - do - local v_0_0 - local function some0(f, xs) - local result = nil - local n = 1 - while (nil_3f(result) and (n <= count(xs))) do - local candidate = f(xs[n]) - if candidate then - result = candidate - end - n = inc(n) - end - return result - end - v_0_0 = some0 - _0_["some"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["some"] = v_0_ - some = v_0_ +_2amodule_2a["map"] = map +local function map_indexed(f, xs) + return map(f, kv_pairs(xs)) end -local butlast -do - local v_0_ - do - local v_0_0 - local function butlast0(xs) - local total = count(xs) - local function _4_(_3_) - local _arg_0_ = _3_ - local n = _arg_0_[1] - local v = _arg_0_[2] - return (n ~= total) - end - return map(second, filter(_4_, kv_pairs(xs))) - end - v_0_0 = butlast0 - _0_["butlast"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["butlast"] = v_0_ - butlast = v_0_ +_2amodule_2a["map-indexed"] = map_indexed +local function identity(x) + return x end -local rest -do - local v_0_ - do - local v_0_0 - local function rest0(xs) - local function _4_(_3_) - local _arg_0_ = _3_ - local n = _arg_0_[1] - local v = _arg_0_[2] - return (n ~= 1) - end - return map(second, filter(_4_, kv_pairs(xs))) - end - v_0_0 = rest0 - _0_["rest"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["identity"] = identity +local function reduce(f, init, xs) + local result = init + local function _16_(x) + result = f(result, x) + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["rest"] = v_0_ - rest = v_0_ + run_21(_16_, xs) + return result end -local concat -do - local v_0_ - do - local v_0_0 - local function concat0(...) - local result = {} - local function _3_(xs) - local function _4_(x) - return table.insert(result, x) - end - return run_21(_4_, xs) - end - run_21(_3_, {...}) - return result +_2amodule_2a["reduce"] = reduce +local function some(f, xs) + local result = nil + local n = 1 + while (nil_3f(result) and (n <= count(xs))) do + local candidate = f(xs[n]) + if candidate then + result = candidate + else end - v_0_0 = concat0 - _0_["concat"] = v_0_0 - v_0_ = v_0_0 + n = inc(n) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["concat"] = v_0_ - concat = v_0_ + return result end -local mapcat -do - local v_0_ - do - local v_0_0 - local function mapcat0(f, xs) - return concat(unpack(map(f, xs))) - end - v_0_0 = mapcat0 - _0_["mapcat"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["some"] = some +local function butlast(xs) + local total = count(xs) + local function _20_(_18_) + local _arg_19_ = _18_ + local n = _arg_19_[1] + local v = _arg_19_[2] + return (n ~= total) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["mapcat"] = v_0_ - mapcat = v_0_ + return map(second, filter(_20_, kv_pairs(xs))) end -local pr_str -do - local v_0_ - do - local v_0_0 - local function pr_str0(...) - local s - local function _3_(x) - return view.serialise(x, {["one-line"] = true}) - end - s = table.concat(map(_3_, {...}), " ") - if (nil_3f(s) or ("" == s)) then - return "nil" - else - return s - end - end - v_0_0 = pr_str0 - _0_["pr-str"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["butlast"] = butlast +local function rest(xs) + local function _23_(_21_) + local _arg_22_ = _21_ + local n = _arg_22_[1] + local v = _arg_22_[2] + return (n ~= 1) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["pr-str"] = v_0_ - pr_str = v_0_ + return map(second, filter(_23_, kv_pairs(xs))) end -local str -do - local v_0_ - do - local v_0_0 - local function str0(...) - local function _3_(acc, s) - return (acc .. s) - end - local function _4_(s) - if string_3f(s) then - return s - else - return pr_str(s) - end - end - return reduce(_3_, "", map(_4_, {...})) +_2amodule_2a["rest"] = rest +local function concat(...) + local result = {} + local function _24_(xs) + local function _25_(x) + return table.insert(result, x) end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 + return run_21(_25_, xs) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + run_21(_24_, {...}) + return result end -local println -do - local v_0_ - do - local v_0_0 - local function println0(...) - local function _3_(acc, s) - return (acc .. s) - end - local function _5_(_4_) - local _arg_0_ = _4_ - local i = _arg_0_[1] - local s = _arg_0_[2] - if (1 == i) then - return s - else - return (" " .. s) - end - end - local function _6_(s) - if string_3f(s) then - return s - else - return pr_str(s) - end - end - return print(reduce(_3_, "", map_indexed(_5_, map(_6_, {...})))) - end - v_0_0 = println0 - _0_["println"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["println"] = v_0_ - println = v_0_ +_2amodule_2a["concat"] = concat +local function mapcat(f, xs) + return concat(unpack(map(f, xs))) end -local pr -do - local v_0_ - do - local v_0_0 - local function pr0(...) - return println(pr_str(...)) - end - v_0_0 = pr0 - _0_["pr"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["mapcat"] = mapcat +local function pr_str(...) + local s + local function _26_(x) + return view.serialise(x, {["one-line"] = true}) + end + s = table.concat(map(_26_, {...}), " ") + if (nil_3f(s) or ("" == s)) then + return "nil" + else + return s end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["pr"] = v_0_ - pr = v_0_ end -local slurp -do - local v_0_ - do - local v_0_0 - local function slurp0(path, silent_3f) - local _3_, _4_ = io.open(path, "r") - if ((_3_ == nil) and (nil ~= _4_)) then - local msg = _4_ - return nil - elseif (nil ~= _3_) then - local f = _3_ - local content = f:read("*all") - f:close() - return content - end +_2amodule_2a["pr-str"] = pr_str +local function str(...) + local function _28_(acc, s) + return (acc .. s) + end + local function _29_(s) + if string_3f(s) then + return s + else + return pr_str(s) end - v_0_0 = slurp0 - _0_["slurp"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["slurp"] = v_0_ - slurp = v_0_ + return reduce(_28_, "", map(_29_, {...})) end -local spit -do - local v_0_ - do - local v_0_0 - local function spit0(path, content) - local _3_, _4_ = io.open(path, "w") - if ((_3_ == nil) and (nil ~= _4_)) then - local msg = _4_ - return error(("Could not open file: " .. msg)) - elseif (nil ~= _3_) then - local f = _3_ - f:write(content) - f:close() - return nil - end +_2amodule_2a["str"] = str +local function println(...) + local function _31_(acc, s) + return (acc .. s) + end + local function _34_(_32_) + local _arg_33_ = _32_ + local i = _arg_33_[1] + local s = _arg_33_[2] + if (1 == i) then + return s + else + return (" " .. s) end - v_0_0 = spit0 - _0_["spit"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["spit"] = v_0_ - spit = v_0_ + local function _36_(s) + if string_3f(s) then + return s + else + return pr_str(s) + end + end + return print(reduce(_31_, "", map_indexed(_34_, map(_36_, {...})))) +end +_2amodule_2a["println"] = println +local function pr(...) + return println(pr_str(...)) +end +_2amodule_2a["pr"] = pr +local function slurp(path, silent_3f) + local _38_, _39_ = io.open(path, "r") + if ((_38_ == nil) and (nil ~= _39_)) then + local msg = _39_ + return nil + elseif (nil ~= _38_) then + local f = _38_ + local content = f:read("*all") + f:close() + return content + else + return nil + end +end +_2amodule_2a["slurp"] = slurp +local function spit(path, content) + local _41_, _42_ = io.open(path, "w") + if ((_41_ == nil) and (nil ~= _42_)) then + local msg = _42_ + return error(("Could not open file: " .. msg)) + elseif (nil ~= _41_) then + local f = _41_ + f:write(content) + f:close() + return nil + else + return nil + end end -local merge_21 -do - local v_0_ - do - local v_0_0 - local function merge_210(base, ...) - local function _3_(acc, m) - if m then - for k, v in pairs(m) do - acc[k] = v - end - end - return acc +_2amodule_2a["spit"] = spit +local function merge_21(base, ...) + local function _44_(acc, m) + if m then + for k, v in pairs(m) do + acc[k] = v end - return reduce(_3_, (base or {}), {...}) + else end - v_0_0 = merge_210 - _0_["merge!"] = v_0_0 - v_0_ = v_0_0 + return acc end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["merge!"] = v_0_ - merge_21 = v_0_ + return reduce(_44_, (base or {}), {...}) end -local merge -do - local v_0_ - do - local v_0_0 - local function merge0(...) - return merge_21({}, ...) - end - v_0_0 = merge0 - _0_["merge"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["merge"] = v_0_ - merge = v_0_ +_2amodule_2a["merge!"] = merge_21 +local function merge(...) + return merge_21({}, ...) end -local select_keys -do - local v_0_ - do - local v_0_0 - local function select_keys0(t, ks) - if (t and ks) then - local function _3_(acc, k) - if k then - acc[k] = t[k] - end - return acc - end - return reduce(_3_, {}, ks) +_2amodule_2a["merge"] = merge +local function select_keys(t, ks) + if (t and ks) then + local function _46_(acc, k) + if k then + acc[k] = t[k] else - return {} end + return acc end - v_0_0 = select_keys0 - _0_["select-keys"] = v_0_0 - v_0_ = v_0_0 + return reduce(_46_, {}, ks) + else + return {} end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["select-keys"] = v_0_ - select_keys = v_0_ end -local get -do - local v_0_ - do - local v_0_0 - local function get0(t, k, d) - local res - if table_3f(t) then - local val = t[k] - if not nil_3f(val) then - res = val - else - res = nil - end - else +_2amodule_2a["select-keys"] = select_keys +local function get(t, k, d) + local res + if table_3f(t) then + local val = t[k] + if not nil_3f(val) then + res = val + else res = nil - end - if nil_3f(res) then - return d - else - return res - end end - v_0_0 = get0 - _0_["get"] = v_0_0 - v_0_ = v_0_0 + else + res = nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get"] = v_0_ - get = v_0_ -end -local get_in -do - local v_0_ - do - local v_0_0 - local function get_in0(t, ks, d) - local res - local function _3_(acc, k) - if table_3f(acc) then - return get(acc, k) - end - end - res = reduce(_3_, t, ks) - if nil_3f(res) then - return d - else - return res - end - end - v_0_0 = get_in0 - _0_["get-in"] = v_0_0 - v_0_ = v_0_0 + if nil_3f(res) then + return d + else + return res end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-in"] = v_0_ - get_in = v_0_ end -local assoc -do - local v_0_ - do - local v_0_0 - local function assoc0(t, ...) - local _let_0_ = {...} - local k = _let_0_[1] - local v = _let_0_[2] - local xs = {(table.unpack or unpack)(_let_0_, 3)} - local rem = count(xs) - local t0 = (t or {}) - if odd_3f(rem) then - error("assoc expects even number of arguments after table, found odd number") - end - if not nil_3f(k) then - t0[k] = v - end - if (rem > 0) then - assoc0(t0, unpack(xs)) - end - return t0 +_2amodule_2a["get"] = get +local function get_in(t, ks, d) + local res + local function _52_(acc, k) + if table_3f(acc) then + return get(acc, k) + else + return nil end - v_0_0 = assoc0 - _0_["assoc"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["assoc"] = v_0_ - assoc = v_0_ -end -local assoc_in -do - local v_0_ - do - local v_0_0 - local function assoc_in0(t, ks, v) - local path = butlast(ks) - local final = last(ks) - local t0 = (t or {}) - local function _3_(acc, k) - local step = get(acc, k) - if nil_3f(step) then - return get(assoc(acc, k, {}), k) - else - return step - end - end - assoc(reduce(_3_, t0, path), final, v) - return t0 - end - v_0_0 = assoc_in0 - _0_["assoc-in"] = v_0_0 - v_0_ = v_0_0 + res = reduce(_52_, t, ks) + if nil_3f(res) then + return d + else + return res + end +end +_2amodule_2a["get-in"] = get_in +local function assoc(t, ...) + local _let_55_ = {...} + local k = _let_55_[1] + local v = _let_55_[2] + local xs = (function (t, k, e) local mt = getmetatable(t) if 'table' == type(mt) and mt.__fennelrest then return mt.__fennelrest(t, k) elseif e then local rest = {} for k, v in pairs(t) do if not e[k] then rest[k] = v end end return rest else return {(table.unpack or unpack)(t, k)} end end)(_let_55_, 3) + local rem = count(xs) + local t0 = (t or {}) + if odd_3f(rem) then + error("assoc expects even number of arguments after table, found odd number") + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["assoc-in"] = v_0_ - assoc_in = v_0_ -end -local update -do - local v_0_ - do - local v_0_0 - local function update0(t, k, f) - return assoc(t, k, f(get(t, k))) - end - v_0_0 = update0 - _0_["update"] = v_0_0 - v_0_ = v_0_0 + if not nil_3f(k) then + t0[k] = v + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["update"] = v_0_ - update = v_0_ -end -local update_in -do - local v_0_ - do - local v_0_0 - local function update_in0(t, ks, f) - return assoc_in(t, ks, f(get_in(t, ks))) + if (rem > 0) then + assoc(t0, unpack(xs)) + else + end + return t0 +end +_2amodule_2a["assoc"] = assoc +local function assoc_in(t, ks, v) + local path = butlast(ks) + local final = last(ks) + local t0 = (t or {}) + local function _59_(acc, k) + local step = get(acc, k) + if nil_3f(step) then + return get(assoc(acc, k, {}), k) + else + return step end - v_0_0 = update_in0 - _0_["update-in"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["update-in"] = v_0_ - update_in = v_0_ + assoc(reduce(_59_, t0, path), final, v) + return t0 end -local constantly -do - local v_0_ - do - local v_0_0 - local function constantly0(v) - local function _3_() - return v - end - return _3_ - end - v_0_0 = constantly0 - _0_["constantly"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["assoc-in"] = assoc_in +local function update(t, k, f) + return assoc(t, k, f(get(t, k))) +end +_2amodule_2a["update"] = update +local function update_in(t, ks, f) + return assoc_in(t, ks, f(get_in(t, ks))) +end +_2amodule_2a["update-in"] = update_in +local function constantly(v) + local function _61_() + return v end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["constantly"] = v_0_ - constantly = v_0_ + return _61_ end -return nil +_2amodule_2a["constantly"] = constantly +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/deps/fennel.lua b/lua/nvim-tree-docs/aniseed/deps/fennel.lua index 59f55ca..223f1cf 100644 --- a/lua/nvim-tree-docs/aniseed/deps/fennel.lua +++ b/lua/nvim-tree-docs/aniseed/deps/fennel.lua @@ -3,15 +3,17 @@ package.preload["nvim-tree-docs.aniseed.fennel.repl"] = package.preload["nvim-tr local parser = require("nvim-tree-docs.aniseed.fennel.parser") local compiler = require("nvim-tree-docs.aniseed.fennel.compiler") local specials = require("nvim-tree-docs.aniseed.fennel.specials") + local view = require("nvim-tree-docs.aniseed.fennel.view") + local unpack = (table.unpack or _G.unpack) local function default_read_chunk(parser_state) - local function _0_() + local function _631_() if (0 < parser_state["stack-size"]) then return ".." else return ">> " end end - io.write(_0_()) + io.write(_631_()) io.flush() local input = io.read() return (input and (input .. "\n")) @@ -21,100 +23,256 @@ package.preload["nvim-tree-docs.aniseed.fennel.repl"] = package.preload["nvim-tr return io.write("\n") end local function default_on_error(errtype, err, lua_source) - local function _1_() - local _0_0 = errtype - if (_0_0 == "Lua Compile") then + local function _633_() + local _632_ = errtype + if (_632_ == "Lua Compile") then return ("Bad code generated - likely a bug with the compiler:\n" .. "--- Generated Lua Start ---\n" .. lua_source .. "--- Generated Lua End ---\n") - elseif (_0_0 == "Runtime") then + elseif (_632_ == "Runtime") then return (compiler.traceback(tostring(err), 4) .. "\n") - else - local _ = _0_0 + elseif true then + local _ = _632_ return ("%s error: %s\n"):format(errtype, tostring(err)) + else + return nil + end + end + return io.write(_633_()) + end + local function splice_save_locals(env, lua_source, scope) + local saves + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for name in pairs(env.___replLocals___) do + local val_18_auto = ("local %s = ___replLocals___['%s']"):format(name, name) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + saves = tbl_16_auto + end + local binds + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, name in pairs(scope.manglings) do + local val_18_auto + if not scope.gensyms[name] then + val_18_auto = ("___replLocals___['%s'] = %s"):format(name, name) + else + val_18_auto = nil + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + binds = tbl_16_auto + end + local gap + if lua_source:find("\n") then + gap = "\n" + else + gap = " " + end + local function _639_() + if next(saves) then + return (table.concat(saves, " ") .. gap) + else + return "" + end + end + local function _642_() + local _640_, _641_ = lua_source:match("^(.*)[\n ](return .*)$") + if ((nil ~= _640_) and (nil ~= _641_)) then + local body = _640_ + local _return = _641_ + return (body .. gap .. table.concat(binds, " ") .. gap .. _return) + elseif true then + local _ = _640_ + return lua_source + else + return nil end end - return io.write(_1_()) + return (_639_() .. _642_()) end - local save_source = table.concat({"local ___i___ = 1", "while true do", " local name, value = debug.getlocal(1, ___i___)", " if(name and name ~= \"___i___\") then", " ___replLocals___[name] = value", " ___i___ = ___i___ + 1", " else break end end"}, "\n") - local function splice_save_locals(env, lua_source) - env.___replLocals___ = (env.___replLocals___ or {}) - local spliced_source = {} - local bind = "local %s = ___replLocals___['%s']" - for line in lua_source:gmatch("([^\n]+)\n?") do - table.insert(spliced_source, line) + local function completer(env, scope, text) + local max_items = 2000 + local seen = {} + local matches = {} + local input_fragment = text:gsub(".*[%s)(]+", "") + local stop_looking_3f = false + local function add_partials(input, tbl, prefix) + local scope_first_3f = ((tbl == env) or (tbl == env.___replLocals___)) + local tbl_16_auto = matches + local i_17_auto = #tbl_16_auto + local function _644_() + if scope_first_3f then + return scope.manglings + else + return tbl + end + end + for k, is_mangled in utils.allpairs(_644_()) do + if (max_items <= #matches) then break end + local val_18_auto + do + local lookup_k + if scope_first_3f then + lookup_k = is_mangled + else + lookup_k = k + end + if ((type(k) == "string") and (input == k:sub(0, #input)) and not seen[k] and ((":" ~= prefix:sub(-1)) or ("function" == type(tbl[lookup_k])))) then + seen[k] = true + val_18_auto = (prefix .. k) + else + val_18_auto = nil + end + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + return tbl_16_auto + end + local function descend(input, tbl, prefix, add_matches, method_3f) + local splitter + if method_3f then + splitter = "^([^:]+):(.*)" + else + splitter = "^([^.]+)%.(.*)" + end + local head, tail = input:match(splitter) + local raw_head = (scope.manglings[head] or head) + if (type(tbl[raw_head]) == "table") then + stop_looking_3f = true + if method_3f then + return add_partials(tail, tbl[raw_head], (prefix .. head .. ":")) + else + return add_matches(tail, tbl[raw_head], (prefix .. head)) + end + else + return nil + end end - for name in pairs(env.___replLocals___) do - table.insert(spliced_source, 1, bind:format(name, name)) + local function add_matches(input, tbl, prefix) + local prefix0 + if prefix then + prefix0 = (prefix .. ".") + else + prefix0 = "" + end + if (not input:find("%.") and input:find(":")) then + return descend(input, tbl, prefix0, add_matches, true) + elseif not input:find("%.") then + return add_partials(input, tbl, prefix0) + else + return descend(input, tbl, prefix0, add_matches, false) + end end - if ((1 < #spliced_source) and (spliced_source[#spliced_source]):match("^ *return .*$")) then - table.insert(spliced_source, #spliced_source, save_source) + for _, source in ipairs({scope.specials, scope.macros, (env.___replLocals___ or {}), env, env._G}) do + if stop_looking_3f then break end + add_matches(input_fragment, source) end - return table.concat(spliced_source, "\n") + return matches end local commands = {} local function command_3f(input) return input:match("^%s*,") end local function command_docs() - local _0_ + local _653_ do - local tbl_0_ = {} + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto for name, f in pairs(commands) do - tbl_0_[(#tbl_0_ + 1)] = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented")) + local val_18_auto = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented")) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end end - _0_ = tbl_0_ + _653_ = tbl_16_auto end - return table.concat(_0_, "\n") + return table.concat(_653_, "\n") end commands.help = function(_, _0, on_values) - return on_values({("Welcome to Fennel.\nThis is the REPL where you can enter code to be evaluated.\nYou can also run these repl commands:\n\n" .. command_docs() .. "\n ,exit - Leave the repl.\n\nUse (doc something) to see descriptions for individual macros and special forms.\n\nFor more information about the language, see https://fennel-lang.org/reference")}) + return on_values({("Welcome to Fennel.\nThis is the REPL where you can enter code to be evaluated.\nYou can also run these repl commands:\n\n" .. command_docs() .. "\n ,exit - Leave the repl.\n\nUse ,doc something to see descriptions for individual macros and special forms.\n\nFor more information about the language, see https://fennel-lang.org/reference")}) end do end (compiler.metadata):set(commands.help, "fnl/docstring", "Show this message.") local function reload(module_name, env, on_values, on_error) - local _0_0, _1_0 = pcall(specials["load-code"]("return require(...)", env), module_name) - if ((_0_0 == true) and (nil ~= _1_0)) then - local old = _1_0 - local _ = nil + local _655_, _656_ = pcall(specials["load-code"]("return require(...)", env), module_name) + if ((_655_ == true) and (nil ~= _656_)) then + local old = _656_ + local _ package.loaded[module_name] = nil _ = nil local ok, new = pcall(require, module_name) - local new0 = nil + local new0 if not ok then on_values({new}) new0 = old else new0 = new end + specials["macro-loaded"][module_name] = nil if ((type(old) == "table") and (type(new0) == "table")) then for k, v in pairs(new0) do old[k] = v end for k in pairs(old) do - if (nil == new0[k]) then + if (nil == (new0)[k]) then old[k] = nil + else end end package.loaded[module_name] = old + else end return on_values({"ok"}) - elseif ((_0_0 == false) and (nil ~= _1_0)) then - local msg = _1_0 - local function _3_() - local _2_0 = msg:gsub("\n.*", "") - return _2_0 + elseif ((_655_ == false) and (nil ~= _656_)) then + local msg = _656_ + if msg:match("loop or previous error loading module") then + package.loaded[module_name] = nil + return reload(module_name, env, on_values, on_error) + elseif (specials["macro-loaded"])[module_name] then + specials["macro-loaded"][module_name] = nil + return nil + else + local function _661_() + local _660_ = msg:gsub("\n.*", "") + return _660_ + end + return on_error("Runtime", _661_()) end - return on_error("Runtime", _3_()) + else + return nil + end + end + local function run_command(read, on_error, f) + local _664_, _665_, _666_ = pcall(read) + if ((_664_ == true) and (_665_ == true) and (nil ~= _666_)) then + local val = _666_ + return f(val) + elseif (_664_ == false) then + return on_error("Parse", "Couldn't parse input.") + else + return nil end end commands.reload = function(env, read, on_values, on_error) - local _0_0, _1_0, _2_0 = pcall(read) - if ((_0_0 == true) and (_1_0 == true) and (nil ~= _2_0)) then - local module_sym = _2_0 - return reload(tostring(module_sym), env, on_values, on_error) - elseif ((_0_0 == false) and true and true) then - local _3fparse_ok = _1_0 - local _3fmsg = _2_0 - return on_error("Parse", (_3fmsg or _3fparse_ok)) + local function _668_(_241) + return reload(tostring(_241), env, on_values, on_error) end + return run_command(read, on_error, _668_) end do end (compiler.metadata):set(commands.reload, "fnl/docstring", "Reload the specified module.") commands.reset = function(env, _, on_values) @@ -122,123 +280,375 @@ package.preload["nvim-tree-docs.aniseed.fennel.repl"] = package.preload["nvim-tr return on_values({"ok"}) end do end (compiler.metadata):set(commands.reset, "fnl/docstring", "Erase all repl-local scope.") - local function load_plugin_commands() - if (utils.root and utils.root.options and utils.root.options.plugins) then - for _, plugin in ipairs(utils.root.options.plugins) do - for name, f in pairs(plugin) do - local _0_0 = name:match("^repl%-command%-(.*)") - if (nil ~= _0_0) then - local cmd_name = _0_0 - commands[cmd_name] = (commands[cmd_name] or f) + commands.complete = function(env, read, on_values, on_error, scope, chars) + local function _669_() + return on_values(completer(env, scope, string.char(unpack(chars)):gsub(",complete +", ""):sub(1, -2))) + end + return run_command(read, on_error, _669_) + end + do end (compiler.metadata):set(commands.complete, "fnl/docstring", "Print all possible completions for a given input symbol.") + local function apropos_2a(pattern, tbl, prefix, seen, names) + for name, subtbl in pairs(tbl) do + if (("string" == type(name)) and (package ~= subtbl)) then + local _670_ = type(subtbl) + if (_670_ == "function") then + if ((prefix .. name)):match(pattern) then + table.insert(names, (prefix .. name)) + else + end + elseif (_670_ == "table") then + if not seen[subtbl] then + local _673_ + do + local _672_ = seen + _672_[subtbl] = true + _673_ = _672_ + end + apropos_2a(pattern, subtbl, (prefix .. name:gsub("%.", "/") .. "."), _673_, names) + else + end + else + end + else + end + end + return names + end + local function apropos(pattern) + local names = apropos_2a(pattern, package.loaded, "", {}, {}) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, name in ipairs(names) do + local val_18_auto = name:gsub("^_G%.", "") + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + return tbl_16_auto + end + commands.apropos = function(_env, read, on_values, on_error, _scope) + local function _678_(_241) + return on_values(apropos(tostring(_241))) + end + return run_command(read, on_error, _678_) + end + do end (compiler.metadata):set(commands.apropos, "fnl/docstring", "Print all functions matching a pattern in all loaded modules.") + local function apropos_follow_path(path) + local paths + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for p in path:gmatch("[^%.]+") do + local val_18_auto = p + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + paths = tbl_16_auto + end + local tgt = package.loaded + for _, path0 in ipairs(paths) do + if (nil == tgt) then break end + local _681_ + do + local _680_ = path0:gsub("%/", ".") + _681_ = _680_ + end + tgt = tgt[_681_] + end + return tgt + end + local function apropos_doc(pattern) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, path in ipairs(apropos(".*")) do + local val_18_auto + do + local tgt = apropos_follow_path(path) + if ("function" == type(tgt)) then + local _682_ = (compiler.metadata):get(tgt, "fnl/docstring") + if (nil ~= _682_) then + local docstr = _682_ + val_18_auto = (docstr:match(pattern) and path) + else + val_18_auto = nil end + else + val_18_auto = nil end end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + return tbl_16_auto + end + commands["apropos-doc"] = function(_env, read, on_values, on_error, _scope) + local function _686_(_241) + return on_values(apropos_doc(tostring(_241))) + end + return run_command(read, on_error, _686_) + end + do end (compiler.metadata):set(commands["apropos-doc"], "fnl/docstring", "Print all functions that match the pattern in their docs") + local function apropos_show_docs(on_values, pattern) + for _, path in ipairs(apropos(pattern)) do + local tgt = apropos_follow_path(path) + if (("function" == type(tgt)) and (compiler.metadata):get(tgt, "fnl/docstring")) then + on_values(specials.doc(tgt, path)) + on_values() + else + end + end + return nil + end + commands["apropos-show-docs"] = function(_env, read, on_values, on_error) + local function _688_(_241) + return apropos_show_docs(on_values, tostring(_241)) + end + return run_command(read, on_error, _688_) + end + do end (compiler.metadata):set(commands["apropos-show-docs"], "fnl/docstring", "Print all documentations matching a pattern in function name") + local function resolve(identifier, _689_, scope) + local _arg_690_ = _689_ + local ___replLocals___ = _arg_690_["___replLocals___"] + local env = _arg_690_ + local e + local function _691_(_241, _242) + return (___replLocals___[_242] or env[_242]) + end + e = setmetatable({}, {__index = _691_}) + local _692_, _693_ = pcall(compiler["compile-string"], tostring(identifier), {scope = scope}) + if ((_692_ == true) and (nil ~= _693_)) then + local code = _693_ + return specials["load-code"](code, e)() + else return nil end end - local function run_command(input, read, loop, env, on_values, on_error) - load_plugin_commands() + commands.find = function(env, read, on_values, on_error, scope) + local function _695_(_241) + local _696_ + do + local _697_ = utils["sym?"](_241) + if (nil ~= _697_) then + local _698_ = resolve(_697_, env, scope) + if (nil ~= _698_) then + _696_ = debug.getinfo(_698_) + else + _696_ = _698_ + end + else + _696_ = _697_ + end + end + if ((_G.type(_696_) == "table") and ((_696_).what == "Lua") and (nil ~= (_696_).source) and (nil ~= (_696_).linedefined) and (nil ~= (_696_).short_src)) then + local source = (_696_).source + local line = (_696_).linedefined + local src = (_696_).short_src + local fnlsrc + do + local t_701_ = compiler.sourcemap + if (nil ~= t_701_) then + t_701_ = (t_701_)[source] + else + end + if (nil ~= t_701_) then + t_701_ = (t_701_)[line] + else + end + if (nil ~= t_701_) then + t_701_ = (t_701_)[2] + else + end + fnlsrc = t_701_ + end + return on_values({string.format("%s:%s", src, (fnlsrc or line))}) + elseif (_696_ == nil) then + return on_error("Repl", "Unknown value") + elseif true then + local _ = _696_ + return on_error("Repl", "No source info") + else + return nil + end + end + return run_command(read, on_error, _695_) + end + do end (compiler.metadata):set(commands.find, "fnl/docstring", "Print the filename and line number for a given function") + commands.doc = function(env, read, on_values, on_error, scope) + local function _706_(_241) + local name = tostring(_241) + local path = (utils["multi-sym?"](name) or {name}) + local ok_3f, target = nil, nil + local function _707_() + return (utils["get-in"](scope.specials, path) or utils["get-in"](scope.macros, path) or resolve(name, env, scope)) + end + ok_3f, target = pcall(_707_) + if ok_3f then + return on_values({specials.doc(target, name)}) + else + return on_error("Repl", "Could not resolve value for docstring lookup") + end + end + return run_command(read, on_error, _706_) + end + do end (compiler.metadata):set(commands.doc, "fnl/docstring", "Print the docstring and arglist for a function, macro, or special form.") + commands.compile = function(env, read, on_values, on_error, scope) + local function _709_(_241) + local allowedGlobals = specials["current-global-names"](env) + local ok_3f, result = pcall(compiler.compile, _241, {env = env, scope = scope, allowedGlobals = allowedGlobals}) + if ok_3f then + return on_values({result}) + else + return on_error("Repl", ("Error compiling expression: " .. result)) + end + end + return run_command(read, on_error, _709_) + end + do end (compiler.metadata):set(commands.compile, "fnl/docstring", "compiles the expression into lua and prints the result.") + local function load_plugin_commands(plugins) + for _, plugin in ipairs((plugins or {})) do + for name, f in pairs(plugin) do + local _711_ = name:match("^repl%-command%-(.*)") + if (nil ~= _711_) then + local cmd_name = _711_ + commands[cmd_name] = (commands[cmd_name] or f) + else + end + end + end + return nil + end + local function run_command_loop(input, read, loop, env, on_values, on_error, scope, chars) local command_name = input:match(",([^%s/]+)") do - local _0_0 = commands[command_name] - if (nil ~= _0_0) then - local command = _0_0 - command(env, read, on_values, on_error) - else - local _ = _0_0 + local _713_ = commands[command_name] + if (nil ~= _713_) then + local command = _713_ + command(env, read, on_values, on_error, scope, chars) + elseif true then + local _ = _713_ if ("exit" ~= command_name) then on_values({"Unknown command", command_name}) + else end + else end end if ("exit" ~= command_name) then return loop() + else + return nil end end - local function completer(env, scope, text) - local matches = {} - local input_fragment = text:gsub(".*[%s)(]+", "") - local function add_partials(input, tbl, prefix) - for k in utils.allpairs(tbl) do - local k0 = nil - if ((tbl == env) or (tbl == env.___replLocals___)) then - k0 = scope.unmanglings[k] + local function try_readline_21(opts, ok, readline) + if ok then + if readline.set_readline_name then + readline.set_readline_name("fennel") + else + end + readline.set_options({keeplines = 1000, histfile = ""}) + opts.readChunk = function(parser_state) + local prompt + if (0 < parser_state["stack-size"]) then + prompt = ".. " else - k0 = k + prompt = ">> " end - if ((#matches < 2000) and (type(k0) == "string") and (input == k0:sub(0, #input))) then - table.insert(matches, (prefix .. k0)) + local str = readline.readline(prompt) + if str then + return (str .. "\n") + else + return nil end end - return nil - end - local function add_matches(input, tbl, prefix) - local prefix0 = nil - if prefix then - prefix0 = (prefix .. ".") - else - prefix0 = "" + local completer0 = nil + opts.registerCompleter = function(repl_completer) + completer0 = repl_completer + return nil end - if not input:find("%.") then - return add_partials(input, tbl, prefix0) - else - local head, tail = input:match("^([^.]+)%.(.*)") - local raw_head = nil - if ((tbl == env) or (tbl == env.___replLocals___)) then - raw_head = scope.manglings[head] + local function repl_completer(text, from, to) + if completer0 then + readline.set_completion_append_character("") + return completer0(text:sub(from, to)) else - raw_head = head - end - if (type(tbl[raw_head]) == "table") then - return add_matches(tail, tbl[raw_head], (prefix0 .. head)) + return {} end end + readline.set_complete_function(repl_completer) + return readline + else + return nil end - add_matches(input_fragment, (scope.specials or {})) - add_matches(input_fragment, (scope.macros or {})) - add_matches(input_fragment, (env.___replLocals___ or {})) - add_matches(input_fragment, env) - add_matches(input_fragment, (env._ENV or env._G or {})) - return matches end - local function repl(options) + local function should_use_readline_3f(opts) + return (("dumb" ~= os.getenv("TERM")) and not opts.readChunk and not opts.registerCompleter) + end + local function repl(_3foptions) local old_root_options = utils.root.options - local env = nil - if options.env then - env = specials["wrap-env"](options.env) + local _let_722_ = utils.copy(_3foptions) + local _3ffennelrc = _let_722_["fennelrc"] + local opts = _let_722_ + local _ + opts.fennelrc = nil + _ = nil + local readline = (should_use_readline_3f(opts) and try_readline_21(opts, pcall(require, "readline"))) + local _0 + if _3ffennelrc then + _0 = _3ffennelrc() else - env = setmetatable({}, {__index = (rawget(_G, "_ENV") or _G)}) + _0 = nil end - local save_locals_3f = ((options.saveLocals ~= false) and env.debug and env.debug.getlocal) - local opts = {} - local _ = nil - for k, v in pairs(options) do - opts[k] = v - end - _ = nil + local env = specials["wrap-env"]((opts.env or rawget(_G, "_ENV") or _G)) + local save_locals_3f = (opts.saveLocals ~= false) local read_chunk = (opts.readChunk or default_read_chunk) local on_values = (opts.onValues or default_on_values) local on_error = (opts.onError or default_on_error) - local pp = (opts.pp or tostring) + local pp = (opts.pp or view) local byte_stream, clear_stream = parser.granulate(read_chunk) local chars = {} local read, reset = nil, nil - local function _1_(parser_state) + local function _724_(parser_state) local c = byte_stream(parser_state) table.insert(chars, c) return c end - read, reset = parser.parser(_1_) - local scope = compiler["make-scope"]() - opts.useMetadata = (options.useMetadata ~= false) + read, reset = parser.parser(_724_) + opts.env, opts.scope = env, compiler["make-scope"]() + opts.useMetadata = (opts.useMetadata ~= false) if (opts.allowedGlobals == nil) then - opts.allowedGlobals = specials["current-global-names"](opts.env) + opts.allowedGlobals = specials["current-global-names"](env) + else end if opts.registerCompleter then - local function _3_(...) - return completer(env, scope, ...) + local function _728_() + local _726_ = env + local _727_ = opts.scope + local function _729_(...) + return completer(_726_, _727_, ...) + end + return _729_ + end + opts.registerCompleter(_728_()) + else + end + load_plugin_commands(opts.plugins) + if save_locals_3f then + local function newindex(t, k, v) + if opts.scope.unmanglings[k] then + return rawset(t, k, v) + else + return nil + end end - opts.registerCompleter(_3_) + env.___replLocals___ = setmetatable({}, {__newindex = newindex}) + else end local function print_values(...) local vals = {...} @@ -253,492 +663,154 @@ package.preload["nvim-tree-docs.aniseed.fennel.repl"] = package.preload["nvim-tr for k in pairs(chars) do chars[k] = nil end - local ok, parse_ok_3f, x = pcall(read) - local src_string = string.char((table.unpack or _G.unpack)(chars)) - utils.root.options = opts + reset() + local ok, parser_not_eof_3f, x = pcall(read) + local src_string = string.char(unpack(chars)) + local readline_not_eof_3f = (not readline or (src_string ~= "(null)")) + local not_eof_3f = (readline_not_eof_3f and parser_not_eof_3f) if not ok then - on_error("Parse", parse_ok_3f) + on_error("Parse", not_eof_3f) clear_stream() - reset() return loop() elseif command_3f(src_string) then - return run_command(src_string, read, loop, env, on_values, on_error) + return run_command_loop(src_string, read, loop, env, on_values, on_error, opts.scope, chars) else - if parse_ok_3f then + if not_eof_3f then do - local _4_0, _5_0 = pcall(compiler.compile, x, {["assert-compile"] = opts["assert-compile"], ["parse-error"] = opts["parse-error"], correlate = opts.correlate, moduleName = opts.moduleName, scope = scope, source = src_string, useBitLib = opts.useBitLib, useMetadata = opts.useMetadata}) - if ((_4_0 == false) and (nil ~= _5_0)) then - local msg = _5_0 + local _733_, _734_ = nil, nil + local function _736_() + local _735_ = opts + _735_["source"] = src_string + return _735_ + end + _733_, _734_ = pcall(compiler.compile, x, _736_()) + if ((_733_ == false) and (nil ~= _734_)) then + local msg = _734_ clear_stream() on_error("Compile", msg) - elseif ((_4_0 == true) and (nil ~= _5_0)) then - local src = _5_0 - local src0 = nil + elseif ((_733_ == true) and (nil ~= _734_)) then + local src = _734_ + local src0 if save_locals_3f then - src0 = splice_save_locals(env, src) + src0 = splice_save_locals(env, src, opts.scope) else src0 = src end - local _7_0, _8_0 = pcall(specials["load-code"], src0, env) - if ((_7_0 == false) and (nil ~= _8_0)) then - local msg = _8_0 + local _738_, _739_ = pcall(specials["load-code"], src0, env) + if ((_738_ == false) and (nil ~= _739_)) then + local msg = _739_ clear_stream() on_error("Lua Compile", msg, src0) - elseif (true and (nil ~= _8_0)) then - local _0 = _7_0 - local chunk = _8_0 - local function _9_() + elseif (true and (nil ~= _739_)) then + local _1 = _738_ + local chunk = _739_ + local function _740_() return print_values(chunk()) end - local function _10_(...) - return on_error("Runtime", ...) + local function _741_() + local function _742_(...) + return on_error("Runtime", ...) + end + return _742_ end - xpcall(_9_, _10_) + xpcall(_740_, _741_()) + else end + else end end utils.root.options = old_root_options return loop() + else + return nil end end end - return loop() + loop() + if readline then + return readline.save_history() + else + return nil + end end return repl end -package.preload["nvim-tree-docs.aniseed.fennel.view"] = package.preload["nvim-tree-docs.aniseed.fennel.view"] or function(...) - local type_order = {["function"] = 5, boolean = 2, number = 1, string = 3, table = 4, thread = 7, userdata = 6} - 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 tb = type(b) - if ((ta == tb) and ((ta == "string") or (ta == "number"))) then - return (a < b) - else - local dta = type_order[ta] - local dtb = type_order[tb] - if (dta and dtb) then - return (dta < dtb) - elseif dta then - return true - elseif dtb then - return false +package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvim-tree-docs.aniseed.fennel.specials"] or function(...) + local utils = require("nvim-tree-docs.aniseed.fennel.utils") + local view = require("nvim-tree-docs.aniseed.fennel.view") + local parser = require("nvim-tree-docs.aniseed.fennel.parser") + local compiler = require("nvim-tree-docs.aniseed.fennel.compiler") + local unpack = (table.unpack or _G.unpack) + local SPECIALS = compiler.scopes.global.specials + local function wrap_env(env) + local function _424_(_, key) + if utils["string?"](key) then + return env[compiler["global-unmangling"](key)] else - return (ta < tb) + return env[key] end end - end - local function table_kv_pairs(t) - local assoc_3f = false - local i = 1 - local kv = {} - local insert = table.insert - for k, v in pairs(t) do - if ((type(k) ~= "number") or (k ~= i)) then - assoc_3f = true + local function _426_(_, key, value) + if utils["string?"](key) then + env[compiler["global-unmangling"](key)] = value + return nil + else + env[key] = value + return nil end - i = (i + 1) - insert(kv, {k, v}) end - table.sort(kv, sort_keys) - if (#kv == 0) then - return kv, "empty" - else - local function _2_() - if assoc_3f then - return "table" + local function _428_() + local function putenv(k, v) + local _429_ + if utils["string?"](k) then + _429_ = compiler["global-unmangling"](k) else - return "seq" + _429_ = k end + return _429_, v end - return kv, _2_() + return next, utils.kvmap(env, putenv), nil end + return setmetatable({}, {__index = _424_, __newindex = _426_, __pairs = _428_}) end - local function count_table_appearances(t, appearances) - if (type(t) == "table") then - if not appearances[t] then - appearances[t] = 1 - for k, v in pairs(t) do - count_table_appearances(k, appearances) - count_table_appearances(v, appearances) + local function current_global_names(_3fenv) + local mt + do + local _431_ = getmetatable(_3fenv) + if ((_G.type(_431_) == "table") and (nil ~= (_431_).__pairs)) then + local mtpairs = (_431_).__pairs + local tbl_13_auto = {} + for k, v in mtpairs(_3fenv) do + local k_14_auto, v_15_auto = k, v + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end end + mt = tbl_13_auto + elseif (_431_ == nil) then + mt = (_3fenv or _G) else - appearances[t] = ((appearances[t] or 0) + 1) - end - end - return appearances - end - local function save_table(t, seen) - local seen0 = (seen or {len = 0}) - local id = (seen0.len + 1) - if not seen0[t] then - seen0[t] = id - seen0.len = id - end - return seen0 - end - local function detect_cycle(t, seen, _3fk) - if ("table" == type(t)) then - seen[t] = true - local _2_0, _3_0 = next(t, _3fk) - if ((nil ~= _2_0) and (nil ~= _3_0)) then - local k = _2_0 - local v = _3_0 - return (seen[k] or detect_cycle(k, seen) or seen[v] or detect_cycle(v, seen) or detect_cycle(t, seen, k)) - end - end - end - 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))) - end - local function table_indent(t, indent, id) - local opener_length = nil - if id then - opener_length = (#tostring(id) + 2) - else - opener_length = 1 - end - return (indent + opener_length) - end - local pp = nil - local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix) - local indent_str = ("\n" .. string.rep(" ", indent)) - local open = nil - local function _2_() - if ("seq" == table_type) then - return "[" - else - return "{" - end - end - open = ((prefix or "") .. _2_()) - local close = nil - if ("seq" == table_type) then - close = "]" - else - close = "}" - end - local oneline = (open .. table.concat(elements, " ") .. close) - if (not options["one-line?"] and (multiline_3f or ((indent + #oneline) > options["line-length"]))) then - return (open .. table.concat(elements, indent_str) .. close) - else - return oneline - end - end - local function pp_associative(t, kv, options, indent, key_3f) - local multiline_3f = false - local id = options.seen[t] - if (options.level >= options.depth) then - return "{...}" - elseif (id and options["detect-cycles?"]) then - return ("@" .. id .. "{...}") - else - local visible_cycle_3f0 = visible_cycle_3f(t, options) - local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) - local slength = nil - local function _3_() - local _2_0 = rawget(_G, "utf8") - if _2_0 then - return _2_0.len - else - return _2_0 - end - end - local function _4_(_241) - return #_241 - end - slength = ((options["utf8?"] and _3_()) or _4_) - local prefix = nil - if visible_cycle_3f0 then - prefix = ("@" .. id0) - else - prefix = "" - end - local items = nil - do - local tbl_0_ = {} - for _, _6_0 in pairs(kv) do - local _7_ = _6_0 - local k = _7_[1] - local v = _7_[2] - local _8_ - do - local k0 = pp(k, options, (indent0 + 1), true) - local v0 = pp(v, options, (indent0 + slength(k0) + 1)) - multiline_3f = (multiline_3f or k0:find("\n") or v0:find("\n")) - _8_ = (k0 .. " " .. v0) - end - tbl_0_[(#tbl_0_ + 1)] = _8_ - end - items = tbl_0_ - end - return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix) - end - end - local function pp_sequence(t, kv, options, indent) - local multiline_3f = false - local id = options.seen[t] - if (options.level >= options.depth) then - return "[...]" - elseif (id and options["detect-cycles?"]) then - return ("@" .. id .. "[...]") - else - local visible_cycle_3f0 = visible_cycle_3f(t, options) - local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) - local prefix = nil - if visible_cycle_3f0 then - prefix = ("@" .. id0) - else - prefix = "" - end - local items = nil - do - local tbl_0_ = {} - for _, _3_0 in pairs(kv) do - local _4_ = _3_0 - local _0 = _4_[1] - local v = _4_[2] - local _5_ - do - local v0 = pp(v, options, indent0) - multiline_3f = (multiline_3f or v0:find("\n")) - _5_ = v0 - end - tbl_0_[(#tbl_0_ + 1)] = _5_ - end - items = tbl_0_ - end - return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix) - end - end - local function concat_lines(lines, options, indent, force_multi_line_3f) - if (#lines == 0) then - if options["empty-as-sequence?"] then - return "[]" - else - return "{}" - end - else - local oneline = nil - local _2_ - do - local tbl_0_ = {} - for _, line in ipairs(lines) do - tbl_0_[(#tbl_0_ + 1)] = line:gsub("^%s+", "") - end - _2_ = tbl_0_ - end - oneline = table.concat(_2_, " ") - if (not options["one-line?"] and (force_multi_line_3f or oneline:find("\n") or ((indent + #oneline) > options["line-length"]))) then - return table.concat(lines, ("\n" .. string.rep(" ", indent))) - else - return oneline - end - end - end - local function pp_metamethod(t, metamethod, options, indent) - if (options.level >= options.depth) then - if options["empty-as-sequence?"] then - return "[...]" - else - return "{...}" - end - else - local _ = nil - local function _2_(_241) - return visible_cycle_3f(_241, options) - end - options["visible-cycle?"] = _2_ - _ = nil - local lines, force_multi_line_3f = metamethod(t, pp, options, indent) - options["visible-cycle?"] = nil - local _3_0 = type(lines) - if (_3_0 == "string") then - return lines - elseif (_3_0 == "table") then - return concat_lines(lines, options, indent, force_multi_line_3f) - else - local _0 = _3_0 - return error("__fennelview metamethod must return a table of lines") - end - end - end - local function pp_table(x, options, indent) - options.level = (options.level + 1) - local x0 = nil - do - local _2_0 = nil - if options["metamethod?"] then - local _3_0 = x - if _3_0 then - local _4_0 = getmetatable(_3_0) - if _4_0 then - _2_0 = _4_0.__fennelview - else - _2_0 = _4_0 - end - else - _2_0 = _3_0 - end - else - _2_0 = nil - end - if (nil ~= _2_0) then - local metamethod = _2_0 - x0 = pp_metamethod(x, metamethod, options, indent) - else - local _ = _2_0 - local _4_0, _5_0 = table_kv_pairs(x) - if (true and (_5_0 == "empty")) then - local _0 = _4_0 - if options["empty-as-sequence?"] then - x0 = "[]" - else - x0 = "{}" - end - elseif ((nil ~= _4_0) and (_5_0 == "table")) then - local kv = _4_0 - x0 = pp_associative(x, kv, options, indent) - elseif ((nil ~= _4_0) and (_5_0 == "seq")) then - local kv = _4_0 - x0 = pp_sequence(x, kv, options, indent) - else - x0 = nil - end - end - end - options.level = (options.level - 1) - return x0 - end - local function number__3estring(n) - local _2_0 = string.gsub(tostring(n), ",", ".") - return _2_0 - end - local function colon_string_3f(s) - 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 - local function make_options(t, options) - 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}} - for k, v in pairs((options or {})) do - defaults[k] = v - end - for k, v in pairs(overrides) do - defaults[k] = v - end - return defaults - end - local function _2_(x, options, indent, colon_3f) - local indent0 = (indent or 0) - local options0 = (options or make_options(x)) - local tv = type(x) - local function _4_() - local _3_0 = getmetatable(x) - if _3_0 then - return _3_0.__fennelview - else - return _3_0 - end - end - if ((tv == "table") or ((tv == "userdata") and _4_())) then - return pp_table(x, options0, indent0) - elseif (tv == "number") then - return number__3estring(x) - 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) - elseif (tv == "string") then - return pp_string(x, options0, indent0) - elseif ((tv == "boolean") or (tv == "nil")) then - return tostring(x) - else - return ("#<" .. tostring(x) .. ">") - end - end - end - pp = _2_ - local function view(x, options) - return pp(x, make_options(x, options), 0) - end - return view -end -package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvim-tree-docs.aniseed.fennel.specials"] or function(...) - local utils = require("nvim-tree-docs.aniseed.fennel.utils") - local view = require("nvim-tree-docs.aniseed.fennel.view") - local parser = require("nvim-tree-docs.aniseed.fennel.parser") - local compiler = require("nvim-tree-docs.aniseed.fennel.compiler") - local unpack = (table.unpack or _G.unpack) - local SPECIALS = compiler.scopes.global.specials - local function wrap_env(env) - local function _0_(_, key) - if (type(key) == "string") then - return env[compiler["global-unmangling"](key)] - else - return env[key] - end - end - local function _1_(_, key, value) - if (type(key) == "string") then - env[compiler["global-unmangling"](key)] = value - return nil - else - env[key] = value - return nil - end - end - local function _2_() - local function putenv(k, v) - local _3_ - if (type(k) == "string") then - _3_ = compiler["global-unmangling"](k) - else - _3_ = k - end - return _3_, v - end - return next, utils.kvmap(env, putenv), nil - end - return setmetatable({}, {__index = _0_, __newindex = _1_, __pairs = _2_}) - end - local function current_global_names(env) - return utils.kvmap((env or _G), compiler["global-unmangling"]) - end - local function load_code(code, environment, filename) - local environment0 = (environment or rawget(_G, "_ENV") or _G) - if (rawget(_G, "setfenv") and rawget(_G, "loadstring")) then - local f = assert(_G.loadstring(code, filename)) - _G.setfenv(f, environment0) - return f + mt = nil + end + end + return (mt and utils.kvmap(mt, compiler["global-unmangling"])) + end + local function load_code(code, _3fenv, _3ffilename) + local env = (_3fenv or rawget(_G, "_ENV") or _G) + local _434_, _435_ = rawget(_G, "setfenv"), rawget(_G, "loadstring") + if ((nil ~= _434_) and (nil ~= _435_)) then + local setfenv = _434_ + local loadstring = _435_ + local f = assert(loadstring(code, _3ffilename)) + local _436_ = f + setfenv(_436_, env) + return _436_ + elseif true then + local _ = _434_ + return assert(load(code, _3ffilename, "t", env)) else - return assert(load(code, filename, "t", environment0)) + return nil end end local function doc_2a(tgt, name) @@ -749,52 +821,54 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local mt = getmetatable(tgt) if ((type(tgt) == "function") or ((type(mt) == "table") and (type(mt.__call) == "function"))) then local arglist = table.concat(((compiler.metadata):get(tgt, "fnl/arglist") or {"#"}), " ") - local _0_ - if (#arglist > 0) then - _0_ = " " + local _438_ + if (0 < #arglist) then + _438_ = " " else - _0_ = "" + _438_ = "" end - return string.format("(%s%s%s)\n %s", name, _0_, arglist, docstring) + return string.format("(%s%s%s)\n %s", name, _438_, arglist, docstring) else return string.format("%s\n %s", name, docstring) end end end local function doc_special(name, arglist, docstring, body_form_3f) - compiler.metadata[SPECIALS[name]] = {["fnl/arglist"] = arglist, ["fnl/body-form?"] = body_form_3f, ["fnl/docstring"] = docstring} + compiler.metadata[SPECIALS[name]] = {["fnl/arglist"] = arglist, ["fnl/docstring"] = docstring, ["fnl/body-form?"] = body_form_3f} return nil end - local function compile_do(ast, scope, parent, start) - local start0 = (start or 2) + local function compile_do(ast, scope, parent, _3fstart) + local start = (_3fstart or 2) local len = #ast local sub_scope = compiler["make-scope"](scope) - for i = start0, len do + for i = start, len do compiler.compile1(ast[i], sub_scope, parent, {nval = 0}) end return nil end - SPECIALS["do"] = function(ast, scope, parent, opts, start, chunk, sub_scope, pre_syms) - local start0 = (start or 2) - local sub_scope0 = (sub_scope or compiler["make-scope"](scope)) - local chunk0 = (chunk or {}) + SPECIALS["do"] = function(ast, scope, parent, opts, _3fstart, _3fchunk, _3fsub_scope, _3fpre_syms) + local start = (_3fstart or 2) + local sub_scope = (_3fsub_scope or compiler["make-scope"](scope)) + local chunk = (_3fchunk or {}) local len = #ast local retexprs = {returned = true} local function compile_body(outer_target, outer_tail, outer_retexprs) - if (len < start0) then - compiler.compile1(nil, sub_scope0, chunk0, {tail = outer_tail, target = outer_target}) + if (len < start) then + compiler.compile1(nil, sub_scope, chunk, {tail = outer_tail, target = outer_target}) else - for i = start0, len do + for i = start, len do local subopts = {nval = (((i ~= len) and 0) or opts.nval), tail = (((i == len) and outer_tail) or nil), target = (((i == len) and outer_target) or nil)} local _ = utils["propagate-options"](opts, subopts) - local subexprs = compiler.compile1(ast[i], sub_scope0, chunk0, subopts) + local subexprs = compiler.compile1(ast[i], sub_scope, chunk, subopts) if (i ~= len) then compiler["keep-side-effects"](subexprs, parent, nil, ast[i]) + else end end end - compiler.emit(parent, chunk0, ast) + compiler.emit(parent, chunk, ast) compiler.emit(parent, "end", ast) + utils.hook("do", ast, sub_scope) return (outer_retexprs or retexprs) end if (opts.target or (opts.nval == 0) or opts.tail) then @@ -803,8 +877,8 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi elseif opts.nval then local syms = {} for i = 1, opts.nval do - local s = ((pre_syms and pre_syms[i]) or compiler.gensym(scope)) - syms[i] = s + local s = ((_3fpre_syms and (_3fpre_syms)[i]) or compiler.gensym(scope)) + do end (syms)[i] = s retexprs[i] = utils.expr(s, "sym") end local outer_target = table.concat(syms, ", ") @@ -813,14 +887,13 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi return compile_body(outer_target, opts.tail) else local fname = compiler.gensym(scope) - local fargs = nil + local fargs if scope.vararg then fargs = "..." else fargs = "" end compiler.emit(parent, string.format("local function %s(%s)", fname, fargs), ast) - utils.hook("do", ast, sub_scope0) return compile_body(nil, true, utils.expr((fname .. "(" .. fargs .. ")"), "statement")) end end @@ -835,97 +908,172 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi for j = 2, #subexprs do table.insert(exprs, subexprs[j]) end + else end end return exprs end doc_special("values", {"..."}, "Return multiple values from a function. Must be in tail position.") - local function deep_tostring(x, key_3f) - local elems = {} - if utils["sequence?"](x) then - local _0_ - do - local tbl_0_ = {} - for _, v in ipairs(x) do - tbl_0_[(#tbl_0_ + 1)] = deep_tostring(v) - end - _0_ = tbl_0_ - end - return ("[" .. table.concat(_0_, " ") .. "]") - elseif utils["table?"](x) then - local _0_ - do - local tbl_0_ = {} - for k, v in pairs(x) do - tbl_0_[(#tbl_0_ + 1)] = (deep_tostring(k, true) .. " " .. deep_tostring(v)) + local function __3estack(stack, tbl) + for k, v in pairs(tbl) do + local _447_ = stack + table.insert(_447_, k) + table.insert(_447_, v) + end + return stack + end + local function literal_3f(val) + local res = true + if utils["list?"](val) then + res = false + elseif utils["table?"](val) then + local stack = __3estack({}, val) + for _, elt in ipairs(stack) do + if not res then break end + if utils["list?"](elt) then + res = false + elseif utils["table?"](elt) then + __3estack(stack, elt) + else end - _0_ = tbl_0_ end - return ("{" .. table.concat(_0_, " ") .. "}") - elseif (key_3f and (type(x) == "string") and x:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then - return (":" .. x) - elseif (type(x) == "string") then - return string.format("%q", x):gsub("\\\"", "\\\\\""):gsub("\"", "\\\"") else - return tostring(x) end + return res end - local function set_fn_metadata(arg_list, docstring, parent, fn_name) - if utils.root.options.useMetadata then - local args = nil - local function _0_(_241) - return ("\"%s\""):format(deep_tostring(_241)) + local function compile_value(v) + local opts = {nval = 1, tail = false} + local scope = compiler["make-scope"]() + local chunk = {} + local _let_450_ = compiler.compile1(v, scope, chunk, opts) + local _let_451_ = _let_450_[1] + local v0 = _let_451_[1] + return v0 + end + local function insert_meta(meta, k, v) + local view_opts = {["escape-newlines?"] = true, ["line-length"] = math.huge, ["one-line?"] = true} + compiler.assert((type(k) == "string"), ("expected string keys in metadata table, got: %s"):format(view(k, view_opts))) + compiler.assert(literal_3f(v), ("expected literal value in metadata table, got: %s %s"):format(view(k, view_opts), view(v, view_opts))) + local _452_ = meta + table.insert(_452_, view(k)) + local function _453_() + if ("string" == type(v)) then + return view(v, view_opts) + else + return compile_value(v) end - args = utils.map(arg_list, _0_) - local meta_fields = {"\"fnl/arglist\"", ("{" .. table.concat(args, ", ") .. "}")} - if docstring then - table.insert(meta_fields, "\"fnl/docstring\"") - table.insert(meta_fields, ("\"" .. docstring:gsub("%s+$", ""):gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\"", "\\\"") .. "\"")) + end + table.insert(_452_, _453_()) + return _452_ + end + local function insert_arglist(meta, arg_list) + local view_opts = {["one-line?"] = true, ["escape-newlines?"] = true, ["line-length"] = math.huge} + local _454_ = meta + table.insert(_454_, "\"fnl/arglist\"") + local function _455_(_241) + return view(view(_241, view_opts)) + end + table.insert(_454_, ("{" .. table.concat(utils.map(arg_list, _455_), ", ") .. "}")) + return _454_ + end + local function set_fn_metadata(f_metadata, parent, fn_name) + if utils.root.options.useMetadata then + local meta_fields = {} + for k, v in utils.stablepairs(f_metadata) do + if (k == "fnl/arglist") then + insert_arglist(meta_fields, v) + else + insert_meta(meta_fields, k, v) + end end local meta_str = ("require(\"%s\").metadata"):format((utils.root.options.moduleName or "fennel")) return compiler.emit(parent, ("pcall(function() %s:setall(%s, %s) end)"):format(meta_str, fn_name, table.concat(meta_fields, ", "))) + else + return nil end end local function get_fn_name(ast, scope, fn_name, multi) if (fn_name and (fn_name[1] ~= "nil")) then - local _0_ + local _458_ if not multi then - _0_ = compiler["declare-local"](fn_name, {}, scope, ast) + _458_ = compiler["declare-local"](fn_name, {}, scope, ast) else - _0_ = compiler["symbol-to-expression"](fn_name, scope)[1] + _458_ = (compiler["symbol-to-expression"](fn_name, scope))[1] end - return _0_, not multi, 3 + return _458_, not multi, 3 else return nil, true, 2 end end - local function compile_named_fn(ast, f_scope, f_chunk, parent, index, fn_name, local_3f, arg_name_list, arg_list, docstring) + local function compile_named_fn(ast, f_scope, f_chunk, parent, index, fn_name, local_3f, arg_name_list, f_metadata) for i = (index + 1), #ast do compiler.compile1(ast[i], f_scope, f_chunk, {nval = (((i ~= #ast) and 0) or nil), tail = (i == #ast)}) end - local _0_ + local _461_ if local_3f then - _0_ = "local function %s(%s)" + _461_ = "local function %s(%s)" else - _0_ = "%s = function(%s)" + _461_ = "%s = function(%s)" end - compiler.emit(parent, string.format(_0_, fn_name, table.concat(arg_name_list, ", ")), ast) + compiler.emit(parent, string.format(_461_, fn_name, table.concat(arg_name_list, ", ")), ast) compiler.emit(parent, f_chunk, ast) compiler.emit(parent, "end", ast) - set_fn_metadata(arg_list, docstring, parent, fn_name) + set_fn_metadata(f_metadata, parent, fn_name) utils.hook("fn", ast, f_scope) return utils.expr(fn_name, "sym") end - local function compile_anonymous_fn(ast, f_scope, f_chunk, parent, index, arg_name_list, arg_list, docstring, scope) + local function compile_anonymous_fn(ast, f_scope, f_chunk, parent, index, arg_name_list, f_metadata, scope) local fn_name = compiler.gensym(scope) - return compile_named_fn(ast, f_scope, f_chunk, parent, index, fn_name, true, arg_name_list, arg_list, docstring) + return compile_named_fn(ast, f_scope, f_chunk, parent, index, fn_name, true, arg_name_list, f_metadata) + end + local function assoc_table_3f(t) + local len = #t + local nxt, t0, k = pairs(t) + local function _463_() + if (len == 0) then + return k + else + return len + end + end + return (nil ~= nxt(t0, _463_())) + end + local function get_function_metadata(ast, arg_list, index) + local f_metadata = {["fnl/arglist"] = arg_list} + local index_2a = (index + 1) + local expr = ast[index_2a] + if (utils["string?"](expr) and (index_2a < #ast)) then + local _465_ + do + local _464_ = f_metadata + _464_["fnl/docstring"] = expr + _465_ = _464_ + end + return _465_, index_2a + elseif (utils["table?"](expr) and (index_2a < #ast) and assoc_table_3f(expr)) then + local _466_ + do + local tbl_13_auto = f_metadata + for k, v in pairs(expr) do + local k_14_auto, v_15_auto = k, v + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end + end + _466_ = tbl_13_auto + end + return _466_, index_2a + else + return f_metadata, index + end end SPECIALS.fn = function(ast, scope, parent) - local f_scope = nil + local f_scope do - local _0_0 = compiler["make-scope"](scope) - _0_0["vararg"] = false - f_scope = _0_0 + local _469_ = compiler["make-scope"](scope) + do end (_469_)["vararg"] = false + f_scope = _469_ end local f_chunk = {} local fn_sym = utils["sym?"](ast[2]) @@ -933,75 +1081,103 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local fn_name, local_3f, index = get_fn_name(ast, scope, fn_sym, multi) local arg_list = compiler.assert(utils["table?"](ast[index]), "expected parameters table", ast) compiler.assert((not multi or not multi["multi-sym-method-call"]), ("unexpected multi symbol " .. tostring(fn_name)), fn_sym) - local function get_arg_name(arg) - if utils["varg?"](arg) then + local function destructure_arg(arg) + local raw = utils.sym(compiler.gensym(scope)) + local declared = compiler["declare-local"](raw, {}, f_scope, ast) + compiler.destructure(arg, raw, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"}) + return declared + end + local function destructure_amp(i) + compiler.assert((i == (#arg_list - 1)), "expected rest argument before last parameter", arg_list[(i + 1)], arg_list) + f_scope.vararg = true + compiler.destructure(arg_list[#arg_list], {utils.varg()}, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"}) + return "..." + end + local function get_arg_name(arg, i) + if f_scope.vararg then + return nil + elseif utils["varg?"](arg) then compiler.assert((arg == arg_list[#arg_list]), "expected vararg as last parameter", ast) f_scope.vararg = true return "..." - elseif (utils["sym?"](arg) and (utils.deref(arg) ~= "nil") and not utils["multi-sym?"](utils.deref(arg))) then + elseif (utils.sym("&") == arg) then + return destructure_amp(i) + elseif (utils["sym?"](arg) and (tostring(arg) ~= "nil") and not utils["multi-sym?"](tostring(arg))) then return compiler["declare-local"](arg, {}, f_scope, ast) elseif utils["table?"](arg) then - local raw = utils.sym(compiler.gensym(scope)) - local declared = compiler["declare-local"](raw, {}, f_scope, ast) - compiler.destructure(arg, raw, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"}) - return declared + return destructure_arg(arg) else - return compiler.assert(false, ("expected symbol for function parameter: %s"):format(tostring(arg)), ast[2]) + return compiler.assert(false, ("expected symbol for function parameter: %s"):format(tostring(arg)), ast[index]) end end - local arg_name_list = utils.map(arg_list, get_arg_name) - local index0, docstring = nil, nil - if ((type(ast[(index + 1)]) == "string") and ((index + 1) < #ast)) then - index0, docstring = (index + 1), ast[(index + 1)] - else - index0, docstring = index, nil + local arg_name_list + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for i, a in ipairs(arg_list) do + local val_18_auto = get_arg_name(a, i) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + arg_name_list = tbl_16_auto end + local f_metadata, index0 = get_function_metadata(ast, arg_list, index) if fn_name then - return compile_named_fn(ast, f_scope, f_chunk, parent, index0, fn_name, local_3f, arg_name_list, arg_list, docstring) + return compile_named_fn(ast, f_scope, f_chunk, parent, index0, fn_name, local_3f, arg_name_list, f_metadata) else - return compile_anonymous_fn(ast, f_scope, f_chunk, parent, index0, arg_name_list, arg_list, docstring, scope) + return compile_anonymous_fn(ast, f_scope, f_chunk, parent, index0, arg_name_list, f_metadata, scope) end end - doc_special("fn", {"name?", "args", "docstring?", "..."}, "Function syntax. May optionally include a name and docstring.\nIf a name is provided, the function will be bound in the current scope.\nWhen called with the wrong number of args, excess args will be discarded\nand lacking args will be nil, use lambda for arity-checked functions.", true) + doc_special("fn", {"name?", "args", "docstring?", "..."}, "Function syntax. May optionally include a name and docstring or a metadata table.\nIf a name is provided, the function will be bound in the current scope.\nWhen called with the wrong number of args, excess args will be discarded\nand lacking args will be nil, use lambda for arity-checked functions.", true) SPECIALS.lua = function(ast, _, parent) compiler.assert(((#ast == 2) or (#ast == 3)), "expected 1 or 2 arguments", ast) - if (ast[2] ~= nil) then + local _474_ + do + local _473_ = utils["sym?"](ast[2]) + if (nil ~= _473_) then + _474_ = tostring(_473_) + else + _474_ = _473_ + end + end + if ("nil" ~= _474_) then table.insert(parent, {ast = ast, leaf = tostring(ast[2])}) + else end - if (ast[3] ~= nil) then - return tostring(ast[3]) + local _478_ + do + local _477_ = utils["sym?"](ast[3]) + if (nil ~= _477_) then + _478_ = tostring(_477_) + else + _478_ = _477_ + end end - end - SPECIALS.doc = function(ast, scope, parent) - assert(utils.root.options.useMetadata, "can't look up doc with metadata disabled.") - compiler.assert((#ast == 2), "expected one argument", ast) - local target = utils.deref(ast[2]) - local special_or_macro = (scope.specials[target] or scope.macros[target]) - if special_or_macro then - return ("print(%q)"):format(doc_2a(special_or_macro, target)) + if ("nil" ~= _478_) then + return tostring(ast[3]) else - local _0_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local value = _0_[1] - return ("print(require('%s').doc(%s, '%s'))"):format((utils.root.options.moduleName or "fennel"), tostring(value), tostring(ast[2])) + return nil end end - doc_special("doc", {"x"}, "Print the docstring and arglist for a function, macro, or special form.") local function dot(ast, scope, parent) compiler.assert((1 < #ast), "expected table argument", ast) local len = #ast - local _0_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local lhs = _0_[1] + local _let_481_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) + local lhs = _let_481_[1] if (len == 2) then return tostring(lhs) else local indices = {} for i = 3, len do local index = ast[i] - if ((type(index) == "string") and utils["valid-lua-identifier?"](index)) then + if (utils["string?"](index) and utils["valid-lua-identifier?"](index)) then table.insert(indices, ("." .. index)) else - local _1_ = compiler.compile1(index, scope, parent, {nval = 1}) - local index0 = _1_[1] + local _let_482_ = compiler.compile1(index, scope, parent, {nval = 1}) + local index0 = _let_482_[1] table.insert(indices, ("[" .. tostring(index0) .. "]")) end end @@ -1045,12 +1221,34 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi return nil end doc_special("var", {"name", "val"}, "Introduce new mutable local.") + local function kv_3f(t) + local _486_ + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for k in pairs(t) do + local val_18_auto + if ("number" ~= type(k)) then + val_18_auto = k + else + val_18_auto = nil + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + _486_ = tbl_16_auto + end + return (_486_)[1] + end SPECIALS.let = function(ast, scope, parent, opts) local bindings = ast[2] local pre_syms = {} - compiler.assert((utils["list?"](bindings) or utils["table?"](bindings)), "expected binding table", ast) + compiler.assert((utils["table?"](bindings) and not kv_3f(bindings)), "expected binding sequence", bindings) compiler.assert(((#bindings % 2) == 0), "expected even number of name/value bindings", ast[2]) - compiler.assert((#ast >= 3), "expected body expression", ast[1]) + compiler.assert((3 <= #ast), "expected body expression", ast[1]) for _ = 1, (opts.nval or 0) do table.insert(pre_syms, compiler.gensym(scope)) end @@ -1070,27 +1268,29 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi end end local function disambiguate_3f(rootstr, parent) - local function _1_() - local _0_0 = get_prev_line(parent) - if (nil ~= _0_0) then - local prev_line = _0_0 + local function _491_() + local _490_ = get_prev_line(parent) + if (nil ~= _490_) then + local prev_line = _490_ return prev_line:match("%)$") + else + return nil end end - return (rootstr:match("^{") or _1_()) + return (rootstr:match("^{") or _491_()) end SPECIALS.tset = function(ast, scope, parent) - compiler.assert((#ast > 3), "expected table, key, and value arguments", ast) - local root = compiler.compile1(ast[2], scope, parent, {nval = 1})[1] + compiler.assert((3 < #ast), "expected table, key, and value arguments", ast) + local root = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1] local keys = {} for i = 3, (#ast - 1) do - local _0_ = compiler.compile1(ast[i], scope, parent, {nval = 1}) - local key = _0_[1] + local _let_493_ = compiler.compile1(ast[i], scope, parent, {nval = 1}) + local key = _let_493_[1] table.insert(keys, tostring(key)) end - local value = compiler.compile1(ast[#ast], scope, parent, {nval = 1})[1] + local value = (compiler.compile1(ast[#ast], scope, parent, {nval = 1}))[1] local rootstr = tostring(root) - local fmtstr = nil + local fmtstr if disambiguate_3f(rootstr, parent) then fmtstr = "do end (%s)[%s] = %s" else @@ -1107,7 +1307,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local target_exprs = {} for i = 1, opts.nval do local s = compiler.gensym(scope) - accum[i] = s + do end (accum)[i] = s target_exprs[i] = utils.expr(s, "sym") end return "target", opts.tail, table.concat(accum, ", "), target_exprs @@ -1116,6 +1316,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi end end local function if_2a(ast, scope, parent, opts) + compiler.assert((2 < #ast), "expected condition and body", ast) local do_scope = compiler["make-scope"](scope) local branches = {} local wrapper, inner_tail, inner_target, target_exprs = calculate_target(scope, opts) @@ -1126,6 +1327,10 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi compiler["keep-side-effects"](compiler.compile1(ast[i], cscope, chunk, body_opts), chunk, nil, ast[i]) return {chunk = chunk, scope = cscope} end + if (1 == (#ast % 2)) then + table.insert(ast, utils.sym("nil")) + else + end for i = 2, (#ast - 1), 2 do local condchunk = {} local res = compiler.compile1(ast[i], do_scope, condchunk, {nval = 1}) @@ -1136,26 +1341,20 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi branch.nested = ((i ~= 2) and (next(condchunk, nil) == nil)) table.insert(branches, branch) end - local has_else_3f = ((#ast > 3) and ((#ast % 2) == 0)) - local else_branch = (has_else_3f and compile_body(#ast)) + local else_branch = compile_body(#ast) local s = compiler.gensym(scope) local buffer = {} local last_buffer = buffer for i = 1, #branches do local branch = branches[i] - local fstr = nil + local fstr if not branch.nested then fstr = "if %s then" else fstr = "elseif %s then" end local cond = tostring(branch.cond) - local cond_line = nil - if ((cond == "true") and branch.nested and (i == #branches) and not has_else_3f) then - cond_line = "else" - else - cond_line = fstr:format(cond) - end + local cond_line = fstr:format(cond) if branch.nested then compiler.emit(last_buffer, branch.condchunk, ast) else @@ -1166,20 +1365,16 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi compiler.emit(last_buffer, cond_line, ast) compiler.emit(last_buffer, branch.chunk, ast) if (i == #branches) then - if has_else_3f then - compiler.emit(last_buffer, "else", ast) - compiler.emit(last_buffer, else_branch.chunk, ast) - elseif (inner_target and (cond_line ~= "else")) then - compiler.emit(last_buffer, "else", ast) - compiler.emit(last_buffer, ("%s = nil"):format(inner_target), ast) - end + compiler.emit(last_buffer, "else", ast) + compiler.emit(last_buffer, else_branch.chunk, ast) compiler.emit(last_buffer, "end", ast) - elseif not branches[(i + 1)].nested then + elseif not (branches[(i + 1)]).nested then local next_buffer = {} compiler.emit(last_buffer, "else", ast) compiler.emit(last_buffer, next_buffer, ast) compiler.emit(last_buffer, "end", ast) last_buffer = next_buffer + else end end if (wrapper == "iife") then @@ -1204,20 +1399,25 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi SPECIALS["if"] = if_2a doc_special("if", {"cond1", "body1", "...", "condN", "bodyN"}, "Conditional form.\nTakes any number of condition/body pairs and evaluates the first body where\nthe condition evaluates to truthy. Similar to cond in other lisps.") local function remove_until_condition(bindings) - if ("until" == bindings[(#bindings - 1)]) then + local last_item = bindings[(#bindings - 1)] + if ((utils["sym?"](last_item) and (tostring(last_item) == "&until")) or ("until" == last_item)) then table.remove(bindings, (#bindings - 1)) return table.remove(bindings) + else + return nil end end local function compile_until(condition, scope, chunk) if condition then - local _0_ = compiler.compile1(condition, scope, chunk, {nval = 1}) - local condition_lua = _0_[1] - return compiler.emit(chunk, ("if %s then break end"):format(tostring(condition_lua)), condition) + local _let_502_ = compiler.compile1(condition, scope, chunk, {nval = 1}) + local condition_lua = _let_502_[1] + return compiler.emit(chunk, ("if %s then break end"):format(tostring(condition_lua)), utils.expr(condition, "expression")) + else + return nil end end SPECIALS.each = function(ast, scope, parent) - compiler.assert((#ast >= 3), "expected body expression", ast[1]) + compiler.assert((3 <= #ast), "expected body expression", ast[1]) local binding = compiler.assert(utils["table?"](ast[2]), "expected binding table", ast) local _ = compiler.assert((2 <= #binding), "expected binding and iterator", binding) local until_condition = remove_until_condition(binding) @@ -1226,16 +1426,17 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local new_manglings = {} local sub_scope = compiler["make-scope"](scope) local function destructure_binding(v) + compiler.assert(not utils["string?"](v), ("unexpected iterator clause " .. tostring(v)), binding) if utils["sym?"](v) then return compiler["declare-local"](v, {}, sub_scope, ast, new_manglings) else local raw = utils.sym(compiler.gensym(sub_scope)) - destructures[raw] = v + do end (destructures)[raw] = v return compiler["declare-local"](raw, {}, sub_scope, ast) end end local bind_vars = utils.map(binding, destructure_binding) - local vals = compiler.compile1(iter, sub_scope, parent) + local vals = compiler.compile1(iter, scope, parent) local val_names = utils.map(vals, tostring) local chunk = {} compiler.emit(parent, ("for %s in %s do"):format(table.concat(bind_vars, ", "), table.concat(val_names, ", ")), ast) @@ -1251,13 +1452,13 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi doc_special("each", {"[key value (iterator)]", "..."}, "Runs the body once for each set of values provided by the given iterator.\nMost commonly used with ipairs for sequential tables or pairs for undefined\norder, but can be used with any iterator.", true) local function while_2a(ast, scope, parent) local len1 = #parent - local condition = compiler.compile1(ast[2], scope, parent, {nval = 1})[1] + local condition = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1] local len2 = #parent local sub_chunk = {} if (len1 ~= len2) then for i = (len1 + 1), len2 do table.insert(sub_chunk, parent[i]) - parent[i] = nil + do end (parent)[i] = nil end compiler.emit(parent, "while true do", ast) compiler.emit(sub_chunk, ("if not %s then break end"):format(condition[1]), ast) @@ -1278,9 +1479,10 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local range_args = {} local chunk = {} compiler.assert(utils["sym?"](binding_sym), ("unable to bind %s %s"):format(type(binding_sym), tostring(binding_sym)), ast[2]) - compiler.assert((#ast >= 3), "expected body expression", ast[1]) + compiler.assert((3 <= #ast), "expected body expression", ast[1]) + compiler.assert((#ranges <= 3), "unexpected arguments", ranges[4]) for i = 1, math.min(#ranges, 3) do - range_args[i] = tostring(compiler.compile1(ranges[i], sub_scope, parent, {nval = 1})[1]) + range_args[i] = tostring((compiler.compile1(ranges[i], scope, parent, {nval = 1}))[1]) end compiler.emit(parent, ("for %s = %s do"):format(compiler["declare-local"](binding_sym, {}, sub_scope, ast), table.concat(range_args, ", ")), ast) compile_until(until_condition, sub_scope, chunk) @@ -1291,12 +1493,12 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi SPECIALS["for"] = for_2a doc_special("for", {"[index start stop step?]", "..."}, "Numeric loop construct.\nEvaluates body once for each value between start and stop (inclusive).", true) local function native_method_call(ast, _scope, _parent, target, args) - local _0_ = ast - local _ = _0_[1] - local _0 = _0_[2] - local method_string = _0_[3] - local call_string = nil - if ((target.type == "literal") or (target.type == "expression")) then + local _let_506_ = ast + local _ = _let_506_[1] + local _0 = _let_506_[2] + local method_string = _let_506_[3] + local call_string + if ((target.type == "literal") or (target.type == "varg") or (target.type == "expression")) then call_string = "(%s):%s(%s)" else call_string = "%s:%s(%s)" @@ -1304,33 +1506,33 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi return utils.expr(string.format(call_string, tostring(target), method_string, table.concat(args, ", ")), "statement") end local function nonnative_method_call(ast, scope, parent, target, args) - local method_string = tostring(compiler.compile1(ast[3], scope, parent, {nval = 1})[1]) + local method_string = tostring((compiler.compile1(ast[3], scope, parent, {nval = 1}))[1]) local args0 = {tostring(target), unpack(args)} return utils.expr(string.format("%s[%s](%s)", tostring(target), method_string, table.concat(args0, ", ")), "statement") end local function double_eval_protected_method_call(ast, scope, parent, target, args) - local method_string = tostring(compiler.compile1(ast[3], scope, parent, {nval = 1})[1]) + local method_string = tostring((compiler.compile1(ast[3], scope, parent, {nval = 1}))[1]) local call = "(function(tgt, m, ...) return tgt[m](tgt, ...) end)(%s, %s)" table.insert(args, 1, method_string) return utils.expr(string.format(call, tostring(target), table.concat(args, ", ")), "statement") end local function method_call(ast, scope, parent) compiler.assert((2 < #ast), "expected at least 2 arguments", ast) - local _0_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local target = _0_[1] + local _let_508_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) + local target = _let_508_[1] local args = {} for i = 4, #ast do - local subexprs = nil - local _1_ + local subexprs + local _509_ if (i ~= #ast) then - _1_ = 1 + _509_ = 1 else - _1_ = nil + _509_ = nil end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _1_}) + subexprs = compiler.compile1(ast[i], scope, parent, {nval = _509_}) utils.map(subexprs, tostring, args) end - if ((type(ast[3]) == "string") and utils["valid-lua-identifier?"](ast[3])) then + if (utils["string?"](ast[3]) and utils["valid-lua-identifier?"](ast[3])) then return native_method_call(ast, scope, parent, target, args) elseif (target.type == "sym") then return nonnative_method_call(ast, scope, parent, target, args) @@ -1343,17 +1545,13 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi SPECIALS.comment = function(ast, _, parent) local els = {} for i = 2, #ast do - local function _1_() - local _0_0 = tostring(ast[i]):gsub("\n", " ") - return _0_0 - end - table.insert(els, _1_()) + table.insert(els, view(ast[i], {["one-line?"] = true})) end - return compiler.emit(parent, ("-- " .. table.concat(els, " ")), ast) + return compiler.emit(parent, ("--[[ " .. table.concat(els, " ") .. " ]]"), ast) end doc_special("comment", {"..."}, "Comment which will be emitted in Lua output.", true) local function hashfn_max_used(f_scope, i, max) - local max0 = nil + local max0 if f_scope.symmeta[("$" .. i)].used then max0 = i else @@ -1367,12 +1565,12 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi end SPECIALS.hashfn = function(ast, scope, parent) compiler.assert((#ast == 2), "expected one argument", ast) - local f_scope = nil + local f_scope do - local _0_0 = compiler["make-scope"](scope) - _0_0["vararg"] = false - _0_0["hashfn"] = true - f_scope = _0_0 + local _514_ = compiler["make-scope"](scope) + do end (_514_)["vararg"] = false + _514_["hashfn"] = true + f_scope = _514_ end local f_chunk = {} local name = compiler.gensym(scope) @@ -1383,12 +1581,12 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi args[i] = compiler["declare-local"](utils.sym(("$" .. i)), {}, f_scope, ast) end local function walker(idx, node, parent_node) - if (utils["sym?"](node) and (utils.deref(node) == "$...")) then + if (utils["sym?"](node) and (tostring(node) == "$...")) then parent_node[idx] = utils.varg() f_scope.vararg = true return nil else - return (utils["list?"](node) or utils["table?"](node)) + return (("table" == type(node)) and (utils.sym("hashfn") ~= node[1]) and (utils["list?"](node) or utils["table?"](node))) end end utils["walk-tree"](ast[2], walker) @@ -1396,10 +1594,11 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local max_used = hashfn_max_used(f_scope, 1, 0) if f_scope.vararg then compiler.assert((max_used == 0), "$ and $... in hashfn are mutually exclusive", ast) + else end - local arg_str = nil + local arg_str if f_scope.vararg then - arg_str = utils.deref(utils.varg()) + arg_str = tostring(utils.varg()) else arg_str = table.concat(args, ", ", 1, max_used) end @@ -1409,41 +1608,63 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi return utils.expr(name, "sym") end doc_special("hashfn", {"..."}, "Function literal shorthand; args are either $... OR $1, $2, etc.") + local function maybe_short_circuit_protect(ast, i, name, _518_) + local _arg_519_ = _518_ + local mac = _arg_519_["macros"] + local call = (utils["list?"](ast) and tostring(ast[1])) + if ((("or" == name) or ("and" == name)) and (1 < i) and (mac[call] or ("set" == call) or ("tset" == call) or ("global" == call))) then + return utils.list(utils.sym("do"), ast) + else + return ast + end + end local function arithmetic_special(name, zero_arity, unary_prefix, ast, scope, parent) local len = #ast - if (len == 1) then - compiler.assert(zero_arity, "Expected more than 0 arguments", ast) - return utils.expr(zero_arity, "literal") - else - local operands = {} - local padded_op = (" " .. name .. " ") - for i = 2, len do - local subexprs = nil - local _0_ - if (i ~= len) then - _0_ = 1 - else - _0_ = nil - end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _0_}) + local operands = {} + local padded_op = (" " .. name .. " ") + for i = 2, len do + local subast = maybe_short_circuit_protect(ast[i], i, name, scope) + local subexprs = compiler.compile1(subast, scope, parent) + if (i == len) then utils.map(subexprs, tostring, operands) + else + table.insert(operands, tostring(subexprs[1])) end - if (#operands == 1) then - if unary_prefix then - return ("(" .. unary_prefix .. padded_op .. operands[1] .. ")") - else - return operands[1] - end + end + local _522_ = #operands + if (_522_ == 0) then + local _524_ + do + local _523_ = zero_arity + compiler.assert(_523_, "Expected more than 0 arguments", ast) + _524_ = _523_ + end + return utils.expr(_524_, "literal") + elseif (_522_ == 1) then + if unary_prefix then + return ("(" .. unary_prefix .. padded_op .. operands[1] .. ")") else - return ("(" .. table.concat(operands, padded_op) .. ")") + return operands[1] end + elseif true then + local _ = _522_ + return ("(" .. table.concat(operands, padded_op) .. ")") + else + return nil end end - local function define_arithmetic_special(name, zero_arity, unary_prefix, lua_name) - local function _0_(...) - return arithmetic_special((lua_name or name), zero_arity, unary_prefix, ...) + local function define_arithmetic_special(name, zero_arity, unary_prefix, _3flua_name) + local _530_ + do + local _527_ = (_3flua_name or name) + local _528_ = zero_arity + local _529_ = unary_prefix + local function _531_(...) + return arithmetic_special(_527_, _528_, _529_, ...) + end + _530_ = _531_ end - SPECIALS[name] = _0_ + SPECIALS[name] = _530_ return doc_special(name, {"a", "b", "..."}, "Arithmetic operator; works the same as Lua but accepts more arguments.") end define_arithmetic_special("+", "0") @@ -1454,6 +1675,14 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi define_arithmetic_special("%") define_arithmetic_special("/", nil, "1") define_arithmetic_special("//", nil, "1") + SPECIALS["or"] = function(ast, scope, parent) + return arithmetic_special("or", "false", nil, ast, scope, parent) + end + SPECIALS["and"] = function(ast, scope, parent) + return arithmetic_special("and", "true", nil, ast, scope, parent) + end + doc_special("and", {"a", "b", "..."}, "Boolean operator; works the same as Lua but accepts more arguments.") + doc_special("or", {"a", "b", "..."}, "Boolean operator; works the same as Lua but accepts more arguments.") local function bitop_special(native_name, lib_name, zero_arity, unary_prefix, ast, scope, parent) if (#ast == 1) then return compiler.assert(zero_arity, "Expected more than 0 arguments.", ast) @@ -1463,14 +1692,14 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local padded_native_name = (" " .. native_name .. " ") local prefixed_lib_name = ("bit." .. lib_name) for i = 2, len do - local subexprs = nil - local _0_ + local subexprs + local _532_ if (i ~= len) then - _0_ = 1 + _532_ = 1 else - _0_ = nil + _532_ = nil end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _0_}) + subexprs = compiler.compile1(ast[i], scope, parent, {nval = _532_}) utils.map(subexprs, tostring, operands) end if (#operands == 1) then @@ -1489,10 +1718,18 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi end end local function define_bitop_special(name, zero_arity, unary_prefix, native) - local function _0_(...) - return bitop_special(native, name, zero_arity, unary_prefix, ...) + local _542_ + do + local _538_ = native + local _539_ = name + local _540_ = zero_arity + local _541_ = unary_prefix + local function _543_(...) + return bitop_special(_538_, _539_, _540_, _541_, ...) + end + _542_ = _543_ end - SPECIALS[name] = _0_ + SPECIALS[name] = _542_ return nil end define_bitop_special("lshift", nil, "1", "<<") @@ -1505,22 +1742,50 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi doc_special("band", {"x1", "x2", "..."}, "Bitwise AND of any number of arguments.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.") doc_special("bor", {"x1", "x2", "..."}, "Bitwise OR of any number of arguments.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.") doc_special("bxor", {"x1", "x2", "..."}, "Bitwise XOR of any number of arguments.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.") - define_arithmetic_special("or", "false") - define_arithmetic_special("and", "true") - doc_special("and", {"a", "b", "..."}, "Boolean operator; works the same as Lua but accepts more arguments.") - doc_special("or", {"a", "b", "..."}, "Boolean operator; works the same as Lua but accepts more arguments.") doc_special("..", {"a", "b", "..."}, "String concatenation operator; works the same as Lua but accepts more arguments.") - local function native_comparator(op, _0_0, scope, parent) - local _1_ = _0_0 - local _ = _1_[1] - local lhs_ast = _1_[2] - local rhs_ast = _1_[3] - local _2_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1}) - local lhs = _2_[1] - local _3_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1}) - local rhs = _3_[1] + local function native_comparator(op, _544_, scope, parent) + local _arg_545_ = _544_ + local _ = _arg_545_[1] + local lhs_ast = _arg_545_[2] + local rhs_ast = _arg_545_[3] + local _let_546_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1}) + local lhs = _let_546_[1] + local _let_547_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1}) + local rhs = _let_547_[1] return string.format("(%s %s %s)", tostring(lhs), op, tostring(rhs)) end + local function idempotent_comparator(op, chain_op, ast, scope, parent) + local vals + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for i = 2, #ast do + local val_18_auto = tostring((compiler.compile1(ast[i], scope, parent, {nval = 1}))[1]) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + vals = tbl_16_auto + end + local comparisons + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for i = 1, (#vals - 1) do + local val_18_auto = string.format("(%s %s %s)", vals[i], op, vals[(i + 1)]) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + comparisons = tbl_16_auto + end + local chain = string.format(" %s ", (chain_op or "and")) + return table.concat(comparisons, chain) + end local function double_eval_protected_comparator(op, chain_op, ast, scope, parent) local arglist = {} local comparisons = {} @@ -1528,22 +1793,33 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local chain = string.format(" %s ", (chain_op or "and")) for i = 2, #ast do table.insert(arglist, tostring(compiler.gensym(scope))) - table.insert(vals, tostring(compiler.compile1(ast[i], scope, parent, {nval = 1})[1])) + table.insert(vals, tostring((compiler.compile1(ast[i], scope, parent, {nval = 1}))[1])) end - for i = 1, (#arglist - 1) do - table.insert(comparisons, string.format("(%s %s %s)", arglist[i], op, arglist[(i + 1)])) + do + local tbl_16_auto = comparisons + local i_17_auto = #tbl_16_auto + for i = 1, (#arglist - 1) do + local val_18_auto = string.format("(%s %s %s)", arglist[i], op, arglist[(i + 1)]) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end end return string.format("(function(%s) return %s end)(%s)", table.concat(arglist, ","), table.concat(comparisons, chain), table.concat(vals, ",")) end - local function define_comparator_special(name, lua_op, chain_op) + local function define_comparator_special(name, _3flua_op, _3fchain_op) do - local op = (lua_op or name) + local op = (_3flua_op or name) local function opfn(ast, scope, parent) compiler.assert((2 < #ast), "expected at least two arguments", ast) if (3 == #ast) then return native_comparator(op, ast, scope, parent) + elseif utils["every?"](utils["idempotent-expr?"], {unpack(ast, 2)}) then + return idempotent_comparator(op, _3fchain_op, ast, scope, parent) else - return double_eval_protected_comparator(op, chain_op, ast, scope, parent) + return double_eval_protected_comparator(op, _3fchain_op, ast, scope, parent) end end SPECIALS[name] = opfn @@ -1556,11 +1832,11 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi define_comparator_special("<=") define_comparator_special("=", "==") define_comparator_special("not=", "~=", "or") - local function define_unary_special(op, realop) + local function define_unary_special(op, _3frealop) local function opfn(ast, scope, parent) compiler.assert((#ast == 2), "expected one argument", ast) local tail = compiler.compile1(ast[2], scope, parent, {nval = 1}) - return ((realop or op) .. tostring(tail[1])) + return ((_3frealop or op) .. tostring(tail[1])) end SPECIALS[op] = opfn return nil @@ -1571,196 +1847,338 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi doc_special("bnot", {"x"}, "Bitwise negation; only works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.") define_unary_special("length", "#") doc_special("length", {"x"}, "Returns the length of a table or string.") - SPECIALS["~="] = SPECIALS["not="] + do end (SPECIALS)["~="] = SPECIALS["not="] SPECIALS["#"] = SPECIALS.length SPECIALS.quote = function(ast, scope, parent) - compiler.assert((#ast == 2), "expected one argument") + compiler.assert((#ast == 2), "expected one argument", ast) local runtime, this_scope = true, scope while this_scope do this_scope = this_scope.parent if (this_scope == compiler.scopes.compiler) then runtime = false + else end end return compiler["do-quote"](ast[2], scope, parent, runtime) end doc_special("quote", {"x"}, "Quasiquote the following form. Only works in macro/compiler scope.") - local already_warned_3f = {} - local compile_env_warning = table.concat({"WARNING: Attempting to %s %s in compile scope.", "In future versions of Fennel this will not be allowed without the", "--no-compiler-sandbox flag or passing a :compilerEnv globals table", "in the options.\n"}, "\n") - local function compiler_env_warn(_, key) - local v = _G[key] - if (v and io and io.stderr and not already_warned_3f[key]) then - already_warned_3f[key] = true - do end (io.stderr):write(compile_env_warning:format("use global", key)) - end - return v - end + local macro_loaded = {} local function safe_getmetatable(tbl) local mt = getmetatable(tbl) assert((mt ~= getmetatable("")), "Illegal metatable access!") return mt end local safe_require = nil - local function safe_compiler_env(strict_3f) - local _1_ - if strict_3f then - _1_ = nil + local function safe_compiler_env() + local _554_ + do + local _553_ = rawget(_G, "utf8") + if (nil ~= _553_) then + _554_ = utils.copy(_553_) + else + _554_ = _553_ + end + end + return {table = utils.copy(table), math = utils.copy(math), string = utils.copy(string), pairs = utils.stablepairs, ipairs = ipairs, select = select, tostring = tostring, tonumber = tonumber, bit = rawget(_G, "bit"), pcall = pcall, xpcall = xpcall, next = next, print = print, type = type, assert = assert, error = error, setmetatable = setmetatable, getmetatable = safe_getmetatable, require = safe_require, rawlen = rawget(_G, "rawlen"), rawget = rawget, rawset = rawset, rawequal = rawequal, _VERSION = _VERSION, utf8 = _554_} + end + local function combined_mt_pairs(env) + local combined = {} + local _let_556_ = getmetatable(env) + local __index = _let_556_["__index"] + if ("table" == type(__index)) then + for k, v in pairs(__index) do + combined[k] = v + end else - _1_ = compiler_env_warn end - return setmetatable({assert = assert, bit = rawget(_G, "bit"), error = error, getmetatable = safe_getmetatable, ipairs = ipairs, math = utils.copy(math), next = next, pairs = pairs, pcall = pcall, print = print, rawequal = rawequal, rawget = rawget, rawlen = rawget(_G, "rawlen"), rawset = rawset, require = safe_require, select = select, setmetatable = setmetatable, string = utils.copy(string), table = utils.copy(table), tonumber = tonumber, tostring = tostring, type = type, xpcall = xpcall}, {__index = _1_}) + for k, v in next, env, nil do + combined[k] = v + end + return next, combined, nil end - local function make_compiler_env(ast, scope, parent, strict_3f) - local function _1_() + local function make_compiler_env(ast, scope, parent, _3fopts) + local provided + do + local _558_ = (_3fopts or utils.root.options) + if ((_G.type(_558_) == "table") and ((_558_)["compiler-env"] == "strict")) then + provided = safe_compiler_env() + elseif ((_G.type(_558_) == "table") and (nil ~= (_558_).compilerEnv)) then + local compilerEnv = (_558_).compilerEnv + provided = compilerEnv + elseif ((_G.type(_558_) == "table") and (nil ~= (_558_)["compiler-env"])) then + local compiler_env = (_558_)["compiler-env"] + provided = compiler_env + elseif true then + local _ = _558_ + provided = safe_compiler_env(false) + else + provided = nil + end + end + local env + local function _560_(base) + return utils.sym(compiler.gensym((compiler.scopes.macro or scope), base)) + end + local function _561_() return compiler.scopes.macro end - local function _2_(symbol) + local function _562_(symbol) compiler.assert(compiler.scopes.macro, "must call from macro", ast) return compiler.scopes.macro.manglings[tostring(symbol)] end - local function _3_(base) - return utils.sym(compiler.gensym((compiler.scopes.macro or scope), base)) - end - local function _4_(form) + local function _563_(form) compiler.assert(compiler.scopes.macro, "must call from macro", ast) return compiler.macroexpand(form, compiler.scopes.macro) end - local _6_ - do - local _5_0 = utils.root.options - if ((type(_5_0) == "table") and (_5_0["compiler-env"] == "strict")) then - _6_ = safe_compiler_env(true) - elseif ((type(_5_0) == "table") and (nil ~= _5_0.compilerEnv)) then - local compilerEnv = _5_0.compilerEnv - _6_ = compilerEnv - elseif ((type(_5_0) == "table") and (nil ~= _5_0["compiler-env"])) then - local compiler_env = _5_0["compiler-env"] - _6_ = compiler_env + env = {_AST = ast, _CHUNK = parent, _IS_COMPILER = true, _SCOPE = scope, _SPECIALS = compiler.scopes.global.specials, _VARARG = utils.varg(), ["macro-loaded"] = macro_loaded, unpack = unpack, ["assert-compile"] = compiler.assert, view = view, version = utils.version, metadata = compiler.metadata, ["ast-source"] = utils["ast-source"], list = utils.list, ["list?"] = utils["list?"], ["table?"] = utils["table?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], sym = utils.sym, ["sym?"] = utils["sym?"], ["multi-sym?"] = utils["multi-sym?"], comment = utils.comment, ["comment?"] = utils["comment?"], ["varg?"] = utils["varg?"], gensym = _560_, ["get-scope"] = _561_, ["in-scope?"] = _562_, macroexpand = _563_} + env._G = env + return setmetatable(env, {__index = provided, __newindex = provided, __pairs = combined_mt_pairs}) + end + local function _565_(...) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for c in string.gmatch((package.config or ""), "([^\n]+)") do + local val_18_auto = c + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto else - local _ = _5_0 - _6_ = safe_compiler_env(false) end end - return setmetatable({["assert-compile"] = compiler.assert, ["get-scope"] = _1_, ["in-scope?"] = _2_, ["list?"] = utils["list?"], ["multi-sym?"] = utils["multi-sym?"], ["sequence?"] = utils["sequence?"], ["sym?"] = utils["sym?"], ["table?"] = utils["table?"], ["varg?"] = utils["varg?"], _AST = ast, _CHUNK = parent, _IS_COMPILER = true, _SCOPE = scope, _SPECIALS = compiler.scopes.global.specials, _VARARG = utils.varg(), gensym = _3_, list = utils.list, macroexpand = _4_, sequence = utils.sequence, sym = utils.sym, unpack = unpack, view = view}, {__index = _6_}) + return tbl_16_auto end - local cfg = string.gmatch(package.config, "([^\n]+)") - local dirsep, pathsep, pathmark = (cfg() or "/"), (cfg() or ";"), (cfg() or "?") - local pkg_config = {dirsep = dirsep, pathmark = pathmark, pathsep = pathsep} + local _local_564_ = _565_(...) + local dirsep = _local_564_[1] + local pathsep = _local_564_[2] + local pathmark = _local_564_[3] + local pkg_config = {dirsep = (dirsep or "/"), pathmark = (pathmark or ";"), pathsep = (pathsep or "?")} local function escapepat(str) return string.gsub(str, "[^%w]", "%%%1") end - local function search_module(modulename, pathstring) + local function search_module(modulename, _3fpathstring) local pathsepesc = escapepat(pkg_config.pathsep) local pattern = ("([^%s]*)%s"):format(pathsepesc, pathsepesc) local no_dot_module = modulename:gsub("%.", pkg_config.dirsep) - local fullpath = ((pathstring or utils["fennel-module"].path) .. pkg_config.pathsep) + local fullpath = ((_3fpathstring or utils["fennel-module"].path) .. pkg_config.pathsep) local function try_path(path) local filename = path:gsub(escapepat(pkg_config.pathmark), no_dot_module) local filename2 = path:gsub(escapepat(pkg_config.pathmark), modulename) - local _1_0 = (io.open(filename) or io.open(filename2)) - if (nil ~= _1_0) then - local file = _1_0 + local _567_ = (io.open(filename) or io.open(filename2)) + if (nil ~= _567_) then + local file = _567_ file:close() return filename + elseif true then + local _ = _567_ + return nil, ("no file '" .. filename .. "'") + else + return nil end end - local function find_in_path(start) - local _1_0 = fullpath:match(pattern, start) - if (nil ~= _1_0) then - local path = _1_0 - return (try_path(path) or find_in_path((start + #path + 1))) + local function find_in_path(start, _3ftried_paths) + local _569_ = fullpath:match(pattern, start) + if (nil ~= _569_) then + local path = _569_ + local _570_, _571_ = try_path(path) + if (nil ~= _570_) then + local filename = _570_ + return filename + elseif ((_570_ == nil) and (nil ~= _571_)) then + local error = _571_ + local function _573_() + local _572_ = (_3ftried_paths or {}) + table.insert(_572_, error) + return _572_ + end + return find_in_path((start + #path + 1), _573_()) + else + return nil + end + elseif true then + local _ = _569_ + local function _575_() + local tried_paths = table.concat((_3ftried_paths or {}), "\n\9") + if (_VERSION < "Lua 5.4") then + return ("\n\9" .. tried_paths) + else + return tried_paths + end + end + return nil, _575_() + else + return nil end end return find_in_path(1) end - local function make_searcher(options) - local function _1_(module_name) + local function make_searcher(_3foptions) + local function _578_(module_name) local opts = utils.copy(utils.root.options) - for k, v in pairs((options or {})) do + for k, v in pairs((_3foptions or {})) do opts[k] = v end opts["module-name"] = module_name - local _2_0 = search_module(module_name) - if (nil ~= _2_0) then - local filename = _2_0 - local function _3_(...) - return utils["fennel-module"].dofile(filename, opts, ...) + local _579_, _580_ = search_module(module_name) + if (nil ~= _579_) then + local filename = _579_ + local _583_ + do + local _581_ = filename + local _582_ = opts + local function _584_(...) + return utils["fennel-module"].dofile(_581_, _582_, ...) + end + _583_ = _584_ end - return _3_, filename + return _583_, filename + elseif ((_579_ == nil) and (nil ~= _580_)) then + local error = _580_ + return error + else + return nil end end - return _1_ + return _578_ end - local function macro_globals(env, globals) - local allowed = current_global_names(env) - for _, k in pairs((globals or {})) do - table.insert(allowed, k) + local function dofile_with_searcher(fennel_macro_searcher, filename, opts, ...) + local searchers = (package.loaders or package.searchers or {}) + local _ = table.insert(searchers, 1, fennel_macro_searcher) + local m = utils["fennel-module"].dofile(filename, opts, ...) + table.remove(searchers, 1) + return m + end + local function fennel_macro_searcher(module_name) + local opts + do + local _586_ = utils.copy(utils.root.options) + do end (_586_)["module-name"] = module_name + _586_["env"] = "_COMPILER" + _586_["requireAsInclude"] = false + _586_["allowedGlobals"] = nil + opts = _586_ + end + local _587_ = search_module(module_name, utils["fennel-module"]["macro-path"]) + if (nil ~= _587_) then + local filename = _587_ + local _588_ + if (opts["compiler-env"] == _G) then + local _589_ = fennel_macro_searcher + local _590_ = filename + local _591_ = opts + local function _593_(...) + return dofile_with_searcher(_589_, _590_, _591_, ...) + end + _588_ = _593_ + else + local _594_ = filename + local _595_ = opts + local function _597_(...) + return utils["fennel-module"].dofile(_594_, _595_, ...) + end + _588_ = _597_ + end + return _588_, filename + else + return nil end - return allowed end - local function default_macro_searcher(module_name) - local _1_0 = search_module(module_name) - if (nil ~= _1_0) then - local filename = _1_0 - local function _2_(...) - return utils["fennel-module"].dofile(filename, {env = "_COMPILER"}, ...) + local function lua_macro_searcher(module_name) + local _600_ = search_module(module_name, package.path) + if (nil ~= _600_) then + local filename = _600_ + local code + do + local f = io.open(filename) + local function close_handlers_8_auto(ok_9_auto, ...) + f:close() + if ok_9_auto then + return ... + else + return error(..., 0) + end + end + local function _602_() + return assert(f:read("*a")) + end + code = close_handlers_8_auto(_G.xpcall(_602_, (package.loaded.fennel or debug).traceback)) end - return _2_, filename + local chunk = load_code(code, make_compiler_env(), filename) + return chunk, filename + else + return nil end end - local macro_searchers = {default_macro_searcher} + local macro_searchers = {fennel_macro_searcher, lua_macro_searcher} local function search_macro_module(modname, n) - local _1_0 = macro_searchers[n] - if (nil ~= _1_0) then - local f = _1_0 - local _2_0, _3_0 = f(modname) - if ((nil ~= _2_0) and true) then - local loader = _2_0 - local _3ffilename = _3_0 + local _604_ = macro_searchers[n] + if (nil ~= _604_) then + local f = _604_ + local _605_, _606_ = f(modname) + if ((nil ~= _605_) and true) then + local loader = _605_ + local _3ffilename = _606_ return loader, _3ffilename - else - local _ = _2_0 + elseif true then + local _ = _605_ return search_macro_module(modname, (n + 1)) + else + return nil end + else + return nil end end - local macro_loaded = {} - local function metadata_only_fennel(modname) + local function sandbox_fennel_module(modname) if ((modname == "nvim-tree-docs.aniseed.fennel.macros") or (package and package.loaded and ("table" == type(package.loaded[modname])) and (package.loaded[modname].metadata == compiler.metadata))) then - return {metadata = compiler.metadata} + return {metadata = compiler.metadata, view = view} + else + return nil end end - local function _1_(modname) - local function _2_() + local function _610_(modname) + local function _611_() local loader, filename = search_macro_module(modname, 1) compiler.assert(loader, (modname .. " module not found.")) - macro_loaded[modname] = loader(modname, filename) + do end (macro_loaded)[modname] = loader(modname, filename) return macro_loaded[modname] end - return (macro_loaded[modname] or metadata_only_fennel(modname) or _2_()) + return (macro_loaded[modname] or sandbox_fennel_module(modname) or _611_()) end - safe_require = _1_ + safe_require = _610_ local function add_macros(macros_2a, ast, scope) compiler.assert(utils["table?"](macros_2a), "expected macros to be table", ast) for k, v in pairs(macros_2a) do compiler.assert((type(v) == "function"), "expected each macro to be function", ast) - scope.macros[k] = v + compiler["check-binding-valid"](utils.sym(k), scope, ast, {["macro?"] = true}) + do end (scope.macros)[k] = v end return nil end - SPECIALS["require-macros"] = function(ast, scope, parent, real_ast) - compiler.assert((#ast == 2), "Expected one module name argument", (real_ast or ast)) - local filename = (ast[2].filename or ast.filename) - local modname_chunk = load_code(compiler.compile(ast[2]), nil, filename) - local modname = modname_chunk(utils.root.options["module-name"], filename) - compiler.assert((type(modname) == "string"), "module name must compile to string", (real_ast or ast)) + local function resolve_module_name(_612_, _scope, _parent, opts) + local _arg_613_ = _612_ + local filename = _arg_613_["filename"] + local second = _arg_613_[2] + local filename0 = (filename or (utils["table?"](second) and second.filename)) + local module_name = utils.root.options["module-name"] + local modexpr = compiler.compile(second, opts) + local modname_chunk = load_code(modexpr) + return modname_chunk(module_name, filename0) + end + SPECIALS["require-macros"] = function(ast, scope, parent, _3freal_ast) + compiler.assert((#ast == 2), "Expected one module name argument", (_3freal_ast or ast)) + local modname = resolve_module_name(ast, scope, parent, {}) + compiler.assert(utils["string?"](modname), "module name must compile to string", (_3freal_ast or ast)) if not macro_loaded[modname] then - local env = make_compiler_env(ast, scope, parent) - local loader, filename0 = search_macro_module(modname, 1) + local loader, filename = search_macro_module(modname, 1) compiler.assert(loader, (modname .. " module not found."), ast) - macro_loaded[modname] = loader(modname, filename0) + do end (macro_loaded)[modname] = compiler.assert(utils["table?"](loader(modname, filename)), "expected macros to be table", (_3freal_ast or ast)) + else + end + if ("import-macros" == tostring(ast[1])) then + return macro_loaded[modname] + else + return add_macros(macro_loaded[modname], ast, scope, parent) end - return add_macros(macro_loaded[modname], ast, scope, parent) end doc_special("require-macros", {"macro-module-name"}, "Load given module and use its contents as macro definitions in current scope.\nMacro module should return a table of macro functions with string keys.\nConsider using import-macros instead as it is more flexible.") local function emit_included_fennel(src, path, opts, sub_chunk) @@ -1768,12 +2186,13 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local forms = {} if utils.root.options.requireAsInclude then subscope.specials.require = compiler["require-include"] + else end for _, val in parser.parser(parser["string-stream"](src), path) do table.insert(forms, val) end for i = 1, #forms do - local subopts = nil + local subopts if (i == #forms) then subopts = {tail = true} else @@ -1786,21 +2205,21 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi end local function include_path(ast, opts, path, mod, fennel_3f) utils.root.scope.includes[mod] = "fnl/loading" - local src = nil + local src do local f = assert(io.open(path)) - local function close_handlers_0_(ok_0_, ...) + local function close_handlers_8_auto(ok_9_auto, ...) f:close() - if ok_0_ then + if ok_9_auto then return ... else return error(..., 0) end end - local function _2_() - return f:read("*all"):gsub("[\13\n]*$", "") + local function _619_() + return assert(f:read("*all")):gsub("[\13\n]*$", "") end - src = close_handlers_0_(xpcall(_2_, (package.loaded.fennel or debug).traceback)) + src = close_handlers_8_auto(_G.xpcall(_619_, (package.loaded.fennel or debug).traceback)) end local ret = utils.expr(("require(\"" .. mod .. "\")"), "statement") local target = ("package.preload[%q]"):format(mod) @@ -1809,8 +2228,8 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi compiler.emit(temp_chunk, preload_str, ast) compiler.emit(temp_chunk, sub_chunk) compiler.emit(temp_chunk, "end", ast) - for i, v in ipairs(temp_chunk) do - table.insert(utils.root.chunk, i, v) + for _, v in ipairs(temp_chunk) do + table.insert(utils.root.chunk, v) end if fennel_3f then emit_included_fennel(src, path, opts, sub_chunk) @@ -1824,11 +2243,25 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi if (utils.root.scope.includes[mod] == "fnl/loading") then compiler.assert(fallback, "circular include detected", ast) return fallback(modexpr) + else + return nil end end SPECIALS.include = function(ast, scope, parent, opts) compiler.assert((#ast == 2), "expected one argument", ast) - local modexpr = compiler.compile1(ast[2], scope, parent, {nval = 1})[1] + local modexpr + do + local _622_, _623_ = pcall(resolve_module_name, ast, scope, parent, opts) + if ((_622_ == true) and (nil ~= _623_)) then + local modname = _623_ + modexpr = utils.expr(string.format("%q", modname), "literal") + elseif true then + local _ = _622_ + modexpr = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1] + else + modexpr = nil + end + end if ((modexpr.type ~= "literal") or ((modexpr[1]):byte() ~= 34)) then if opts.fallback then return opts.fallback(modexpr) @@ -1837,13 +2270,18 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi end else local mod = load_code(("return " .. modexpr[1]))() - local function _3_() - local _2_0 = search_module(mod) - if (nil ~= _2_0) then - local fennel_path = _2_0 + local oldmod = utils.root.options["module-name"] + local _ + utils.root.options["module-name"] = mod + _ = nil + local res + local function _627_() + local _626_ = search_module(mod) + if (nil ~= _626_) then + local fennel_path = _626_ return include_path(ast, opts, fennel_path, mod, true) - else - local _ = _2_0 + elseif true then + local _0 = _626_ local lua_path = search_module(mod, package.path) if lua_path then return include_path(ast, opts, lua_path, mod, false) @@ -1852,9 +2290,13 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi else return compiler.assert(false, ("module not found " .. mod), ast) end + else + return nil end end - return (include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _3_()) + res = ((utils["member?"](mod, (utils.root.options.skipInclude or {})) and opts.fallback(modexpr, true)) or include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _627_()) + utils.root.options["module-name"] = oldmod + return res end end doc_special("include", {"module-name-literal"}, "Like require but load the target module during compilation and embed it in the\nLua output. The module must be a string literal and resolvable at compile time.") @@ -1862,11 +2304,11 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local env = make_compiler_env(ast, scope, parent) local opts = utils.copy(utils.root.options) opts.scope = compiler["make-scope"](compiler.scopes.compiler) - opts.allowedGlobals = macro_globals(env, current_global_names()) - return load_code(compiler.compile(ast, opts), wrap_env(env))(opts["module-name"], ast.filename) + opts.allowedGlobals = current_global_names(env) + return assert(load_code(compiler.compile(ast, opts), wrap_env(env)), opts["module-name"], ast.filename)() end SPECIALS.macros = function(ast, scope, parent) - compiler.assert((#ast == 2), "Expected one table argument", ast) + compiler.assert(((#ast == 2) and utils["table?"](ast[2])), "Expected one table argument", ast) return add_macros(eval_compiler_2a(ast[2], scope, parent), ast, scope, parent) end doc_special("macros", {"{:macro-name-1 (fn [...] ...) ... :macro-name-N macro-body-N}"}, "Define all functions in the given table as macros local to the current scope.") @@ -1874,11 +2316,11 @@ package.preload["nvim-tree-docs.aniseed.fennel.specials"] = package.preload["nvi local old_first = ast[1] ast[1] = utils.sym("do") local val = eval_compiler_2a(ast, scope, parent) - ast[1] = old_first + do end (ast)[1] = old_first return val end doc_special("eval-compiler", {"..."}, "Evaluate the body at compile-time. Use the macro system instead if possible.", true) - return {["current-global-names"] = current_global_names, ["load-code"] = load_code, ["macro-loaded"] = macro_loaded, ["macro-searchers"] = macro_searchers, ["make-compiler-env"] = make_compiler_env, ["make-searcher"] = make_searcher, ["search-module"] = search_module, ["wrap-env"] = wrap_env, doc = doc_2a} + return {doc = doc_2a, ["current-global-names"] = current_global_names, ["load-code"] = load_code, ["macro-loaded"] = macro_loaded, ["macro-searchers"] = macro_searchers, ["make-compiler-env"] = make_compiler_env, ["search-module"] = search_module, ["make-searcher"] = make_searcher, ["wrap-env"] = wrap_env} end package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvim-tree-docs.aniseed.fennel.compiler"] or function(...) local utils = require("nvim-tree-docs.aniseed.fennel.utils") @@ -1886,18 +2328,18 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi local friend = require("nvim-tree-docs.aniseed.fennel.friend") local unpack = (table.unpack or _G.unpack) local scopes = {} - local function make_scope(parent) - local parent0 = (parent or scopes.global) - local _0_ - if parent0 then - _0_ = ((parent0.depth or 0) + 1) + local function make_scope(_3fparent) + local parent = (_3fparent or scopes.global) + local _268_ + if parent then + _268_ = ((parent.depth or 0) + 1) else - _0_ = 0 + _268_ = 0 end - return {autogensyms = setmetatable({}, {__index = (parent0 and parent0.autogensyms)}), depth = _0_, gensyms = setmetatable({}, {__index = (parent0 and parent0.gensyms)}), hashfn = (parent0 and parent0.hashfn), includes = setmetatable({}, {__index = (parent0 and parent0.includes)}), macros = setmetatable({}, {__index = (parent0 and parent0.macros)}), manglings = setmetatable({}, {__index = (parent0 and parent0.manglings)}), parent = parent0, refedglobals = setmetatable({}, {__index = (parent0 and parent0.refedglobals)}), specials = setmetatable({}, {__index = (parent0 and parent0.specials)}), symmeta = setmetatable({}, {__index = (parent0 and parent0.symmeta)}), unmanglings = setmetatable({}, {__index = (parent0 and parent0.unmanglings)}), vararg = (parent0 and parent0.vararg)} + return {includes = setmetatable({}, {__index = (parent and parent.includes)}), macros = setmetatable({}, {__index = (parent and parent.macros)}), manglings = setmetatable({}, {__index = (parent and parent.manglings)}), specials = setmetatable({}, {__index = (parent and parent.specials)}), symmeta = setmetatable({}, {__index = (parent and parent.symmeta)}), unmanglings = setmetatable({}, {__index = (parent and parent.unmanglings)}), gensyms = setmetatable({}, {__index = (parent and parent.gensyms)}), autogensyms = setmetatable({}, {__index = (parent and parent.autogensyms)}), vararg = (parent and parent.vararg), depth = _268_, hashfn = (parent and parent.hashfn), refedglobals = {}, parent = parent} end local function assert_msg(ast, msg) - local ast_tbl = nil + local ast_tbl if ("table" == type(ast)) then ast_tbl = ast else @@ -1906,28 +2348,32 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi local m = getmetatable(ast) local filename = ((m and m.filename) or ast_tbl.filename or "unknown") local line = ((m and m.line) or ast_tbl.line or "?") - local target = nil - local function _1_() - if utils["sym?"](ast_tbl[1]) then - return utils.deref(ast_tbl[1]) - else - return (ast_tbl[1] or "()") - end - end - target = tostring(_1_()) - return string.format("Compile error in '%s' %s:%s: %s", target, filename, line, msg) + local col = ((m and m.col) or ast_tbl.col or "?") + local target = tostring((utils["sym?"](ast_tbl[1]) or ast_tbl[1] or "()")) + return string.format("%s:%s:%s Compile error in '%s': %s", filename, line, col, target, msg) end - local function assert_compile(condition, msg, ast) + local function assert_compile(condition, msg, ast, _3ffallback_ast) if not condition then - local _0_ = (utils.root.options or {}) - local source = _0_["source"] - local unfriendly = _0_["unfriendly"] - utils.root.reset() - if unfriendly then - error(assert_msg(ast, msg), 0) + local _let_271_ = (utils.root.options or {}) + local source = _let_271_["source"] + local unfriendly = _let_271_["unfriendly"] + local error_pinpoint = _let_271_["error-pinpoint"] + local ast0 + if next(utils["ast-source"](ast)) then + ast0 = ast else - friend["assert-compile"](condition, msg, ast, source) + ast0 = (_3ffallback_ast or {}) end + if (nil == utils.hook("assert-compile", condition, msg, ast0, utils.root.reset)) then + utils.root.reset() + if (unfriendly or not friend or not _G.io or not _G.io.read) then + error(assert_msg(ast0, msg), 0) + else + friend["assert-compile"](condition, msg, ast0, source, {["error-pinpoint"] = error_pinpoint}) + end + else + end + else end return condition end @@ -1935,36 +2381,38 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi scopes.global.vararg = true scopes.compiler = make_scope(scopes.global) scopes.macro = scopes.global - local serialize_subst = {["\11"] = "\\v", ["\12"] = "\\f", ["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "n"} + local serialize_subst = {["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "n", ["\11"] = "\\v", ["\12"] = "\\f"} local function serialize_string(str) - local function _0_(_241) + local function _276_(_241) return ("\\" .. _241:byte()) end - return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _0_) + return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _276_) end local function global_mangling(str) if utils["valid-lua-identifier?"](str) then return str else - local function _0_(_241) + local function _277_(_241) return string.format("_%02x", _241:byte()) end - return ("__fnl_global__" .. str:gsub("[^%w]", _0_)) + return ("__fnl_global__" .. str:gsub("[^%w]", _277_)) end end local function global_unmangling(identifier) - local _0_0 = string.match(identifier, "^__fnl_global__(.*)$") - if (nil ~= _0_0) then - local rest = _0_0 - local _1_0 = nil - local function _2_(_241) + local _279_ = string.match(identifier, "^__fnl_global__(.*)$") + if (nil ~= _279_) then + local rest = _279_ + local _280_ + local function _281_(_241) return string.char(tonumber(_241:sub(2), 16)) end - _1_0 = string.gsub(rest, "_[%da-f][%da-f]", _2_) - return _1_0 - else - local _ = _0_0 + _280_ = string.gsub(rest, "_[%da-f][%da-f]", _281_) + return _280_ + elseif true then + local _ = _279_ return identifier + else + return nil end end local allowed_globals = nil @@ -1978,31 +2426,31 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi return mangling end end - local function local_mangling(str, scope, ast, temp_manglings) + local function local_mangling(str, scope, ast, _3ftemp_manglings) assert_compile(not utils["multi-sym?"](str), ("unexpected multi symbol " .. str), ast) - local raw = nil - if (utils["lua-keywords"][str] or str:match("^%d")) then + local raw + if ((utils["lua-keywords"])[str] or str:match("^%d")) then raw = ("_" .. str) else raw = str end - local mangling = nil - local function _1_(_241) + local mangling + local function _285_(_241) return string.format("_%02x", _241:byte()) end - mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _1_) + mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _285_) local unique = unique_mangling(mangling, mangling, scope, 0) - scope.unmanglings[unique] = str + do end (scope.unmanglings)[unique] = str do - local manglings = (temp_manglings or scope.manglings) - manglings[str] = unique + local manglings = (_3ftemp_manglings or scope.manglings) + do end (manglings)[str] = unique end return unique end local function apply_manglings(scope, new_manglings, ast) for raw, mangled in pairs(new_manglings) do assert_compile(not scope.refedglobals[mangled], ("use of global " .. raw .. " is aliased by a local"), ast) - scope.manglings[raw] = mangled + do end (scope.manglings)[raw] = mangled end return nil end @@ -2021,48 +2469,66 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi end return ret end - local function gensym(scope, base) - local append, mangling = 0, ((base or "") .. "_0_") + local function next_append() + utils.root.scope["gensym-append"] = ((utils.root.scope["gensym-append"] or 0) + 1) + return ("_" .. utils.root.scope["gensym-append"] .. "_") + end + local function gensym(scope, _3fbase, _3fsuffix) + local mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or "")) while scope.unmanglings[mangling] do - mangling = ((base or "") .. "_" .. append .. "_") - append = (append + 1) + mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or "")) end - scope.unmanglings[mangling] = (base or true) - scope.gensyms[mangling] = true + scope.unmanglings[mangling] = (_3fbase or true) + do end (scope.gensyms)[mangling] = true return mangling end + local function combine_auto_gensym(parts, first) + parts[1] = first + local last = table.remove(parts) + local last2 = table.remove(parts) + local last_joiner = ((parts["multi-sym-method-call"] and ":") or ".") + table.insert(parts, (last2 .. last_joiner .. last)) + return table.concat(parts, ".") + end local function autogensym(base, scope) - local _0_0 = utils["multi-sym?"](base) - if (nil ~= _0_0) then - local parts = _0_0 - parts[1] = autogensym(parts[1], scope) - return table.concat(parts, ((parts["multi-sym-method-call"] and ":") or ".")) - else - local _ = _0_0 - local function _1_() - local mangling = gensym(scope, base:sub(1, ( - 2))) - scope.autogensyms[base] = mangling + local _288_ = utils["multi-sym?"](base) + if (nil ~= _288_) then + local parts = _288_ + return combine_auto_gensym(parts, autogensym(parts[1], scope)) + elseif true then + local _ = _288_ + local function _289_() + local mangling = gensym(scope, base:sub(1, ( - 2)), "auto") + do end (scope.autogensyms)[base] = mangling return mangling end - return (scope.autogensyms[base] or _1_()) + return (scope.autogensyms[base] or _289_()) + else + return nil end end - local already_warned = {} - local function check_binding_valid(symbol, scope, ast) - local name = utils.deref(symbol) - if (io and io.stderr and name:find("&") and not already_warned[symbol]) then - already_warned[symbol] = true - do end (io.stderr):write(("-- Warning: & will not be allowed in identifier names in " .. "future versions: " .. (symbol.filename or "unknown") .. ":" .. (symbol.line or "?") .. "\n")) + local function check_binding_valid(symbol, scope, ast, _3fopts) + local name = tostring(symbol) + local macro_3f + do + local t_291_ = _3fopts + if (nil ~= t_291_) then + t_291_ = (t_291_)["macro?"] + else + end + macro_3f = t_291_ end - assert_compile(not (scope.specials[name] or scope.macros[name]), ("local %s was overshadowed by a special form or macro"):format(name), ast) + assert_compile(not name:find("&"), "invalid character: &", symbol) + assert_compile(not name:find("^%."), "invalid character: .", symbol) + assert_compile(not (scope.specials[name] or (not macro_3f and scope.macros[name])), ("local %s was overshadowed by a special form or macro"):format(name), ast) return assert_compile(not utils["quoted?"](symbol), string.format("macro tried to bind %s without gensym", name), symbol) end - local function declare_local(symbol, meta, scope, ast, temp_manglings) + local function declare_local(symbol, meta, scope, ast, _3ftemp_manglings) check_binding_valid(symbol, scope, ast) - local name = utils.deref(symbol) + local name = tostring(symbol) assert_compile(not utils["multi-sym?"](name), ("unexpected multi symbol " .. name), ast) - scope.symmeta[name] = meta - return local_mangling(name, scope, ast, temp_manglings) + do end (scope.symmeta)[name] = meta + return local_mangling(name, scope, ast, _3ftemp_manglings) end local function hashfn_arg_name(name, multi_sym_parts, scope) if not scope.hashfn then @@ -2072,38 +2538,45 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi elseif multi_sym_parts then if (multi_sym_parts and (multi_sym_parts[1] == "$")) then multi_sym_parts[1] = "$1" + else end return table.concat(multi_sym_parts, ".") + else + return nil end end - local function symbol_to_expression(symbol, scope, reference_3f) - utils.hook("symbol-to-expression", symbol, scope, reference_3f) + local function symbol_to_expression(symbol, scope, _3freference_3f) + utils.hook("symbol-to-expression", symbol, scope, _3freference_3f) local name = symbol[1] local multi_sym_parts = utils["multi-sym?"](name) local name0 = (hashfn_arg_name(name, multi_sym_parts, scope) or name) local parts = (multi_sym_parts or {name0}) - local etype = (((#parts > 1) and "expression") or "sym") + local etype = (((1 < #parts) and "expression") or "sym") local local_3f = scope.manglings[parts[1]] if (local_3f and scope.symmeta[parts[1]]) then scope.symmeta[parts[1]]["used"] = true + else end - assert_compile((not reference_3f or local_3f or ("_ENV" == parts[1]) or global_allowed_3f(parts[1])), ("unknown global in strict mode: " .. tostring(parts[1])), symbol) - if (allowed_globals and not local_3f) then - utils.root.scope.refedglobals[parts[1]] = true + assert_compile(not scope.macros[parts[1]], "tried to reference a macro without calling it", symbol) + assert_compile((not scope.specials[parts[1]] or ("require" == parts[1])), "tried to reference a special form without calling it", symbol) + assert_compile((not _3freference_3f or local_3f or ("_ENV" == parts[1]) or global_allowed_3f(parts[1])), ("unknown identifier: " .. tostring(parts[1])), symbol) + if (allowed_globals and not local_3f and scope.parent) then + scope.parent.refedglobals[parts[1]] = true + else end return utils.expr(combine_parts(parts, scope), etype) end - local function emit(chunk, out, ast) + local function emit(chunk, out, _3fast) if (type(out) == "table") then return table.insert(chunk, out) else - return table.insert(chunk, {ast = ast, leaf = out}) + return table.insert(chunk, {ast = _3fast, leaf = out}) end end local function peephole(chunk) if chunk.leaf then return chunk - elseif ((#chunk >= 3) and (chunk[(#chunk - 2)].leaf == "do") and not chunk[(#chunk - 1)].leaf and (chunk[#chunk].leaf == "end")) then + elseif ((3 <= #chunk) and (chunk[(#chunk - 2)].leaf == "do") and not chunk[(#chunk - 1)].leaf and (chunk[#chunk].leaf == "end")) then local kid = peephole(chunk[(#chunk - 1)]) local new_chunk = {ast = chunk.ast} for i = 1, (#chunk - 3) do @@ -2117,10 +2590,6 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi return utils.map(chunk, peephole) end end - local function ast_source(ast) - local m = getmetatable(ast) - return ((m and m.line and m) or (("table" == type(ast)) and ast) or {}) - end local function flatten_chunk_correlated(main_chunk, options) local function flatten(chunk, out, last_line, file) local last_line0 = last_line @@ -2128,12 +2597,14 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi out[last_line0] = ((out[last_line0] or "") .. " " .. chunk.leaf) else for _, subchunk in ipairs(chunk) do - if (subchunk.leaf or (#subchunk > 0)) then - local source = ast_source(subchunk.ast) + if (subchunk.leaf or (0 < #subchunk)) then + local source = utils["ast-source"](subchunk.ast) if (file == source.filename) then last_line0 = math.max(last_line0, (source.line or 0)) + else end last_line0 = flatten(subchunk, out, last_line0, file) + else end end end @@ -2144,48 +2615,50 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi for i = 1, last do if (out[i] == nil) then out[i] = "" + else end end return table.concat(out, "\n") end - local function flatten_chunk(sm, chunk, tab, depth) + local function flatten_chunk(file_sourcemap, chunk, tab, depth) if chunk.leaf then - local code = chunk.leaf - local info = chunk.ast - if sm then - table.insert(sm, {(info and info.filename), (info and info.line)}) - end - return code + local _let_303_ = utils["ast-source"](chunk.ast) + local filename = _let_303_["filename"] + local line = _let_303_["line"] + table.insert(file_sourcemap, {filename, line}) + return chunk.leaf else - local tab0 = nil + local tab0 do - local _0_0 = tab - if (_0_0 == true) then + local _304_ = tab + if (_304_ == true) then tab0 = " " - elseif (_0_0 == false) then + elseif (_304_ == false) then tab0 = "" - elseif (_0_0 == tab) then + elseif (_304_ == tab) then tab0 = tab - elseif (_0_0 == nil) then + elseif (_304_ == nil) then tab0 = "" else - tab0 = nil + tab0 = nil end end local function parter(c) - if (c.leaf or (#c > 0)) then - local sub = flatten_chunk(sm, c, tab0, (depth + 1)) - if (depth > 0) then + if (c.leaf or (0 < #c)) then + local sub = flatten_chunk(file_sourcemap, c, tab0, (depth + 1)) + if (0 < depth) then return (tab0 .. sub:gsub("\n", ("\n" .. tab0))) else return sub end + else + return nil end end return table.concat(utils.map(chunk, parter), "\n") end end - local fennel_sourcemap = {} + local sourcemap = {} local function make_short_src(source) local source0 = source:gsub("\n", " ") if (#source0 <= 49) then @@ -2199,36 +2672,37 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi if options.correlate then return flatten_chunk_correlated(chunk0, options), {} else - local sm = {} - local ret = flatten_chunk(sm, chunk0, options.indent, 0) - if sm then - sm.short_src = (options.filename or make_short_src((options.source or ret))) - if options.filename then - sm.key = ("@" .. options.filename) - else - sm.key = ret - end - fennel_sourcemap[sm.key] = sm + local file_sourcemap = {} + local src = flatten_chunk(file_sourcemap, chunk0, options.indent, 0) + file_sourcemap.short_src = (options.filename or make_short_src((options.source or src))) + if options.filename then + file_sourcemap.key = ("@" .. options.filename) + else + file_sourcemap.key = src end - return ret, sm + sourcemap[file_sourcemap.key] = file_sourcemap + return src, file_sourcemap end end local function make_metadata() - local function _0_(self, tgt, key) + local function _312_(self, tgt, key) if self[tgt] then return self[tgt][key] + else + return nil end end - local function _1_(self, tgt, key, value) + local function _314_(self, tgt, key, value) self[tgt] = (self[tgt] or {}) - self[tgt][key] = value + do end (self[tgt])[key] = value return tgt end - local function _2_(self, tgt, ...) + local function _315_(self, tgt, ...) local kv_len = select("#", ...) local kvs = {...} if ((kv_len % 2) ~= 0) then error("metadata:setall() expected even number of k/v pairs") + else end self[tgt] = (self[tgt] or {}) for i = 1, kv_len, 2 do @@ -2236,10 +2710,10 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi end return tgt end - return setmetatable({}, {__index = {get = _0_, set = _1_, setall = _2_}, __mode = "k"}) + return setmetatable({}, {__index = {get = _312_, set = _314_, setall = _315_}, __mode = "k"}) end local function exprs1(exprs) - return table.concat(utils.map(exprs, 1), ", ") + return table.concat(utils.map(exprs, tostring), ", ") end local function keep_side_effects(exprs, chunk, start, ast) local start0 = (start or 1) @@ -2249,13 +2723,14 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi emit(chunk, string.format("do local _ = %s end", tostring(se)), ast) elseif (se.type == "statement") then local code = tostring(se) - local disambiguated = nil + local disambiguated if (code:byte() == 40) then disambiguated = ("do end " .. code) else disambiguated = code end emit(chunk, disambiguated, ast) + else end end return nil @@ -2265,7 +2740,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi local n = opts.nval local len = #exprs if (n ~= len) then - if (len > n) then + if (n < len) then keep_side_effects(exprs, parent, (n + 1), ast) for i = (n + 1), len do exprs[i] = nil @@ -2275,88 +2750,160 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi exprs[i] = utils.expr("nil", "literal") end end + else end + else end if opts.tail then emit(parent, string.format("return %s", exprs1(exprs)), ast) + else end if opts.target then local result = exprs1(exprs) - local function _2_() + local function _323_() if (result == "") then return "nil" else return result end end - emit(parent, string.format("%s = %s", opts.target, _2_()), ast) + emit(parent, string.format("%s = %s", opts.target, _323_()), ast) + else end if (opts.tail or opts.target) then return {returned = true} else - local _3_0 = exprs - _3_0["returned"] = true - return _3_0 + local _325_ = exprs + _325_["returned"] = true + return _325_ end end - local function find_macro(ast, scope, multi_sym_parts) - local function find_in_table(t, i) - if (i <= #multi_sym_parts) then - return find_in_table((utils["table?"](t) and t[multi_sym_parts[i]]), (i + 1)) + local function find_macro(ast, scope) + local macro_2a + do + local _327_ = utils["sym?"](ast[1]) + if (_327_ ~= nil) then + local _328_ = tostring(_327_) + if (_328_ ~= nil) then + macro_2a = scope.macros[_328_] + else + macro_2a = _328_ + end else - return t + macro_2a = _327_ end end - local macro_2a = (utils["sym?"](ast[1]) and scope.macros[utils.deref(ast[1])]) + local multi_sym_parts = utils["multi-sym?"](ast[1]) if (not macro_2a and multi_sym_parts) then - local nested_macro = find_in_table(scope.macros, 1) + local nested_macro = utils["get-in"](scope.macros, multi_sym_parts) assert_compile((not scope.macros[multi_sym_parts[1]] or (type(nested_macro) == "function")), "macro not found in imported macro module", ast) return nested_macro else return macro_2a end end - local function macroexpand_2a(ast, scope, once) - local _0_0 = nil + local function propagate_trace_info(_332_, _index, node) + local _arg_333_ = _332_ + local filename = _arg_333_["filename"] + local line = _arg_333_["line"] + local bytestart = _arg_333_["bytestart"] + local byteend = _arg_333_["byteend"] + do + local src = utils["ast-source"](node) + if (("table" == type(node)) and (filename ~= src.filename)) then + src.filename, src.line, src["from-macro?"] = filename, line, true + src.bytestart, src.byteend = bytestart, byteend + else + end + end + return ("table" == type(node)) + end + local function quote_literal_nils(index, node, parent) + if (parent and utils["list?"](parent)) then + for i = 1, utils.maxn(parent) do + local _335_ = parent[i] + if (_335_ == nil) then + parent[i] = utils.sym("nil") + else + end + end + else + end + return index, node, parent + end + local function comp(f, g) + local function _338_(...) + return f(g(...)) + end + return _338_ + end + local function built_in_3f(m) + local found_3f = false + for _, f in pairs(scopes.global.macros) do + if found_3f then break end + found_3f = (f == m) + end + return found_3f + end + local function macroexpand_2a(ast, scope, _3fonce) + local _339_ if utils["list?"](ast) then - _0_0 = find_macro(ast, scope, utils["multi-sym?"](ast[1])) + _339_ = find_macro(ast, scope) else - _0_0 = nil + _339_ = nil end - if (_0_0 == false) then + if (_339_ == false) then return ast - elseif (nil ~= _0_0) then - local macro_2a = _0_0 + elseif (nil ~= _339_) then + local macro_2a = _339_ local old_scope = scopes.macro - local _ = nil + local _ scopes.macro = scope _ = nil local ok, transformed = nil, nil - local function _2_() + local function _341_() return macro_2a(unpack(ast, 2)) end - ok, transformed = xpcall(_2_, debug.traceback) + local function _342_() + if built_in_3f(macro_2a) then + return tostring + else + return debug.traceback + end + end + ok, transformed = xpcall(_341_, _342_()) + local _344_ + do + local _343_ = ast + local function _345_(...) + return propagate_trace_info(_343_, ...) + end + _344_ = _345_ + end + utils["walk-tree"](transformed, comp(_344_, quote_literal_nils)) scopes.macro = old_scope assert_compile(ok, transformed, ast) - if (once or not transformed) then + if (_3fonce or not transformed) then return transformed else return macroexpand_2a(transformed, scope) end - else - local _ = _0_0 + elseif true then + local _ = _339_ return ast + else + return nil end end local function compile_special(ast, scope, parent, opts, special) local exprs = (special(ast, scope, parent, opts) or utils.expr("nil", "literal")) - local exprs0 = nil - if (type(exprs) == "string") then + local exprs0 + if ("table" ~= type(exprs)) then exprs0 = utils.expr(exprs, "expression") else exprs0 = exprs end - local exprs2 = nil + local exprs2 if utils["expr?"](exprs0) then exprs2 = {exprs0} else @@ -2372,18 +2919,18 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi end local function compile_function_call(ast, scope, parent, opts, compile1, len) local fargs = {} - local fcallee = compile1(ast[1], scope, parent, {nval = 1})[1] - assert_compile((("string" == type(ast[1])) or (fcallee.type ~= "literal")), ("cannot call literal value " .. tostring(ast[1])), ast) + local fcallee = (compile1(ast[1], scope, parent, {nval = 1}))[1] + assert_compile((utils["sym?"](ast[1]) or utils["list?"](ast[1]) or ("string" == type(ast[1]))), ("cannot call literal value " .. tostring(ast[1])), ast) for i = 2, len do - local subexprs = nil - local _0_ + local subexprs + local _351_ if (i ~= len) then - _0_ = 1 + _351_ = 1 else - _0_ = nil + _351_ = nil end - subexprs = compile1(ast[i], scope, parent, {nval = _0_}) - table.insert(fargs, (subexprs[1] or utils.expr("nil", "literal"))) + subexprs = compile1(ast[i], scope, parent, {nval = _351_}) + table.insert(fargs, subexprs[1]) if (i == len) then for j = 2, #subexprs do table.insert(fargs, subexprs[j]) @@ -2392,7 +2939,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi keep_side_effects(subexprs, parent, 2, ast[i]) end end - local pat = nil + local pat if ("string" == type(ast[1])) then pat = "(%s)(%s)" else @@ -2406,27 +2953,33 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi local len = #ast local first = ast[1] local multi_sym_parts = utils["multi-sym?"](first) - local special = (utils["sym?"](first) and scope.specials[utils.deref(first)]) - assert_compile((len > 0), "expected a function, macro, or special to call", ast) + local special = (utils["sym?"](first) and scope.specials[tostring(first)]) + assert_compile((0 < len), "expected a function, macro, or special to call", ast) if special then return compile_special(ast, scope, parent, opts, special) elseif (multi_sym_parts and multi_sym_parts["multi-sym-method-call"]) then local table_with_method = table.concat({unpack(multi_sym_parts, 1, (#multi_sym_parts - 1))}, ".") local method_to_call = multi_sym_parts[#multi_sym_parts] - local new_ast = utils.list(utils.sym(":", nil, scope), utils.sym(table_with_method, nil, scope), method_to_call, select(2, unpack(ast))) + local new_ast = utils.list(utils.sym(":", ast), utils.sym(table_with_method, ast), method_to_call, select(2, unpack(ast))) return compile1(new_ast, scope, parent, opts) else return compile_function_call(ast, scope, parent, opts, compile1, len) end end local function compile_varg(ast, scope, parent, opts) - assert_compile(scope.vararg, "unexpected vararg", ast) + local _356_ + if scope.hashfn then + _356_ = "use $... in hashfn" + else + _356_ = "unexpected vararg" + end + assert_compile(scope.vararg, _356_, ast) return handle_compile_opts({utils.expr("...", "varg")}, parent, opts, ast) end local function compile_sym(ast, scope, parent, opts) local multi_sym_parts = utils["multi-sym?"](ast) assert_compile(not (multi_sym_parts and multi_sym_parts["multi-sym-method-call"]), "multisym method calls may only be in call position", ast) - local e = nil + local e if (ast[1] == "nil") then e = utils.expr("nil", "literal") else @@ -2435,94 +2988,105 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi return handle_compile_opts({e}, parent, opts, ast) end local function serialize_number(n) - local _0_0 = string.gsub(tostring(n), ",", ".") - return _0_0 + local _359_ = string.gsub(tostring(n), ",", ".") + return _359_ end local function compile_scalar(ast, _scope, parent, opts) - local serialize = nil + local serialize do - local _0_0 = type(ast) - if (_0_0 == "nil") then + local _360_ = type(ast) + if (_360_ == "nil") then serialize = tostring - elseif (_0_0 == "boolean") then + elseif (_360_ == "boolean") then serialize = tostring - elseif (_0_0 == "string") then + elseif (_360_ == "string") then serialize = serialize_string - elseif (_0_0 == "number") then + elseif (_360_ == "number") then serialize = serialize_number else - serialize = nil + serialize = nil end end return handle_compile_opts({utils.expr(serialize(ast), "literal")}, parent, opts) end local function compile_table(ast, scope, parent, opts, compile1) - local buffer = {} - for i = 1, #ast do - local nval = ((i ~= #ast) and 1) - table.insert(buffer, exprs1(compile1(ast[i], scope, parent, {nval = nval}))) - end - local function write_other_values(k) - if ((type(k) ~= "number") or (math.floor(k) ~= k) or (k < 1) or (k > #ast)) then - if ((type(k) == "string") and utils["valid-lua-identifier?"](k)) then - return {k, k} + local function escape_key(k) + if ((type(k) == "string") and utils["valid-lua-identifier?"](k)) then + return k + else + local _let_362_ = compile1(k, scope, parent, {nval = 1}) + local compiled = _let_362_[1] + return ("[" .. tostring(compiled) .. "]") + end + end + local keys = {} + local buffer + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for i, elem in ipairs(ast) do + local val_18_auto + do + local nval = ((nil ~= ast[(i + 1)]) and 1) + do end (keys)[i] = true + val_18_auto = exprs1(compile1(elem, scope, parent, {nval = nval})) + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto else - local _0_ = compile1(k, scope, parent, {nval = 1}) - local compiled = _0_[1] - local kstr = ("[" .. tostring(compiled) .. "]") - return {kstr, k} end end + buffer = tbl_16_auto end do - local keys = nil - do - local _0_0 = utils.kvmap(ast, write_other_values) - local function _1_(a, b) - return (a[1] < b[1]) + local tbl_16_auto = buffer + local i_17_auto = #tbl_16_auto + for k, v in utils.stablepairs(ast) do + local val_18_auto + if not keys[k] then + local _let_365_ = compile1(ast[k], scope, parent, {nval = 1}) + local v0 = _let_365_[1] + val_18_auto = string.format("%s = %s", escape_key(k), tostring(v0)) + else + val_18_auto = nil + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else end - table.sort(_0_0, _1_) - keys = _0_0 - end - local function _1_(_2_0) - local _3_ = _2_0 - local k1 = _3_[1] - local k2 = _3_[2] - local _4_ = compile1(ast[k2], scope, parent, {nval = 1}) - local v = _4_[1] - return string.format("%s = %s", k1, tostring(v)) end - utils.map(keys, _1_, buffer) end return handle_compile_opts({utils.expr(("{" .. table.concat(buffer, ", ") .. "}"), "expression")}, parent, opts, ast) end - local function compile1(ast, scope, parent, opts) - local opts0 = (opts or {}) + local function compile1(ast, scope, parent, _3fopts) + local opts = (_3fopts or {}) local ast0 = macroexpand_2a(ast, scope) if utils["list?"](ast0) then - return compile_call(ast0, scope, parent, opts0, compile1) + return compile_call(ast0, scope, parent, opts, compile1) elseif utils["varg?"](ast0) then - return compile_varg(ast0, scope, parent, opts0) + return compile_varg(ast0, scope, parent, opts) elseif utils["sym?"](ast0) then - return compile_sym(ast0, scope, parent, opts0) + return compile_sym(ast0, scope, parent, opts) elseif (type(ast0) == "table") then - return compile_table(ast0, scope, parent, opts0, compile1) + return compile_table(ast0, scope, parent, opts, compile1) elseif ((type(ast0) == "nil") or (type(ast0) == "boolean") or (type(ast0) == "number") or (type(ast0) == "string")) then - return compile_scalar(ast0, scope, parent, opts0) + return compile_scalar(ast0, scope, parent, opts) else return assert_compile(false, ("could not compile value of type " .. type(ast0)), ast0) end end local function destructure(to, from, ast, scope, parent, opts) local opts0 = (opts or {}) - local _0_ = opts0 - local declaration = _0_["declaration"] - local forceglobal = _0_["forceglobal"] - local forceset = _0_["forceset"] - local isvar = _0_["isvar"] - local symtype = _0_["symtype"] + local _let_369_ = opts0 + local isvar = _let_369_["isvar"] + local declaration = _let_369_["declaration"] + local forceglobal = _let_369_["forceglobal"] + local forceset = _let_369_["forceset"] + local symtype = _let_369_["symtype"] local symtype0 = ("_" .. (symtype or "dst")) - local setter = nil + local setter if declaration then setter = "local %s = %s" else @@ -2537,40 +3101,46 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi else local parts = (utils["multi-sym?"](raw) or {raw}) local meta = scope.symmeta[parts[1]] + assert_compile(not raw:find(":"), "cannot set method sym", symbol) if ((#parts == 1) and not forceset) then assert_compile(not (forceglobal and meta), string.format("global %s conflicts with local", tostring(symbol)), symbol) assert_compile(not (meta and not meta.var), ("expected var " .. raw), symbol) - assert_compile((meta or not opts0.noundef), ("expected local " .. parts[1]), symbol) + else end + assert_compile((meta or not opts0.noundef or global_allowed_3f(parts[1])), ("expected local " .. parts[1]), symbol) if forceglobal then assert_compile(not scope.symmeta[scope.unmanglings[raw]], ("global " .. raw .. " conflicts with local"), symbol) - scope.manglings[raw] = global_mangling(raw) - scope.unmanglings[global_mangling(raw)] = raw + do end (scope.manglings)[raw] = global_mangling(raw) + do end (scope.unmanglings)[global_mangling(raw)] = raw if allowed_globals then table.insert(allowed_globals, raw) + else end + else end return symbol_to_expression(symbol, scope)[1] end end local function compile_top_target(lvalues) - local inits = nil - local function _2_(_241) + local inits + local function _375_(_241) if scope.manglings[_241] then return _241 else return "nil" end end - inits = utils.map(lvalues, _2_) + inits = utils.map(lvalues, _375_) local init = table.concat(inits, ", ") local lvalue = table.concat(lvalues, ", ") - local plen, plast = #parent, parent[#parent] + local plast = parent[#parent] + local plen = #parent local ret = compile1(from, scope, parent, {target = lvalue}) if declaration then for pi = plen, #parent do if (parent[pi] == plast) then plen = pi + else end end if ((#parent == (plen + 1)) and parent[#parent].leaf) then @@ -2580,6 +3150,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi else table.insert(parent, (plen + 1), {ast = ast, leaf = ("local " .. lvalue .. " = " .. init)}) end + else end return ret end @@ -2592,54 +3163,88 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi emit(parent, setter:format(lname, exprs1(rightexprs)), left) end if declaration then - scope.symmeta[utils.deref(left)] = {var = isvar} + scope.symmeta[tostring(left)] = {var = isvar} + return nil + else return nil end end - local function destructure_table(left, rightexprs, top_3f, destructure1) - local s = gensym(scope, symtype0) - local right = nil + local unpack_fn = "function (t, k, e)\n local mt = getmetatable(t)\n if 'table' == type(mt) and mt.__fennelrest then\n return mt.__fennelrest(t, k)\n elseif e then\n local rest = {}\n for k, v in pairs(t) do\n if not e[k] then rest[k] = v end\n end\n return rest\n else\n return {(table.unpack or unpack)(t, k)}\n end\n end" + local function destructure_kv_rest(s, v, left, excluded_keys, destructure1) + local exclude_str + local _382_ do - local _2_0 = nil - if top_3f then - _2_0 = exprs1(compile1(from, scope, parent)) - else - _2_0 = exprs1(rightexprs) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, k in ipairs(excluded_keys) do + local val_18_auto = string.format("[%s] = true", serialize_string(k)) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end end - if (_2_0 == "") then + _382_ = tbl_16_auto + end + exclude_str = table.concat(_382_, ", ") + local subexpr = utils.expr(string.format(string.gsub(("(" .. unpack_fn .. ")(%s, %s, {%s})"), "\n%s*", " "), s, tostring(v), exclude_str), "expression") + return destructure1(v, {subexpr}, left) + end + local function destructure_rest(s, k, left, destructure1) + local unpack_str = ("(" .. unpack_fn .. ")(%s, %s)") + local formatted = string.format(string.gsub(unpack_str, "\n%s*", " "), s, k) + local subexpr = utils.expr(formatted, "expression") + assert_compile((utils["sequence?"](left) and (nil == left[(k + 2)])), "expected rest argument before last parameter", left) + return destructure1(left[(k + 1)], {subexpr}, left) + end + local function destructure_table(left, rightexprs, top_3f, destructure1) + local s = gensym(scope, symtype0) + local right + do + local _384_ + if top_3f then + _384_ = exprs1(compile1(from, scope, parent)) + else + _384_ = exprs1(rightexprs) + end + if (_384_ == "") then right = "nil" - elseif (nil ~= _2_0) then - local right0 = _2_0 + elseif (nil ~= _384_) then + local right0 = _384_ right = right0 else - right = nil + right = nil end end + local excluded_keys = {} emit(parent, string.format("local %s = %s", s, right), left) for k, v in utils.stablepairs(left) do if not (("number" == type(k)) and tostring(left[(k - 1)]):find("^&")) then - if (utils["sym?"](v) and (utils.deref(v) == "&")) then - local unpack_str = "{(table.unpack or unpack)(%s, %s)}" - local formatted = string.format(unpack_str, s, k) - local subexpr = utils.expr(formatted, "expression") - assert_compile((utils["sequence?"](left) and (nil == left[(k + 2)])), "expected rest argument before last parameter", left) - destructure1(left[(k + 1)], {subexpr}, left) - elseif (utils["sym?"](k) and (utils.deref(k) == "&as")) then + if (utils["sym?"](k) and (tostring(k) == "&")) then + destructure_kv_rest(s, v, left, excluded_keys, destructure1) + elseif (utils["sym?"](v) and (tostring(v) == "&")) then + destructure_rest(s, k, left, destructure1) + elseif (utils["sym?"](k) and (tostring(k) == "&as")) then destructure_sym(v, {utils.expr(tostring(s))}, left) - elseif (utils["sequence?"](left) and (utils.deref(v) == "&as")) then + elseif (utils["sequence?"](left) and (tostring(v) == "&as")) then local _, next_sym, trailing = select(k, unpack(left)) assert_compile((nil == trailing), "expected &as argument before last parameter", left) destructure_sym(next_sym, {utils.expr(tostring(s))}, left) else - local key = nil + local key if (type(k) == "string") then key = serialize_string(k) else key = k end local subexpr = utils.expr(string.format("%s[%s]", s, key), "expression") + if (type(k) == "string") then + table.insert(excluded_keys, k) + else + end destructure1(v, {subexpr}, left) end + else end end return nil @@ -2652,17 +3257,20 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi else local symname = gensym(scope, symtype0) table.insert(left_names, symname) - tables[i] = {name, utils.expr(symname, "sym")} + do end (tables)[i] = {name, utils.expr(symname, "sym")} end end + assert_compile(left[1], "must provide at least one value", left) assert_compile(top_3f, "can't nest multi-value destructuring", left) compile_top_target(left_names) if declaration then for _, sym in ipairs(left) do if utils["sym?"](sym) then - scope.symmeta[utils.deref(sym)] = {var = isvar} + scope.symmeta[tostring(sym)] = {var = isvar} + else end end + else end for _, pair in utils.stablepairs(tables) do destructure1(pair[1], {pair[2]}, left) @@ -2677,19 +3285,25 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi elseif utils["list?"](left) then destructure_values(left, up1, top_3f, destructure1) else - assert_compile(false, string.format("unable to bind %s %s", type(left), tostring(left)), (((type(up1[2]) == "table") and up1[2]) or up1)) + assert_compile(false, string.format("unable to bind %s %s", type(left), tostring(left)), (((type((up1)[2]) == "table") and (up1)[2]) or up1)) end if top_3f then return {returned = true} + else + return nil end end local ret = destructure1(to, nil, ast, true) - utils.hook("destructure", from, to, scope) + utils.hook("destructure", from, to, scope, opts0) apply_manglings(scope, new_manglings, ast) return ret end local function require_include(ast, scope, parent, opts) - opts.fallback = function(e) + opts.fallback = function(e, no_warn) + if (not no_warn and ("literal" == e.type)) then + utils.warn(("include module not found, falling back to require: %s"):format(tostring(e))) + else + end return utils.expr(string.format("require(%s)", tostring(e)), "statement") end return scopes.global.specials.include(ast, scope, parent, opts) @@ -2700,14 +3314,15 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi local scope = (opts.scope or make_scope(scopes.global)) local vals = {} local chunk = {} - local _0_ = utils.root - _0_["set-reset"](_0_) + do end (function(tgt, m, ...) return tgt[m](tgt, ...) end)(utils.root, "set-reset") allowed_globals = opts.allowedGlobals if (opts.indent == nil) then opts.indent = " " + else end if opts.requireAsInclude then scope.specials.require = require_include + else end utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts for _, val in parser.parser(strm, opts.filename, opts) do @@ -2716,31 +3331,38 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi for i = 1, #vals do local exprs = compile1(vals[i], scope, chunk, {nval = (((i < #vals) and 0) or nil), tail = (i == #vals)}) keep_side_effects(exprs, chunk, nil, vals[i]) + if (i == #vals) then + utils.hook("chunk", vals[i], scope) + else + end end allowed_globals = old_globals utils.root.reset() return flatten(chunk, opts) end - local function compile_string(str, opts) - return compile_stream(parser["string-stream"](str), (opts or {})) + local function compile_string(str, _3fopts) + local opts = (_3fopts or {}) + return compile_stream(parser["string-stream"](str, opts), opts) end local function compile(ast, opts) local opts0 = utils.copy(opts) local old_globals = allowed_globals local chunk = {} local scope = (opts0.scope or make_scope(scopes.global)) - local _0_ = utils.root - _0_["set-reset"](_0_) + do end (function(tgt, m, ...) return tgt[m](tgt, ...) end)(utils.root, "set-reset") allowed_globals = opts0.allowedGlobals if (opts0.indent == nil) then opts0.indent = " " + else end if opts0.requireAsInclude then scope.specials.require = require_include + else end utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts0 local exprs = compile1(ast, scope, chunk, {tail = true}) keep_side_effects(exprs, chunk, nil, ast) + utils.hook("chunk", ast, scope) allowed_globals = old_globals utils.root.reset() return flatten(chunk, opts0) @@ -2751,24 +3373,25 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi elseif (info.what == "C") then return " [C]: in ?" else - local remap = fennel_sourcemap[info.source] + local remap = sourcemap[info.source] if (remap and remap[info.currentline]) then - if remap[info.currentline][1] then - info.short_src = fennel_sourcemap[("@" .. remap[info.currentline][1])].short_src + if ((remap[info.currentline][1] or "unknown") ~= "unknown") then + info.short_src = sourcemap[("@" .. remap[info.currentline][1])].short_src else info.short_src = remap.short_src end info.currentline = (remap[info.currentline][2] or -1) + else end if (info.what == "Lua") then - local function _1_() + local function _404_() if info.name then return ("'" .. info.name .. "'") else return "?" end end - return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _1_()) + return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _404_()) elseif (info.short_src == "(tail call)") then return " (tail call)" else @@ -2776,28 +3399,29 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi end end end - local function traceback(msg, start) - local msg0 = tostring((msg or "")) - if ((msg0:find("^Compile error") or msg0:find("^Parse error")) and not utils["debug-on?"]("trace")) then - return msg0 + local function traceback(_3fmsg, _3fstart) + local msg = tostring((_3fmsg or "")) + if ((msg:find("^%g+:%d+:%d+ Compile error:.*") or msg:find("^%g+:%d+:%d+ Parse error:.*")) and not utils["debug-on?"]("trace")) then + return msg else local lines = {} - if (msg0:find("^Compile error") or msg0:find("^Parse error")) then - table.insert(lines, msg0) + if (msg:find("^%g+:%d+:%d+ Compile error:") or msg:find("^%g+:%d+:%d+ Parse error:")) then + table.insert(lines, msg) else - local newmsg = msg0:gsub("^[^:]*:%d+:%s+", "runtime error: ") + local newmsg = msg:gsub("^[^:]*:%d+:%s+", "runtime error: ") table.insert(lines, newmsg) end table.insert(lines, "stack traceback:") - local done_3f, level = false, (start or 2) + local done_3f, level = false, (_3fstart or 2) while not done_3f do do - local _1_0 = debug.getinfo(level, "Sln") - if (_1_0 == nil) then + local _408_ = debug.getinfo(level, "Sln") + if (_408_ == nil) then done_3f = true - elseif (nil ~= _1_0) then - local info = _1_0 + elseif (nil ~= _408_) then + local info = _408_ table.insert(lines, traceback_frame(info)) + else end end level = (level + 1) @@ -2806,14 +3430,14 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi end end local function entry_transform(fk, fv) - local function _0_(k, v) + local function _411_(k, v) if (type(k) == "number") then return k, fv(v) else return fk(k), fv(v) end end - return _0_ + return _411_ end local function mixed_concat(t, joiner) local seen = {} @@ -2827,6 +3451,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi if not seen[k] then ret = (ret .. s .. "[" .. k .. "]" .. "=" .. v) s = joiner + else end end return ret @@ -2839,30 +3464,30 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi assert_compile(not runtime_3f, "quoted ... may only be used at compile time", form) return "_VARARG" elseif utils["sym?"](form) then - local filename = nil + local filename if form.filename then filename = string.format("%q", form.filename) else filename = "nil" end - local symstr = utils.deref(form) + local symstr = tostring(form) assert_compile(not runtime_3f, "symbols may only be used at compile time", form) if (symstr:find("#$") or symstr:find("#[:.]")) then return string.format("sym('%s', {filename=%s, line=%s})", autogensym(symstr, scope), filename, (form.line or "nil")) else return string.format("sym('%s', {quoted=true, filename=%s, line=%s})", symstr, filename, (form.line or "nil")) end - elseif (utils["list?"](form) and utils["sym?"](form[1]) and (utils.deref(form[1]) == "unquote")) then + elseif (utils["list?"](form) and utils["sym?"](form[1]) and (tostring(form[1]) == "unquote")) then local payload = form[2] local res = unpack(compile1(payload, scope, parent)) return res[1] elseif utils["list?"](form) then - local mapped = nil - local function _0_() + local mapped + local function _416_() return nil end - mapped = utils.kvmap(form, entry_transform(_0_, q)) - local filename = nil + mapped = utils.kvmap(form, entry_transform(_416_, q)) + local filename if form.filename then filename = string.format("%q", form.filename) else @@ -2873,135 +3498,160 @@ package.preload["nvim-tree-docs.aniseed.fennel.compiler"] = package.preload["nvi elseif utils["sequence?"](form) then local mapped = utils.kvmap(form, entry_transform(q, q)) local source = getmetatable(form) - local filename = nil + local filename if source.filename then filename = string.format("%q", source.filename) else filename = "nil" end - local _1_ + local _419_ if source then - _1_ = source.line + _419_ = source.line else - _1_ = "nil" + _419_ = "nil" end - return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _1_, "(getmetatable(sequence()))['sequence']") + return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _419_, "(getmetatable(sequence()))['sequence']") elseif (type(form) == "table") then local mapped = utils.kvmap(form, entry_transform(q, q)) local source = getmetatable(form) - local filename = nil + local filename if source.filename then filename = string.format("%q", source.filename) else filename = "nil" end - local function _1_() + local function _422_() if source then return source.line else return "nil" end end - return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _1_()) + return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _422_()) elseif (type(form) == "string") then return serialize_string(form) else return tostring(form) end end - return {["apply-manglings"] = apply_manglings, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, ["declare-local"] = declare_local, ["do-quote"] = do_quote, ["global-mangling"] = global_mangling, ["global-unmangling"] = global_unmangling, ["keep-side-effects"] = keep_side_effects, ["make-scope"] = make_scope, ["require-include"] = require_include, ["symbol-to-expression"] = symbol_to_expression, assert = assert_compile, autogensym = autogensym, compile = compile, compile1 = compile1, destructure = destructure, emit = emit, gensym = gensym, macroexpand = macroexpand_2a, metadata = make_metadata(), scopes = scopes, traceback = traceback} + return {compile = compile, compile1 = compile1, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, ["check-binding-valid"] = check_binding_valid, emit = emit, destructure = destructure, ["require-include"] = require_include, autogensym = autogensym, gensym = gensym, ["do-quote"] = do_quote, ["global-mangling"] = global_mangling, ["global-unmangling"] = global_unmangling, ["apply-manglings"] = apply_manglings, macroexpand = macroexpand_2a, ["declare-local"] = declare_local, ["make-scope"] = make_scope, ["keep-side-effects"] = keep_side_effects, ["symbol-to-expression"] = symbol_to_expression, assert = assert_compile, scopes = scopes, traceback = traceback, metadata = make_metadata(), sourcemap = sourcemap} end package.preload["nvim-tree-docs.aniseed.fennel.friend"] = package.preload["nvim-tree-docs.aniseed.fennel.friend"] or function(...) - local function ast_source(ast) - local m = getmetatable(ast) - return ((m and m.line and m) or (("table" == type(ast)) and ast) or {}) - end - local suggestions = {["$ and $... in hashfn are mutually exclusive"] = {"modifying the hashfn so it only contains $... or $, $1, $2, $3, etc"}, ["can't start multisym segment with a digit"] = {"removing the digit", "adding a non-digit before the digit"}, ["cannot call literal value"] = {"checking for typos", "checking for a missing function name"}, ["could not compile value of type "] = {"debugging the macro you're calling to return a list or table"}, ["could not read number (.*)"] = {"removing the non-digit character", "beginning the identifier with a non-digit if it is not meant to be a number"}, ["expected a function.* to call"] = {"removing the empty parentheses", "using square brackets if you want an empty table"}, ["expected binding and iterator"] = {"making sure you haven't omitted a local name or iterator"}, ["expected binding table"] = {"placing a table here in square brackets containing identifiers to bind"}, ["expected body expression"] = {"putting some code in the body of this form after the bindings"}, ["expected each macro to be function"] = {"ensuring that the value for each key in your macros table contains a function", "avoid defining nested macro tables"}, ["expected even number of name/value bindings"] = {"finding where the identifier or value is missing"}, ["expected even number of values in table literal"] = {"removing a key", "adding a value"}, ["expected local"] = {"looking for a typo", "looking for a local which is used out of its scope"}, ["expected macros to be table"] = {"ensuring your macro definitions return a table"}, ["expected parameters"] = {"adding function parameters as a list of identifiers in brackets"}, ["expected rest argument before last parameter"] = {"moving & to right before the final identifier when destructuring"}, ["expected symbol for function parameter: (.*)"] = {"changing %s to an identifier instead of a literal value"}, ["expected var (.*)"] = {"declaring %s using var instead of let/local", "introducing a new local instead of changing the value of %s"}, ["expected vararg as last parameter"] = {"moving the \"...\" to the end of the parameter list"}, ["expected whitespace before opening delimiter"] = {"adding whitespace"}, ["global (.*) conflicts with local"] = {"renaming local %s"}, ["illegal character: (.)"] = {"deleting or replacing %s", "avoiding reserved characters like \", \\, ', ~, ;, @, `, and comma"}, ["local (.*) was overshadowed by a special form or macro"] = {"renaming local %s"}, ["macro not found in macro module"] = {"checking the keys of the imported macro module's returned table"}, ["macro tried to bind (.*) without gensym"] = {"changing to %s# when introducing identifiers inside macros"}, ["malformed multisym"] = {"ensuring each period or colon is not followed by another period or colon"}, ["may only be used at compile time"] = {"moving this to inside a macro if you need to manipulate symbols/lists", "using square brackets instead of parens to construct a table"}, ["method must be last component"] = {"using a period instead of a colon for field access", "removing segments after the colon", "making the method call, then looking up the field on the result"}, ["mismatched closing delimiter (.), expected (.)"] = {"replacing %s with %s", "deleting %s", "adding matching opening delimiter earlier"}, ["multisym method calls may only be in call position"] = {"using a period instead of a colon to reference a table's fields", "putting parens around this"}, ["unable to bind (.*)"] = {"replacing the %s with an identifier"}, ["unexpected closing delimiter (.)"] = {"deleting %s", "adding matching opening delimiter earlier"}, ["unexpected multi symbol (.*)"] = {"removing periods or colons from %s"}, ["unexpected vararg"] = {"putting \"...\" at the end of the fn parameters if the vararg was intended"}, ["unknown global in strict mode: (.*)"] = {"looking to see if there's a typo", "using the _G table instead, eg. _G.%s if you really want a global", "moving this code to somewhere that %s is in scope", "binding %s as a local in the scope of this code"}, ["unused local (.*)"] = {"fixing a typo so %s is used", "renaming the local to _%s"}, ["use of global (.*) is aliased by a local"] = {"renaming local %s", "refer to the global using _G.%s instead of directly"}} + local utils = require("nvim-tree-docs.aniseed.fennel.utils") + local utf8_ok_3f, utf8 = pcall(require, "utf8") + local suggestions = {["unexpected multi symbol (.*)"] = {"removing periods or colons from %s"}, ["use of global (.*) is aliased by a local"] = {"renaming local %s", "refer to the global using _G.%s instead of directly"}, ["local (.*) was overshadowed by a special form or macro"] = {"renaming local %s"}, ["global (.*) conflicts with local"] = {"renaming local %s"}, ["expected var (.*)"] = {"declaring %s using var instead of let/local", "introducing a new local instead of changing the value of %s"}, ["expected macros to be table"] = {"ensuring your macro definitions return a table"}, ["expected each macro to be function"] = {"ensuring that the value for each key in your macros table contains a function", "avoid defining nested macro tables"}, ["macro not found in macro module"] = {"checking the keys of the imported macro module's returned table"}, ["macro tried to bind (.*) without gensym"] = {"changing to %s# when introducing identifiers inside macros"}, ["unknown identifier: (.*)"] = {"looking to see if there's a typo", "using the _G table instead, eg. _G.%s if you really want a global", "moving this code to somewhere that %s is in scope", "binding %s as a local in the scope of this code"}, ["expected a function.* to call"] = {"removing the empty parentheses", "using square brackets if you want an empty table"}, ["cannot call literal value"] = {"checking for typos", "checking for a missing function name", "making sure to use prefix operators, not infix"}, ["unexpected vararg"] = {"putting \"...\" at the end of the fn parameters if the vararg was intended"}, ["multisym method calls may only be in call position"] = {"using a period instead of a colon to reference a table's fields", "putting parens around this"}, ["unused local (.*)"] = {"renaming the local to _%s if it is meant to be unused", "fixing a typo so %s is used", "disabling the linter which checks for unused locals"}, ["expected parameters"] = {"adding function parameters as a list of identifiers in brackets"}, ["unable to bind (.*)"] = {"replacing the %s with an identifier"}, ["expected rest argument before last parameter"] = {"moving & to right before the final identifier when destructuring"}, ["expected vararg as last parameter"] = {"moving the \"...\" to the end of the parameter list"}, ["expected symbol for function parameter: (.*)"] = {"changing %s to an identifier instead of a literal value"}, ["could not compile value of type "] = {"debugging the macro you're calling to return a list or table"}, ["expected local"] = {"looking for a typo", "looking for a local which is used out of its scope"}, ["expected body expression"] = {"putting some code in the body of this form after the bindings"}, ["expected binding and iterator"] = {"making sure you haven't omitted a local name or iterator"}, ["expected binding sequence"] = {"placing a table here in square brackets containing identifiers to bind"}, ["expected even number of name/value bindings"] = {"finding where the identifier or value is missing"}, ["may only be used at compile time"] = {"moving this to inside a macro if you need to manipulate symbols/lists", "using square brackets instead of parens to construct a table"}, ["unexpected closing delimiter (.)"] = {"deleting %s", "adding matching opening delimiter earlier"}, ["mismatched closing delimiter (.), expected (.)"] = {"replacing %s with %s", "deleting %s", "adding matching opening delimiter earlier"}, ["expected even number of values in table literal"] = {"removing a key", "adding a value"}, ["expected whitespace before opening delimiter"] = {"adding whitespace"}, ["invalid character: (.)"] = {"deleting or replacing %s", "avoiding reserved characters like \", \\, ', ~, ;, @, `, and comma"}, ["could not read number (.*)"] = {"removing the non-digit character", "beginning the identifier with a non-digit if it is not meant to be a number"}, ["can't start multisym segment with a digit"] = {"removing the digit", "adding a non-digit before the digit"}, ["malformed multisym"] = {"ensuring each period or colon is not followed by another period or colon"}, ["method must be last component"] = {"using a period instead of a colon for field access", "removing segments after the colon", "making the method call, then looking up the field on the result"}, ["$ and $... in hashfn are mutually exclusive"] = {"modifying the hashfn so it only contains $... or $, $1, $2, $3, etc"}, ["tried to reference a macro without calling it"] = {"renaming the macro so as not to conflict with locals"}, ["tried to reference a special form without calling it"] = {"making sure to use prefix operators, not infix", "wrapping the special in a function if you need it to be first class"}, ["missing subject"] = {"adding an item to operate on"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["expected at least one pattern/body pair"] = {"adding a pattern and a body to execute when the pattern matches"}, ["unexpected arguments"] = {"removing an argument", "checking for typos"}, ["unexpected iterator clause"] = {"removing an argument", "checking for typos"}} local unpack = (table.unpack or _G.unpack) local function suggest(msg) - local suggestion = nil + local s = nil for pat, sug in pairs(suggestions) do + if s then break end local matches = {msg:match(pat)} if (0 < #matches) then - if ("table" == type(sug)) then - local out = {} - for _, s in ipairs(sug) do - table.insert(out, s:format(unpack(matches))) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, s0 in ipairs(sug) do + local val_18_auto = s0:format(unpack(matches)) + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else end - suggestion = out + end + s = tbl_16_auto + else + s = nil + end + end + return s + end + local function read_line(filename, line, _3fsource) + if _3fsource then + local matcher = string.gmatch((_3fsource .. "\n"), "(.-)(\13?\n)") + for _ = 2, line do + matcher() + end + return matcher() + else + local f = assert(io.open(filename)) + local function close_handlers_8_auto(ok_9_auto, ...) + f:close() + if ok_9_auto then + return ... else - suggestion = sug(matches) + return error(..., 0) + end + end + local function _185_() + for _ = 2, line do + f:read() end + return f:read() end + return close_handlers_8_auto(_G.xpcall(_185_, (package.loaded.fennel or debug).traceback)) end - return suggestion end - local function read_line_from_file(filename, line) - local bytes = 0 - local f = assert(io.open(filename)) - local _ = nil - for _0 = 1, (line - 1) do - bytes = (bytes + 1 + #f:read()) + local function sub(str, start, _end) + if ((_end < start) or (#str < start) or (#str < _end)) then + return "" + elseif utf8_ok_3f then + return string.sub(str, utf8.offset(str, start), ((utf8.offset(str, (_end + 1)) or (utf8.len(str) + 1)) - 1)) + else + return string.sub(str, start, math.min(_end, str:len())) end - _ = nil - local codeline = f:read() - f:close() - return codeline, bytes - end - local function read_line_from_string(matcher, target_line, _3fcurrent_line, _3fbytes) - local this_line, newline = matcher() - local current_line = (_3fcurrent_line or 1) - local bytes = ((_3fbytes or 0) + #this_line + #newline) - if (target_line == current_line) then - return this_line, bytes - elseif this_line then - return read_line_from_string(matcher, target_line, (current_line + 1), bytes) - end - end - local function read_line(filename, line, source) - if source then - return read_line_from_string(string.gmatch((source .. "\n"), "(.-)(\13?\n)"), line) - else - return read_line_from_file(filename, line) - end - end - local function friendly_msg(msg, _0_0, source) - local _1_ = _0_0 - local byteend = _1_["byteend"] - local bytestart = _1_["bytestart"] - local filename = _1_["filename"] - local line = _1_["line"] - local ok, codeline, bol = pcall(read_line, filename, line, source) - local suggestions0 = suggest(msg) + end + local function highlight_line(codeline, col, _3fendcol, opts) + if ((opts and (false == opts["error-pinpoint"])) or (os and os.getenv and os.getenv("NO_COLOR"))) then + return codeline + else + local _let_188_ = (opts or {}) + local error_pinpoint = _let_188_["error-pinpoint"] + local endcol = (_3fendcol or col) + local eol + if utf8_ok_3f then + eol = utf8.len(codeline) + else + eol = string.len(codeline) + end + local _let_190_ = (error_pinpoint or {"\27[7m", "\27[0m"}) + local open = _let_190_[1] + local close = _let_190_[2] + return (sub(codeline, 1, col) .. open .. sub(codeline, (col + 1), (endcol + 1)) .. close .. sub(codeline, (endcol + 2), eol)) + end + end + local function friendly_msg(msg, _192_, source, opts) + local _arg_193_ = _192_ + local filename = _arg_193_["filename"] + local line = _arg_193_["line"] + local col = _arg_193_["col"] + local endcol = _arg_193_["endcol"] + local ok, codeline = pcall(read_line, filename, line, source) local out = {msg, ""} if (ok and codeline) then - table.insert(out, codeline) - end - if (ok and codeline and bytestart and byteend) then - table.insert(out, (string.rep(" ", (bytestart - bol - 1)) .. "^" .. string.rep("^", math.min((byteend - bytestart), ((bol + #codeline) - bytestart))))) - end - if (ok and codeline and bytestart and not byteend) then - table.insert(out, (string.rep("-", (bytestart - bol - 1)) .. "^")) - table.insert(out, "") - end - if suggestions0 then - for _, suggestion in ipairs(suggestions0) do - table.insert(out, ("* Try %s."):format(suggestion)) + if col then + table.insert(out, highlight_line(codeline, col, endcol, opts)) + else + table.insert(out, codeline) end + else + end + for _, suggestion in ipairs((suggest(msg) or {})) do + table.insert(out, ("* Try %s."):format(suggestion)) end return table.concat(out, "\n") end - local function assert_compile(condition, msg, ast, source) + local function assert_compile(condition, msg, ast, source, opts) if not condition then - local _1_ = ast_source(ast) - local filename = _1_["filename"] - local line = _1_["line"] - error(friendly_msg(("Compile error in %s:%s\n %s"):format((filename or "unknown"), (line or "?"), msg), ast_source(ast), source), 0) + local _let_196_ = utils["ast-source"](ast) + local filename = _let_196_["filename"] + local line = _let_196_["line"] + local col = _let_196_["col"] + error(friendly_msg(("%s:%s:%s Compile error: %s"):format((filename or "unknown"), (line or "?"), (col or "?"), msg), utils["ast-source"](ast), source, opts), 0) + else end return condition end - local function parse_error(msg, filename, line, bytestart, source) - return error(friendly_msg(("Parse error in %s:%s\n %s"):format(filename, line, msg), {bytestart = bytestart, filename = filename, line = line}, source), 0) + local function parse_error(msg, filename, line, col, source, opts) + return error(friendly_msg(("%s:%s:%s Parse error: %s"):format(filename, line, col, msg), {filename = filename, line = line, col = col}, source, opts), 0) end return {["assert-compile"] = assert_compile, ["parse-error"] = parse_error} end @@ -3011,70 +3661,85 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- local unpack = (table.unpack or _G.unpack) local function granulate(getchunk) local c, index, done_3f = "", 1, false - local function _0_(parser_state) + local function _198_(parser_state) if not done_3f then if (index <= #c) then local b = c:byte(index) index = (index + 1) return b else - local _1_0, _2_0, _3_0 = getchunk(parser_state) - local _4_ - do - local char = _1_0 - _4_ = ((nil ~= _1_0) and (char ~= "")) + local _199_ = getchunk(parser_state) + local function _200_() + local char = _199_ + return (char ~= "") end - if _4_ then - local char = _1_0 + if ((nil ~= _199_) and _200_()) then + local char = _199_ c = char index = 2 return c:byte() - else - local _ = _1_0 + elseif true then + local _ = _199_ done_3f = true return nil + else + return nil end end + else + return nil end end - local function _1_() + local function _204_() c = "" return nil end - return _0_, _1_ + return _198_, _204_ end - local function string_stream(str) + local function string_stream(str, _3foptions) local str0 = str:gsub("^#!", ";;") + if _3foptions then + _3foptions.source = str0 + else + end local index = 1 - local function _0_() + local function _206_() local r = str0:byte(index) index = (index + 1) return r end - return _0_ - end - local delims = {[123] = 125, [125] = true, [40] = 41, [41] = true, [91] = 93, [93] = true} - local function whitespace_3f(b) - return ((b == 32) or ((b >= 9) and (b <= 13))) + return _206_ end + local delims = {[40] = 41, [41] = true, [91] = 93, [93] = true, [123] = 125, [125] = true} local function sym_char_3f(b) - local b0 = nil + local b0 if ("number" == type(b)) then b0 = b else b0 = string.byte(b) end - return ((b0 > 32) and not delims[b0] and (b0 ~= 127) and (b0 ~= 34) and (b0 ~= 39) and (b0 ~= 126) and (b0 ~= 59) and (b0 ~= 44) and (b0 ~= 64) and (b0 ~= 96)) + return ((32 < b0) and not delims[b0] and (b0 ~= 127) and (b0 ~= 34) and (b0 ~= 39) and (b0 ~= 126) and (b0 ~= 59) and (b0 ~= 44) and (b0 ~= 64) and (b0 ~= 96)) end local prefixes = {[35] = "hashfn", [39] = "quote", [44] = "unquote", [96] = "quote"} - local function parser(getbyte, filename, options) + local function char_starter_3f(b) + return ((function(_208_,_209_,_210_) return (_208_ < _209_) and (_209_ < _210_) end)(1,b,127) or (function(_211_,_212_,_213_) return (_211_ < _212_) and (_212_ < _213_) end)(192,b,247)) + end + local function parser_fn(getbyte, filename, _214_) + local _arg_215_ = _214_ + local source = _arg_215_["source"] + local unfriendly = _arg_215_["unfriendly"] + local comments = _arg_215_["comments"] + local options = _arg_215_ local stack = {} - local line = 1 - local byteindex = 0 - local lastb = nil + local line, byteindex, col, prev_col, lastb = 1, 0, 0, 0, nil local function ungetb(ub) + if char_starter_3f(ub) then + col = (col - 1) + else + end if (ub == 10) then - line = (line - 1) + line, col = (line - 1), prev_col + else end byteindex = (byteindex - 1) lastb = ub @@ -3088,64 +3753,87 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- r = getbyte({["stack-size"] = #stack}) end byteindex = (byteindex + 1) + if (r and char_starter_3f(r)) then + col = (col + 1) + else + end if (r == 10) then - line = (line + 1) + line, col, prev_col = (line + 1), 0, col + else end return r end - assert(((nil == filename) or ("string" == type(filename))), "expected filename as second argument to parser") - local function parse_error(msg, byteindex_override) - local _0_ = (options or utils.root.options or {}) - local source = _0_["source"] - local unfriendly = _0_["unfriendly"] - utils.root.reset() - if unfriendly then - return error(string.format("Parse error in %s:%s: %s", (filename or "unknown"), (line or "?"), msg), 0) + local function whitespace_3f(b) + local function _225_() + local t_224_ = options.whitespace + if (nil ~= t_224_) then + t_224_ = (t_224_)[b] + else + end + return t_224_ + end + return ((b == 32) or (function(_221_,_222_,_223_) return (_221_ <= _222_) and (_222_ <= _223_) end)(9,b,13) or _225_()) + end + local function parse_error(msg, _3fcol_adjust) + local col0 = (col + (_3fcol_adjust or -1)) + if (nil == utils["hook-opts"]("parse-error", options, msg, filename, (line or "?"), col0, source, utils.root.reset)) then + utils.root.reset() + if (unfriendly or not _G.io or not _G.io.read) then + return error(string.format("%s:%s:%s Parse error: %s", filename, (line or "?"), col0, msg), 0) + else + return friend["parse-error"](msg, filename, (line or "?"), col0, source, options) + end else - return friend["parse-error"](msg, (filename or "unknown"), (line or "?"), (byteindex_override or byteindex), source) + return nil end end local function parse_stream() local whitespace_since_dispatch, done_3f, retval = true + local function set_source_fields(source0) + source0.byteend, source0.endcol = byteindex, (col - 1) + return nil + end local function dispatch(v) - local _0_0 = stack[#stack] - if (_0_0 == nil) then + local _229_ = stack[#stack] + if (_229_ == nil) then retval, done_3f, whitespace_since_dispatch = v, true, false return nil - elseif ((type(_0_0) == "table") and (nil ~= _0_0.prefix)) then - local prefix = _0_0.prefix - local source = nil + elseif ((_G.type(_229_) == "table") and (nil ~= (_229_).prefix)) then + local prefix = (_229_).prefix + local source0 do - local _1_0 = table.remove(stack) - _1_0["byteend"] = byteindex - source = _1_0 + local _230_ = table.remove(stack) + set_source_fields(_230_) + source0 = _230_ end - local list = utils.list(utils.sym(prefix, source), v) - for k, v0 in pairs(source) do + local list = utils.list(utils.sym(prefix, source0), v) + for k, v0 in pairs(source0) do list[k] = v0 end return dispatch(list) - elseif (nil ~= _0_0) then - local top = _0_0 + elseif (nil ~= _229_) then + local top = _229_ whitespace_since_dispatch = false return table.insert(top, v) + else + return nil end end local function badend() local accum = utils.map(stack, "closer") - local _0_ + local _232_ if (#stack == 1) then - _0_ = "" + _232_ = "" else - _0_ = "s" + _232_ = "s" end - return parse_error(string.format("expected closing delimiter%s %s", _0_, string.char(unpack(accum)))) + return parse_error(string.format("expected closing delimiter%s %s", _232_, string.char(unpack(accum)))) end local function skip_whitespace(b) if (b and whitespace_3f(b)) then whitespace_since_dispatch = true return skip_whitespace(getb()) - elseif (not b and (#stack > 0)) then + elseif (not b and (0 < #stack)) then return badend() else return b @@ -3153,23 +3841,25 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- end local function parse_comment(b, contents) if (b and (10 ~= b)) then - local function _1_() - local _0_0 = contents - table.insert(_0_0, string.char(b)) - return _0_0 + local function _236_() + local _235_ = contents + table.insert(_235_, string.char(b)) + return _235_ end - return parse_comment(getb(), _1_()) - elseif (options and options.comments) then - return dispatch(utils.comment(table.concat(contents), {filename = filename, line = (line - 1)})) + return parse_comment(getb(), _236_()) + elseif comments then + ungetb(10) + return dispatch(utils.comment(table.concat(contents), {line = line, filename = filename})) else - return b + return nil end end local function open_table(b) if not whitespace_since_dispatch then parse_error(("expected whitespace before opening delimiter " .. string.char(b))) + else end - return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = filename, line = line}) + return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = filename, line = line, col = (col - 1)}) end local function close_list(list) return dispatch(setmetatable(list, getmetatable(utils.list()))) @@ -3181,63 +3871,70 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- end return dispatch(val) end - local function add_comment_at(comments, index, node) - local _0_0 = comments[index] - if (nil ~= _0_0) then - local existing = _0_0 + local function add_comment_at(comments0, index, node) + local _239_ = (comments0)[index] + if (nil ~= _239_) then + local existing = _239_ return table.insert(existing, node) + elseif true then + local _ = _239_ + comments0[index] = {node} + return nil else - local _ = _0_0 - comments[index] = {node} return nil end end local function next_noncomment(tbl, i) if utils["comment?"](tbl[i]) then return next_noncomment(tbl, (i + 1)) + elseif (utils.sym(":") == tbl[i]) then + return tostring(tbl[(i + 1)]) else return tbl[i] end end local function extract_comments(tbl) - local comments = {keys = {}, last = {}, values = {}} + local comments0 = {keys = {}, values = {}, last = {}} while utils["comment?"](tbl[#tbl]) do - table.insert(comments.last, 1, table.remove(tbl)) + table.insert(comments0.last, 1, table.remove(tbl)) end local last_key_3f = false for i, node in ipairs(tbl) do if not utils["comment?"](node) then last_key_3f = not last_key_3f elseif last_key_3f then - add_comment_at(comments.values, next_noncomment(tbl, i), node) + add_comment_at(comments0.values, next_noncomment(tbl, i), node) else - add_comment_at(comments.keys, next_noncomment(tbl, i), node) + add_comment_at(comments0.keys, next_noncomment(tbl, i), node) end end for i = #tbl, 1, -1 do if utils["comment?"](tbl[i]) then table.remove(tbl, i) + else end end - return comments + return comments0 end local function close_curly_table(tbl) - local comments = extract_comments(tbl) + local comments0 = extract_comments(tbl) local keys = {} local val = {} if ((#tbl % 2) ~= 0) then byteindex = (byteindex - 1) parse_error("expected even number of values in table literal") + else end setmetatable(val, tbl) for i = 1, #tbl, 2 do if ((tostring(tbl[i]) == ":") and utils["sym?"](tbl[(i + 1)]) and utils["sym?"](tbl[i])) then tbl[i] = tostring(tbl[(i + 1)]) + else end val[tbl[i]] = tbl[(i + 1)] table.insert(keys, tbl[i]) end - tbl.comments = comments + tbl.comments = comments0 tbl.keys = keys return dispatch(val) end @@ -3245,11 +3942,13 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- local top = table.remove(stack) if (top == nil) then parse_error(("unexpected closing delimiter " .. string.char(b))) + else end if (top.closer and (top.closer ~= b)) then parse_error(("mismatched closing delimiter " .. string.char(b) .. ", expected " .. string.char(top.closer))) + else end - top.byteend = byteindex + set_source_fields(top) if (b == 41) then return close_list(top) elseif (b == 93) then @@ -3260,16 +3959,21 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- end local function parse_string_loop(chars, b, state) table.insert(chars, b) - local state0 = nil + local state0 do - local _0_0 = {state, b} - if ((type(_0_0) == "table") and (_0_0[1] == "base") and (_0_0[2] == 92)) then + local _249_ = {state, b} + if ((_G.type(_249_) == "table") and ((_249_)[1] == "base") and ((_249_)[2] == 92)) then state0 = "backslash" - elseif ((type(_0_0) == "table") and (_0_0[1] == "base") and (_0_0[2] == 34)) then + elseif ((_G.type(_249_) == "table") and ((_249_)[1] == "base") and ((_249_)[2] == 34)) then state0 = "done" - else - local _ = _0_0 + elseif ((_G.type(_249_) == "table") and ((_249_)[1] == "backslash") and ((_249_)[2] == 10)) then + table.remove(chars, (#chars - 1)) + state0 = "base" + elseif true then + local _ = _249_ state0 = "base" + else + state0 = nil end end if (b and (state0 ~= "done")) then @@ -3279,34 +3983,39 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- end end local function escape_char(c) - return ({nil, nil, nil, nil, nil, nil, "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r"})[c:byte()] + return ({[7] = "\\a", [8] = "\\b", [9] = "\\t", [10] = "\\n", [11] = "\\v", [12] = "\\f", [13] = "\\r"})[c:byte()] end local function parse_string() table.insert(stack, {closer = 34}) local chars = {34} if not parse_string_loop(chars, getb(), "base") then badend() + else end table.remove(stack) local raw = string.char(unpack(chars)) local formatted = raw:gsub("[\7-\13]", escape_char) - local _1_0 = (rawget(_G, "loadstring") or load)(("return " .. formatted)) - if (nil ~= _1_0) then - local load_fn = _1_0 + local _253_ = (rawget(_G, "loadstring") or load)(("return " .. formatted)) + if (nil ~= _253_) then + local load_fn = _253_ return dispatch(load_fn()) - elseif (_1_0 == nil) then + elseif (_253_ == nil) then return parse_error(("Invalid string: " .. raw)) + else + return nil end end local function parse_prefix(b) - table.insert(stack, {bytestart = byteindex, filename = filename, line = line, prefix = prefixes[b]}) + table.insert(stack, {prefix = prefixes[b], filename = filename, line = line, bytestart = byteindex, col = (col - 1)}) local nextb = getb() if (whitespace_3f(nextb) or (true == delims[nextb])) then if (b ~= 35) then parse_error("invalid whitespace after quoting prefix") + else end table.remove(stack) dispatch(utils.sym("#")) + else end return ungetb(nextb) end @@ -3317,6 +4026,7 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- else if b then ungetb(b) + else end return chars end @@ -3327,43 +4037,53 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- dispatch((tonumber(number_with_stripped_underscores) or parse_error(("could not read number \"" .. rawstr .. "\"")))) return true else - local _0_0 = tonumber(number_with_stripped_underscores) - if (nil ~= _0_0) then - local x = _0_0 + local _259_ = tonumber(number_with_stripped_underscores) + if (nil ~= _259_) then + local x = _259_ dispatch(x) return true - else - local _ = _0_0 + elseif true then + local _ = _259_ return false + else + return nil end end end local function check_malformed_sym(rawstr) + local function col_adjust(pat) + return (rawstr:find(pat) - utils.len(rawstr) - 1) + end if (rawstr:match("^~") and (rawstr ~= "~=")) then - return parse_error("illegal character: ~") + return parse_error("invalid character: ~") elseif rawstr:match("%.[0-9]") then - return parse_error(("can't start multisym segment with a digit: " .. rawstr), (((byteindex - #rawstr) + rawstr:find("%.[0-9]")) + 1)) + return parse_error(("can't start multisym segment with a digit: " .. rawstr), col_adjust("%.[0-9]")) elseif (rawstr:match("[%.:][%.:]") and (rawstr ~= "..") and (rawstr ~= "$...")) then - return parse_error(("malformed multisym: " .. rawstr), ((byteindex - #rawstr) + 1 + rawstr:find("[%.:][%.:]"))) + return parse_error(("malformed multisym: " .. rawstr), col_adjust("[%.:][%.:]")) + elseif ((rawstr ~= ":") and rawstr:match(":$")) then + return parse_error(("malformed multisym: " .. rawstr), col_adjust(":$")) elseif rawstr:match(":.+[%.:]") then - return parse_error(("method must be last component of multisym: " .. rawstr), ((byteindex - #rawstr) + rawstr:find(":.+[%.:]"))) + return parse_error(("method must be last component of multisym: " .. rawstr), col_adjust(":.+[%.:]")) else return rawstr end end local function parse_sym(b) - local bytestart = byteindex + local source0 = {bytestart = byteindex, filename = filename, line = line, col = (col - 1)} local rawstr = string.char(unpack(parse_sym_loop({b}, getb()))) + set_source_fields(source0) if (rawstr == "true") then return dispatch(true) elseif (rawstr == "false") then return dispatch(false) elseif (rawstr == "...") then - return dispatch(utils.varg()) + return dispatch(utils.varg(source0)) elseif rawstr:match("^:.+$") then return dispatch(rawstr:sub(2)) elseif not parse_number(rawstr) then - return dispatch(utils.sym(check_malformed_sym(rawstr), {byteend = byteindex, bytestart = bytestart, filename = filename, line = line})) + return dispatch(utils.sym(check_malformed_sym(rawstr), source0)) + else + return nil end end local function parse_loop(b) @@ -3380,120 +4100,930 @@ package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim- parse_prefix(b) elseif (sym_char_3f(b) or (b == string.byte("~"))) then parse_sym(b) + elseif not utils["hook-opts"]("illegal-char", options, b, getb, ungetb, dispatch) then + parse_error(("invalid character: " .. string.char(b))) else - parse_error(("illegal character: " .. string.char(b))) end if not b then return nil elseif done_3f then return true, retval else - return parse_loop(skip_whitespace(getb())) + return parse_loop(skip_whitespace(getb())) + end + end + return parse_loop(skip_whitespace(getb())) + end + local function _266_() + stack, line, byteindex, col, lastb = {}, 1, 0, 0, nil + return nil + end + return parse_stream, _266_ + end + local function parser(stream_or_string, _3ffilename, _3foptions) + local filename = (_3ffilename or "unknown") + local options = (_3foptions or utils.root.options or {}) + assert(("string" == type(filename)), "expected filename as second argument to parser") + if ("string" == type(stream_or_string)) then + return parser_fn(string_stream(stream_or_string, options), filename, options) + else + return parser_fn(stream_or_string, filename, options) + end + end + return {granulate = granulate, parser = parser, ["string-stream"] = string_stream, ["sym-char?"] = sym_char_3f} +end +local utils +package.preload["nvim-tree-docs.aniseed.fennel.view"] = package.preload["nvim-tree-docs.aniseed.fennel.view"] or function(...) + local type_order = {number = 1, boolean = 2, string = 3, table = 4, ["function"] = 5, userdata = 6, thread = 7} + local default_opts = {["one-line?"] = false, ["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["metamethod?"] = true, ["prefer-colon?"] = false, ["escape-newlines?"] = false, ["utf8?"] = true, ["line-length"] = 80, depth = 128, ["max-sparse-gap"] = 10} + local lua_pairs = pairs + local lua_ipairs = ipairs + local function pairs(t) + local _1_ = getmetatable(t) + if ((_G.type(_1_) == "table") and (nil ~= (_1_).__pairs)) then + local p = (_1_).__pairs + return p(t) + elseif true then + local _ = _1_ + return lua_pairs(t) + else + return nil + end + end + local function ipairs(t) + local _3_ = getmetatable(t) + if ((_G.type(_3_) == "table") and (nil ~= (_3_).__ipairs)) then + local i = (_3_).__ipairs + return i(t) + elseif true then + local _ = _3_ + return lua_ipairs(t) + else + return nil + end + end + local function length_2a(t) + local _5_ = getmetatable(t) + if ((_G.type(_5_) == "table") and (nil ~= (_5_).__len)) then + local l = (_5_).__len + return l(t) + elseif true then + local _ = _5_ + return #t + else + return nil + end + end + local function get_default(key) + local _7_ = default_opts[key] + if (_7_ == nil) then + return error(("option '%s' doesn't have a default value, use the :after key to set it"):format(tostring(key))) + elseif (nil ~= _7_) then + local v = _7_ + return v + else + return nil + end + end + local function getopt(options, key) + local val = options[key] + local _9_ = val + if ((_G.type(_9_) == "table") and (nil ~= (_9_).once)) then + local val_2a = (_9_).once + return val_2a + elseif true then + local _ = _9_ + return val + else + return nil + end + end + local function normalize_opts(options) + local tbl_13_auto = {} + for k, v in pairs(options) do + local k_14_auto, v_15_auto = nil, nil + local function _12_() + local _11_ = v + if ((_G.type(_11_) == "table") and (nil ~= (_11_).after)) then + local val = (_11_).after + return val + else + local function _13_() + return v.once + end + if ((_G.type(_11_) == "table") and _13_()) then + return get_default(k) + elseif true then + local _ = _11_ + return v + else + return nil + end + end + end + k_14_auto, v_15_auto = k, _12_() + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end + end + return tbl_13_auto + end + local function sort_keys(_16_, _18_) + local _arg_17_ = _16_ + local a = _arg_17_[1] + local _arg_19_ = _18_ + local b = _arg_19_[1] + local ta = type(a) + local tb = type(b) + if ((ta == tb) and ((ta == "string") or (ta == "number"))) then + return (a < b) + else + local dta = type_order[ta] + local dtb = type_order[tb] + if (dta and dtb) then + return (dta < dtb) + elseif dta then + return true + elseif dtb then + return false + else + return (ta < tb) + end + end + end + local function max_index_gap(kv) + local gap = 0 + if (0 < length_2a(kv)) then + local i = 0 + for _, _22_ in ipairs(kv) do + local _each_23_ = _22_ + local k = _each_23_[1] + if (gap < (k - i)) then + gap = (k - i) + else + end + i = k + end + else + end + return gap + end + local function fill_gaps(kv) + local missing_indexes = {} + local i = 0 + for _, _26_ in ipairs(kv) do + local _each_27_ = _26_ + local j = _each_27_[1] + i = (i + 1) + while (i < j) do + table.insert(missing_indexes, i) + i = (i + 1) + end + end + for _, k in ipairs(missing_indexes) do + table.insert(kv, k, {k}) + end + return nil + end + local function table_kv_pairs(t, options) + local assoc_3f = false + local kv = {} + local insert = table.insert + for k, v in pairs(t) do + if ((type(k) ~= "number") or (k < 1)) then + assoc_3f = true + else + end + insert(kv, {k, v}) + end + table.sort(kv, sort_keys) + if not assoc_3f then + if (options["max-sparse-gap"] < max_index_gap(kv)) then + assoc_3f = true + else + fill_gaps(kv) + end + else + end + if (length_2a(kv) == 0) then + return kv, "empty" + else + local function _31_() + if assoc_3f then + return "table" + else + return "seq" + end + end + return kv, _31_() + end + end + local function count_table_appearances(t, appearances) + if (type(t) == "table") then + if not appearances[t] then + appearances[t] = 1 + for k, v in pairs(t) do + count_table_appearances(k, appearances) + count_table_appearances(v, appearances) + end + else + appearances[t] = ((appearances[t] or 0) + 1) + end + else + end + return appearances + end + local function save_table(t, seen) + local seen0 = (seen or {len = 0}) + local id = (seen0.len + 1) + if not (seen0)[t] then + seen0[t] = id + seen0.len = id + else + end + return seen0 + end + local function detect_cycle(t, seen, _3fk) + if ("table" == type(t)) then + seen[t] = true + local _36_, _37_ = next(t, _3fk) + if ((nil ~= _36_) and (nil ~= _37_)) then + local k = _36_ + local v = _37_ + return (seen[k] or detect_cycle(k, seen) or seen[v] or detect_cycle(v, seen) or detect_cycle(t, seen, k)) + else + return nil + end + else + return nil + end + end + local function visible_cycle_3f(t, options) + return (getopt(options, "detect-cycles?") and detect_cycle(t, {}) and save_table(t, options.seen) and (1 < (options.appearances[t] or 0))) + end + local function table_indent(indent, id) + local opener_length + if id then + opener_length = (length_2a(tostring(id)) + 2) + else + opener_length = 1 + end + return (indent + opener_length) + end + local pp = nil + local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix, last_comment_3f) + local indent_str = ("\n" .. string.rep(" ", indent)) + local open + local function _41_() + if ("seq" == table_type) then + return "[" + else + return "{" + end + end + open = ((prefix or "") .. _41_()) + local close + if ("seq" == table_type) then + close = "]" + else + close = "}" + end + local oneline = (open .. table.concat(elements, " ") .. close) + if (not getopt(options, "one-line?") and (multiline_3f or (options["line-length"] < (indent + length_2a(oneline))) or last_comment_3f)) then + local function _43_() + if last_comment_3f then + return indent_str + else + return "" + end + end + return (open .. table.concat(elements, indent_str) .. _43_() .. close) + else + return oneline + end + end + local function utf8_len(x) + local n = 0 + for _ in string.gmatch(x, "[%z\1-\127\192-\247]") do + n = (n + 1) + end + return n + end + local function comment_3f(x) + if ("table" == type(x)) then + local fst = x[1] + return (("string" == type(fst)) and (nil ~= fst:find("^;"))) + else + return false + end + end + local function pp_associative(t, kv, options, indent) + local multiline_3f = false + local id = options.seen[t] + if (options.depth <= options.level) then + return "{...}" + elseif (id and getopt(options, "detect-cycles?")) then + return ("@" .. id .. "{...}") + else + local visible_cycle_3f0 = visible_cycle_3f(t, options) + local id0 = (visible_cycle_3f0 and options.seen[t]) + local indent0 = table_indent(indent, id0) + local slength + if getopt(options, "utf8?") then + slength = utf8_len + else + local function _46_(_241) + return #_241 + end + slength = _46_ + end + local prefix + if visible_cycle_3f0 then + prefix = ("@" .. id0) + else + prefix = "" + end + local items + do + local options0 = normalize_opts(options) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, _49_ in ipairs(kv) do + local _each_50_ = _49_ + local k = _each_50_[1] + local v = _each_50_[2] + local val_18_auto + do + local k0 = pp(k, options0, (indent0 + 1), true) + local v0 = pp(v, options0, (indent0 + slength(k0) + 1)) + multiline_3f = (multiline_3f or k0:find("\n") or v0:find("\n")) + val_18_auto = (k0 .. " " .. v0) + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + items = tbl_16_auto + end + return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix, false) + end + end + local function pp_sequence(t, kv, options, indent) + local multiline_3f = false + local id = options.seen[t] + if (options.depth <= options.level) then + return "[...]" + elseif (id and getopt(options, "detect-cycles?")) then + return ("@" .. id .. "[...]") + else + local visible_cycle_3f0 = visible_cycle_3f(t, options) + local id0 = (visible_cycle_3f0 and options.seen[t]) + local indent0 = table_indent(indent, id0) + local prefix + if visible_cycle_3f0 then + prefix = ("@" .. id0) + else + prefix = "" + end + local last_comment_3f = comment_3f(t[#t]) + local items + do + local options0 = normalize_opts(options) + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, _54_ in ipairs(kv) do + local _each_55_ = _54_ + local _0 = _each_55_[1] + local v = _each_55_[2] + local val_18_auto + do + local v0 = pp(v, options0, indent0) + multiline_3f = (multiline_3f or v0:find("\n") or v0:find("^;")) + val_18_auto = v0 + end + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + items = tbl_16_auto + end + return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix, last_comment_3f) + end + end + local function concat_lines(lines, options, indent, force_multi_line_3f) + if (length_2a(lines) == 0) then + if getopt(options, "empty-as-sequence?") then + return "[]" + else + return "{}" + end + else + local oneline + local _59_ + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for _, line in ipairs(lines) do + local val_18_auto = line:gsub("^%s+", "") + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + _59_ = tbl_16_auto + end + oneline = table.concat(_59_, " ") + if (not getopt(options, "one-line?") and (force_multi_line_3f or oneline:find("\n") or (options["line-length"] < (indent + length_2a(oneline))))) then + return table.concat(lines, ("\n" .. string.rep(" ", indent))) + else + return oneline + end + end + end + local function pp_metamethod(t, metamethod, options, indent) + if (options.depth <= options.level) then + if getopt(options, "empty-as-sequence?") then + return "[...]" + else + return "{...}" + end + else + local _ + local function _64_(_241) + return visible_cycle_3f(_241, options) + end + options["visible-cycle?"] = _64_ + _ = nil + local lines, force_multi_line_3f = nil, nil + do + local options0 = normalize_opts(options) + lines, force_multi_line_3f = metamethod(t, pp, options0, indent) + end + options["visible-cycle?"] = nil + local _65_ = type(lines) + if (_65_ == "string") then + return lines + elseif (_65_ == "table") then + return concat_lines(lines, options, indent, force_multi_line_3f) + elseif true then + local _0 = _65_ + return error("__fennelview metamethod must return a table of lines") + else + return nil + end + end + end + local function pp_table(x, options, indent) + options.level = (options.level + 1) + local x0 + do + local _68_ + if getopt(options, "metamethod?") then + local _69_ = x + if (nil ~= _69_) then + local _70_ = getmetatable(_69_) + if (nil ~= _70_) then + _68_ = (_70_).__fennelview + else + _68_ = _70_ + end + else + _68_ = _69_ + end + else + _68_ = nil + end + if (nil ~= _68_) then + local metamethod = _68_ + x0 = pp_metamethod(x, metamethod, options, indent) + elseif true then + local _ = _68_ + local _74_, _75_ = table_kv_pairs(x, options) + if (true and (_75_ == "empty")) then + local _0 = _74_ + if getopt(options, "empty-as-sequence?") then + x0 = "[]" + else + x0 = "{}" + end + elseif ((nil ~= _74_) and (_75_ == "table")) then + local kv = _74_ + x0 = pp_associative(x, kv, options, indent) + elseif ((nil ~= _74_) and (_75_ == "seq")) then + local kv = _74_ + x0 = pp_sequence(x, kv, options, indent) + else + x0 = nil + end + else + x0 = nil + end + end + options.level = (options.level - 1) + return x0 + end + local function number__3estring(n) + local _79_ = string.gsub(tostring(n), ",", ".") + return _79_ + end + local function colon_string_3f(s) + return s:find("^[-%w?^_!$%&*+./@|<=>]+$") + end + local utf8_inits = {{["min-byte"] = 0, ["max-byte"] = 127, ["min-code"] = 0, ["max-code"] = 127, len = 1}, {["min-byte"] = 192, ["max-byte"] = 223, ["min-code"] = 128, ["max-code"] = 2047, len = 2}, {["min-byte"] = 224, ["max-byte"] = 239, ["min-code"] = 2048, ["max-code"] = 65535, len = 3}, {["min-byte"] = 240, ["max-byte"] = 247, ["min-code"] = 65536, ["max-code"] = 1114111, len = 4}} + local function utf8_escape(str) + local function validate_utf8(str0, index) + local inits = utf8_inits + local byte = string.byte(str0, index) + local init + do + local ret = nil + for _, init0 in ipairs(inits) do + if ret then break end + ret = (byte and (function(_80_,_81_,_82_) return (_80_ <= _81_) and (_81_ <= _82_) end)(init0["min-byte"],byte,init0["max-byte"]) and init0) + end + init = ret + end + local code + local function _83_() + local code0 + if init then + code0 = (byte - init["min-byte"]) + else + code0 = nil + end + for i = (index + 1), (index + init.len + -1) do + local byte0 = string.byte(str0, i) + code0 = (byte0 and code0 and (function(_85_,_86_,_87_) return (_85_ <= _86_) and (_86_ <= _87_) end)(128,byte0,191) and ((code0 * 64) + (byte0 - 128))) + end + return code0 + end + code = (init and _83_()) + if (code and (function(_88_,_89_,_90_) return (_88_ <= _89_) and (_89_ <= _90_) end)(init["min-code"],code,init["max-code"]) and not (function(_91_,_92_,_93_) return (_91_ <= _92_) and (_92_ <= _93_) end)(55296,code,57343)) then + return init.len + else + return nil + end + end + local index = 1 + local output = {} + while (index <= #str) do + local nexti = (string.find(str, "[\128-\255]", index) or (#str + 1)) + local len = validate_utf8(str, nexti) + table.insert(output, string.sub(str, index, (nexti + (len or 0) + -1))) + if (not len and (nexti <= #str)) then + table.insert(output, string.format("\\%03d", string.byte(str, nexti))) + else + end + if len then + index = (nexti + len) + else + index = (nexti + 1) + end + end + return table.concat(output) + end + local function pp_string(str, options, indent) + local len = length_2a(str) + local esc_newline_3f = ((len < 2) or (getopt(options, "escape-newlines?") and (len < (options["line-length"] - indent)))) + local escs + local _97_ + if esc_newline_3f then + _97_ = "\\n" + else + _97_ = "\n" + end + local function _99_(_241, _242) + return ("\\%03d"):format(_242:byte()) + end + escs = setmetatable({["\7"] = "\\a", ["\8"] = "\\b", ["\12"] = "\\f", ["\11"] = "\\v", ["\13"] = "\\r", ["\9"] = "\\t", ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = _97_}, {__index = _99_}) + local str0 = ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"") + if getopt(options, "utf8?") then + return utf8_escape(str0) + else + return str0 + end + end + local function make_options(t, options) + local defaults + do + local tbl_13_auto = {} + for k, v in pairs(default_opts) do + local k_14_auto, v_15_auto = k, v + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end + end + defaults = tbl_13_auto + end + local overrides = {level = 0, appearances = count_table_appearances(t, {}), seen = {len = 0}} + for k, v in pairs((options or {})) do + defaults[k] = v + end + for k, v in pairs(overrides) do + defaults[k] = v + end + return defaults + end + local function _102_(x, options, indent, colon_3f) + local indent0 = (indent or 0) + local options0 = (options or make_options(x)) + local x0 + if options0.preprocess then + x0 = options0.preprocess(x, options0) + else + x0 = x + end + local tv = type(x0) + local function _105_() + local _104_ = getmetatable(x0) + if (nil ~= _104_) then + return (_104_).__fennelview + else + return _104_ + end + end + if ((tv == "table") or ((tv == "userdata") and _105_())) then + return pp_table(x0, options0, indent0) + elseif (tv == "number") then + return number__3estring(x0) + else + local function _107_() + if (colon_3f ~= nil) then + return colon_3f + elseif ("function" == type(options0["prefer-colon?"])) then + return options0["prefer-colon?"](x0) + else + return getopt(options0, "prefer-colon?") end end - return parse_loop(skip_whitespace(getb())) - end - local function _0_() - stack = {} - return nil + if ((tv == "string") and colon_string_3f(x0) and _107_()) then + return (":" .. x0) + elseif (tv == "string") then + return pp_string(x0, options0, indent0) + elseif ((tv == "boolean") or (tv == "nil")) then + return tostring(x0) + else + return ("#<" .. tostring(x0) .. ">") + end end - return parse_stream, _0_ end - return {["string-stream"] = string_stream, ["sym-char?"] = sym_char_3f, granulate = granulate, parser = parser} + pp = _102_ + local function view(x, _3foptions) + return pp(x, make_options(x, _3foptions), 0) + end + return view end -local utils = nil package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-tree-docs.aniseed.fennel.utils"] or function(...) - local function stablepairs(t) - local keys = {} - local succ = {} - for k in pairs(t) do - table.insert(keys, k) + local view = require("nvim-tree-docs.aniseed.fennel.view") + local version = "1.3.0" + local function luajit_vm_3f() + return ((nil ~= _G.jit) and (type(_G.jit) == "table") and (nil ~= _G.jit.on) and (nil ~= _G.jit.off) and (type(_G.jit.version_num) == "number")) + end + local function luajit_vm_version() + local jit_os + if (_G.jit.os == "OSX") then + jit_os = "macOS" + else + jit_os = _G.jit.os + end + return (_G.jit.version .. " " .. jit_os .. "/" .. _G.jit.arch) + end + local function fengari_vm_3f() + return ((nil ~= _G.fengari) and (type(_G.fengari) == "table") and (nil ~= _G.fengari.VERSION) and (type(_G.fengari.VERSION_NUM) == "number")) + end + local function fengari_vm_version() + return (_G.fengari.RELEASE .. " (" .. _VERSION .. ")") + end + local function lua_vm_version() + if luajit_vm_3f() then + return luajit_vm_version() + elseif fengari_vm_3f() then + return fengari_vm_version() + else + return ("PUC " .. _VERSION) end - local function _0_(_241, _242) - return (tostring(_241) < tostring(_242)) + end + local function runtime_version() + return ("Fennel " .. version .. " on " .. lua_vm_version()) + end + local function warn(message) + if (_G.io and _G.io.stderr) then + return (_G.io.stderr):write(("--WARNING: %s\n"):format(tostring(message))) + else + return nil + end + end + local len + do + local _112_, _113_ = pcall(require, "utf8") + if ((_112_ == true) and (nil ~= _113_)) then + local utf8 = _113_ + len = utf8.len + elseif true then + local _ = _112_ + len = string.len + else + len = nil end - table.sort(keys, _0_) - for i, k in ipairs(keys) do - succ[k] = keys[(i + 1)] + end + local function mt_keys_in_order(t, out, used_keys) + for _, k in ipairs(getmetatable(t).keys) do + if (t[k] and not used_keys[k]) then + used_keys[k] = true + table.insert(out, k) + else + end + end + for k in pairs(t) do + if not used_keys[k] then + table.insert(out, k) + else + end end - local function stablenext(tbl, idx) - local key = nil - if (idx == nil) then - key = keys[1] + return out + end + local function stablepairs(t) + local keys + local _118_ + do + local t_117_ = getmetatable(t) + if (nil ~= t_117_) then + t_117_ = (t_117_).keys else - key = succ[idx] end - local value = nil + _118_ = t_117_ + end + if _118_ then + keys = mt_keys_in_order(t, {}, {}) + else + local _120_ + do + local tbl_16_auto = {} + local i_17_auto = #tbl_16_auto + for k in pairs(t) do + local val_18_auto = k + if (nil ~= val_18_auto) then + i_17_auto = (i_17_auto + 1) + do end (tbl_16_auto)[i_17_auto] = val_18_auto + else + end + end + _120_ = tbl_16_auto + end + local function _122_(_241, _242) + return (tostring(_241) < tostring(_242)) + end + table.sort(_120_, _122_) + keys = _120_ + end + local succ + do + local tbl_13_auto = {} + for i, k in ipairs(keys) do + local k_14_auto, v_15_auto = k, keys[(i + 1)] + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end + end + succ = tbl_13_auto + end + local function stablenext(tbl, key) + local next_key if (key == nil) then - value = nil + next_key = keys[1] else - value = tbl[key] + next_key = succ[key] end - return key, value + return next_key, tbl[next_key] end return stablenext, t, nil end - local function map(t, f, out) - local out0 = (out or {}) - local f0 = nil + local function get_in(tbl, path, _3ffallback) + assert(("table" == type(tbl)), "get-in expects path to be a table") + if (0 == #path) then + return _3ffallback + else + local _126_ + do + local t = tbl + for _, k in ipairs(path) do + if (nil == t) then break end + local _127_ = type(t) + if (_127_ == "table") then + t = t[k] + else + t = nil + end + end + _126_ = t + end + if (nil ~= _126_) then + local res = _126_ + return res + elseif true then + local _ = _126_ + return _3ffallback + else + return nil + end + end + end + local function map(t, f, _3fout) + local out = (_3fout or {}) + local f0 if (type(f) == "function") then f0 = f else - local function _0_(_241) - return _241[f] + local function _131_(_241) + return (_241)[f] end - f0 = _0_ + f0 = _131_ end for _, x in ipairs(t) do - local _1_0 = f0(x) - if (nil ~= _1_0) then - local v = _1_0 - table.insert(out0, v) + local _133_ = f0(x) + if (nil ~= _133_) then + local v = _133_ + table.insert(out, v) + else end end - return out0 + return out end - local function kvmap(t, f, out) - local out0 = (out or {}) - local f0 = nil + local function kvmap(t, f, _3fout) + local out = (_3fout or {}) + local f0 if (type(f) == "function") then f0 = f else - local function _0_(_241) - return _241[f] + local function _135_(_241) + return (_241)[f] end - f0 = _0_ + f0 = _135_ end for k, x in stablepairs(t) do - local _1_0, _2_0 = f0(k, x) - if ((nil ~= _1_0) and (nil ~= _2_0)) then - local key = _1_0 - local value = _2_0 - out0[key] = value - elseif (nil ~= _1_0) then - local value = _1_0 - table.insert(out0, value) + local _137_, _138_ = f0(k, x) + if ((nil ~= _137_) and (nil ~= _138_)) then + local key = _137_ + local value = _138_ + out[key] = value + elseif (nil ~= _137_) then + local value = _137_ + table.insert(out, value) + else end end - return out0 + return out end - local function copy(from, to) - local to0 = (to or {}) + local function copy(from, _3fto) + local tbl_13_auto = (_3fto or {}) for k, v in pairs((from or {})) do - to0[k] = v + local k_14_auto, v_15_auto = k, v + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end end - return to0 + return tbl_13_auto end - local function member_3f(x, tbl, n) - local _0_0 = tbl[(n or 1)] - if (_0_0 == x) then + local function member_3f(x, tbl, _3fn) + local _141_ = tbl[(_3fn or 1)] + if (_141_ == x) then return true - elseif (_0_0 == nil) then + elseif (_141_ == nil) then return nil + elseif true then + local _ = _141_ + return member_3f(x, tbl, ((_3fn or 1) + 1)) else - local _ = _0_0 - return member_3f(x, tbl, ((n or 1) + 1)) + return nil + end + end + local function maxn(tbl) + local max = 0 + for k in pairs(tbl) do + if ("number" == type(k)) then + max = math.max(max, k) + else + max = max + end + end + return max + end + local function every_3f(predicate, seq) + local result = true + for _, item in ipairs(seq) do + if not result then break end + result = predicate(item) end + return result end local function allpairs(tbl) assert((type(tbl) == "table"), "allpairs expects a table") @@ -3507,10 +5037,17 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t seen[next_state] = true return next_state, value else - local meta = getmetatable(t) - if (meta and meta.__index) then - t = meta.__index - return allpairs_next(t) + local _144_ = getmetatable(t) + if ((_G.type(_144_) == "table") and true) then + local __index = (_144_).__index + if ("table" == type(__index)) then + t = __index + return allpairs_next(t) + else + return nil + end + else + return nil end end end @@ -3520,17 +5057,22 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t return self[1] end local nil_sym = nil - local function list__3estring(self, tostring2) - local safe, max = {}, 0 - for k in pairs(self) do - if ((type(k) == "number") and (k > max)) then - max = k - end + local function list__3estring(self, _3fview, _3foptions, _3findent) + local safe = {} + local view0 + if _3fview then + local function _148_(_241) + return _3fview(_241, _3foptions, _3findent) + end + view0 = _148_ + else + view0 = view end + local max = maxn(self) for i = 1, max do safe[i] = (((self[i] == nil) and nil_sym) or self[i]) end - return ("(" .. table.concat(map(safe, (tostring2 or tostring)), " ", 1, max) .. ")") + return ("(" .. table.concat(map(safe, view0), " ", 1, max) .. ")") end local function comment_view(c) return c, true @@ -3541,17 +5083,21 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t local function sym_3c(a, b) return (a[1] < tostring(b)) end - local symbol_mt = {"SYMBOL", __eq = sym_3d, __fennelview = deref, __lt = sym_3c, __tostring = deref} - local expr_mt = {"EXPR", __tostring = deref} - local list_mt = {"LIST", __fennelview = list__3estring, __tostring = list__3estring} - local comment_mt = {"COMMENT", __eq = sym_3d, __fennelview = comment_view, __lt = sym_3c, __tostring = deref} + local symbol_mt = {__fennelview = deref, __tostring = deref, __eq = sym_3d, __lt = sym_3c, "SYMBOL"} + local expr_mt + local function _150_(x) + return tostring(deref(x)) + end + expr_mt = {__tostring = _150_, "EXPR"} + local list_mt = {__fennelview = list__3estring, __tostring = list__3estring, "LIST"} + local comment_mt = {__fennelview = comment_view, __tostring = deref, __eq = sym_3d, __lt = sym_3c, "COMMENT"} local sequence_marker = {"SEQUENCE"} - local vararg = setmetatable({"..."}, {"VARARG", __fennelview = deref, __tostring = deref}) - local getenv = nil - local function _0_() + local varg_mt = {__fennelview = deref, __tostring = deref, "VARARG"} + local getenv + local function _151_() return nil end - getenv = ((os and os.getenv) or _0_) + getenv = ((os and os.getenv) or _151_) local function debug_on_3f(flag) local level = (getenv("FENNEL_DEBUG") or "") return ((level == "all") or level:find(flag)) @@ -3559,36 +5105,74 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t local function list(...) return setmetatable({...}, list_mt) end - local function sym(str, _3fsource, _3fscope) - local s = {str, ["?scope"] = _3fscope} - for k, v in pairs((_3fsource or {})) do - if (type(k) == "string") then - s[k] = v + local function sym(str, _3fsource) + local _152_ + do + local tbl_13_auto = {str} + for k, v in pairs((_3fsource or {})) do + local k_14_auto, v_15_auto = nil, nil + if (type(k) == "string") then + k_14_auto, v_15_auto = k, v + else + k_14_auto, v_15_auto = nil + end + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end end + _152_ = tbl_13_auto end - return setmetatable(s, symbol_mt) + return setmetatable(_152_, symbol_mt) end nil_sym = sym("nil") local function sequence(...) - return setmetatable({...}, {sequence = sequence_marker}) + local function _155_(seq, view0, inspector, indent) + local opts + do + local _156_ = inspector + _156_["empty-as-sequence?"] = {once = true, after = inspector["empty-as-sequence?"]} + _156_["metamethod?"] = {once = false, after = inspector["metamethod?"]} + opts = _156_ + end + return view0(seq, opts, indent) + end + return setmetatable({...}, {sequence = sequence_marker, __fennelview = _155_}) end local function expr(strcode, etype) - return setmetatable({strcode, type = etype}, expr_mt) + return setmetatable({type = etype, strcode}, expr_mt) end local function comment_2a(contents, _3fsource) - local _1_ = (_3fsource or {}) - local filename = _1_["filename"] - local line = _1_["line"] - return setmetatable({contents, filename = filename, line = line}, comment_mt) + local _let_157_ = (_3fsource or {}) + local filename = _let_157_["filename"] + local line = _let_157_["line"] + return setmetatable({filename = filename, line = line, contents}, comment_mt) end - local function varg() - return vararg + local function varg(_3fsource) + local _158_ + do + local tbl_13_auto = {"..."} + for k, v in pairs((_3fsource or {})) do + local k_14_auto, v_15_auto = nil, nil + if (type(k) == "string") then + k_14_auto, v_15_auto = k, v + else + k_14_auto, v_15_auto = nil + end + if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then + tbl_13_auto[k_14_auto] = v_15_auto + else + end + end + _158_ = tbl_13_auto + end + return setmetatable(_158_, varg_mt) end local function expr_3f(x) return ((type(x) == "table") and (getmetatable(x) == expr_mt) and x) end local function varg_3f(x) - return ((x == vararg) and x) + return ((type(x) == "table") and (getmetatable(x) == varg_mt) and x) end local function list_3f(x) return ((type(x) == "table") and (getmetatable(x) == list_mt) and x) @@ -3604,7 +5188,10 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t return ((type(x) == "table") and (getmetatable(x) == comment_mt) and x) end local function table_3f(x) - return ((type(x) == "table") and (x ~= vararg) and (getmetatable(x) ~= list_mt) and (getmetatable(x) ~= symbol_mt) and not comment_3f(x) and x) + return ((type(x) == "table") and not varg_3f(x) and (getmetatable(x) ~= list_mt) and (getmetatable(x) ~= symbol_mt) and not comment_3f(x) and x) + end + local function string_3f(x) + return (type(x) == "string") end local function multi_sym_3f(str) if sym_3f(str) then @@ -3612,34 +5199,52 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t elseif (type(str) ~= "string") then return false else - local parts = {} - for part in str:gmatch("[^%.%:]+[%.%:]?") do - local last_char = part:sub(( - 1)) - if (last_char == ":") then - parts["multi-sym-method-call"] = true - end - if ((last_char == ":") or (last_char == ".")) then - parts[(#parts + 1)] = part:sub(1, ( - 2)) - else - parts[(#parts + 1)] = part + local function _161_() + local parts = {} + for part in str:gmatch("[^%.%:]+[%.%:]?") do + local last_char = part:sub(( - 1)) + if (last_char == ":") then + parts["multi-sym-method-call"] = true + else + end + if ((last_char == ":") or (last_char == ".")) then + parts[(#parts + 1)] = part:sub(1, ( - 2)) + else + parts[(#parts + 1)] = part + end end + return ((0 < #parts) and parts) end - return ((#parts > 0) and (str:match("%.") or str:match(":")) and not str:match("%.%.") and (str:byte() ~= string.byte(".")) and (str:byte(( - 1)) ~= string.byte(".")) and parts) + return ((str:match("%.") or str:match(":")) and not str:match("%.%.") and (str:byte() ~= string.byte(".")) and (str:byte(( - 1)) ~= string.byte(".")) and _161_()) end end local function quoted_3f(symbol) return symbol.quoted end - local function walk_tree(root, f, custom_iterator) + local function idempotent_expr_3f(x) + return ((type(x) == "string") or (type(x) == "integer") or (type(x) == "number") or (sym_3f(x) and not multi_sym_3f(x))) + end + local function ast_source(ast) + if (table_3f(ast) or sequence_3f(ast)) then + return (getmetatable(ast) or {}) + elseif ("table" == type(ast)) then + return ast + else + return {} + end + end + local function walk_tree(root, f, _3fcustom_iterator) local function walk(iterfn, parent, idx, node) if f(idx, node, parent) then for k, v in iterfn(node) do walk(iterfn, node, k, v) end return nil + else + return nil end end - walk((custom_iterator or pairs), nil, nil, root) + walk((_3fcustom_iterator or pairs), nil, nil, root) return root end local lua_keywords = {"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while", "goto"} @@ -3656,35 +5261,76 @@ package.preload["nvim-tree-docs.aniseed.fennel.utils"] = package.preload["nvim-t end return subopts end - local root = nil - local function _1_() + local root + local function _167_() end - root = {chunk = nil, options = nil, reset = _1_, scope = nil} - root["set-reset"] = function(_2_0) - local _3_ = _2_0 - local chunk = _3_["chunk"] - local options = _3_["options"] - local reset = _3_["reset"] - local scope = _3_["scope"] + root = {chunk = nil, scope = nil, options = nil, reset = _167_} + root["set-reset"] = function(_168_) + local _arg_169_ = _168_ + local chunk = _arg_169_["chunk"] + local scope = _arg_169_["scope"] + local options = _arg_169_["options"] + local reset = _arg_169_["reset"] root.reset = function() root.chunk, root.scope, root.options, root.reset = chunk, scope, options, reset return nil end return root.reset end - local function hook(event, ...) - if (root.options and root.options.plugins) then - for _, plugin in ipairs(root.options.plugins) do - local _3_0 = plugin[event] - if (nil ~= _3_0) then - local f = _3_0 - f(...) + local warned = {} + local function check_plugin_version(_170_) + local _arg_171_ = _170_ + local name = _arg_171_["name"] + local versions = _arg_171_["versions"] + local plugin = _arg_171_ + if (not member_3f(version:gsub("-dev", ""), (versions or {})) and not warned[plugin]) then + warned[plugin] = true + return warn(string.format("plugin %s does not support Fennel version %s", (name or "unknown"), version)) + else + return nil + end + end + local function hook_opts(event, _3foptions, ...) + local plugins + local function _174_(...) + local t_173_ = _3foptions + if (nil ~= t_173_) then + t_173_ = (t_173_).plugins + else + end + return t_173_ + end + local function _177_(...) + local t_176_ = root.options + if (nil ~= t_176_) then + t_176_ = (t_176_).plugins + else + end + return t_176_ + end + plugins = (_174_(...) or _177_(...)) + if plugins then + local result = nil + for _, plugin in ipairs(plugins) do + if result then break end + check_plugin_version(plugin) + local _179_ = plugin[event] + if (nil ~= _179_) then + local f = _179_ + result = f(...) + else + result = nil end end + return result + else return nil end end - return {["comment?"] = comment_3f, ["debug-on?"] = debug_on_3f, ["expr?"] = expr_3f, ["list?"] = list_3f, ["lua-keywords"] = lua_keywords, ["member?"] = member_3f, ["multi-sym?"] = multi_sym_3f, ["propagate-options"] = propagate_options, ["quoted?"] = quoted_3f, ["sequence?"] = sequence_3f, ["sym?"] = sym_3f, ["table?"] = table_3f, ["valid-lua-identifier?"] = valid_lua_identifier_3f, ["varg?"] = varg_3f, ["walk-tree"] = walk_tree, allpairs = allpairs, comment = comment_2a, copy = copy, deref = deref, expr = expr, hook = hook, kvmap = kvmap, list = list, map = map, path = table.concat({"./?.fnl", "./?/init.fnl", getenv("FENNEL_PATH")}, ";"), root = root, sequence = sequence, stablepairs = stablepairs, sym = sym, varg = varg} + local function hook(event, ...) + return hook_opts(event, root.options, ...) + end + return {warn = warn, allpairs = allpairs, stablepairs = stablepairs, copy = copy, ["get-in"] = get_in, kvmap = kvmap, map = map, ["walk-tree"] = walk_tree, ["member?"] = member_3f, maxn = maxn, ["every?"] = every_3f, list = list, sequence = sequence, sym = sym, varg = varg, expr = expr, comment = comment_2a, ["comment?"] = comment_3f, ["expr?"] = expr_3f, ["list?"] = list_3f, ["multi-sym?"] = multi_sym_3f, ["sequence?"] = sequence_3f, ["sym?"] = sym_3f, ["table?"] = table_3f, ["varg?"] = varg_3f, ["quoted?"] = quoted_3f, ["string?"] = string_3f, ["idempotent-expr?"] = idempotent_expr_3f, ["valid-lua-identifier?"] = valid_lua_identifier_3f, ["lua-keywords"] = lua_keywords, hook = hook, ["hook-opts"] = hook_opts, ["propagate-options"] = propagate_options, root = root, ["debug-on?"] = debug_on_3f, ["ast-source"] = ast_source, version = version, ["runtime-version"] = runtime_version, len = len, path = table.concat({"./?.fnl", "./?/init.fnl", getenv("FENNEL_PATH")}, ";"), ["macro-path"] = table.concat({"./?.fnl", "./?/init-macros.fnl", "./?/init.fnl", getenv("FENNEL_MACRO_PATH")}, ";")} end utils = require("nvim-tree-docs.aniseed.fennel.utils") local parser = require("nvim-tree-docs.aniseed.fennel.parser") @@ -3692,11 +5338,13 @@ local compiler = require("nvim-tree-docs.aniseed.fennel.compiler") local specials = require("nvim-tree-docs.aniseed.fennel.specials") local repl = require("nvim-tree-docs.aniseed.fennel.repl") local view = require("nvim-tree-docs.aniseed.fennel.view") -local function eval_env(env) +local function eval_env(env, opts) if (env == "_COMPILER") then - local env0 = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) - local mt = getmetatable(env0) - mt.__index = _G + local env0 = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}, opts) + if (opts.allowedGlobals == nil) then + opts.allowedGlobals = specials["current-global-names"](env0) + else + end return specials["wrap-env"](env0) else return (env and specials["wrap-env"](env)) @@ -3704,30 +5352,33 @@ local function eval_env(env) end local function eval_opts(options, str) local opts = utils.copy(options) - if ((opts.allowedGlobals == nil) and not getmetatable(opts.env)) then + if (opts.allowedGlobals == nil) then opts.allowedGlobals = specials["current-global-names"](opts.env) + else end if (not opts.filename and not opts.source) then opts.source = str + else end if (opts.env == "_COMPILER") then opts.scope = compiler["make-scope"](compiler.scopes.compiler) + else end return opts end local function eval(str, options, ...) local opts = eval_opts(options, str) - local env = eval_env(opts.env) + local env = eval_env(opts.env, opts) local lua_source = compiler["compile-string"](str, opts) - local loader = nil - local function _0_(...) + local loader + local function _753_(...) if opts.filename then return ("@" .. opts.filename) else return str end end - loader = specials["load-code"](lua_source, env, _0_(...)) + loader = specials["load-code"](lua_source, env, _753_(...)) opts.filename = nil return loader(...) end @@ -3740,42 +5391,62 @@ local function dofile_2a(filename, options, ...) return eval(source, opts, ...) end local function syntax() - local body_3f = {"when", "with-open", "collect", "icollect", "lambda", "\206\187", "macro", "match"} - local binding_3f = {"collect", "icollect", "each", "for", "let", "with-open"} + local body_3f = {"when", "with-open", "collect", "icollect", "fcollect", "lambda", "\206\187", "macro", "match", "match-try", "case", "case-try", "accumulate", "faccumulate", "doto"} + local binding_3f = {"collect", "icollect", "fcollect", "each", "for", "let", "with-open", "accumulate", "faccumulate"} + local define_3f = {"fn", "lambda", "\206\187", "var", "local", "macro", "macros", "global"} local out = {} for k, v in pairs(compiler.scopes.global.specials) do local metadata = (compiler.metadata[v] or {}) - out[k] = {["binding-form?"] = utils["member?"](binding_3f, k), ["body-form?"] = metadata["fnl/body-form?"], ["special?"] = true} + do end (out)[k] = {["special?"] = true, ["body-form?"] = metadata["fnl/body-form?"], ["binding-form?"] = utils["member?"](k, binding_3f), ["define?"] = utils["member?"](k, define_3f)} end for k, v in pairs(compiler.scopes.global.macros) do - out[k] = {["binding-form?"] = utils["member?"](binding_3f, k), ["body-form?"] = utils["member?"](body_3f, k), ["macro?"] = true} + out[k] = {["macro?"] = true, ["body-form?"] = utils["member?"](k, body_3f), ["binding-form?"] = utils["member?"](k, binding_3f), ["define?"] = utils["member?"](k, define_3f)} end for k, v in pairs(_G) do - local _0_0 = type(v) - if (_0_0 == "function") then - out[k] = {["global?"] = true} - elseif (_0_0 == "table") then + local _754_ = type(v) + if (_754_ == "function") then + out[k] = {["global?"] = true, ["function?"] = true} + elseif (_754_ == "table") then for k2, v2 in pairs(v) do - if ("function" == type(v2)) then - out[(k .. "." .. k2)] = {["function?"] = true} + if (("function" == type(v2)) and (k ~= "_G")) then + out[(k .. "." .. k2)] = {["function?"] = true, ["global?"] = true} + else end end + out[k] = {["global?"] = true} + else end end return out end -local mod = {["comment?"] = utils["comment?"], ["compile-stream"] = compiler["compile-stream"], ["compile-string"] = compiler["compile-string"], ["list?"] = utils["list?"], ["load-code"] = specials["load-code"], ["macro-loaded"] = specials["macro-loaded"], ["macro-searchers"] = specials["macro-searchers"], ["make-searcher"] = specials["make-searcher"], ["search-module"] = specials["search-module"], ["sequence?"] = utils["sequence?"], ["string-stream"] = parser["string-stream"], ["sym-char?"] = parser["sym-char?"], ["sym?"] = utils["sym?"], comment = utils.comment, compile = compiler.compile, compile1 = compiler.compile1, compileStream = compiler["compile-stream"], compileString = compiler["compile-string"], doc = specials.doc, dofile = dofile_2a, eval = eval, gensym = compiler.gensym, granulate = parser.granulate, list = utils.list, loadCode = specials["load-code"], macroLoaded = specials["macro-loaded"], makeSearcher = specials["make-searcher"], make_searcher = specials["make-searcher"], mangle = compiler["global-mangling"], metadata = compiler.metadata, parser = parser.parser, path = utils.path, repl = repl, scope = compiler["make-scope"], searchModule = specials["search-module"], searcher = specials["make-searcher"](), sequence = utils.sequence, stringStream = parser["string-stream"], sym = utils.sym, syntax = syntax, traceback = compiler.traceback, unmangle = compiler["global-unmangling"], varg = utils.varg, version = "0.9.3-dev", view = view} +local mod = {list = utils.list, ["list?"] = utils["list?"], sym = utils.sym, ["sym?"] = utils["sym?"], ["multi-sym?"] = utils["multi-sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], ["table?"] = utils["table?"], comment = utils.comment, ["comment?"] = utils["comment?"], varg = utils.varg, ["varg?"] = utils["varg?"], ["sym-char?"] = parser["sym-char?"], parser = parser.parser, compile = compiler.compile, ["compile-string"] = compiler["compile-string"], ["compile-stream"] = compiler["compile-stream"], eval = eval, repl = repl, view = view, dofile = dofile_2a, ["load-code"] = specials["load-code"], doc = specials.doc, metadata = compiler.metadata, traceback = compiler.traceback, version = utils.version, ["runtime-version"] = utils["runtime-version"], ["ast-source"] = utils["ast-source"], path = utils.path, ["macro-path"] = utils["macro-path"], ["macro-loaded"] = specials["macro-loaded"], ["macro-searchers"] = specials["macro-searchers"], ["search-module"] = specials["search-module"], ["make-searcher"] = specials["make-searcher"], searcher = specials["make-searcher"](), syntax = syntax, gensym = compiler.gensym, scope = compiler["make-scope"], mangle = compiler["global-mangling"], unmangle = compiler["global-unmangling"], compile1 = compiler.compile1, ["string-stream"] = parser["string-stream"], granulate = parser.granulate, loadCode = specials["load-code"], make_searcher = specials["make-searcher"], makeSearcher = specials["make-searcher"], searchModule = specials["search-module"], macroPath = utils["macro-path"], macroSearchers = specials["macro-searchers"], macroLoaded = specials["macro-loaded"], compileStream = compiler["compile-stream"], compileString = compiler["compile-string"], stringStream = parser["string-stream"], runtimeVersion = utils["runtime-version"]} +mod.install = function(_3fopts) + table.insert((package.searchers or package.loaders), specials["make-searcher"](_3fopts)) + return mod +end utils["fennel-module"] = mod do - local builtin_macros = [===[;; This module contains all the built-in Fennel macros. Unlike all the other - ;; modules that are loaded by the old bootstrap compiler, this runs in the - ;; compiler scope of the version of the compiler being defined. - - ;; The code for these macros is somewhat idiosyncratic because it cannot use any - ;; macros which have not yet been defined. + local module_name = "nvim-tree-docs.aniseed.fennel.macros" + local _ + local function _757_() + return mod + end + package.preload[module_name] = _757_ + _ = nil + local env + do + local _758_ = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) + do end (_758_)["utils"] = utils + _758_["fennel"] = mod + env = _758_ + end + local built_ins = eval([===[;; These macros are awkward because their definition cannot rely on the any + ;; built-in macros, only special forms. (no when, no icollect, etc) - ;; TODO: some of these macros modify their arguments; we should stop doing that, - ;; but in a way that preserves file/line metadata. + (fn copy [t] + (let [out []] + (each [_ v (ipairs t)] (table.insert out v)) + (setmetatable out (getmetatable t)))) (fn ->* [val ...] "Thread-first macro. @@ -3783,7 +5454,7 @@ do The value of the second form is spliced into the first arg of the third, etc." (var x val) (each [_ e (ipairs [...])] - (let [elt (if (list? e) e (list e))] + (let [elt (if (list? e) (copy e) (list e))] (table.insert elt 2 x) (set x elt))) x) @@ -3793,40 +5464,36 @@ do Same as ->, except splices the value into the last position of each form rather than the first." (var x val) - (each [_ e (pairs [...])] - (let [elt (if (list? e) e (list e))] + (each [_ e (ipairs [...])] + (let [elt (if (list? e) (copy e) (list e))] (table.insert elt x) (set x elt))) x) - (fn -?>* [val ...] + (fn -?>* [val ?e ...] "Nil-safe thread-first macro. Same as -> except will short-circuit with nil when it encounters a nil value." - (if (= 0 (select "#" ...)) + (if (= nil ?e) val - (let [els [...] - e (table.remove els 1) - el (if (list? e) e (list e)) + (let [el (if (list? ?e) (copy ?e) (list ?e)) tmp (gensym)] (table.insert el 2 tmp) `(let [,tmp ,val] - (if ,tmp - (-?> ,el ,(unpack els)) + (if (not= nil ,tmp) + (-?> ,el ,...) ,tmp))))) - (fn -?>>* [val ...] + (fn -?>>* [val ?e ...] "Nil-safe thread-last macro. Same as ->> except will short-circuit with nil when it encounters a nil value." - (if (= 0 (select "#" ...)) + (if (= nil ?e) val - (let [els [...] - e (table.remove els 1) - el (if (list? e) e (list e)) + (let [el (if (list? ?e) (copy ?e) (list ?e)) tmp (gensym)] (table.insert el tmp) `(let [,tmp ,val] - (if ,tmp - (-?>> ,el ,(unpack els)) + (if (not= ,tmp nil) + (-?>> ,el ,...) ,tmp))))) (fn ?dot [tbl ...] @@ -3834,21 +5501,27 @@ do Same as . (dot), except will short-circuit with nil when it encounters a nil value in any of subsequent keys." (let [head (gensym :t) - lookups `(do (var ,head ,tbl) ,head)] + lookups `(do + (var ,head ,tbl) + ,head)] (each [_ k (ipairs [...])] ;; Kinda gnarly to reassign in place like this, but it emits the best lua. - ;; With this impl, it emits a flat, concise, and readable set of if blocks. + ;; With this impl, it emits a flat, concise, and readable set of ifs (table.insert lookups (# lookups) `(if (not= nil ,head) (set ,head (. ,head ,k))))) lookups)) (fn doto* [val ...] - "Evaluates val and splices it into the first argument of subsequent forms." - (let [name (gensym) - form `(let [,name ,val])] - (each [_ elt (pairs [...])] - (table.insert elt 2 name) - (table.insert form elt)) + "Evaluate val and splice it into the first argument of subsequent forms." + (assert (not= val nil) "missing subject") + (let [rebind? (or (not (sym? val)) + (multi-sym? val)) + name (if rebind? (gensym) val) + form (if rebind? `(let [,name ,val]) `(do))] + (each [_ elt (ipairs [...])] + (let [elt (if (list? elt) (copy elt) (list elt))] + (table.insert elt 2 name) + (table.insert form elt))) (table.insert form name) form)) @@ -3875,65 +5548,185 @@ do (table.insert closer 4 `(: ,(. closable-bindings i) :close))) `(let ,closable-bindings ,closer - (close-handlers# (xpcall ,bodyfn ,traceback))))) + (close-handlers# (_G.xpcall ,bodyfn ,traceback))))) + + (fn extract-into [iter-tbl] + (var (into iter-out found?) (values [] (copy iter-tbl))) + (for [i (length iter-tbl) 2 -1] + (let [item (. iter-tbl i)] + (if (or (= `&into item) + (= :into item)) + (do + (assert (not found?) "expected only one &into clause") + (set found? true) + (set into (. iter-tbl (+ i 1))) + (table.remove iter-out i) + (table.remove iter-out i))))) + (assert (or (not found?) (sym? into) (table? into) (list? into)) + "expected table, function call, or symbol in &into clause") + (values into iter-out)) - (fn collect* [iter-tbl key-value-expr ...] - "Returns a table made by running an iterator and evaluating an expression - that returns key-value pairs to be inserted sequentially into the table. - This can be thought of as a \"table comprehension\". The provided key-value - expression must return either 2 values, or nil. + (fn collect* [iter-tbl key-expr value-expr ...] + "Return a table made by running an iterator and evaluating an expression that + returns key-value pairs to be inserted sequentially into the table. This can + be thought of as a table comprehension. The body should provide two expressions + (used as key and value) or nil, which causes it to be omitted. For example, (collect [k v (pairs {:apple \"red\" :orange \"orange\"})] (values v k)) returns - {:red \"apple\" :orange \"orange\"}" - (assert (and (sequence? iter-tbl) (>= (length iter-tbl) 2)) + {:red \"apple\" :orange \"orange\"} + + Supports an &into clause after the iterator to put results in an existing table. + Supports early termination with an &until clause." + (assert (and (sequence? iter-tbl) (<= 2 (length iter-tbl))) "expected iterator binding table") - (assert (not= nil key-value-expr) "expected key-value expression") + (assert (not= nil key-expr) "expected key and value expression") (assert (= nil ...) - "expected exactly one body expression. Wrap multiple expressions with do") - `(let [tbl# {}] - (each ,iter-tbl - (match ,key-value-expr - (k# v#) (tset tbl# k# v#))) - tbl#)) + "expected 1 or 2 body expressions; wrap multiple expressions with do") + (let [kv-expr (if (= nil value-expr) key-expr `(values ,key-expr ,value-expr)) + (into iter) (extract-into iter-tbl)] + `(let [tbl# ,into] + (each ,iter + (let [(k# v#) ,kv-expr] + (if (and (not= k# nil) (not= v# nil)) + (tset tbl# k# v#)))) + tbl#))) + + (fn seq-collect [how iter-tbl value-expr ...] + "Common part between icollect and fcollect for producing sequential tables. + + Iteration code only differs in using the for or each keyword, the rest + of the generated code is identical." + (assert (not= nil value-expr) "expected table value expression") + (assert (= nil ...) + "expected exactly one body expression. Wrap multiple expressions in do") + (let [(into iter) (extract-into iter-tbl)] + `(let [tbl# ,into] + ;; believe it or not, using a var here has a pretty good performance + ;; boost: https://p.hagelb.org/icollect-performance.html + (var i# (length tbl#)) + (,how ,iter + (let [val# ,value-expr] + (when (not= nil val#) + (set i# (+ i# 1)) + (tset tbl# i# val#)))) + tbl#))) (fn icollect* [iter-tbl value-expr ...] - "Returns a sequential table made by running an iterator and evaluating an + "Return a sequential table made by running an iterator and evaluating an expression that returns values to be inserted sequentially into the table. - This can be thought of as a \"list comprehension\". + This can be thought of as a table comprehension. If the body evaluates to nil + that element is omitted. For example, - (icollect [_ v (ipairs [1 2 3 4 5])] (when (> v 2) (* v v))) + (icollect [_ v (ipairs [1 2 3 4 5])] + (when (not= v 3) + (* v v))) returns - [9 16 25]" - (assert (and (sequence? iter-tbl) (>= (length iter-tbl) 2)) + [1 4 16 25] + + Supports an &into clause after the iterator to put results in an existing table. + Supports early termination with an &until clause." + (assert (and (sequence? iter-tbl) (<= 2 (length iter-tbl))) "expected iterator binding table") - (assert (not= nil value-expr) "expected table value expression") + (seq-collect 'each iter-tbl value-expr ...)) + + (fn fcollect* [iter-tbl value-expr ...] + "Return a sequential table made by advancing a range as specified by + for, and evaluating an expression that returns values to be inserted + sequentially into the table. This can be thought of as a range + comprehension. If the body evaluates to nil that element is omitted. + + For example, + (fcollect [i 1 10 2] + (when (not= i 3) + (* i i))) + returns + [1 25 49 81] + + Supports an &into clause after the range to put results in an existing table. + Supports early termination with an &until clause." + (assert (and (sequence? iter-tbl) (< 2 (length iter-tbl))) + "expected range binding table") + (seq-collect 'for iter-tbl value-expr ...)) + + (fn accumulate-impl [for? iter-tbl body ...] + (assert (and (sequence? iter-tbl) (<= 4 (length iter-tbl))) + "expected initial value and iterator binding table") + (assert (not= nil body) "expected body expression") (assert (= nil ...) "expected exactly one body expression. Wrap multiple expressions with do") - `(let [tbl# []] - (each ,iter-tbl - (tset tbl# (+ (length tbl#) 1) ,value-expr)) - tbl#)) + (let [[accum-var accum-init] iter-tbl + iter (sym (if for? "for" "each"))] ; accumulate or faccumulate? + `(do + (var ,accum-var ,accum-init) + (,iter ,[(unpack iter-tbl 3)] + (set ,accum-var ,body)) + ,(if (list? accum-var) + (list (sym :values) (unpack accum-var)) + accum-var)))) + + (fn accumulate* [iter-tbl body ...] + "Accumulation macro. + + It takes a binding table and an expression as its arguments. In the binding + table, the first form starts out bound to the second value, which is an initial + accumulator. The rest are an iterator binding table in the format `each` takes. + + It runs through the iterator in each step of which the given expression is + evaluated, and the accumulator is set to the value of the expression. It + eventually returns the final value of the accumulator. + + For example, + (accumulate [total 0 + _ n (pairs {:apple 2 :orange 3})] + (+ total n)) + returns 5" + (accumulate-impl false iter-tbl body ...)) + + (fn faccumulate* [iter-tbl body ...] + "Identical to accumulate, but after the accumulator the binding table is the + same as `for` instead of `each`. Like collect to fcollect, will iterate over a + numerical range like `for` rather than an iterator." + (accumulate-impl true iter-tbl body ...)) + + (fn double-eval-safe? [x type] + (or (= :number type) (= :string type) (= :boolean type) + (and (sym? x) (not (multi-sym? x))))) (fn partial* [f ...] - "Returns a function with all arguments partially applied to f." + "Return a function with all arguments partially applied to f." (assert f "expected a function to partially apply") - (let [body (list f ...)] - (table.insert body _VARARG) - `(fn [,_VARARG] - ,body))) + (let [bindings [] + args []] + (each [_ arg (ipairs [...])] + (if (double-eval-safe? arg (type arg)) + (table.insert args arg) + (let [name (gensym)] + (table.insert bindings name) + (table.insert bindings arg) + (table.insert args name)))) + (let [body (list f (unpack args))] + (table.insert body _VARARG) + ;; only use the extra let if we need double-eval protection + (if (= 0 (length bindings)) + `(fn [,_VARARG] ,body) + `(let ,bindings + (fn [,_VARARG] ,body)))))) (fn pick-args* [n f] - "Creates a function of arity n that applies its arguments to f. + "Create a function of arity n that applies its arguments to f. For example, (pick-args 2 func) expands to (fn [_0_ _1_] (func _0_ _1_))" - (assert (and (= (type n) :number) (= n (math.floor n)) (>= n 0)) + (if (and _G.io _G.io.stderr) + (_G.io.stderr:write + "-- WARNING: pick-args is deprecated and will be removed in the future.\n")) + (assert (and (= (type n) :number) (= n (math.floor n)) (<= 0 n)) (.. "Expected n to be an integer literal >= 0, got " (tostring n))) (let [bindings []] (for [i 1 n] @@ -3942,14 +5735,14 @@ do (,f ,(unpack bindings))))) (fn pick-values* [n ...] - "Like the `values` special, but emits exactly n values. + "Evaluate to exactly n values. For example, (pick-values 2 ...) expands to (let [(_0_ _1_) ...] (values _0_ _1_))" - (assert (and (= :number (type n)) (>= n 0) (= n (math.floor n))) + (assert (and (= :number (type n)) (<= 0 n) (= n (math.floor n))) (.. "Expected n to be an integer >= 0, got " (tostring n))) (let [let-syms (list) let-values (if (= 1 (select "#" ...)) ... `(values ,...))] @@ -3960,14 +5753,14 @@ do (values ,(unpack let-syms)))))) (fn lambda* [...] - "Function literal with arity checking. - Will throw an exception if a declared argument is passed in as nil, unless - that argument name begins with ?." + "Function literal with nil-checked arguments. + Like `fn`, but will throw an exception if a declared argument is passed in as + nil, unless that argument's name begins with a question mark." (let [args [...] has-internal-name? (sym? (. args 1)) arglist (if has-internal-name? (. args 2) (. args 1)) docstring-position (if has-internal-name? 3 2) - has-docstring? (and (> (length args) docstring-position) + has-docstring? (and (< docstring-position (length args)) (= :string (type (. args docstring-position)))) arity-check-position (- 4 (if has-internal-name? 0 1) (if has-docstring? 0 1)) @@ -3978,13 +5771,13 @@ do (check! a)) (let [as (tostring a)] (and (not (as:match "^?")) (not= as "&") (not= as "_") - (not= as "..."))) + (not= as "...") (not= as "&as"))) (table.insert args arity-check-position - `(assert (not= nil ,a) - (string.format "Missing argument %s on %s:%s" - ,(tostring a) - ,(or a.filename :unknown) - ,(or a.line "?")))))) + `(_G.assert (not= nil ,a) + ,(: "Missing argument %s on %s:%s" :format + (tostring a) + (or a.filename :unknown) + (or a.line "?")))))) (assert (= :table (type arglist)) "expected arg list") (each [_ a (ipairs arglist)] @@ -4006,7 +5799,7 @@ do `(,handle ,(view (macroexpand form _SCOPE))))) (fn import-macros* [binding1 module-name1 ...] - "Binds a table of macros from each macro module according to a binding form. + "Bind a table of macros from each macro module according to a binding form. Each binding form can be either a symbol or a k/v destructuring table. Example: (import-macros mymacros :my-macros ; bind to symbol @@ -4014,52 +5807,95 @@ do (assert (and binding1 module-name1 (= 0 (% (select "#" ...) 2))) "expected even number of binding/modulename pairs") (for [i 1 (select "#" binding1 module-name1 ...) 2] + ;; delegate the actual loading of the macros to the require-macros + ;; special which already knows how to set up the compiler env and stuff. + ;; this is weird because require-macros is deprecated but it works. (let [(binding modname) (select i binding1 module-name1 ...) - ;; generate a subscope of current scope, use require-macros - ;; to bring in macro module. after that, we just copy the - ;; macros from subscope to scope. scope (get-scope) - subscope (fennel.scope scope)] - (_SPECIALS.require-macros `(require-macros ,modname) subscope {} ast) + ;; if the module-name is an expression (and not just a string) we + ;; patch our expression to have the correct source filename so + ;; require-macros can pass it down when resolving the module-name. + expr `(import-macros ,modname) + filename (if (list? modname) (. modname 1 :filename) :unknown) + _ (tset expr :filename filename) + macros* (_SPECIALS.require-macros expr scope {} binding)] (if (sym? binding) ;; bind whole table of macros to table bound to symbol - (do - (tset scope.macros (. binding 1) {}) - (each [k v (pairs subscope.macros)] - (tset (. scope.macros (. binding 1)) k v))) + (tset scope.macros (. binding 1) macros*) ;; 1-level table destructuring for importing individual macros (table? binding) (each [macro-name [import-key] (pairs binding)] - (assert (= :function (type (. subscope.macros macro-name))) + (assert (= :function (type (. macros* macro-name))) (.. "macro " macro-name " not found in module " (tostring modname))) - (tset scope.macros import-key (. subscope.macros macro-name)))))) + (tset scope.macros import-key (. macros* macro-name)))))) nil) - ;;; Pattern matching + {:-> ->* + :->> ->>* + :-?> -?>* + :-?>> -?>>* + :?. ?dot + :doto doto* + :when when* + :with-open with-open* + :collect collect* + :icollect icollect* + :fcollect fcollect* + :accumulate accumulate* + :faccumulate faccumulate* + :partial partial* + :lambda lambda* + :λ lambda* + :pick-args pick-args* + :pick-values pick-values* + :macro macro* + :macrodebug macrodebug* + :import-macros import-macros*} + ]===], {env = env, scope = compiler.scopes.compiler, useMetadata = true, filename = "src/fennel/macros.fnl", moduleName = module_name}) + local _0 + for k, v in pairs(built_ins) do + compiler.scopes.global.macros[k] = v + end + _0 = nil + local match_macros = eval([===[;;; Pattern matching + ;; This is separated out so we can use the "core" macros during the + ;; implementation of pattern matching. + + (fn copy [t] (collect [k v (pairs t)] k v)) + + (fn with [opts k] + (doto (copy opts) (tset k true))) + + (fn without [opts k] + (doto (copy opts) (tset k nil))) - (fn match-values [vals pattern unifications match-pattern] + (fn case-values [vals pattern unifications case-pattern opts] (let [condition `(and) bindings []] (each [i pat (ipairs pattern)] - (let [(subcondition subbindings) (match-pattern [(. vals i)] pat - unifications)] + (let [(subcondition subbindings) (case-pattern [(. vals i)] pat + unifications (without opts :multival?))] (table.insert condition subcondition) - (each [_ b (ipairs subbindings)] - (table.insert bindings b)))) + (icollect [_ b (ipairs subbindings) &into bindings] b))) (values condition bindings))) - (fn match-table [val pattern unifications match-pattern] - (let [condition `(and (= (type ,val) :table)) + (fn case-table [val pattern unifications case-pattern opts] + (let [condition `(and (= (_G.type ,val) :table)) bindings []] (each [k pat (pairs pattern)] (if (= pat `&) - (do + (let [rest-pat (. pattern (+ k 1)) + rest-val `(select ,k ((or table.unpack _G.unpack) ,val)) + subcondition (case-table `(pick-values 1 ,rest-val) + rest-pat unifications case-pattern + (without opts :multival?))] + (if (not (sym? rest-pat)) + (table.insert condition subcondition)) (assert (= nil (. pattern (+ k 2))) "expected & rest argument before last parameter") - (table.insert bindings (. pattern (+ k 1))) - (table.insert bindings - [`(select ,k ((or table.unpack _G.unpack) ,val))])) + (table.insert bindings rest-pat) + (table.insert bindings [rest-val])) (= k `&as) (do (table.insert bindings pat) @@ -4074,25 +5910,124 @@ do (or (not= :number (type k)) (and (not= `&as (. pattern (- k 1))) (not= `& (. pattern (- k 1))))) (let [subval `(. ,val ,k) - (subcondition subbindings) (match-pattern [subval] pat - unifications)] + (subcondition subbindings) (case-pattern [subval] pat + unifications + (without opts :multival?))] (table.insert condition subcondition) - (each [_ b (ipairs subbindings)] - (table.insert bindings b))))) + (icollect [_ b (ipairs subbindings) &into bindings] b)))) (values condition bindings))) - (fn match-pattern [vals pattern unifications] - "Takes the AST of values and a single pattern and returns a condition + (fn case-guard [vals condition guards unifications case-pattern opts] + (if (= 0 (length guards)) + (case-pattern vals condition unifications opts) + (let [(pcondition bindings) (case-pattern vals condition unifications opts) + condition `(and ,(unpack guards))] + (values `(and ,pcondition + (let ,bindings + ,condition)) bindings)))) + + (fn symbols-in-pattern [pattern] + "gives the set of symbols inside a pattern" + (if (list? pattern) + (let [result {}] + (each [_ child-pattern (ipairs pattern)] + (collect [name symbol (pairs (symbols-in-pattern child-pattern)) &into result] + name symbol)) + result) + (sym? pattern) + (if (and (not= pattern `or) + (not= pattern `where) + (not= pattern `?) + (not= pattern `nil)) + {(tostring pattern) pattern} + {}) + (= (type pattern) :table) + (let [result {}] + (each [key-pattern value-pattern (pairs pattern)] + (collect [name symbol (pairs (symbols-in-pattern key-pattern)) &into result] + name symbol) + (collect [name symbol (pairs (symbols-in-pattern value-pattern)) &into result] + name symbol)) + result) + {})) + + (fn symbols-in-every-pattern [pattern-list infer-unification?] + "gives a list of symbols that are present in every pattern in the list" + (let [?symbols (accumulate [?symbols nil + _ pattern (ipairs pattern-list)] + (let [in-pattern (symbols-in-pattern pattern)] + (if ?symbols + (do + (each [name symbol (pairs ?symbols)] + (when (not (. in-pattern name)) + (tset ?symbols name nil))) + ?symbols) + in-pattern)))] + (icollect [_ symbol (pairs (or ?symbols {}))] + (if (not (and infer-unification? + (in-scope? symbol))) + symbol)))) + + (fn case-or [vals pattern guards unifications case-pattern opts] + (let [pattern [(unpack pattern 2)] + bindings (symbols-in-every-pattern pattern opts.infer-unification?)] ;; TODO opts.infer-unification instead of opts.unification? + (if (= 0 (length bindings)) + ;; no bindings special case generates simple code + (let [condition + (icollect [i subpattern (ipairs pattern) &into `(or)] + (let [(subcondition subbindings) (case-pattern vals subpattern unifications opts)] + subcondition))] + (values + (if (= 0 (length guards)) + condition + `(and ,condition ,(unpack guards))) + [])) + ;; case with bindings is handled specially, and returns three values instead of two + (let [matched? (gensym :matched?) + bindings-mangled (icollect [_ binding (ipairs bindings)] + (gensym (tostring binding))) + pre-bindings `(if)] + (each [i subpattern (ipairs pattern)] + (let [(subcondition subbindings) (case-guard vals subpattern guards {} case-pattern opts)] + (table.insert pre-bindings subcondition) + (table.insert pre-bindings `(let ,subbindings + (values true ,(unpack bindings)))))) + (values matched? + [`(,(unpack bindings)) `(values ,(unpack bindings-mangled))] + [`(,matched? ,(unpack bindings-mangled)) pre-bindings]))))) + + (fn case-pattern [vals pattern unifications opts top-level?] + "Take the AST of values and a single pattern and returns a condition to determine if it matches as well as a list of bindings to introduce for the duration of the body if it does match." + + ;; This function returns the following values (multival): + ;; a "condition", which is an expression that determines whether the + ;; pattern should match, + ;; a "bindings", which bind all of the symbols used in a pattern + ;; an optional "pre-bindings", which is a list of bindings that happen + ;; before the condition and bindings are evaluated. These should only + ;; come from a (case-or). In this case there should be no recursion: + ;; the call stack should be case-condition > case-pattern > case-or + ;; + ;; Here are the expected flags in the opts table: + ;; :infer-unification? boolean - if the pattern should guess when to unify (ie, match -> true, case -> false) + ;; :multival? boolean - if the pattern can contain multivals (in order to disallow patterns like [(1 2)]) + ;; :in-where? boolean - if the pattern is surrounded by (where) (where opts into more pattern features) + ;; :legacy-guard-allowed? boolean - if the pattern should allow `(a ? b) patterns + ;; we have to assume we're matching against multiple values here until we ;; know we're either in a multi-valued clause (in which case we know the # ;; of vals) or we're not, in which case we only care about the first one. (let [[val] vals] - (if (or (and (sym? pattern) ; unification with outer locals (or nil) - (not= "_" (tostring pattern)) ; never unify _ - (or (in-scope? pattern) (= :nil (tostring pattern)))) - (and (multi-sym? pattern) (in-scope? (. (multi-sym? pattern) 1)))) + (if (and (sym? pattern) + (or (= pattern `nil) + (and opts.infer-unification? + (in-scope? pattern) + (not= pattern `_)) + (and opts.infer-unification? + (multi-sym? pattern) + (in-scope? (. (multi-sym? pattern) 1))))) (values `(= ,val ,pattern) []) ;; unify a local we've seen already (and (sym? pattern) (. unifications (tostring pattern))) @@ -4103,165 +6038,210 @@ do (if (not wildcard?) (tset unifications (tostring pattern) val)) (values (if (or wildcard? (string.find (tostring pattern) "^?")) true `(not= ,(sym :nil) ,val)) [pattern val])) + ;; opt-in unify with (=) + (and (list? pattern) + (= (. pattern 1) `=) + (sym? (. pattern 2))) + (let [bind (. pattern 2)] + (assert-compile (= 2 (length pattern)) "(=) should take only one argument" pattern) + (assert-compile (not opts.infer-unification?) "(=) cannot be used inside of match" pattern) + (assert-compile opts.in-where? "(=) must be used in (where) patterns" pattern) + (assert-compile (and (sym? bind) (not= bind `nil) "= has to bind to a symbol" bind)) + (values `(= ,val ,bind) [])) + ;; where-or clause + (and (list? pattern) (= (. pattern 1) `where) (list? (. pattern 2)) (= (. pattern 2 1) `or)) + (do + (assert-compile top-level? "can't nest (where) pattern" pattern) + (case-or vals (. pattern 2) [(unpack pattern 3)] unifications case-pattern (with opts :in-where?))) + ;; where clause + (and (list? pattern) (= (. pattern 1) `where)) + (do + (assert-compile top-level? "can't nest (where) pattern" pattern) + (case-guard vals (. pattern 2) [(unpack pattern 3)] unifications case-pattern (with opts :in-where?))) + ;; or clause (not allowed on its own) + (and (list? pattern) (= (. pattern 1) `or)) + (do + (assert-compile top-level? "can't nest (or) pattern" pattern) + ;; This assertion can be removed to make patterns more permissive + (assert-compile false "(or) must be used in (where) patterns" pattern) + (case-or vals pattern [] unifications case-pattern opts)) ;; guard clause (and (list? pattern) (= (. pattern 2) `?)) - (let [(pcondition bindings) (match-pattern vals (. pattern 1) - unifications) - condition `(and ,(unpack pattern 3))] - (values `(and ,pcondition - (let ,bindings - ,condition)) bindings)) + (do + (assert-compile opts.legacy-guard-allowed? "legacy guard clause not supported in case" pattern) + (case-guard vals (. pattern 1) [(unpack pattern 3)] unifications case-pattern opts)) ;; multi-valued patterns (represented as lists) (list? pattern) - (match-values vals pattern unifications match-pattern) + (do + (assert-compile opts.multival? "can't nest multi-value destructuring" pattern) + (case-values vals pattern unifications case-pattern opts)) ;; table patterns (= (type pattern) :table) - (match-table val pattern unifications match-pattern) + (case-table val pattern unifications case-pattern opts) ;; literal value (values `(= ,val ,pattern) [])))) - (fn match-condition [vals clauses] + (fn add-pre-bindings [out pre-bindings] + "Decide when to switch from the current `if` AST to a new one" + (if pre-bindings + ;; `out` no longer needs to grow. + ;; Instead, a new tail `if` AST is introduced, which is where the rest of + ;; the clauses will get appended. This way, all future clauses have the + ;; pre-bindings in scope. + (let [tail `(if)] + (table.insert out true) + (table.insert out `(let ,pre-bindings ,tail)) + tail) + ;; otherwise, keep growing the current `if` AST. + out)) + + (fn case-condition [vals clauses match?] "Construct the actual `if` AST for the given match values and clauses." - (if (not= 0 (% (length clauses) 2)) ; treat odd final clause as default - (table.insert clauses (length clauses) (sym "_"))) - (let [out `(if)] - (for [i 1 (length clauses) 2] + ;; root is the original `if` AST. + ;; out is the `if` AST that is currently being grown. + (let [root `(if)] + (faccumulate [out root + i 1 (length clauses) 2] (let [pattern (. clauses i) body (. clauses (+ i 1)) - (condition bindings) (match-pattern vals pattern {})] + (condition bindings pre-bindings) (case-pattern vals pattern {} + {:multival? true + :infer-unification? match? + :legacy-guard-allowed? match?} + true) + out (add-pre-bindings out pre-bindings)] + ;; grow the `if` AST by one extra condition (table.insert out condition) (table.insert out `(let ,bindings - ,body)))) - out)) + ,body)) + out)) + root)) - (fn match-val-syms [clauses] - "How many multi-valued clauses are there? return a list of that many gensyms." - (let [syms (list (gensym))] - (for [i 1 (length clauses) 2] - (let [clause (if (and (list? (. clauses i)) (= `? (. clauses i 2))) - (. clauses i 1) - (. clauses i))] - (if (list? clause) - (each [valnum (ipairs clause)] - (if (not (. syms valnum)) - (tset syms valnum (gensym))))))) - syms)) + (fn count-case-multival [pattern] + "Identify the amount of multival values that a pattern requires." + (if (and (list? pattern) (= (. pattern 2) `?)) + (count-case-multival (. pattern 1)) + (and (list? pattern) (= (. pattern 1) `where)) + (count-case-multival (. pattern 2)) + (and (list? pattern) (= (. pattern 1) `or)) + (accumulate [longest 0 + _ child-pattern (ipairs pattern)] + (math.max longest (count-case-multival child-pattern))) + (list? pattern) + (length pattern) + 1)) - (fn match* [val ...] - ;; Old implementation of match macro, which doesn't directly support - ;; `where' and `or'. New syntax is implemented in `match-where', - ;; which simply generates old syntax and feeds it to `match*'. + (fn case-val-syms [clauses] + "What is the length of the largest multi-valued clause? return a list of that + many gensyms." + (let [patterns (fcollect [i 1 (length clauses) 2] + (. clauses i)) + sym-count (accumulate [longest 0 + _ pattern (ipairs patterns)] + (math.max longest (count-case-multival pattern)))] + (fcollect [i 1 sym-count &into (list)] + (gensym)))) + + (fn case-impl [match? val ...] + "The shared implementation of case and match." + (assert (not= val nil) "missing subject") + (assert (= 0 (math.fmod (select :# ...) 2)) + "expected even number of pattern/body pairs") + (assert (not= 0 (select :# ...)) + "expected at least one pattern/body pair") (let [clauses [...] - vals (match-val-syms clauses)] + vals (case-val-syms clauses)] ;; protect against multiple evaluation of the value, bind against as ;; many values as we ever match against in the clauses. - (list `let [vals val] (match-condition vals clauses)))) + (list `let [vals val] (case-condition vals clauses match?)))) - ;; Construction of old match syntax from new syntax - - (fn partition-2 [seq] - ;; Partition `seq` by 2. - ;; If `seq` has odd amount of elements, the last one is dropped. - ;; - ;; Input: [1 2 3 4 5] - ;; Output: [[1 2] [3 4]] - (let [firsts [] - seconds [] - res []] - (for [i 1 (length seq) 2] - (let [first (. seq i) - second (. seq (+ i 1))] - (table.insert firsts (if (not= nil first) first `nil)) - (table.insert seconds (if (not= nil second) second `nil)))) - (each [i v1 (ipairs firsts)] - (let [v2 (. seconds i)] - (if (not= nil v2) - (table.insert res [v1 v2])))) - res)) + (fn case* [val ...] + "Perform pattern matching on val. See reference for details. - (fn transform-or [[_ & pats] guards] - ;; Transforms `(or pat pats*)` lists into match `guard` patterns. - ;; - ;; (or pat1 pat2), guard => [(pat1 ? guard) (pat2 ? guard)] - (let [res []] - (each [_ pat (ipairs pats)] - (table.insert res (list pat `? (unpack guards)))) - res)) + Syntax: - (fn transform-cond [cond] - ;; Transforms `where` cond into sequence of `match` guards. - ;; - ;; pat => [pat] - ;; (where pat guard) => [(pat ? guard)] - ;; (where (or pat1 pat2) guard) => [(pat1 ? guard) (pat2 ? guard)] - (if (and (list? cond) (= (. cond 1) `where)) - (let [second (. cond 2)] - (if (and (list? second) (= (. second 1) `or)) - (transform-or second [(unpack cond 3)]) - :else - [(list second `? (unpack cond 3))])) - :else - [cond])) + (case data-expression + pattern body + (where pattern guards*) body + (or pattern patterns*) body + (where (or pattern patterns*) guards*) body + ;; legacy: + (pattern ? guards*) body)" + (case-impl false val ...)) - (fn match-where [val ...] - "Perform pattern matching on val. See reference for details. + (fn match* [val ...] + "Perform pattern matching on val, automatically unifying on variables in + local scope. See reference for details. Syntax: (match data-expression pattern body - (where pattern guard guards*) body - (where (or pattern patterns*) guard guards*) body)" - (let [conds-bodies (partition-2 [...]) - else-branch (if (not= 0 (% (select "#" ...) 2)) - (select (select "#" ...) ...)) - match-body []] - (each [_ [cond body] (ipairs conds-bodies)] - (each [_ cond (ipairs (transform-cond cond))] - (table.insert match-body cond) - (table.insert match-body body))) - (if else-branch - (table.insert match-body else-branch)) - (match* val (unpack match-body)))) + (where pattern guards*) body + (or pattern patterns*) body + (where (or pattern patterns*) guards*) body + ;; legacy: + (pattern ? guards*) body)" + (case-impl true val ...)) - {:-> ->* - :->> ->>* - :-?> -?>* - :-?>> -?>>* - :?. ?dot - :doto doto* - :when when* - :with-open with-open* - :collect collect* - :icollect icollect* - :partial partial* - :lambda lambda* - :pick-args pick-args* - :pick-values pick-values* - :macro macro* - :macrodebug macrodebug* - :import-macros import-macros* - :match match-where} - ]===] - local module_name = "nvim-tree-docs.aniseed.fennel.macros" - local _ = nil - local function _0_() - return mod - end - package.preload[module_name] = _0_ - _ = nil - local env = nil - do - local _1_0 = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) - _1_0["utils"] = utils - _1_0["fennel"] = mod - env = _1_0 - end - local built_ins = eval(builtin_macros, {allowedGlobals = false, env = env, filename = "src/fennel/macros.fnl", moduleName = module_name, scope = compiler.scopes.compiler, useMetadata = true}) - for k, v in pairs(built_ins) do + (fn case-try-step [how expr else pattern body ...] + (if (= nil pattern body) + expr + ;; unlike regular match, we can't know how many values the value + ;; might evaluate to, so we have to capture them all in ... via IIFE + ;; to avoid double-evaluation. + `((fn [...] + (,how ... + ,pattern ,(case-try-step how body else ...) + ,(unpack else))) + ,expr))) + + (fn case-try-impl [how expr pattern body ...] + (let [clauses [pattern body ...] + last (. clauses (length clauses)) + catch (if (= `catch (and (= :table (type last)) (. last 1))) + (let [[_ & e] (table.remove clauses)] e) ; remove `catch sym + [`_# `...])] + (assert (= 0 (math.fmod (length clauses) 2)) + "expected every pattern to have a body") + (assert (= 0 (math.fmod (length catch) 2)) + "expected every catch pattern to have a body") + (case-try-step how expr catch (unpack clauses)))) + + (fn case-try* [expr pattern body ...] + "Perform chained pattern matching for a sequence of steps which might fail. + + The values from the initial expression are matched against the first pattern. + If they match, the first body is evaluated and its values are matched against + the second pattern, etc. + + If there is a (catch pat1 body1 pat2 body2 ...) form at the end, any mismatch + from the steps will be tried against these patterns in sequence as a fallback + just like a normal match. If there is no catch, the mismatched values will be + returned as the value of the entire expression." + (case-try-impl `case expr pattern body ...)) + + (fn match-try* [expr pattern body ...] + "Perform chained pattern matching for a sequence of steps which might fail. + + The values from the initial expression are matched against the first pattern. + If they match, the first body is evaluated and its values are matched against + the second pattern, etc. + + If there is a (catch pat1 body1 pat2 body2 ...) form at the end, any mismatch + from the steps will be tried against these patterns in sequence as a fallback + just like a normal match. If there is no catch, the mismatched values will be + returned as the value of the entire expression." + (case-try-impl `match expr pattern body ...)) + + {:case case* + :case-try case-try* + :match match* + :match-try match-try*} + ]===], {env = env, scope = compiler.scopes.compiler, allowedGlobals = false, useMetadata = true, filename = "src/fennel/match.fnl", moduleName = module_name}) + for k, v in pairs(match_macros) do compiler.scopes.global.macros[k] = v end - compiler.scopes.global.macros["\206\187"] = compiler.scopes.global.macros.lambda package.preload[module_name] = nil end return mod diff --git a/lua/nvim-tree-docs/aniseed/deps/fennelview.lua b/lua/nvim-tree-docs/aniseed/deps/fennelview.lua deleted file mode 100644 index 9935951..0000000 --- a/lua/nvim-tree-docs/aniseed/deps/fennelview.lua +++ /dev/null @@ -1,382 +0,0 @@ -local type_order = {["function"] = 5, boolean = 2, number = 1, string = 3, table = 4, thread = 7, userdata = 6} -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 tb = type(b) - if ((ta == tb) and ((ta == "string") or (ta == "number"))) then - return (a < b) - else - local dta = type_order[ta] - local dtb = type_order[tb] - if (dta and dtb) then - return (dta < dtb) - elseif dta then - return true - elseif dtb then - return false - else - return (ta < tb) - end - end -end -local function table_kv_pairs(t) - local assoc_3f = false - local i = 1 - local kv = {} - local insert = table.insert - for k, v in pairs(t) do - if ((type(k) ~= "number") or (k ~= i)) then - assoc_3f = true - end - i = (i + 1) - insert(kv, {k, v}) - end - table.sort(kv, sort_keys) - if (#kv == 0) then - return kv, "empty" - else - local function _2_() - if assoc_3f then - return "table" - else - return "seq" - end - end - return kv, _2_() - end -end -local function count_table_appearances(t, appearances) - if (type(t) == "table") then - if not appearances[t] then - appearances[t] = 1 - for k, v in pairs(t) do - count_table_appearances(k, appearances) - count_table_appearances(v, appearances) - end - else - appearances[t] = ((appearances[t] or 0) + 1) - end - end - return appearances -end -local function save_table(t, seen) - local seen0 = (seen or {len = 0}) - local id = (seen0.len + 1) - if not seen0[t] then - seen0[t] = id - seen0.len = id - end - return seen0 -end -local function detect_cycle(t, seen, _3fk) - if ("table" == type(t)) then - seen[t] = true - local _2_0, _3_0 = next(t, _3fk) - if ((nil ~= _2_0) and (nil ~= _3_0)) then - local k = _2_0 - local v = _3_0 - return (seen[k] or detect_cycle(k, seen) or seen[v] or detect_cycle(v, seen) or detect_cycle(t, seen, k)) - end - end -end -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))) -end -local function table_indent(t, indent, id) - local opener_length = nil - if id then - opener_length = (#tostring(id) + 2) - else - opener_length = 1 - end - return (indent + opener_length) -end -local pp = nil -local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix) - local indent_str = ("\n" .. string.rep(" ", indent)) - local open = nil - local function _2_() - if ("seq" == table_type) then - return "[" - else - return "{" - end - end - open = ((prefix or "") .. _2_()) - local close = nil - if ("seq" == table_type) then - close = "]" - else - close = "}" - end - local oneline = (open .. table.concat(elements, " ") .. close) - if (not options["one-line?"] and (multiline_3f or ((indent + #oneline) > options["line-length"]))) then - return (open .. table.concat(elements, indent_str) .. close) - else - return oneline - end -end -local function pp_associative(t, kv, options, indent, key_3f) - local multiline_3f = false - local id = options.seen[t] - if (options.level >= options.depth) then - return "{...}" - elseif (id and options["detect-cycles?"]) then - return ("@" .. id .. "{...}") - else - local visible_cycle_3f0 = visible_cycle_3f(t, options) - local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) - local slength = nil - local function _3_() - local _2_0 = rawget(_G, "utf8") - if _2_0 then - return _2_0.len - else - return _2_0 - end - end - local function _4_(_241) - return #_241 - end - slength = ((options["utf8?"] and _3_()) or _4_) - local prefix = nil - if visible_cycle_3f0 then - prefix = ("@" .. id0) - else - prefix = "" - end - local items = nil - do - local tbl_0_ = {} - for _, _6_0 in pairs(kv) do - local _7_ = _6_0 - local k = _7_[1] - local v = _7_[2] - local _8_ - do - local k0 = pp(k, options, (indent0 + 1), true) - local v0 = pp(v, options, (indent0 + slength(k0) + 1)) - multiline_3f = (multiline_3f or k0:find("\n") or v0:find("\n")) - _8_ = (k0 .. " " .. v0) - end - tbl_0_[(#tbl_0_ + 1)] = _8_ - end - items = tbl_0_ - end - return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix) - end -end -local function pp_sequence(t, kv, options, indent) - local multiline_3f = false - local id = options.seen[t] - if (options.level >= options.depth) then - return "[...]" - elseif (id and options["detect-cycles?"]) then - return ("@" .. id .. "[...]") - else - local visible_cycle_3f0 = visible_cycle_3f(t, options) - local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) - local prefix = nil - if visible_cycle_3f0 then - prefix = ("@" .. id0) - else - prefix = "" - end - local items = nil - do - local tbl_0_ = {} - for _, _3_0 in pairs(kv) do - local _4_ = _3_0 - local _0 = _4_[1] - local v = _4_[2] - local _5_ - do - local v0 = pp(v, options, indent0) - multiline_3f = (multiline_3f or v0:find("\n")) - _5_ = v0 - end - tbl_0_[(#tbl_0_ + 1)] = _5_ - end - items = tbl_0_ - end - return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix) - end -end -local function concat_lines(lines, options, indent, force_multi_line_3f) - if (#lines == 0) then - if options["empty-as-sequence?"] then - return "[]" - else - return "{}" - end - else - local oneline = nil - local _2_ - do - local tbl_0_ = {} - for _, line in ipairs(lines) do - tbl_0_[(#tbl_0_ + 1)] = line:gsub("^%s+", "") - end - _2_ = tbl_0_ - end - oneline = table.concat(_2_, " ") - if (not options["one-line?"] and (force_multi_line_3f or oneline:find("\n") or ((indent + #oneline) > options["line-length"]))) then - return table.concat(lines, ("\n" .. string.rep(" ", indent))) - else - return oneline - end - end -end -local function pp_metamethod(t, metamethod, options, indent) - if (options.level >= options.depth) then - if options["empty-as-sequence?"] then - return "[...]" - else - return "{...}" - end - else - local _ = nil - local function _2_(_241) - return visible_cycle_3f(_241, options) - end - options["visible-cycle?"] = _2_ - _ = nil - local lines, force_multi_line_3f = metamethod(t, pp, options, indent) - options["visible-cycle?"] = nil - local _3_0 = type(lines) - if (_3_0 == "string") then - return lines - elseif (_3_0 == "table") then - return concat_lines(lines, options, indent, force_multi_line_3f) - else - local _0 = _3_0 - return error("__fennelview metamethod must return a table of lines") - end - end -end -local function pp_table(x, options, indent) - options.level = (options.level + 1) - local x0 = nil - do - local _2_0 = nil - if options["metamethod?"] then - local _3_0 = x - if _3_0 then - local _4_0 = getmetatable(_3_0) - if _4_0 then - _2_0 = _4_0.__fennelview - else - _2_0 = _4_0 - end - else - _2_0 = _3_0 - end - else - _2_0 = nil - end - if (nil ~= _2_0) then - local metamethod = _2_0 - x0 = pp_metamethod(x, metamethod, options, indent) - else - local _ = _2_0 - local _4_0, _5_0 = table_kv_pairs(x) - if (true and (_5_0 == "empty")) then - local _0 = _4_0 - if options["empty-as-sequence?"] then - x0 = "[]" - else - x0 = "{}" - end - elseif ((nil ~= _4_0) and (_5_0 == "table")) then - local kv = _4_0 - x0 = pp_associative(x, kv, options, indent) - elseif ((nil ~= _4_0) and (_5_0 == "seq")) then - local kv = _4_0 - x0 = pp_sequence(x, kv, options, indent) - else - x0 = nil - end - end - end - options.level = (options.level - 1) - return x0 -end -local function number__3estring(n) - local _2_0 = string.gsub(tostring(n), ",", ".") - return _2_0 -end -local function colon_string_3f(s) - 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 -local function make_options(t, options) - 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}} - for k, v in pairs((options or {})) do - defaults[k] = v - end - for k, v in pairs(overrides) do - defaults[k] = v - end - return defaults -end -local function _2_(x, options, indent, colon_3f) - local indent0 = (indent or 0) - local options0 = (options or make_options(x)) - local tv = type(x) - local function _4_() - local _3_0 = getmetatable(x) - if _3_0 then - return _3_0.__fennelview - else - return _3_0 - end - end - if ((tv == "table") or ((tv == "userdata") and _4_())) then - return pp_table(x, options0, indent0) - elseif (tv == "number") then - return number__3estring(x) - 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) - elseif (tv == "string") then - return pp_string(x, options0, indent0) - elseif ((tv == "boolean") or (tv == "nil")) then - return tostring(x) - else - return ("#<" .. tostring(x) .. ">") - end - end -end -pp = _2_ -local function view(x, options) - return pp(x, make_options(x, options), 0) -end -return view diff --git a/lua/nvim-tree-docs/aniseed/deps/fun.lua b/lua/nvim-tree-docs/aniseed/deps/fun.lua new file mode 100644 index 0000000..efd1440 --- /dev/null +++ b/lua/nvim-tree-docs/aniseed/deps/fun.lua @@ -0,0 +1,1058 @@ +--- +--- Lua Fun - a high-performance functional programming library for LuaJIT +--- +--- Copyright (c) 2013-2017 Roman Tsisyk +--- +--- Distributed under the MIT/X11 License. See COPYING.md for more details. +--- + +local exports = {} +local methods = {} + +-- compatibility with Lua 5.1/5.2 +local unpack = rawget(table, "unpack") or unpack + +-------------------------------------------------------------------------------- +-- Tools +-------------------------------------------------------------------------------- + +local return_if_not_empty = function(state_x, ...) + if state_x == nil then + return nil + end + return ... +end + +local call_if_not_empty = function(fun, state_x, ...) + if state_x == nil then + return nil + end + return state_x, fun(...) +end + +local function deepcopy(orig) -- used by cycle() + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + else + copy = orig + end + return copy +end + +local iterator_mt = { + -- usually called by for-in loop + __call = function(self, param, state) + return self.gen(param, state) + end; + __tostring = function(self) + return '' + end; + -- add all exported methods + __index = methods; +} + +local wrap = function(gen, param, state) + return setmetatable({ + gen = gen, + param = param, + state = state + }, iterator_mt), param, state +end +exports.wrap = wrap + +local unwrap = function(self) + return self.gen, self.param, self.state +end +methods.unwrap = unwrap + +-------------------------------------------------------------------------------- +-- Basic Functions +-------------------------------------------------------------------------------- + +local nil_gen = function(_param, _state) + return nil +end + +local string_gen = function(param, state) + local state = state + 1 + if state > #param then + return nil + end + local r = string.sub(param, state, state) + return state, r +end + +local ipairs_gen = ipairs({}) -- get the generating function from ipairs + +local pairs_gen = pairs({ a = 0 }) -- get the generating function from pairs +local map_gen = function(tab, key) + local value + local key, value = pairs_gen(tab, key) + return key, key, value +end + +local rawiter = function(obj, param, state) + assert(obj ~= nil, "invalid iterator") + if type(obj) == "table" then + local mt = getmetatable(obj); + if mt ~= nil then + if mt == iterator_mt then + return obj.gen, obj.param, obj.state + elseif mt.__ipairs ~= nil then + return mt.__ipairs(obj) + elseif mt.__pairs ~= nil then + return mt.__pairs(obj) + end + end + if #obj > 0 then + -- array + return ipairs(obj) + else + -- hash + return map_gen, obj, nil + end + elseif (type(obj) == "function") then + return obj, param, state + elseif (type(obj) == "string") then + if #obj == 0 then + return nil_gen, nil, nil + end + return string_gen, obj, 0 + end + error(string.format('object %s of type "%s" is not iterable', + obj, type(obj))) +end + +local iter = function(obj, param, state) + return wrap(rawiter(obj, param, state)) +end +exports.iter = iter + +local method0 = function(fun) + return function(self) + return fun(self.gen, self.param, self.state) + end +end + +local method1 = function(fun) + return function(self, arg1) + return fun(arg1, self.gen, self.param, self.state) + end +end + +local method2 = function(fun) + return function(self, arg1, arg2) + return fun(arg1, arg2, self.gen, self.param, self.state) + end +end + +local export0 = function(fun) + return function(gen, param, state) + return fun(rawiter(gen, param, state)) + end +end + +local export1 = function(fun) + return function(arg1, gen, param, state) + return fun(arg1, rawiter(gen, param, state)) + end +end + +local export2 = function(fun) + return function(arg1, arg2, gen, param, state) + return fun(arg1, arg2, rawiter(gen, param, state)) + end +end + +local each = function(fun, gen, param, state) + repeat + state = call_if_not_empty(fun, gen(param, state)) + until state == nil +end +methods.each = method1(each) +exports.each = export1(each) +methods.for_each = methods.each +exports.for_each = exports.each +methods.foreach = methods.each +exports.foreach = exports.each + +-------------------------------------------------------------------------------- +-- Generators +-------------------------------------------------------------------------------- + +local range_gen = function(param, state) + local stop, step = param[1], param[2] + local state = state + step + if state > stop then + return nil + end + return state, state +end + +local range_rev_gen = function(param, state) + local stop, step = param[1], param[2] + local state = state + step + if state < stop then + return nil + end + return state, state +end + +local range = function(start, stop, step) + if step == nil then + if stop == nil then + if start == 0 then + return nil_gen, nil, nil + end + stop = start + start = stop > 0 and 1 or -1 + end + step = start <= stop and 1 or -1 + end + + assert(type(start) == "number", "start must be a number") + assert(type(stop) == "number", "stop must be a number") + assert(type(step) == "number", "step must be a number") + assert(step ~= 0, "step must not be zero") + + if (step > 0) then + return wrap(range_gen, {stop, step}, start - step) + elseif (step < 0) then + return wrap(range_rev_gen, {stop, step}, start - step) + end +end +exports.range = range + +local duplicate_table_gen = function(param_x, state_x) + return state_x + 1, unpack(param_x) +end + +local duplicate_fun_gen = function(param_x, state_x) + return state_x + 1, param_x(state_x) +end + +local duplicate_gen = function(param_x, state_x) + return state_x + 1, param_x +end + +local duplicate = function(...) + if select('#', ...) <= 1 then + return wrap(duplicate_gen, select(1, ...), 0) + else + return wrap(duplicate_table_gen, {...}, 0) + end +end +exports.duplicate = duplicate +exports.replicate = duplicate +exports.xrepeat = duplicate + +local tabulate = function(fun) + assert(type(fun) == "function") + return wrap(duplicate_fun_gen, fun, 0) +end +exports.tabulate = tabulate + +local zeros = function() + return wrap(duplicate_gen, 0, 0) +end +exports.zeros = zeros + +local ones = function() + return wrap(duplicate_gen, 1, 0) +end +exports.ones = ones + +local rands_gen = function(param_x, _state_x) + return 0, math.random(param_x[1], param_x[2]) +end + +local rands_nil_gen = function(_param_x, _state_x) + return 0, math.random() +end + +local rands = function(n, m) + if n == nil and m == nil then + return wrap(rands_nil_gen, 0, 0) + end + assert(type(n) == "number", "invalid first arg to rands") + if m == nil then + m = n + n = 0 + else + assert(type(m) == "number", "invalid second arg to rands") + end + assert(n < m, "empty interval") + return wrap(rands_gen, {n, m - 1}, 0) +end +exports.rands = rands + +-------------------------------------------------------------------------------- +-- Slicing +-------------------------------------------------------------------------------- + +local nth = function(n, gen_x, param_x, state_x) + assert(n > 0, "invalid first argument to nth") + -- An optimization for arrays and strings + if gen_x == ipairs_gen then + return param_x[n] + elseif gen_x == string_gen then + if n <= #param_x then + return string.sub(param_x, n, n) + else + return nil + end + end + for i=1,n-1,1 do + state_x = gen_x(param_x, state_x) + if state_x == nil then + return nil + end + end + return return_if_not_empty(gen_x(param_x, state_x)) +end +methods.nth = method1(nth) +exports.nth = export1(nth) + +local head_call = function(state, ...) + if state == nil then + error("head: iterator is empty") + end + return ... +end + +local head = function(gen, param, state) + return head_call(gen(param, state)) +end +methods.head = method0(head) +exports.head = export0(head) +exports.car = exports.head +methods.car = methods.head + +local tail = function(gen, param, state) + state = gen(param, state) + if state == nil then + return wrap(nil_gen, nil, nil) + end + return wrap(gen, param, state) +end +methods.tail = method0(tail) +exports.tail = export0(tail) +exports.cdr = exports.tail +methods.cdr = methods.tail + +local take_n_gen_x = function(i, state_x, ...) + if state_x == nil then + return nil + end + return {i, state_x}, ... +end + +local take_n_gen = function(param, state) + local n, gen_x, param_x = param[1], param[2], param[3] + local i, state_x = state[1], state[2] + if i >= n then + return nil + end + return take_n_gen_x(i + 1, gen_x(param_x, state_x)) +end + +local take_n = function(n, gen, param, state) + assert(n >= 0, "invalid first argument to take_n") + return wrap(take_n_gen, {n, gen, param}, {0, state}) +end +methods.take_n = method1(take_n) +exports.take_n = export1(take_n) + +local take_while_gen_x = function(fun, state_x, ...) + if state_x == nil or not fun(...) then + return nil + end + return state_x, ... +end + +local take_while_gen = function(param, state_x) + local fun, gen_x, param_x = param[1], param[2], param[3] + return take_while_gen_x(fun, gen_x(param_x, state_x)) +end + +local take_while = function(fun, gen, param, state) + assert(type(fun) == "function", "invalid first argument to take_while") + return wrap(take_while_gen, {fun, gen, param}, state) +end +methods.take_while = method1(take_while) +exports.take_while = export1(take_while) + +local take = function(n_or_fun, gen, param, state) + if type(n_or_fun) == "number" then + return take_n(n_or_fun, gen, param, state) + else + return take_while(n_or_fun, gen, param, state) + end +end +methods.take = method1(take) +exports.take = export1(take) + +local drop_n = function(n, gen, param, state) + assert(n >= 0, "invalid first argument to drop_n") + local i + for i=1,n,1 do + state = gen(param, state) + if state == nil then + return wrap(nil_gen, nil, nil) + end + end + return wrap(gen, param, state) +end +methods.drop_n = method1(drop_n) +exports.drop_n = export1(drop_n) + +local drop_while_x = function(fun, state_x, ...) + if state_x == nil or not fun(...) then + return state_x, false + end + return state_x, true, ... +end + +local drop_while = function(fun, gen_x, param_x, state_x) + assert(type(fun) == "function", "invalid first argument to drop_while") + local cont, state_x_prev + repeat + state_x_prev = deepcopy(state_x) + state_x, cont = drop_while_x(fun, gen_x(param_x, state_x)) + until not cont + if state_x == nil then + return wrap(nil_gen, nil, nil) + end + return wrap(gen_x, param_x, state_x_prev) +end +methods.drop_while = method1(drop_while) +exports.drop_while = export1(drop_while) + +local drop = function(n_or_fun, gen_x, param_x, state_x) + if type(n_or_fun) == "number" then + return drop_n(n_or_fun, gen_x, param_x, state_x) + else + return drop_while(n_or_fun, gen_x, param_x, state_x) + end +end +methods.drop = method1(drop) +exports.drop = export1(drop) + +local split = function(n_or_fun, gen_x, param_x, state_x) + return take(n_or_fun, gen_x, param_x, state_x), + drop(n_or_fun, gen_x, param_x, state_x) +end +methods.split = method1(split) +exports.split = export1(split) +methods.split_at = methods.split +exports.split_at = exports.split +methods.span = methods.split +exports.span = exports.split + +-------------------------------------------------------------------------------- +-- Indexing +-------------------------------------------------------------------------------- + +local index = function(x, gen, param, state) + local i = 1 + for _k, r in gen, param, state do + if r == x then + return i + end + i = i + 1 + end + return nil +end +methods.index = method1(index) +exports.index = export1(index) +methods.index_of = methods.index +exports.index_of = exports.index +methods.elem_index = methods.index +exports.elem_index = exports.index + +local indexes_gen = function(param, state) + local x, gen_x, param_x = param[1], param[2], param[3] + local i, state_x = state[1], state[2] + local r + while true do + state_x, r = gen_x(param_x, state_x) + if state_x == nil then + return nil + end + i = i + 1 + if r == x then + return {i, state_x}, i + end + end +end + +local indexes = function(x, gen, param, state) + return wrap(indexes_gen, {x, gen, param}, {0, state}) +end +methods.indexes = method1(indexes) +exports.indexes = export1(indexes) +methods.elem_indexes = methods.indexes +exports.elem_indexes = exports.indexes +methods.indices = methods.indexes +exports.indices = exports.indexes +methods.elem_indices = methods.indexes +exports.elem_indices = exports.indexes + +-------------------------------------------------------------------------------- +-- Filtering +-------------------------------------------------------------------------------- + +local filter1_gen = function(fun, gen_x, param_x, state_x, a) + while true do + if state_x == nil or fun(a) then break; end + state_x, a = gen_x(param_x, state_x) + end + return state_x, a +end + +-- call each other +local filterm_gen +local filterm_gen_shrink = function(fun, gen_x, param_x, state_x) + return filterm_gen(fun, gen_x, param_x, gen_x(param_x, state_x)) +end + +filterm_gen = function(fun, gen_x, param_x, state_x, ...) + if state_x == nil then + return nil + end + if fun(...) then + return state_x, ... + end + return filterm_gen_shrink(fun, gen_x, param_x, state_x) +end + +local filter_detect = function(fun, gen_x, param_x, state_x, ...) + if select('#', ...) < 2 then + return filter1_gen(fun, gen_x, param_x, state_x, ...) + else + return filterm_gen(fun, gen_x, param_x, state_x, ...) + end +end + +local filter_gen = function(param, state_x) + local fun, gen_x, param_x = param[1], param[2], param[3] + return filter_detect(fun, gen_x, param_x, gen_x(param_x, state_x)) +end + +local filter = function(fun, gen, param, state) + return wrap(filter_gen, {fun, gen, param}, state) +end +methods.filter = method1(filter) +exports.filter = export1(filter) +methods.remove_if = methods.filter +exports.remove_if = exports.filter + +local grep = function(fun_or_regexp, gen, param, state) + local fun = fun_or_regexp + if type(fun_or_regexp) == "string" then + fun = function(x) return string.find(x, fun_or_regexp) ~= nil end + end + return filter(fun, gen, param, state) +end +methods.grep = method1(grep) +exports.grep = export1(grep) + +local partition = function(fun, gen, param, state) + local neg_fun = function(...) + return not fun(...) + end + return filter(fun, gen, param, state), + filter(neg_fun, gen, param, state) +end +methods.partition = method1(partition) +exports.partition = export1(partition) + +-------------------------------------------------------------------------------- +-- Reducing +-------------------------------------------------------------------------------- + +local foldl_call = function(fun, start, state, ...) + if state == nil then + return nil, start + end + return state, fun(start, ...) +end + +local foldl = function(fun, start, gen_x, param_x, state_x) + while true do + state_x, start = foldl_call(fun, start, gen_x(param_x, state_x)) + if state_x == nil then + break; + end + end + return start +end +methods.foldl = method2(foldl) +exports.foldl = export2(foldl) +methods.reduce = methods.foldl +exports.reduce = exports.foldl + +local length = function(gen, param, state) + if gen == ipairs_gen or gen == string_gen then + return #param + end + local len = 0 + repeat + state = gen(param, state) + len = len + 1 + until state == nil + return len - 1 +end +methods.length = method0(length) +exports.length = export0(length) + +local is_null = function(gen, param, state) + return gen(param, deepcopy(state)) == nil +end +methods.is_null = method0(is_null) +exports.is_null = export0(is_null) + +local is_prefix_of = function(iter_x, iter_y) + local gen_x, param_x, state_x = iter(iter_x) + local gen_y, param_y, state_y = iter(iter_y) + + local r_x, r_y + for i=1,10,1 do + state_x, r_x = gen_x(param_x, state_x) + state_y, r_y = gen_y(param_y, state_y) + if state_x == nil then + return true + end + if state_y == nil or r_x ~= r_y then + return false + end + end +end +methods.is_prefix_of = is_prefix_of +exports.is_prefix_of = is_prefix_of + +local all = function(fun, gen_x, param_x, state_x) + local r + repeat + state_x, r = call_if_not_empty(fun, gen_x(param_x, state_x)) + until state_x == nil or not r + return state_x == nil +end +methods.all = method1(all) +exports.all = export1(all) +methods.every = methods.all +exports.every = exports.all + +local any = function(fun, gen_x, param_x, state_x) + local r + repeat + state_x, r = call_if_not_empty(fun, gen_x(param_x, state_x)) + until state_x == nil or r + return not not r +end +methods.any = method1(any) +exports.any = export1(any) +methods.some = methods.any +exports.some = exports.any + +local sum = function(gen, param, state) + local s = 0 + local r = 0 + repeat + s = s + r + state, r = gen(param, state) + until state == nil + return s +end +methods.sum = method0(sum) +exports.sum = export0(sum) + +local product = function(gen, param, state) + local p = 1 + local r = 1 + repeat + p = p * r + state, r = gen(param, state) + until state == nil + return p +end +methods.product = method0(product) +exports.product = export0(product) + +local min_cmp = function(m, n) + if n < m then return n else return m end +end + +local max_cmp = function(m, n) + if n > m then return n else return m end +end + +local min = function(gen, param, state) + local state, m = gen(param, state) + if state == nil then + error("min: iterator is empty") + end + + local cmp + if type(m) == "number" then + -- An optimization: use math.min for numbers + cmp = math.min + else + cmp = min_cmp + end + + for _, r in gen, param, state do + m = cmp(m, r) + end + return m +end +methods.min = method0(min) +exports.min = export0(min) +methods.minimum = methods.min +exports.minimum = exports.min + +local min_by = function(cmp, gen_x, param_x, state_x) + local state_x, m = gen_x(param_x, state_x) + if state_x == nil then + error("min: iterator is empty") + end + + for _, r in gen_x, param_x, state_x do + m = cmp(m, r) + end + return m +end +methods.min_by = method1(min_by) +exports.min_by = export1(min_by) +methods.minimum_by = methods.min_by +exports.minimum_by = exports.min_by + +local max = function(gen_x, param_x, state_x) + local state_x, m = gen_x(param_x, state_x) + if state_x == nil then + error("max: iterator is empty") + end + + local cmp + if type(m) == "number" then + -- An optimization: use math.max for numbers + cmp = math.max + else + cmp = max_cmp + end + + for _, r in gen_x, param_x, state_x do + m = cmp(m, r) + end + return m +end +methods.max = method0(max) +exports.max = export0(max) +methods.maximum = methods.max +exports.maximum = exports.max + +local max_by = function(cmp, gen_x, param_x, state_x) + local state_x, m = gen_x(param_x, state_x) + if state_x == nil then + error("max: iterator is empty") + end + + for _, r in gen_x, param_x, state_x do + m = cmp(m, r) + end + return m +end +methods.max_by = method1(max_by) +exports.max_by = export1(max_by) +methods.maximum_by = methods.max_by +exports.maximum_by = exports.max_by + +local totable = function(gen_x, param_x, state_x) + local tab, key, val = {} + while true do + state_x, val = gen_x(param_x, state_x) + if state_x == nil then + break + end + table.insert(tab, val) + end + return tab +end +methods.totable = method0(totable) +exports.totable = export0(totable) + +local tomap = function(gen_x, param_x, state_x) + local tab, key, val = {} + while true do + state_x, key, val = gen_x(param_x, state_x) + if state_x == nil then + break + end + tab[key] = val + end + return tab +end +methods.tomap = method0(tomap) +exports.tomap = export0(tomap) + +-------------------------------------------------------------------------------- +-- Transformations +-------------------------------------------------------------------------------- + +local map_gen = function(param, state) + local gen_x, param_x, fun = param[1], param[2], param[3] + return call_if_not_empty(fun, gen_x(param_x, state)) +end + +local map = function(fun, gen, param, state) + return wrap(map_gen, {gen, param, fun}, state) +end +methods.map = method1(map) +exports.map = export1(map) + +local enumerate_gen_call = function(state, i, state_x, ...) + if state_x == nil then + return nil + end + return {i + 1, state_x}, i, ... +end + +local enumerate_gen = function(param, state) + local gen_x, param_x = param[1], param[2] + local i, state_x = state[1], state[2] + return enumerate_gen_call(state, i, gen_x(param_x, state_x)) +end + +local enumerate = function(gen, param, state) + return wrap(enumerate_gen, {gen, param}, {1, state}) +end +methods.enumerate = method0(enumerate) +exports.enumerate = export0(enumerate) + +local intersperse_call = function(i, state_x, ...) + if state_x == nil then + return nil + end + return {i + 1, state_x}, ... +end + +local intersperse_gen = function(param, state) + local x, gen_x, param_x = param[1], param[2], param[3] + local i, state_x = state[1], state[2] + if i % 2 == 1 then + return {i + 1, state_x}, x + else + return intersperse_call(i, gen_x(param_x, state_x)) + end +end + +-- TODO: interperse must not add x to the tail +local intersperse = function(x, gen, param, state) + return wrap(intersperse_gen, {x, gen, param}, {0, state}) +end +methods.intersperse = method1(intersperse) +exports.intersperse = export1(intersperse) + +-------------------------------------------------------------------------------- +-- Compositions +-------------------------------------------------------------------------------- + +local function zip_gen_r(param, state, state_new, ...) + if #state_new == #param / 2 then + return state_new, ... + end + + local i = #state_new + 1 + local gen_x, param_x = param[2 * i - 1], param[2 * i] + local state_x, r = gen_x(param_x, state[i]) + if state_x == nil then + return nil + end + table.insert(state_new, state_x) + return zip_gen_r(param, state, state_new, r, ...) +end + +local zip_gen = function(param, state) + return zip_gen_r(param, state, {}) +end + +-- A special hack for zip/chain to skip last two state, if a wrapped iterator +-- has been passed +local numargs = function(...) + local n = select('#', ...) + if n >= 3 then + -- Fix last argument + local it = select(n - 2, ...) + if type(it) == 'table' and getmetatable(it) == iterator_mt and + it.param == select(n - 1, ...) and it.state == select(n, ...) then + return n - 2 + end + end + return n +end + +local zip = function(...) + local n = numargs(...) + if n == 0 then + return wrap(nil_gen, nil, nil) + end + local param = { [2 * n] = 0 } + local state = { [n] = 0 } + + local i, gen_x, param_x, state_x + for i=1,n,1 do + local it = select(n - i + 1, ...) + gen_x, param_x, state_x = rawiter(it) + param[2 * i - 1] = gen_x + param[2 * i] = param_x + state[i] = state_x + end + + return wrap(zip_gen, param, state) +end +methods.zip = zip +exports.zip = zip + +local cycle_gen_call = function(param, state_x, ...) + if state_x == nil then + local gen_x, param_x, state_x0 = param[1], param[2], param[3] + return gen_x(param_x, deepcopy(state_x0)) + end + return state_x, ... +end + +local cycle_gen = function(param, state_x) + local gen_x, param_x, state_x0 = param[1], param[2], param[3] + return cycle_gen_call(param, gen_x(param_x, state_x)) +end + +local cycle = function(gen, param, state) + return wrap(cycle_gen, {gen, param, state}, deepcopy(state)) +end +methods.cycle = method0(cycle) +exports.cycle = export0(cycle) + +-- call each other +local chain_gen_r1 +local chain_gen_r2 = function(param, state, state_x, ...) + if state_x == nil then + local i = state[1] + i = i + 1 + if param[3 * i - 1] == nil then + return nil + end + local state_x = param[3 * i] + return chain_gen_r1(param, {i, state_x}) + end + return {state[1], state_x}, ... +end + +chain_gen_r1 = function(param, state) + local i, state_x = state[1], state[2] + local gen_x, param_x = param[3 * i - 2], param[3 * i - 1] + return chain_gen_r2(param, state, gen_x(param_x, state[2])) +end + +local chain = function(...) + local n = numargs(...) + if n == 0 then + return wrap(nil_gen, nil, nil) + end + + local param = { [3 * n] = 0 } + local i, gen_x, param_x, state_x + for i=1,n,1 do + local elem = select(i, ...) + gen_x, param_x, state_x = iter(elem) + param[3 * i - 2] = gen_x + param[3 * i - 1] = param_x + param[3 * i] = state_x + end + + return wrap(chain_gen_r1, param, {1, param[3]}) +end +methods.chain = chain +exports.chain = chain + +-------------------------------------------------------------------------------- +-- Operators +-------------------------------------------------------------------------------- + +local operator = { + ---------------------------------------------------------------------------- + -- Comparison operators + ---------------------------------------------------------------------------- + lt = function(a, b) return a < b end, + le = function(a, b) return a <= b end, + eq = function(a, b) return a == b end, + ne = function(a, b) return a ~= b end, + ge = function(a, b) return a >= b end, + gt = function(a, b) return a > b end, + + ---------------------------------------------------------------------------- + -- Arithmetic operators + ---------------------------------------------------------------------------- + add = function(a, b) return a + b end, + div = function(a, b) return a / b end, + floordiv = function(a, b) return math.floor(a/b) end, + intdiv = function(a, b) + local q = a / b + if a >= 0 then return math.floor(q) else return math.ceil(q) end + end, + mod = function(a, b) return a % b end, + mul = function(a, b) return a * b end, + neq = function(a) return -a end, + unm = function(a) return -a end, -- an alias + pow = function(a, b) return a ^ b end, + sub = function(a, b) return a - b end, + truediv = function(a, b) return a / b end, + + ---------------------------------------------------------------------------- + -- String operators + ---------------------------------------------------------------------------- + concat = function(a, b) return a..b end, + len = function(a) return #a end, + length = function(a) return #a end, -- an alias + + ---------------------------------------------------------------------------- + -- Logical operators + ---------------------------------------------------------------------------- + land = function(a, b) return a and b end, + lor = function(a, b) return a or b end, + lnot = function(a) return not a end, + truth = function(a) return not not a end, +} +exports.operator = operator +methods.operator = operator +exports.op = operator +methods.op = operator + +-------------------------------------------------------------------------------- +-- module definitions +-------------------------------------------------------------------------------- + +-- a special syntax sugar to export all functions to the global table +setmetatable(exports, { + __call = function(t, override) + for k, v in pairs(t) do + if rawget(_G, k) ~= nil then + local msg = 'function ' .. k .. ' already exists in global scope.' + if override then + rawset(_G, k, v) + print('WARNING: ' .. msg .. ' Overwritten.') + else + print('NOTICE: ' .. msg .. ' Skipped.') + end + else + rawset(_G, k, v) + end + end + end, +}) + +return exports diff --git a/lua/nvim-tree-docs/aniseed/env.lua b/lua/nvim-tree-docs/aniseed/env.lua index 2cb2b9f..378e977 100644 --- a/lua/nvim-tree-docs/aniseed/env.lua +++ b/lua/nvim-tree-docs/aniseed/env.lua @@ -1,108 +1,63 @@ local _2afile_2a = "fnl/aniseed/env.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.env" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.aniseed.env" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.compile"), autoload("nvim-tree-docs.aniseed.fennel"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim")} +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local compile, fennel, fs, nvim = autoload("nvim-tree-docs.aniseed.compile"), autoload("nvim-tree-docs.aniseed.fennel"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim") +do end (_2amodule_locals_2a)["compile"] = compile +_2amodule_locals_2a["fennel"] = fennel +_2amodule_locals_2a["fs"] = fs +_2amodule_locals_2a["nvim"] = nvim +local config_dir = nvim.fn.stdpath("config") +do end (_2amodule_locals_2a)["config-dir"] = config_dir +local function quiet_require(m) + local ok_3f, err = nil, nil + local function _1_() + return require(m) end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {compile = "nvim-tree-docs.aniseed.compile", fennel = "nvim-tree-docs.aniseed.fennel", fs = "nvim-tree-docs.aniseed.fs", nvim = "nvim-tree-docs.aniseed.nvim"}} - return val_0_ + ok_3f, err = pcall(_1_) + if (not ok_3f and not err:find(("module '" .. m .. "' not found"))) then + return nvim.ex.echoerr(err) else - return print(val_0_) + return nil end end -local _local_0_ = _2_(...) -local compile = _local_0_[1] -local fennel = _local_0_[2] -local fs = _local_0_[3] -local nvim = _local_0_[4] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.env" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local config_dir -do - local v_0_ = nvim.fn.stdpath("config") - local t_0_ = (_0_)["aniseed/locals"] - t_0_["config-dir"] = v_0_ - config_dir = v_0_ -end -local quiet_require -do - local v_0_ - local function quiet_require0(m) - local ok_3f, err = nil, nil - local function _3_() - return require(m) - end - ok_3f, err = pcall(_3_) - if (not ok_3f and not err:find(("module '" .. m .. "' not found"))) then - return nvim.ex.echoerr(err) - end +_2amodule_locals_2a["quiet-require"] = quiet_require +local function init(opts) + local opts0 + if ("table" == type(opts)) then + opts0 = opts + else + opts0 = {} end - v_0_ = quiet_require0 - local t_0_ = (_0_)["aniseed/locals"] - t_0_["quiet-require"] = v_0_ - quiet_require = v_0_ -end -local init -do - local v_0_ - do - local v_0_0 - local function init0(opts) - local opts0 - if ("table" == type(opts)) then - opts0 = opts - else - opts0 = {} - end - local glob_expr = "**/*.fnl" - local fnl_dir = (opts0.input or (config_dir .. fs["path-sep"] .. "fnl")) - local lua_dir = (opts0.output or (config_dir .. fs["path-sep"] .. "lua")) - package.path = (package.path .. ";" .. lua_dir .. fs["path-sep"] .. "?.lua") - local function _4_(path) - if fs["macro-file-path?"](path) then - return path - else - return string.gsub(path, ".fnl$", ".lua") - end - end - if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _4_)) then - fennel["add-path"]((fnl_dir .. fs["path-sep"] .. "?.fnl")) - compile.glob(glob_expr, fnl_dir, lua_dir, opts0) - end - return quiet_require((opts0.module or "init")) + local glob_expr = "**/*.fnl" + local fnl_dir = nvim.fn.expand((opts0.input or (config_dir .. fs["path-sep"] .. "fnl"))) + local lua_dir = nvim.fn.expand((opts0.output or (config_dir .. fs["path-sep"] .. "lua"))) + if opts0.output then + package.path = (package.path .. ";" .. lua_dir .. fs["path-sep"] .. "?.lua") + else + end + local function _5_(path) + if fs["macro-file-path?"](path) then + return path + else + return string.gsub(path, ".fnl$", ".lua") end - v_0_0 = init0 - _0_["init"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["init"] = v_0_ - init = v_0_ + if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _5_)) then + fennel["add-path"]((fnl_dir .. fs["path-sep"] .. "?.fnl")) + compile.glob(glob_expr, fnl_dir, lua_dir, opts0) + else + end + return quiet_require((opts0.module or "init")) end -return nil +_2amodule_2a["init"] = init +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/eval.lua b/lua/nvim-tree-docs/aniseed/eval.lua index bb69f96..da1f349 100644 --- a/lua/nvim-tree-docs/aniseed/eval.lua +++ b/lua/nvim-tree-docs/aniseed/eval.lua @@ -1,67 +1,72 @@ local _2afile_2a = "fnl/aniseed/eval.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.eval" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.aniseed.eval" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.compile"), autoload("nvim-tree-docs.aniseed.fennel"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim")} +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a, compile, fennel, fs, nvim = autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.compile"), autoload("nvim-tree-docs.aniseed.fennel"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim") +do end (_2amodule_locals_2a)["a"] = a +_2amodule_locals_2a["compile"] = compile +_2amodule_locals_2a["fennel"] = fennel +_2amodule_locals_2a["fs"] = fs +_2amodule_locals_2a["nvim"] = nvim +local function str(code, opts) + local fnl = fennel.impl() + local function _1_() + return fnl.eval(compile["wrap-macros"](code, opts), a.merge({compilerEnv = _G}, opts)) end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "nvim-tree-docs.aniseed.core", compile = "nvim-tree-docs.aniseed.compile", fennel = "nvim-tree-docs.aniseed.fennel", fs = "nvim-tree-docs.aniseed.fs", nvim = "nvim-tree-docs.aniseed.nvim"}} - return val_0_ - else - return print(val_0_) + return xpcall(_1_, fnl.traceback) +end +_2amodule_2a["str"] = str +local function clean_values(vals) + local function _2_(val) + if a["table?"](val) then + return (compile["delete-marker"] ~= a.first(val)) + else + return true + end end + return a.filter(_2_, vals) end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local compile = _local_0_[2] -local fennel = _local_0_[3] -local fs = _local_0_[4] -local nvim = _local_0_[5] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.eval" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local str -do - local v_0_ - do - local v_0_0 - local function str0(code, opts) - local fnl = fennel.impl() - local function _3_() - return fnl.eval(compile["macros-prefix"](code, opts), a.merge({["compiler-env"] = _G}, opts)) - end - return xpcall(_3_, fnl.traceback) +_2amodule_locals_2a["clean-values"] = clean_values +local function clean_error(err) + return string.gsub(string.gsub(err, "^%b[string .-%b]:%d+: ", ""), "^Compile error in .-:%d+\n%s+", "") +end +_2amodule_2a["clean-error"] = clean_error +local function repl(opts) + local eval_values = nil + local fnl = fennel.impl() + local opts0 = (opts or {}) + local co + local function _4_() + local function _5_(_241) + eval_values = clean_values(_241) + return nil + end + local function _6_(_241, _242) + return (opts0["error-handler"] or nvim.err_writeln)(clean_error(_242)) end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 + return fnl.repl(a.merge({compilerEnv = _G, pp = a.identity, readChunk = coroutine.yield, onValues = _5_, onError = _6_}, opts0)) + end + co = coroutine.create(_4_) + coroutine.resume(co) + coroutine.resume(co, compile["wrap-macros"](nil, opts0)) + eval_values = nil + local function _7_(code) + ANISEED_STATIC_MODULES = false + coroutine.resume(co, code) + local prev_eval_values = eval_values + eval_values = nil + return prev_eval_values end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + return _7_ end -return nil +_2amodule_2a["repl"] = repl +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/fennel.lua b/lua/nvim-tree-docs/aniseed/fennel.lua index c641522..fad47a2 100644 --- a/lua/nvim-tree-docs/aniseed/fennel.lua +++ b/lua/nvim-tree-docs/aniseed/fennel.lua @@ -1,112 +1,55 @@ local _2afile_2a = "fnl/aniseed/fennel.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.aniseed.fennel" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {fs = "nvim-tree-docs.aniseed.fs", nvim = "nvim-tree-docs.aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local fs = _local_0_[1] -local nvim = _local_0_[2] -local _2amodule_2a = _0_ local _2amodule_name_2a = "nvim-tree-docs.aniseed.fennel" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local sync_rtp +local _2amodule_2a do - local v_0_ - do - local v_0_0 - local function sync_rtp0(compiler) - local sep = fs["path-sep"] - local fnl_suffix = (sep .. "fnl" .. sep .. "?.fnl") - local rtp = nvim.o.runtimepath - local fnl_path = (rtp:gsub(",", (fnl_suffix .. ";")) .. fnl_suffix) - local lua_path = fnl_path:gsub((sep .. "fnl" .. sep), (sep .. "lua" .. sep)) - do end (compiler)["path"] = (fnl_path .. ";" .. lua_path) - return nil - end - v_0_0 = sync_rtp0 - _0_["sync-rtp"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["sync-rtp"] = v_0_ - sync_rtp = v_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local state +local _2amodule_locals_2a do - local v_0_ = {["compiler-loaded?"] = false} - local t_0_ = (_0_)["aniseed/locals"] - t_0_["state"] = v_0_ - state = v_0_ + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -local impl -do - local v_0_ - do - local v_0_0 - local function impl0() - local compiler = require("nvim-tree-docs.aniseed.deps.fennel") - if not state["compiler-loaded?"] then - state["compiler-loaded?"] = true - sync_rtp(compiler) - end - return compiler - end - v_0_0 = impl0 - _0_["impl"] = v_0_0 - v_0_ = v_0_0 +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a, fs, nvim, str = autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim"), autoload("nvim-tree-docs.aniseed.string") +do end (_2amodule_locals_2a)["a"] = a +_2amodule_locals_2a["fs"] = fs +_2amodule_locals_2a["nvim"] = nvim +_2amodule_locals_2a["str"] = str +local function sync_rtp(compiler) + local fnl_suffix = (fs["path-sep"] .. "fnl" .. fs["path-sep"] .. "?.fnl") + local lua_suffix = (fs["path-sep"] .. "lua" .. fs["path-sep"] .. "?.fnl") + local rtps = nvim.list_runtime_paths() + local fnl_paths + local function _1_(_241) + return (_241 .. fnl_suffix) + end + fnl_paths = a.map(_1_, rtps) + local lua_paths + local function _2_(_241) + return (_241 .. lua_suffix) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["impl"] = v_0_ - impl = v_0_ + lua_paths = a.map(_2_, rtps) + do end (compiler)["macro-path"] = str.join(";", a.concat(fnl_paths, lua_paths)) + return nil end -local add_path -do - local v_0_ - do - local v_0_0 - local function add_path0(path) - local fnl = impl() - do end (fnl)["path"] = (fnl.path .. ";" .. path) - return nil - end - v_0_0 = add_path0 - _0_["add-path"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["sync-rtp"] = sync_rtp +local state = {["compiler-loaded?"] = false} +_2amodule_locals_2a["state"] = state +local function impl() + local compiler = require("nvim-tree-docs.aniseed.deps.fennel") + if not state["compiler-loaded?"] then + state["compiler-loaded?"] = true + sync_rtp(compiler) + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["add-path"] = v_0_ - add_path = v_0_ + return compiler +end +_2amodule_2a["impl"] = impl +local function add_path(path) + local fnl = impl() + do end (fnl)["macro-path"] = (fnl["macro-path"] .. ";" .. path) + return nil end -return nil +_2amodule_2a["add-path"] = add_path +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/fs.lua b/lua/nvim-tree-docs/aniseed/fs.lua index 268eeb1..b67415a 100644 --- a/lua/nvim-tree-docs/aniseed/fs.lua +++ b/lua/nvim-tree-docs/aniseed/fs.lua @@ -1,154 +1,58 @@ local _2afile_2a = "fnl/aniseed/fs.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.aniseed.fs" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "nvim-tree-docs.aniseed.core", nvim = "nvim-tree-docs.aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local nvim = _local_0_[2] -local _2amodule_2a = _0_ local _2amodule_name_2a = "nvim-tree-docs.aniseed.fs" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local path_sep -do - local v_0_ - do - local v_0_0 - do - local os = string.lower(jit.os) - if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then - v_0_0 = "/" - else - v_0_0 = "\\" - end - end - _0_["path-sep"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["path-sep"] = v_0_ - path_sep = v_0_ -end -local basename +local _2amodule_2a do - local v_0_ - do - local v_0_0 - local function basename0(path) - return nvim.fn.fnamemodify(path, ":h") - end - v_0_0 = basename0 - _0_["basename"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["basename"] = v_0_ - basename = v_0_ -end -local mkdirp -do - local v_0_ - do - local v_0_0 - local function mkdirp0(dir) - return nvim.fn.mkdir(dir, "p") - end - v_0_0 = mkdirp0 - _0_["mkdirp"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["mkdirp"] = v_0_ - mkdirp = v_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local relglob +local _2amodule_locals_2a do - local v_0_ - do - local v_0_0 - local function relglob0(dir, expr) - local dir_len = a.inc(string.len(dir)) - local function _3_(_241) - return string.sub(_241, dir_len) - end - return a.map(_3_, nvim.fn.globpath(dir, expr, true, true)) + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a, nvim = autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.nvim") +do end (_2amodule_locals_2a)["a"] = a +_2amodule_locals_2a["nvim"] = nvim +local function basename(path) + return nvim.fn.fnamemodify(path, ":h") +end +_2amodule_2a["basename"] = basename +local function mkdirp(dir) + return nvim.fn.mkdir(dir, "p") +end +_2amodule_2a["mkdirp"] = mkdirp +local function relglob(dir, expr) + local dir_len = a.inc(string.len(dir)) + local function _1_(_241) + return string.sub(_241, dir_len) + end + return a.map(_1_, nvim.fn.globpath(dir, expr, true, true)) +end +_2amodule_2a["relglob"] = relglob +local function glob_dir_newer_3f(a_dir, b_dir, expr, b_dir_path_fn) + local newer_3f = false + for _, path in ipairs(relglob(a_dir, expr)) do + if (nvim.fn.getftime((a_dir .. path)) > nvim.fn.getftime((b_dir .. b_dir_path_fn(path)))) then + newer_3f = true + else end - v_0_0 = relglob0 - _0_["relglob"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["relglob"] = v_0_ - relglob = v_0_ + return newer_3f end -local glob_dir_newer_3f +_2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f +local path_sep do - local v_0_ - do - local v_0_0 - local function glob_dir_newer_3f0(a_dir, b_dir, expr, b_dir_path_fn) - local newer_3f = false - for _, path in ipairs(relglob(a_dir, expr)) do - if (nvim.fn.getftime((a_dir .. path)) > nvim.fn.getftime((b_dir .. b_dir_path_fn(path)))) then - newer_3f = true - end - end - return newer_3f - end - v_0_0 = glob_dir_newer_3f0 - _0_["glob-dir-newer?"] = v_0_0 - v_0_ = v_0_0 + local os = string.lower(jit.os) + if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then + path_sep = "/" + else + path_sep = "\\" end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["glob-dir-newer?"] = v_0_ - glob_dir_newer_3f = v_0_ end -local macro_file_path_3f -do - local v_0_ - do - local v_0_0 - local function macro_file_path_3f0(path) - return string.match(path, "macros.fnl$") - end - v_0_0 = macro_file_path_3f0 - _0_["macro-file-path?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["macro-file-path?"] = v_0_ - macro_file_path_3f = v_0_ +_2amodule_2a["path-sep"] = path_sep +local function macro_file_path_3f(path) + return (a["string?"](string.match(path, "macros?.fnl$")) or a["string?"](string.match(path, (path_sep .. "macros?" .. path_sep)))) end -return nil +_2amodule_2a["macro-file-path?"] = macro_file_path_3f +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/macros.fnl b/lua/nvim-tree-docs/aniseed/macros.fnl index 1e5032e..48ebe13 100644 --- a/lua/nvim-tree-docs/aniseed/macros.fnl +++ b/lua/nvim-tree-docs/aniseed/macros.fnl @@ -3,7 +3,16 @@ ;; Automatically loaded through require-macros for all Aniseed based evaluations. -(local module-sym (gensym)) +(fn nil? [x] + (= :nil (type x))) + +(fn seq? [x] + (not (nil? (. x 1)))) + +(fn str [x] + (if (= :string (type x)) + x + (tostring x))) (fn sorted-each [f x] (let [acc []] @@ -12,122 +21,193 @@ (table.sort acc (fn [a b] - (< (. a 1) (. b 1)))) + (< (str (. a 1)) (str (. b 1))))) (each [_ [k v] (ipairs acc)] (f k v)))) -(fn module [name new-local-fns initial-mod] - `(-> [(local ,module-sym - (let [name# ,(tostring name) - module# (let [x# (. package.loaded name#)] - (if (= :table (type x#)) - x# - ,(or initial-mod {})))] - (tset module# :aniseed/module name#) - (tset module# :aniseed/locals (or (. module# :aniseed/locals) {})) - (tset module# :aniseed/local-fns (or (. module# :aniseed/local-fns) {})) - (tset package.loaded name# module#) - module#)) - - ,module-sym - - ;; Meta! Autoload the autoload function, so it's only loaded when used. - (local ,(sym :autoload) - (fn [...] ((. (require :aniseed.autoload) :autoload) ...))) - - ,(let [aliases [] - vals [] - effects [] - pkg (let [x (. package.loaded (tostring name))] - (when (= :table (type x)) - x)) - locals (-?> pkg (. :aniseed/locals)) - local-fns (or (and (not new-local-fns) - (?. pkg :aniseed/local-fns)) - {})] - - (when new-local-fns - (each [action binds (pairs new-local-fns)] - (let [action-str (tostring action) - current (or (. local-fns action-str) {})] - (tset local-fns action-str current) - (each [alias module (pairs binds)] - (if (= :number (type alias)) - (tset current (tostring module) true) - (tset current (tostring alias) (tostring module))))))) - - (sorted-each - (fn [action binds] - (sorted-each - (fn [alias-or-val val] - (if (= true val) - - ;; {require-macros [bar]} - (table.insert effects `(,(sym action) ,alias-or-val)) - - ;; {require {foo bar}} - (do - (table.insert aliases (sym alias-or-val)) - (table.insert vals `(,(sym action) ,val))))) - - binds)) - local-fns) - - (when locals - (sorted-each - (fn [alias val] - (table.insert aliases (sym alias)) - (table.insert vals `(. ,module-sym :aniseed/locals ,alias))) - locals)) - - `[,effects - (local ,aliases - (let [(ok?# val#) - (pcall - (fn [] ,vals))] - (if ok?# - (do - (tset ,module-sym :aniseed/local-fns ,local-fns) - val#) - (print val#)))) - (local ,(sym "*module*") ,module-sym) - (local ,(sym "*module-name*") ,(tostring name))])] - (. 2))) +(fn contains? [t target] + (var seen? false) + (each [k v (pairs t)] + (when (= k target) + (set seen? true))) + seen?) + +(fn ensure-sym [x] + (if (= :string (type x)) + (sym x) + x)) + +;; This marker can be used by a post-processor to delete a useless byproduct line. +(local delete-marker :ANISEED_DELETE_ME) + +;; We store all locals under this for later splatting. +(local locals-key :aniseed/locals) + +;; Various symbols we want to use multiple times. +;; Avoids the compiler complaining that we're introducing locals without gensym. +(local mod-name-sym (sym :*module-name*)) +(local mod-sym (sym :*module*)) +(local mod-locals-sym (sym :*module-locals*)) +(local autoload-sym (sym :autoload)) + +;; Upserts the existence of the module for subsequent def forms and expands the +;; bound function calls into the current context. +;; +;; On subsequent interactive calls it will expand the existing module into your +;; current context. This should be used by Conjure as you enter a buffer. +;; +;; (module foo +;; {require {nvim aniseed.nvim}} +;; {:some-optional-base :table-of-things +;; :to-base :the-module-off-of}) +;; +;; (module foo) ;; expands foo into your current context +(fn module [mod-name mod-fns mod-base] + (let [;; So we can check for existing values and know if we're in an interactive eval. + ;; If the module doesn't exist we're compiling and can skip interactive tooling. + existing-mod (. package.loaded (tostring mod-name)) + + ;; Determine if we're in an interactive eval or not. + + ;; We don't count userdata / other types as an existing module since we + ;; can't really work with anything other than a table. If it's not a + ;; table it's probably not a module Aniseed can work with in general + ;; since it's assumed all Aniseed modules are table based. + + ;; We can also completely disable the interactive mode which is used by + ;; `aniseed.env` but can also be enabled by others. Sadly this works + ;; through global variables but still! + interactive? (and (table? existing-mod) + (not _G.ANISEED_STATIC_MODULES)) + + ;; The final result table that gets returned from the macro. + ;; This is the best way I've found to introduce many (local ...) forms from one macro. + result `[,delete-marker + + ;; We can't refer to things like (local (foo bar) (10 foo)). + ;; So we need to define them in an earlier local. + (local ,mod-name-sym ,(tostring mod-name)) + + ;; Only expose the module table if it doesn't exist yet. + (local ,mod-sym ,(if interactive? + `(. package.loaded ,mod-name-sym) + `(do + (tset package.loaded ,mod-name-sym ,(or mod-base {})) + (. package.loaded ,mod-name-sym)))) + + ;; As we def values we insert them into locals. + ;; This table is then expanded in subsequent interactive evals. + (local ,mod-locals-sym ,(if interactive? + `(. ,mod-sym ,locals-key) + `(do + (tset ,mod-sym ,locals-key {}) + (. ,mod-sym ,locals-key))))] + + ;; Bindings that are returned from the macro. + ;; (=> :some-symbol :some-value) + keys [] + vals [] + => (fn [k v] + (table.insert keys k) + (table.insert vals v))] + + ;; For each function / value pair... + (when mod-fns + (sorted-each + (fn [mod-fn args] + (if (seq? args) + ;; If it's sequential, we execute the fn for side effects. + ;; Works for (require-macros :name) (deprecated in Fennel 0.4.0). + (each [_ arg (ipairs args)] + ;; When arg is ALSO sequential it means we're sending multiple args for side effects. + ;; This works well for (import-macros bind :name) + (=> (sym :_) + (if (seq? arg) + `(,mod-fn ,(unpack arg)) + `(,mod-fn ,(tostring arg))))) + + ;; Otherwise we need to bind the execution to a name. + ;; Works for simple (require :name) calls, binding the result. + (sorted-each + (fn [bind arg] + (=> (ensure-sym bind) `(,mod-fn ,(tostring arg)))) + args))) + mod-fns) + + ;; Only require autoload if it's used. + (when (contains? mod-fns autoload-sym) + (table.insert result `(local ,autoload-sym (. (require "nvim-tree-docs.aniseed.autoload") :autoload))))) + + ;; When we have some keys insert the key/vals pairs locals. + ;; If this is empty we end up generating invalid Lua. + (when (seq? keys) + (table.insert result `(local ,(list (unpack keys)) (values ,(unpack vals)))) + + ;; We also bind these exposed locals into *module-locals* for future splatting. + (each [_ k (ipairs keys)] + (if (sym? k) + ;; Normal symbols can just be assigned into module-locals. + (table.insert result `(tset ,mod-locals-sym ,(tostring k) ,k)) + + ;; Tables mean we're using Fennel destructure syntax. + ;; So we need to unpack the assignments so they can be used later in interactive evals. + (sorted-each + (fn [k v] + (table.insert + result + `(tset ,mod-locals-sym ,(tostring k) ,v))) + k)))) + + ;; Now we can expand any existing locals into the current scope. + ;; Since this will only happen in interactive evals we can generate messy code. + (when interactive? + ;; Expand exported values into the current scope, except aniseed/locals. + (sorted-each + (fn [k v] + (when (not= k locals-key) + (table.insert result `(local ,(sym k) (. ,mod-sym ,k))))) + existing-mod) + + ;; Expand locals into the current scope. + (when (. existing-mod locals-key) + (sorted-each + (fn [k v] + (table.insert result `(local ,(sym k) (. ,mod-locals-sym ,k)))) + (. existing-mod locals-key)))) + + result)) (fn def- [name value] - `(local ,name - (let [v# ,value - t# (. ,module-sym :aniseed/locals)] - (tset t# ,(tostring name) v#) - v#))) + `[,delete-marker + (local ,name ,value) + (tset ,mod-locals-sym ,(tostring name) ,name)]) (fn def [name value] - `(def- ,name - (do - (let [v# ,value] - (tset ,module-sym ,(tostring name) v#) - v#)))) + `[,delete-marker + (local ,name ,value) + (tset ,mod-sym ,(tostring name) ,name)]) (fn defn- [name ...] - `(def- ,name (fn ,name ,...))) + `[,delete-marker + (fn ,name ,...) + (tset ,mod-locals-sym ,(tostring name) ,name)]) (fn defn [name ...] - `(def ,name (fn ,name ,...))) + `[,delete-marker + (fn ,name ,...) + (tset ,mod-sym ,(tostring name) ,name)]) (fn defonce- [name value] - `(def- ,name - (or (. ,module-sym :aniseed/locals ,(tostring name)) - ,value))) + `(def- ,name (or (. ,mod-sym ,(tostring name)) ,value))) (fn defonce [name value] - `(def ,name - (or (. ,module-sym ,(tostring name)) - ,value))) + `(def ,name (or (. ,mod-sym ,(tostring name)) ,value))) (fn deftest [name ...] - `(let [tests# (or (. ,module-sym :aniseed/tests) {})] + `(let [tests# (or (. ,mod-sym :aniseed/tests + ) {})] (tset tests# ,(tostring name) (fn [,(sym :t)] ,...)) - (tset ,module-sym :aniseed/tests tests#))) + (tset ,mod-sym :aniseed/tests tests#))) (fn time [...] `(let [start# (vim.loop.hrtime) @@ -136,9 +216,90 @@ (print (.. "Elapsed time: " (/ (- end# start#) 1000000) " msecs")) result#)) +;; Checks surrounding scope for *module* and, if found, makes sure *module* is +;; inserted after `last-expr` (and therefore *module* is returned) +(fn wrap-last-expr [last-expr] + (if (in-scope? mod-sym) + `(do ,last-expr ,mod-sym) + last-expr)) + +;; Used by aniseed.compile to wrap the entire body of a file, replacing the +;; last expression with another wrapper; `wrap-last-expr` which handles the +;; module's return value. +;; +;; i.e. +;; (wrap-module-body +;; (module foo) +;; (def x 1) +;; (vim.cmd "...")) ; vim.cmd returns a string which becomes the returned value +;; ; for the entire file once compiled +;; --> expands to: +;; (do +;; (module foo) +;; (def x 1) +;; (wrap-last-expr (vim.cmd "..."))) +;; --> expands to: +;; (do +;; (module foo) +;; (def x 1) +;; (do +;; (vim.cmd "...") +;; *module*)) +(fn wrap-module-body [...] + (let [body# [...] + last-expr# (table.remove body#)] + (table.insert body# `(wrap-last-expr ,last-expr#)) + `(do ,(unpack body#)))) + +(fn conditional-let [branch bindings ...] + (assert (= 2 (length bindings)) "expected a single binding pair") + + (let [[bind-expr value-expr] bindings] + (if + ;; Simple symbols + ;; [foo bar] + (sym? bind-expr) + `(let [,bind-expr ,value-expr] + (,branch ,bind-expr ,...)) + + ;; List / values destructure + ;; [(a b) c] + (list? bind-expr) + (do + ;; Even if the user isn't using the first slot, we will. + ;; [(_ val) (pcall #:foo)] + ;; => [(bindGENSYM12345 val) (pcall #:foo)] + (when (= '_ (. bind-expr 1)) + (tset bind-expr 1 (gensym "bind"))) + + `(let [,bind-expr ,value-expr] + (,branch ,(. bind-expr 1) ,...))) + + ;; Sequential and associative table destructure + ;; [[a b] c] + ;; [{: a : b} c] + (table? bind-expr) + `(let [value# ,value-expr + ,bind-expr (or value# {})] + (,branch value# ,...)) + + ;; We should never get here, but just in case. + (assert (.. "unknown bind-expr type: " (type bind-expr)))))) + +(fn if-let [bindings ...] + (assert (<= (length [...]) 2) (.. "if-let does not support more than two branches")) + (conditional-let 'if bindings ...)) + +(fn when-let [bindings ...] + (conditional-let 'when bindings ...)) + {:module module :def- def- :def def :defn- defn- :defn defn :defonce- defonce- :defonce defonce + :if-let if-let + :when-let when-let + :wrap-last-expr wrap-last-expr + :wrap-module-body wrap-module-body :deftest deftest :time time} diff --git a/lua/nvim-tree-docs/aniseed/macros/autocmds.fnl b/lua/nvim-tree-docs/aniseed/macros/autocmds.fnl new file mode 100644 index 0000000..dc832b8 --- /dev/null +++ b/lua/nvim-tree-docs/aniseed/macros/autocmds.fnl @@ -0,0 +1,26 @@ +(fn autocmd [event opt] + `(vim.api.nvim_create_autocmd + ,event ,opt)) + +(fn autocmds [...] + (var form `(do)) + (each [_ v (ipairs [...])] + (table.insert form (autocmd (unpack v)))) + (table.insert form 'nil) + form) + +(fn augroup [name ...] + (var cmds `(do)) + (var group (sym :group)) + (each [_ v (ipairs [...])] + (let [(event opt) (unpack v)] + (tset opt :group group) + (table.insert cmds (autocmd event opt)))) + (table.insert cmds 'nil) + `(let [,group + (vim.api.nvim_create_augroup ,name {:clear true})] + ,cmds)) + +{:autocmd autocmd + :autocmds autocmds + :augroup augroup} diff --git a/lua/nvim-tree-docs/aniseed/nvim.lua b/lua/nvim-tree-docs/aniseed/nvim.lua index 5620615..4ad6287 100644 --- a/lua/nvim-tree-docs/aniseed/nvim.lua +++ b/lua/nvim-tree-docs/aniseed/nvim.lua @@ -1,41 +1,12 @@ local _2afile_2a = "fnl/aniseed/nvim.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.nvim" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.aniseed.nvim" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = require("nvim-tree-docs.aniseed.deps.nvim") - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) + package.loaded[_2amodule_name_2a] = require("nvim-tree-docs.aniseed.deps.nvim") + _2amodule_2a = package.loaded[_2amodule_name_2a] end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {} - return val_0_ - else - return print(val_0_) - end +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -local _local_0_ = _2_(...) -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.nvim" -return ({nil, _0_, nil, {{}, nil, nil, nil}})[2] diff --git a/lua/nvim-tree-docs/aniseed/nvim/util.lua b/lua/nvim-tree-docs/aniseed/nvim/util.lua index a7ff4a0..1be3fe3 100644 --- a/lua/nvim-tree-docs/aniseed/nvim/util.lua +++ b/lua/nvim-tree-docs/aniseed/nvim/util.lua @@ -1,122 +1,63 @@ local _2afile_2a = "fnl/aniseed/nvim/util.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.nvim.util" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.aniseed.nvim.util" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local nvim = autoload("nvim-tree-docs.aniseed.nvim") +do end (_2amodule_locals_2a)["nvim"] = nvim +local function normal(keys) + return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) +end +_2amodule_2a["normal"] = normal +local function fn_bridge(viml_name, mod, lua_name, opts) + local _let_1_ = (opts or {}) + local range = _let_1_["range"] + local _return = _let_1_["return"] local function _2_() - return {autoload("nvim-tree-docs.aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {nvim = "nvim-tree-docs.aniseed.nvim"}} - return val_0_ - else - return print(val_0_) + if range then + return " range" + else + return "" + end end -end -local _local_0_ = _2_(...) -local nvim = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.nvim.util" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local normal -do - local v_0_ - do - local v_0_0 - local function normal0(keys) - return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) + local function _3_() + if (_return ~= false) then + return "return" + else + return "call" end - v_0_0 = normal0 - _0_["normal"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["normal"] = v_0_ - normal = v_0_ -end -local fn_bridge -do - local v_0_ - do - local v_0_0 - local function fn_bridge0(viml_name, mod, lua_name, opts) - local _let_0_ = (opts or {}) - local range = _let_0_["range"] - local _return = _let_0_["return"] - local _3_ - if range then - _3_ = " range" - else - _3_ = "" - end - local _5_ - if (_return ~= false) then - _5_ = "return" - else - _5_ = "call" - end - local _7_ - if range then - _7_ = "\" . a:firstline . \", \" . a:lastline . \", " - else - _7_ = "" - end - return nvim.ex.function_((viml_name .. "(...)" .. _3_ .. "\n " .. _5_ .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _7_ .. "unpack(_A))\", a:000)\n endfunction")) + local function _4_() + if range then + return "\" . a:firstline . \", \" . a:lastline . \", " + else + return "" end - v_0_0 = fn_bridge0 - _0_["fn-bridge"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["fn-bridge"] = v_0_ - fn_bridge = v_0_ + return nvim.ex.function_((viml_name .. "(...)" .. _2_() .. "\n " .. _3_() .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _4_() .. "unpack(_A))\", a:000)\n endfunction")) end -local with_out_str -do - local v_0_ +_2amodule_2a["fn-bridge"] = fn_bridge +local function with_out_str(f) + nvim.ex.redir("=> g:aniseed_nvim_util_out_str") do - local v_0_0 - local function with_out_str0(f) - nvim.ex.redir("=> g:aniseed_nvim_util_out_str") - do - local ok_3f, err = pcall(f) - nvim.ex.redir("END") - nvim.ex.echon("") - nvim.ex.redraw() - if not ok_3f then - error(err) - end - end - return string.gsub(nvim.g.aniseed_nvim_util_out_str, "^(\n?)(.*)$", "%2%1") + local ok_3f, err = pcall(f) + nvim.ex.redir("END") + nvim.ex.echon("") + nvim.ex.redraw() + if not ok_3f then + error(err) + else end - v_0_0 = with_out_str0 - _0_["with-out-str"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["with-out-str"] = v_0_ - with_out_str = v_0_ + return string.gsub(nvim.g.aniseed_nvim_util_out_str, "^(\n?)(.*)$", "%2%1") end -return nil +_2amodule_2a["with-out-str"] = with_out_str +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/setup.lua b/lua/nvim-tree-docs/aniseed/setup.lua new file mode 100644 index 0000000..8656765 --- /dev/null +++ b/lua/nvim-tree-docs/aniseed/setup.lua @@ -0,0 +1,61 @@ +local _2afile_2a = "fnl/aniseed/setup.fnl" +local _2amodule_name_2a = "nvim-tree-docs.aniseed.setup" +local _2amodule_2a +do + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] +end +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a, env, eval, nvim = autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.env"), autoload("nvim-tree-docs.aniseed.eval"), autoload("nvim-tree-docs.aniseed.nvim") +do end (_2amodule_locals_2a)["a"] = a +_2amodule_locals_2a["env"] = env +_2amodule_locals_2a["eval"] = eval +_2amodule_locals_2a["nvim"] = nvim +local function init() + if (1 == nvim.fn.has("nvim-0.7")) then + local function _1_(cmd) + local ok_3f, res = eval.str(cmd.args, {}) + if ok_3f then + return nvim.echo(res) + else + return nvim.err_writeln(res) + end + end + nvim.create_user_command("AniseedEval", _1_, {nargs = 1}) + local function _3_(cmd) + local code + local function _4_() + if ("" == cmd.args) then + return nvim.buf_get_name(nvim.get_current_buf()) + else + return cmd.args + end + end + code = a.slurp(_4_()) + if code then + local ok_3f, res = eval.str(code, {}) + if ok_3f then + return nvim.echo(res) + else + return nvim.err_writeln(res) + end + else + return nvim.err_writeln(("File '" .. (cmd.args or "nil") .. "' not found")) + end + end + nvim.create_user_command("AniseedEvalFile", _3_, {nargs = "?", complete = "file"}) + else + end + if nvim.g["aniseed#env"] then + return env.init(nvim.g["aniseed#env"]) + else + return nil + end +end +_2amodule_2a["init"] = init +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/string.lua b/lua/nvim-tree-docs/aniseed/string.lua index 1374ef2..d0eee23 100644 --- a/lua/nvim-tree-docs/aniseed/string.lua +++ b/lua/nvim-tree-docs/aniseed/string.lua @@ -1,182 +1,84 @@ local _2afile_2a = "fnl/aniseed/string.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.string" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.aniseed.string" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.core")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "nvim-tree-docs.aniseed.core"}} - return val_0_ - else - return print(val_0_) +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a = autoload("nvim-tree-docs.aniseed.core") +do end (_2amodule_locals_2a)["a"] = a +local function join(...) + local args = {...} + local function _2_(...) + if (2 == a.count(args)) then + return args + else + return {"", a.first(args)} + end end -end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.string" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local join -do - local v_0_ - do - local v_0_0 - local function join0(...) - local args = {...} - local function _3_(...) - if (2 == a.count(args)) then - return args - else - return {"", a.first(args)} - end + local _let_1_ = _2_(...) + local sep = _let_1_[1] + local xs = _let_1_[2] + local len = a.count(xs) + local result = {} + if (len > 0) then + for i = 1, len do + local x = xs[i] + local _3_ + if ("string" == type(x)) then + _3_ = x + elseif (nil == x) then + _3_ = x + else + _3_ = a["pr-str"](x) end - local _let_0_ = _3_(...) - local sep = _let_0_[1] - local xs = _let_0_[2] - local len = a.count(xs) - local result = {} - if (len > 0) then - for i = 1, len do - local x = xs[i] - local _4_ - if ("string" == type(x)) then - _4_ = x - elseif (nil == x) then - _4_ = x - else - _4_ = a["pr-str"](x) - end - if _4_ then - table.insert(result, _4_) - else - end - end + if (_3_ ~= nil) then + table.insert(result, _3_) + else end - return table.concat(result, sep) end - v_0_0 = join0 - _0_["join"] = v_0_0 - v_0_ = v_0_0 + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["join"] = v_0_ - join = v_0_ + return table.concat(result, sep) end -local split -do - local v_0_ - do - local v_0_0 - local function split0(s, pat) - local done_3f = false - local acc = {} - local index = 1 - while not done_3f do - local start, _end = string.find(s, pat, index) - if ("nil" == type(start)) then - table.insert(acc, string.sub(s, index)) - done_3f = true - else - table.insert(acc, string.sub(s, index, (start - 1))) - index = (_end + 1) - end - end - return acc +_2amodule_2a["join"] = join +local function split(s, pat) + local done_3f = false + local acc = {} + local index = 1 + while not done_3f do + local start, _end = string.find(s, pat, index) + if ("nil" == type(start)) then + table.insert(acc, string.sub(s, index)) + done_3f = true + else + table.insert(acc, string.sub(s, index, (start - 1))) + index = (_end + 1) end - v_0_0 = split0 - _0_["split"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["split"] = v_0_ - split = v_0_ + return acc end -local blank_3f -do - local v_0_ - do - local v_0_0 - local function blank_3f0(s) - return (a["empty?"](s) or not string.find(s, "[^%s]")) - end - v_0_0 = blank_3f0 - _0_["blank?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["blank?"] = v_0_ - blank_3f = v_0_ +_2amodule_2a["split"] = split +local function blank_3f(s) + return (a["empty?"](s) or not string.find(s, "[^%s]")) end -local triml -do - local v_0_ - do - local v_0_0 - local function triml0(s) - return string.gsub(s, "^%s*(.-)", "%1") - end - v_0_0 = triml0 - _0_["triml"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["triml"] = v_0_ - triml = v_0_ +_2amodule_2a["blank?"] = blank_3f +local function triml(s) + return string.gsub(s, "^%s*(.-)", "%1") end -local trimr -do - local v_0_ - do - local v_0_0 - local function trimr0(s) - return string.gsub(s, "(.-)%s*$", "%1") - end - v_0_0 = trimr0 - _0_["trimr"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["trimr"] = v_0_ - trimr = v_0_ +_2amodule_2a["triml"] = triml +local function trimr(s) + return string.gsub(s, "(.-)%s*$", "%1") end -local trim -do - local v_0_ - do - local v_0_0 - local function trim0(s) - return string.gsub(s, "^%s*(.-)%s*$", "%1") - end - v_0_0 = trim0 - _0_["trim"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["trim"] = v_0_ - trim = v_0_ +_2amodule_2a["trimr"] = trimr +local function trim(s) + return string.gsub(s, "^%s*(.-)%s*$", "%1") end -return nil +_2amodule_2a["trim"] = trim +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/test.lua b/lua/nvim-tree-docs/aniseed/test.lua index b499337..d8ade3b 100644 --- a/lua/nvim-tree-docs/aniseed/test.lua +++ b/lua/nvim-tree-docs/aniseed/test.lua @@ -1,235 +1,157 @@ local _2afile_2a = "fnl/aniseed/test.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.aniseed.test" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim"), autoload("nvim-tree-docs.aniseed.string")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "nvim-tree-docs.aniseed.core", fs = "nvim-tree-docs.aniseed.fs", nvim = "nvim-tree-docs.aniseed.nvim", str = "nvim-tree-docs.aniseed.string"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local fs = _local_0_[2] -local nvim = _local_0_[3] -local str = _local_0_[4] -local _2amodule_2a = _0_ local _2amodule_name_2a = "nvim-tree-docs.aniseed.test" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local ok_3f +local _2amodule_2a do - local v_0_ - do - local v_0_0 - local function ok_3f0(_3_) - local _arg_0_ = _3_ - local tests = _arg_0_["tests"] - local tests_passed = _arg_0_["tests-passed"] - return (tests == tests_passed) - end - v_0_0 = ok_3f0 - _0_["ok?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["ok?"] = v_0_ - ok_3f = v_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local display_results +local _2amodule_locals_2a do - local v_0_ + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local a, fs, nvim, str = autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.aniseed.fs"), autoload("nvim-tree-docs.aniseed.nvim"), autoload("nvim-tree-docs.aniseed.string") +do end (_2amodule_locals_2a)["a"] = a +_2amodule_locals_2a["fs"] = fs +_2amodule_locals_2a["nvim"] = nvim +_2amodule_locals_2a["str"] = str +local function ok_3f(_1_) + local _arg_2_ = _1_ + local tests = _arg_2_["tests"] + local tests_passed = _arg_2_["tests-passed"] + return (tests == tests_passed) +end +_2amodule_2a["ok?"] = ok_3f +local function display_results(results, prefix) do - local v_0_0 - local function display_results0(results, prefix) - do - local _let_0_ = results - local assertions = _let_0_["assertions"] - local assertions_passed = _let_0_["assertions-passed"] - local tests = _let_0_["tests"] - local tests_passed = _let_0_["tests-passed"] - local _3_ - if ok_3f(results) then - _3_ = "OK" - else - _3_ = "FAILED" - end - a.println((prefix .. " " .. _3_ .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) + local _let_3_ = results + local tests = _let_3_["tests"] + local tests_passed = _let_3_["tests-passed"] + local assertions = _let_3_["assertions"] + local assertions_passed = _let_3_["assertions-passed"] + local function _4_() + if ok_3f(results) then + return "OK" + else + return "FAILED" end - return results end - v_0_0 = display_results0 - _0_["display-results"] = v_0_0 - v_0_ = v_0_0 + a.println((prefix .. " " .. _4_() .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["display-results"] = v_0_ - display_results = v_0_ + return results end -local run -do - local v_0_ - do - local v_0_0 - local function run0(mod_name) - local mod = package.loaded[mod_name] - local tests = (a["table?"](mod) and mod["aniseed/tests"]) - if a["table?"](tests) then - local results = {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = #tests} - for label, f in pairs(tests) do - local test_failed = false - a.update(results, "tests", a.inc) - do - local prefix = ("[" .. mod_name .. "/" .. label .. "]") - local fail - local function _3_(desc, ...) - test_failed = true - local function _4_(...) - if desc then - return (" (" .. desc .. ")") - else - return "" - end - end - return a.println((str.join({prefix, " ", ...}) .. _4_(...))) - end - fail = _3_ - local begin - local function _4_() - return a.update(results, "assertions", a.inc) - end - begin = _4_ - local pass - local function _5_() - return a.update(results, "assertions-passed", a.inc) - end - pass = _5_ - local t - local function _6_(e, r, desc) - begin() - if (e == r) then - return pass() - else - return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'") - end - end - local function _7_(r, desc) - begin() - if r then - return pass() - else - return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'") - end - end - local function _8_(e, r, desc) - begin() - local se = a["pr-str"](e) - local sr = a["pr-str"](r) - if (se == sr) then - return pass() - else - return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'") - end - end - t = {["="] = _6_, ["ok?"] = _7_, ["pr="] = _8_} - local _9_, _10_ = nil, nil - local function _11_() - return f(t) - end - _9_, _10_ = pcall(_11_) - if ((_9_ == false) and (nil ~= _10_)) then - local err = _10_ - fail("Exception: ", err) +_2amodule_2a["display-results"] = display_results +local function run(mod_name) + local mod = _G.package.loaded[mod_name] + local tests = (a["table?"](mod) and mod["aniseed/tests"]) + if a["table?"](tests) then + local results = {tests = #tests, ["tests-passed"] = 0, assertions = 0, ["assertions-passed"] = 0} + for label, f in pairs(tests) do + local test_failed = false + a.update(results, "tests", a.inc) + do + local prefix = ("[" .. mod_name .. "/" .. label .. "]") + local fail + local function _5_(desc, ...) + test_failed = true + local function _6_(...) + if desc then + return (" (" .. desc .. ")") + else + return "" end end - if not test_failed then - a.update(results, "tests-passed", a.inc) + return a.println((str.join({prefix, " ", ...}) .. _6_(...))) + end + fail = _5_ + local begin + local function _7_() + return a.update(results, "assertions", a.inc) + end + begin = _7_ + local pass + local function _8_() + return a.update(results, "assertions-passed", a.inc) + end + pass = _8_ + local t + local function _9_(e, r, desc) + begin() + if (e == r) then + return pass() + else + return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'") + end + end + local function _11_(e, r, desc) + begin() + local se = a["pr-str"](e) + local sr = a["pr-str"](r) + if (se == sr) then + return pass() + else + return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'") + end + end + local function _13_(r, desc) + begin() + if r then + return pass() + else + return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'") end end - return display_results(results, ("[" .. mod_name .. "]")) + t = {["="] = _9_, ["pr="] = _11_, ["ok?"] = _13_} + local _15_, _16_ = nil, nil + local function _17_() + return f(t) + end + _15_, _16_ = pcall(_17_) + if ((_15_ == false) and (nil ~= _16_)) then + local err = _16_ + fail("Exception: ", err) + else + end + end + if not test_failed then + a.update(results, "tests-passed", a.inc) + else end end - v_0_0 = run0 - _0_["run"] = v_0_0 - v_0_ = v_0_0 + return display_results(results, ("[" .. mod_name .. "]")) + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["run"] = v_0_ - run = v_0_ end -local run_all -do - local v_0_ - do - local v_0_0 - local function run_all0() - local function _3_(totals, results) - for k, v in pairs(results) do - totals[k] = (v + totals[k]) - end - return totals - end - return display_results(a.reduce(_3_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") +_2amodule_2a["run"] = run +local function run_all() + local function _21_(totals, results) + for k, v in pairs(results) do + totals[k] = (v + totals[k]) end - v_0_0 = run_all0 - _0_["run-all"] = v_0_0 - v_0_ = v_0_0 + return totals end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["run-all"] = v_0_ - run_all = v_0_ + local function _22_(mod_name) + local mod = a.get(_G.package.loaded, mod_name) + return (not a["table?"](mod) or getmetatable(mod)) + end + return display_results(a.reduce(_21_, {tests = 0, ["tests-passed"] = 0, assertions = 0, ["assertions-passed"] = 0}, a.filter(a["table?"], a.map(run, a.remove(_22_, a.keys(_G.package.loaded))))), "[total]") end -local suite -do - local v_0_ +_2amodule_2a["run-all"] = run_all +local function suite() do - local v_0_0 - local function suite0() - do - local sep = fs["path-sep"] - local function _3_(path) - return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, ".")) - end - a["run!"](_3_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true)) - end - if ok_3f(run_all()) then - return nvim.ex.q() - else - return nvim.ex.cq() - end + local sep = fs["path-sep"] + local function _23_(path) + return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, ".")) end - v_0_0 = suite0 - _0_["suite"] = v_0_0 - v_0_ = v_0_0 + a["run!"](_23_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true)) + end + if ok_3f(run_all()) then + return nvim.ex.q() + else + return nvim.ex.cq() end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["suite"] = v_0_ - suite = v_0_ end -return nil +_2amodule_2a["suite"] = suite +return _2amodule_2a diff --git a/lua/nvim-tree-docs/aniseed/view.lua b/lua/nvim-tree-docs/aniseed/view.lua index bbb76a7..a02a811 100644 --- a/lua/nvim-tree-docs/aniseed/view.lua +++ b/lua/nvim-tree-docs/aniseed/view.lua @@ -1,58 +1,19 @@ local _2afile_2a = "fnl/aniseed/view.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.aniseed.view" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.aniseed.view" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {} - return val_0_ - else - return print(val_0_) - end + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local _local_0_ = _2_(...) -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.aniseed.view" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local serialise +local _2amodule_locals_2a do - local v_0_ - do - local v_0_0 - local function _3_(...) - return require("nvim-tree-docs.aniseed.deps.fennelview")(...) - end - v_0_0 = _3_ - _0_["serialise"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["serialise"] = v_0_ - serialise = v_0_ + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local fnl = require("nvim-tree-docs.aniseed.fennel") +do end (_2amodule_locals_2a)["fnl"] = fnl +local function serialise(...) + return fnl.impl().view(...) end -return nil +_2amodule_2a["serialise"] = serialise +return _2amodule_2a diff --git a/lua/nvim-tree-docs/collector.lua b/lua/nvim-tree-docs/collector.lua index a7d6a60..659bf48 100644 --- a/lua/nvim-tree-docs/collector.lua +++ b/lua/nvim-tree-docs/collector.lua @@ -1,249 +1,144 @@ local _2afile_2a = "fnl/nvim-tree-docs/collector.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.collector" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.collector" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.aniseed.core")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {core = "nvim-tree-docs.aniseed.core"}} - return val_0_ - else - return print(val_0_) - end +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -local _local_0_ = _2_(...) -local core = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.collector" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local core = autoload("nvim-tree-docs.aniseed.core") +do end (_2amodule_locals_2a)["core"] = core local collector_metatable -do - local v_0_ - local function _3_(tbl, key) - if (type(key) == "number") then - local id = tbl.__order[key] - if id then - return tbl.__entries[id] - else - return nil - end +local function _1_(tbl, key) + if (type(key) == "number") then + local id = tbl.__order[key] + if id then + return tbl.__entries[id] else - return rawget(tbl, key) + return nil end + else + return rawget(tbl, key) end - v_0_ = {__index = _3_} - local t_0_ = (_0_)["aniseed/locals"] - t_0_["collector-metatable"] = v_0_ - collector_metatable = v_0_ end -local new_collector -do - local v_0_ - do - local v_0_0 - local function new_collector0() - return setmetatable({__entries = {}, __order = {}}, collector_metatable) - end - v_0_0 = new_collector0 - _0_["new-collector"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["new-collector"] = v_0_ - new_collector = v_0_ +collector_metatable = {__index = _1_} +_2amodule_locals_2a["collector-metatable"] = collector_metatable +local function new_collector() + return setmetatable({__entries = {}, __order = {}}, collector_metatable) end -local is_collector -do - local v_0_ - do - local v_0_0 - local function is_collector0(value) - return ((type(value) == "table") and (type(value.__entries) == "table")) - end - v_0_0 = is_collector0 - _0_["is-collector"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["is-collector"] = v_0_ - is_collector = v_0_ +_2amodule_2a["new-collector"] = new_collector +local function is_collector(value) + return ((type(value) == "table") and (type(value.__entries) == "table")) end -local is_collector_empty -do - local v_0_ - do - local v_0_0 - local function is_collector_empty0(collector) - return (#collector.__order == 0) - end - v_0_0 = is_collector_empty0 - _0_["is-collector-empty"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["is-collector-empty"] = v_0_ - is_collector_empty = v_0_ +_2amodule_2a["is-collector"] = is_collector +local function is_collector_empty(collector) + return (#collector.__order == 0) end -local iterate_collector -do - local v_0_ - do - local v_0_0 - local function iterate_collector0(collector) - local i = 1 - local function _3_() - local id = collector.__order[i] - if id then - i = (i + 1) - return {entry = collector.__entries[id], index = (i - 1)} - else - return nil - end - end - return _3_ +_2amodule_2a["is-collector-empty"] = is_collector_empty +local function iterate_collector(collector) + local i = 1 + local function _4_() + local id = collector.__order[i] + if id then + i = (i + 1) + return {index = (i - 1), entry = collector.__entries[id]} + else + return nil end - v_0_0 = iterate_collector0 - _0_["iterate-collector"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["iterate-collector"] = v_0_ - iterate_collector = v_0_ + return _4_ end -local get_node_id -do - local v_0_ - do - local v_0_0 - local function get_node_id0(node) - local srow, scol, erow, ecol = node:range() - return string.format("%d_%d_%d_%d", srow, scol, erow, ecol) - end - v_0_0 = get_node_id0 - _0_["get-node-id"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-node-id"] = v_0_ - get_node_id = v_0_ +_2amodule_2a["iterate-collector"] = iterate_collector +local function get_node_id(node) + local srow, scol, erow, ecol = node:range() + return string.format("%d_%d_%d_%d", srow, scol, erow, ecol) end -local collect_ -do - local v_0_ - do - local v_0_0 - local function collect_0(collector, entry, _match, key, add_fn) - if _match.definition then - if not entry[key] then - entry[key] = new_collector() - end - return add_fn(entry[key], key, _match, collect) - elseif not entry[key] then - entry[key] = _match - return nil - elseif ((key == "start_point") and _match.node) then - local _, _0, current_start = (entry[key].node):start() - local _1, _2, new_start = (_match.node):start() - if (new_start < current_start) then - entry[key] = _match - return nil - end - elseif ((key == "end_point") and _match.node) then - local _, _0, current_end = (entry[key].node):end_() - local _1, _2, new_end = (_match.node):end_() - if (new_end > current_end) then - entry[key] = _match - return nil - end - end +_2amodule_2a["get-node-id"] = get_node_id +local function collect_(collector, entry, _match, key, add_fn) + if _match.definition then + if not entry[key] then + entry[key] = new_collector() + else end - v_0_0 = collect_0 - _0_["collect_"] = v_0_0 - v_0_ = v_0_0 + return add_fn(entry[key], key, _match, collect_) + elseif not entry[key] then + entry[key] = _match + return nil + elseif ((key == "start_point") and _match.node) then + local _, _0, current_start = (entry[key].node):start() + local _1, _2, new_start = (_match.node):start() + if (new_start < current_start) then + entry[key] = _match + return nil + else + return nil + end + elseif ((key == "end_point") and _match.node) then + local _, _0, current_end = (entry[key].node):end_() + local _1, _2, new_end = (_match.node):end_() + if (new_end > current_end) then + entry[key] = _match + return nil + else + return nil + end + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["collect_"] = v_0_ - collect_ = v_0_ end -local add_match -do - local v_0_ - do - local v_0_0 - local function add_match0(collector, kind, _match) - if (_match and _match.definition) then - local _def = _match.definition - local def_node = _def.node - local node_id = get_node_id(def_node) - if not collector.__entries[node_id] then - local order_index = 1 - local _, _0, def_start_byte = def_node:start() - local entry_keys = core.keys(collector.__entries) - local done = false - local i = 1 - while not done do - local entry - do - local _3_ = entry_keys[i] - if _3_ then - entry = collector.__entries[_3_] - else - entry = _3_ - end - end - if not entry then - done = true - else - local _1, _2, start_byte = (entry.definition.node):start() - if (def_start_byte < start_byte) then - done = true - else - order_index = (order_index + 1) - i = (i + 1) - end - end +_2amodule_2a["collect_"] = collect_ +local function add_match(collector, kind, _match) + if (_match and _match.definition) then + local _def = _match.definition + local def_node = _def.node + local node_id = get_node_id(def_node) + if not collector.__entries[node_id] then + local order_index = 1 + local _, _0, def_start_byte = def_node:start() + local entry_keys = core.keys(collector.__entries) + local done = false + local i = 1 + while not done do + local entry + do + local _10_ = entry_keys[i] + if (_10_ ~= nil) then + entry = collector.__entries[_10_] + else + entry = _10_ end - table.insert(collector.__order, order_index, node_id) - do end (collector.__entries)[node_id] = {definition = _def, kind = kind} end - for key, submatch in pairs(_match) do - if (key ~= "definition") then - collect_(collector, collector.__entries[node_id], submatch, key, add_match0) + if not entry then + done = true + else + local _1, _2, start_byte = (entry.definition.node):start() + if (def_start_byte < start_byte) then + done = true + else + order_index = (order_index + 1) + i = (i + 1) end end - return nil + end + table.insert(collector.__order, order_index, node_id) + do end (collector.__entries)[node_id] = {kind = kind, definition = _def} + else + end + for key, submatch in pairs(_match) do + if (key ~= "definition") then + collect_(collector, collector.__entries[node_id], submatch, key, add_match) + else end end - v_0_0 = add_match0 - _0_["add-match"] = v_0_0 - v_0_ = v_0_0 + return nil + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["add-match"] = v_0_ - add_match = v_0_ end -return nil \ No newline at end of file +_2amodule_2a["add-match"] = add_match +return _2amodule_2a \ No newline at end of file diff --git a/lua/nvim-tree-docs/editing.lua b/lua/nvim-tree-docs/editing.lua index 8ba0d9d..56d3bdb 100644 --- a/lua/nvim-tree-docs/editing.lua +++ b/lua/nvim-tree-docs/editing.lua @@ -1,119 +1,64 @@ local _2afile_2a = "fnl/nvim-tree-docs/editing.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.editing" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-treesitter.ts_utils"), autoload("vim.treesitter.query")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {["ts-utils"] = "nvim-treesitter.ts_utils", tsq = "vim.treesitter.query"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local ts_utils = _local_0_[1] -local tsq = _local_0_[2] -local _2amodule_2a = _0_ local _2amodule_name_2a = "nvim-tree-docs.editing" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local ns +local _2amodule_2a do - local v_0_ = vim.api.nvim_create_namespace("doc-edit") - local t_0_ = (_0_)["aniseed/locals"] - t_0_["ns"] = v_0_ - ns = v_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local get_doc_comment_data +local _2amodule_locals_2a do - local v_0_ - do - local v_0_0 - local function get_doc_comment_data0(args) - local _let_0_ = args - local bufnr = _let_0_["bufnr"] - local doc_lang = _let_0_["doc-lang"] - local lang = _let_0_["lang"] - local node = _let_0_["node"] - local doc_lines = ts_utils.get_node_text(node, bufnr) - local doc_string = table.concat(doc_lines, "\n") - local parser = vim.treesitter.get_string_parser(doc_string, doc_lang) - local query = tsq.get_query(doc_lang, "edits") - local iter = query:iter_matches(parser:parse():root(), doc_string, 1, (#doc_string + 1)) - local result = {} - local item = {iter()} - while item[1] do - local _let_1_ = item - local pattern_id = _let_1_[1] - local matches = _let_1_[2] - for id, match_node in pairs(matches) do - local match_name = query.captures[id] - if not result[match_name] then - result[match_name] = {} - end - table.insert(result[match_name], match_node) - end - item = {iter()} + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local ts_utils, tsq = autoload("nvim-treesitter.ts_utils"), autoload("vim.treesitter.query") +do end (_2amodule_locals_2a)["ts-utils"] = ts_utils +_2amodule_locals_2a["tsq"] = tsq +local ns = vim.api.nvim_create_namespace("doc-edit") +do end (_2amodule_locals_2a)["ns"] = ns +local function get_doc_comment_data(args) + local _let_1_ = args + local lang = _let_1_["lang"] + local doc_lang = _let_1_["doc-lang"] + local node = _let_1_["node"] + local bufnr = _let_1_["bufnr"] + local doc_lines = ts_utils.get_node_text(node, bufnr) + local doc_string = table.concat(doc_lines, "\n") + local parser = vim.treesitter.get_string_parser(doc_string, doc_lang) + local query = tsq.get_query(doc_lang, "edits") + local iter = query:iter_matches(parser:parse():root(), doc_string, 1, (#doc_string + 1)) + local result = {} + local item = {iter()} + while item[1] do + local _let_2_ = item + local pattern_id = _let_2_[1] + local matches = _let_2_[2] + for id, match_node in pairs(matches) do + local match_name = query.captures[id] + if not result[match_name] then + result[match_name] = {} + else end - return result + table.insert(result[match_name], match_node) end - v_0_0 = get_doc_comment_data0 - _0_["get-doc-comment-data"] = v_0_0 - v_0_ = v_0_0 + item = {iter()} end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-doc-comment-data"] = v_0_ - get_doc_comment_data = v_0_ + return result end -local edit_doc -do - local v_0_ - do - local v_0_0 - local function edit_doc0(args) - local _let_0_ = args - local bufnr = _let_0_["bufnr"] - local doc_node = _let_0_["node"] - local _let_1_ = get_doc_comment_data(args) - local edit = _let_1_["edit"] - local sr = doc_node:range() - vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1) - for _, node in ipairs(edit) do - local dsr, dsc, der, dec = node:range() - ts_utils.highlight_range({(dsr + sr), dsc, (der + sr), dec}, bufnr, ns, "Visual") - end - return nil - end - v_0_0 = edit_doc0 - _0_["edit-doc"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get-doc-comment-data"] = get_doc_comment_data +local function edit_doc(args) + local _let_4_ = args + local bufnr = _let_4_["bufnr"] + local doc_node = _let_4_["node"] + local _let_5_ = get_doc_comment_data(args) + local edit = _let_5_["edit"] + local sr = doc_node:range() + vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1) + for _, node in ipairs(edit) do + local dsr, dsc, der, dec = node:range() + ts_utils.highlight_range({(dsr + sr), dsc, (der + sr), dec}, bufnr, ns, "Visual") end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["edit-doc"] = v_0_ - edit_doc = v_0_ + return nil end -return nil \ No newline at end of file +_2amodule_2a["edit-doc"] = edit_doc +return _2amodule_2a \ No newline at end of file diff --git a/lua/nvim-tree-docs/internal.lua b/lua/nvim-tree-docs/internal.lua index 051085d..424bfed 100644 --- a/lua/nvim-tree-docs/internal.lua +++ b/lua/nvim-tree-docs/internal.lua @@ -1,521 +1,264 @@ local _2afile_2a = "fnl/nvim-tree-docs/internal.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.internal" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.internal" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-tree-docs.collector"), autoload("nvim-treesitter.configs"), autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.editing"), autoload("nvim-treesitter.query"), autoload("nvim-tree-docs.template"), autoload("nvim-treesitter.ts_utils"), autoload("nvim-tree-docs.utils")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {["ts-utils"] = "nvim-treesitter.ts_utils", collectors = "nvim-tree-docs.collector", configs = "nvim-treesitter.configs", core = "nvim-tree-docs.aniseed.core", editing = "nvim-tree-docs.editing", queries = "nvim-treesitter.query", templates = "nvim-tree-docs.template", utils = "nvim-tree-docs.utils"}} - return val_0_ +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local collectors, configs, core, editing, queries, templates, ts_utils, utils = autoload("nvim-tree-docs.collector"), autoload("nvim-treesitter.configs"), autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-tree-docs.editing"), autoload("nvim-treesitter.query"), autoload("nvim-tree-docs.template"), autoload("nvim-treesitter.ts_utils"), autoload("nvim-tree-docs.utils") +do end (_2amodule_locals_2a)["collectors"] = collectors +_2amodule_locals_2a["configs"] = configs +_2amodule_locals_2a["core"] = core +_2amodule_locals_2a["editing"] = editing +_2amodule_locals_2a["queries"] = queries +_2amodule_locals_2a["templates"] = templates +_2amodule_locals_2a["ts-utils"] = ts_utils +_2amodule_locals_2a["utils"] = utils +local language_specs = {javascript = "jsdoc", lua = "luadoc", typescript = "tsdoc"} +_2amodule_locals_2a["language-specs"] = language_specs +local doc_cache = {} +_2amodule_locals_2a["doc-cache"] = doc_cache +local function get_spec_for_lang(lang) + local spec = language_specs[lang] + if not spec then + error(string.format("No language spec configured for %s", lang)) else - return print(val_0_) end + return spec end -local _local_0_ = _2_(...) -local collectors = _local_0_[1] -local configs = _local_0_[2] -local core = _local_0_[3] -local editing = _local_0_[4] -local queries = _local_0_[5] -local templates = _local_0_[6] -local ts_utils = _local_0_[7] -local utils = _local_0_[8] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.internal" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local language_specs -do - local v_0_ = {javascript = "jsdoc", lua = "luadoc", typescript = "tsdoc"} - local t_0_ = (_0_)["aniseed/locals"] - t_0_["language-specs"] = v_0_ - language_specs = v_0_ +_2amodule_2a["get-spec-for-lang"] = get_spec_for_lang +local function get_spec_config(lang, spec) + local spec_def = templates["get-spec"](lang, spec) + local module_config = configs.get_module("tree_docs") + local spec_default_config = spec_def.config + local lang_config = utils.get({"lang_config", lang, spec}, module_config, {}) + local spec_config = utils.get({"spec_config", spec}, module_config, {}) + return vim.tbl_deep_extend("force", spec_default_config, spec_config, lang_config) end -local doc_cache -do - local v_0_ = {} - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc-cache"] = v_0_ - doc_cache = v_0_ +_2amodule_2a["get-spec-config"] = get_spec_config +local function get_spec_for_buf(bufnr_3f) + local bufnr = (bufnr_3f or vim.api.nvim_get_current_buf()) + return get_spec_for_lang(vim.api.nvim_buf_get_option(bufnr, "ft")) end -local get_spec_for_lang -do - local v_0_ - do - local v_0_0 - local function get_spec_for_lang0(lang) - local spec = language_specs[lang] - if not spec then - error(string.format("No language spec configured for %s", lang)) - end - return spec - end - v_0_0 = get_spec_for_lang0 - _0_["get-spec-for-lang"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get-spec-for-buf"] = get_spec_for_buf +local function generate_docs(data_list, bufnr_3f, lang_3f) + local bufnr = utils["get-bufnr"](bufnr_3f) + local lang = (lang_3f or vim.api.nvim_buf_get_option(bufnr, "ft")) + local spec_name = get_spec_for_lang(lang) + local spec = templates["get-spec"](lang, spec_name) + local spec_config = get_spec_config(lang, spec_name) + local edits = {} + local marks = {} + local function _2_(_241, _242) + local _, _0, start_byte_a = utils["get-start-position"](_241) + local _1, _2, start_byte_b = utils["get-start-position"](_242) + return (start_byte_a < start_byte_b) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-spec-for-lang"] = v_0_ - get_spec_for_lang = v_0_ -end -local get_spec_config -do - local v_0_ - do - local v_0_0 - local function get_spec_config0(lang, spec) - local spec_def = templates["get-spec"](lang, spec) - local module_config = configs.get_module("tree_docs") - local spec_default_config = spec_def.config - local lang_config = utils.get({"lang_config", lang, spec}, module_config, {}) - local spec_config = utils.get({"spec_config", spec}, module_config, {}) - return vim.tbl_deep_extend("force", spec_default_config, spec_config, lang_config) - end - v_0_0 = get_spec_config0 - _0_["get-spec-config"] = v_0_0 - v_0_ = v_0_0 + table.sort(data_list, _2_) + local line_offset = 0 + for _, doc_data in ipairs(data_list) do + local node_sr, node_sc = utils["get-start-position"](doc_data) + local node_er, node_ec = utils["get-end-position"](doc_data) + local content_lines = utils["get-buf-content"](node_sr, node_sc, node_er, node_ec, bufnr) + local replaced_count = ((node_er + 1) - node_sr) + local result = templates["process-template"](doc_data, {spec = spec, bufnr = bufnr, config = spec_config, ["start-line"] = (node_sr + line_offset), ["start-col"] = node_sc, kind = doc_data.kind, content = content_lines}) + table.insert(edits, {newText = (table.concat(result.content, "\n") .. "\n"), range = {start = {line = node_sr, character = 0}, ["end"] = {line = (node_er + 1), character = 0}}}) + vim.list_extend(marks, result.marks) + line_offset = ((line_offset + #result.content) - replaced_count) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-spec-config"] = v_0_ - get_spec_config = v_0_ + return vim.lsp.util.apply_text_edits(edits, bufnr, "utf-16") end -local get_spec_for_buf -do - local v_0_ - do - local v_0_0 - local function get_spec_for_buf0(bufnr_3f) - local bufnr = (bufnr_3f or vim.api.nvim_get_current_buf()) - return get_spec_for_lang(vim.api.nvim_buf_get_option(bufnr, "ft")) - end - v_0_0 = get_spec_for_buf0 - _0_["get-spec-for-buf"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-spec-for-buf"] = v_0_ - get_spec_for_buf = v_0_ -end -local generate_docs -do - local v_0_ - do - local v_0_0 - local function generate_docs0(data_list, bufnr_3f, lang_3f) - local bufnr = utils["get-bufnr"](bufnr_3f) - local lang = (lang_3f or vim.api.nvim_buf_get_option(bufnr, "ft")) - local spec_name = get_spec_for_lang(lang) - local spec = templates["get-spec"](lang, spec_name) - local spec_config = get_spec_config(lang, spec_name) - local edits = {} - local marks = {} - local function _3_(_241, _242) - local _, _0, start_byte_a = utils["get-start-position"](_241) - local _1, _2, start_byte_b = utils["get-start-position"](_242) - return (start_byte_a < start_byte_b) - end - table.sort(data_list, _3_) - local line_offset = 0 - for _, doc_data in ipairs(data_list) do - local node_sr, node_sc = utils["get-start-position"](doc_data) - local node_er, node_ec = utils["get-end-position"](doc_data) - local content_lines = utils["get-buf-content"](node_sr, node_sc, node_er, node_ec, bufnr) - local replaced_count = ((node_er + 1) - node_sr) - local result = templates["process-template"](doc_data, {["start-col"] = node_sc, ["start-line"] = (node_sr + line_offset), bufnr = bufnr, config = spec_config, content = content_lines, kind = doc_data.kind, spec = spec}) - table.insert(edits, {newText = (table.concat(result.content, "\n") .. "\n"), range = {["end"] = {character = 0, line = (node_er + 1)}, start = {character = 0, line = node_sr}}}) - vim.list_extend(marks, result.marks) - line_offset = ((line_offset + #result.content) - replaced_count) +_2amodule_2a["generate-docs"] = generate_docs +local function collect_docs(bufnr_3f) + local bufnr = utils["get-bufnr"](bufnr_3f) + if (utils.get({bufnr, "tick"}, doc_cache) == vim.api.nvim_buf_get_changedtick(bufnr)) then + return utils.get({bufnr, "docs"}, doc_cache) + else + local collector = collectors["new-collector"]() + local doc_matches = queries.collect_group_results(bufnr, "docs") + for _, item in ipairs(doc_matches) do + for kind, _match in pairs(item) do + collectors["add-match"](collector, kind, _match) end - return vim.lsp.util.apply_text_edits(edits, bufnr) end - v_0_0 = generate_docs0 - _0_["generate-docs"] = v_0_0 - v_0_ = v_0_0 + doc_cache[bufnr] = {tick = vim.api.nvim_buf_get_changedtick(bufnr), docs = collector} + return collector end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["generate-docs"] = v_0_ - generate_docs = v_0_ end -local collect_docs -do - local v_0_ - do - local v_0_0 - local function collect_docs0(bufnr_3f) - local bufnr = utils["get-bufnr"](bufnr_3f) - if (utils.get({bufnr, "tick"}, doc_cache) == vim.api.nvim_buf_get_changedtick(bufnr)) then - return utils.get({bufnr, "docs"}, doc_cache) - else - local collector = collectors["new-collector"]() - local doc_matches = queries.collect_group_results(bufnr, "docs") - for _, item in ipairs(doc_matches) do - for kind, _match in pairs(item) do - collectors["add-match"](collector, kind, _match) - end - end - doc_cache[bufnr] = {docs = collector, tick = vim.api.nvim_buf_get_changedtick(bufnr)} - return collector - end +_2amodule_2a["collect-docs"] = collect_docs +local function get_doc_data_for_node(node, bufnr_3f) + local current = nil + local last_start = nil + local last_end = nil + local doc_data = collect_docs(bufnr_3f) + local _, _0, node_start = node:start() + for iter_item in collectors["iterate-collector"](doc_data) do + local is_more_specific = true + local _let_4_ = iter_item + local doc_def = _let_4_["entry"] + local _1, _2, start = utils["get-start-position"](doc_def) + local _3, _4, _end = utils["get-end-position"](doc_def) + local is_in_range = ((node_start >= start) and (node_start < _end)) + if (last_start and last_end) then + is_more_specific = ((start >= last_start) and (_end <= last_end)) + else end - v_0_0 = collect_docs0 - _0_["collect-docs"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["collect-docs"] = v_0_ - collect_docs = v_0_ -end -local get_doc_data_for_node -do - local v_0_ - do - local v_0_0 - local function get_doc_data_for_node0(node, bufnr_3f) - local current = nil - local last_start = nil - local last_end = nil - local doc_data = collect_docs(bufnr_3f) - local _, _0, node_start = node:start() - for iter_item in collectors["iterate-collector"](doc_data) do - local is_more_specific = true - local _let_0_ = iter_item - local doc_def = _let_0_["entry"] - local _1, _2, start = utils["get-start-position"](doc_def) - local _3, _4, _end = utils["get-end-position"](doc_def) - local is_in_range = ((node_start >= start) and (node_start < _end)) - if (last_start and last_end) then - is_more_specific = ((start >= last_start) and (_end <= last_end)) - end - if (is_in_range and is_more_specific) then - last_start = start - last_end = _end - current = doc_def - end - end - return current + if (is_in_range and is_more_specific) then + last_start = start + last_end = _end + current = doc_def + else end - v_0_0 = get_doc_data_for_node0 - _0_["get-doc-data-for-node"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-doc-data-for-node"] = v_0_ - get_doc_data_for_node = v_0_ + return current end -local doc_node -do - local v_0_ - do - local v_0_0 - local function doc_node0(node, bufnr_3f, lang_3f) - if node then - local doc_data = get_doc_data_for_node(node, bufnr_3f) - return generate_docs({doc_data}, bufnr_3f, lang_3f) - end - end - v_0_0 = doc_node0 - _0_["doc-node"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get-doc-data-for-node"] = get_doc_data_for_node +local function doc_node(node, bufnr_3f, lang_3f) + if node then + local doc_data = get_doc_data_for_node(node, bufnr_3f) + return generate_docs({doc_data}, bufnr_3f, lang_3f) + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc-node"] = v_0_ - doc_node = v_0_ end -local doc_node_at_cursor -do - local v_0_ - do - local v_0_0 - local function doc_node_at_cursor0() - return doc_node(ts_utils.get_node_at_cursor()) - end - v_0_0 = doc_node_at_cursor0 - _0_["doc-node-at-cursor"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc-node-at-cursor"] = v_0_ - doc_node_at_cursor = v_0_ +_2amodule_2a["doc-node"] = doc_node +local function doc_node_at_cursor() + return doc_node(ts_utils.get_node_at_cursor()) end -local get_docs_from_position -do - local v_0_ - do - local v_0_0 - local function get_docs_from_position0(args) - local _let_0_ = args - local bufnr_3f = _let_0_["bufnr"] - local end_line = _let_0_["end-line"] - local inclusion_3f = _let_0_["inclusion"] - local position = _let_0_["position"] - local start_line = _let_0_["start-line"] - local is_edit_type_3f = (position == "edit") - local doc_data = collect_docs(bufnr_3f) - local result = {} - for item in collectors["iterate-collector"](doc_data) do - local _let_1_ = item - local _def = _let_1_["entry"] - local start_r - if is_edit_type_3f then - start_r = utils["get-edit-start-position"](_def) - else - start_r = utils["get-start-position"](_def) - end - local end_r - if is_edit_type_3f then - end_r = utils["get-edit-end-position"](_def) - else - end_r = utils["get-end-position"](_def) - end - local _5_ - if inclusion_3f then - _5_ = ((start_line >= start_r) and (end_line <= end_r)) - else - _5_ = ((start_r >= start_line) and (end_r <= end_line)) - end - if _5_ then - table.insert(result, _def) - end - end - return result +_2amodule_2a["doc-node-at-cursor"] = doc_node_at_cursor +local function get_docs_from_position(args) + local _let_8_ = args + local start_line = _let_8_["start-line"] + local end_line = _let_8_["end-line"] + local position = _let_8_["position"] + local inclusion_3f = _let_8_["inclusion"] + local bufnr_3f = _let_8_["bufnr"] + local is_edit_type_3f = (position == "edit") + local doc_data = collect_docs(bufnr_3f) + local result = {} + for item in collectors["iterate-collector"](doc_data) do + local _let_9_ = item + local _def = _let_9_["entry"] + local start_r + if is_edit_type_3f then + start_r = utils["get-edit-start-position"](_def) + else + start_r = utils["get-start-position"](_def) end - v_0_0 = get_docs_from_position0 - _0_["get-docs-from-position"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-docs-from-position"] = v_0_ - get_docs_from_position = v_0_ -end -local get_docs_in_range -do - local v_0_ - do - local v_0_0 - local function get_docs_in_range0(args) - return get_docs_from_position(vim.tbl_extend("force", args, {inclusion = false, position = nil})) + local end_r + if is_edit_type_3f then + end_r = utils["get-edit-end-position"](_def) + else + end_r = utils["get-end-position"](_def) end - v_0_0 = get_docs_in_range0 - _0_["get-docs-in-range"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-docs-in-range"] = v_0_ - get_docs_in_range = v_0_ -end -local get_docs_at_range -do - local v_0_ - do - local v_0_0 - local function get_docs_at_range0(args) - return get_docs_from_position(vim.tbl_extend("force", args, {inclusion = true, position = "edit"})) + local _12_ + if inclusion_3f then + _12_ = ((start_line >= start_r) and (end_line <= end_r)) + else + _12_ = ((start_r >= start_line) and (end_r <= end_line)) end - v_0_0 = get_docs_at_range0 - _0_["get-docs-at-range"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-docs-at-range"] = v_0_ - get_docs_at_range = v_0_ -end -local get_docs_from_selection -do - local v_0_ - do - local v_0_0 - local function get_docs_from_selection0() - local _, start, _0, _1 = unpack(vim.fn.getpos("'<")) - local _2, _end, _3, _4 = unpack(vim.fn.getpos("'>")) - return get_docs_in_range({["end-line"] = (_end - 1), ["start-line"] = (start - 1)}) + if _12_ then + table.insert(result, _def) + else end - v_0_0 = get_docs_from_selection0 - _0_["get-docs-from-selection"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-docs-from-selection"] = v_0_ - get_docs_from_selection = v_0_ + return result end -local doc_all_in_range -do - local v_0_ - do - local v_0_0 - local function doc_all_in_range0() - return generate_docs(get_docs_from_selection()) - end - v_0_0 = doc_all_in_range0 - _0_["doc-all-in-range"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc-all-in-range"] = v_0_ - doc_all_in_range = v_0_ +_2amodule_2a["get-docs-from-position"] = get_docs_from_position +local function get_docs_in_range(args) + return get_docs_from_position(vim.tbl_extend("force", args, {position = nil, inclusion = false})) end -local edit_doc_at_cursor -do - local v_0_ - do - local v_0_0 - local function edit_doc_at_cursor0() - local _let_0_ = vim.api.nvim_win_get_cursor(0) - local row = _let_0_[1] - local doc_data = get_docs_at_range({["end-line"] = (row - 1), ["start-line"] = (row - 1)}) - local bufnr = vim.api.nvim_get_current_buf() - local lang = vim.api.nvim_buf_get_option(bufnr, "ft") - local spec_name = get_spec_for_lang(lang) - local spec = templates["get-spec"](lang, spec_name) - local doc_lang = spec["doc-lang"] - local doc_entry - do - local _3_ = doc_data - if _3_ then - local _4_ = (_3_)[1] - if _4_ then - doc_entry = (_4_).doc - else - doc_entry = _4_ - end - else - doc_entry = _3_ - end - end - if (core["table?"](doc_entry) and doc_entry.node and doc_lang) then - return editing["edit-doc"]({["doc-lang"] = doc_lang, ["spec-name"] = spec_name, bufnr = bufnr, lang = lang, node = doc_entry.node}) - end - end - v_0_0 = edit_doc_at_cursor0 - _0_["edit-doc-at-cursor"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["edit-doc-at-cursor"] = v_0_ - edit_doc_at_cursor = v_0_ +_2amodule_2a["get-docs-in-range"] = get_docs_in_range +local function get_docs_at_range(args) + return get_docs_from_position(vim.tbl_extend("force", args, {inclusion = true, position = "edit"})) end -local attach -do - local v_0_ - do - local v_0_0 - local function attach0(bufnr_3f) - local bufnr = utils["get-bufnr"](bufnr_3f) - local config = configs.get_module("tree_docs") - for _fn, mapping in pairs(config.keymaps) do - local mode = "n" - if (_fn == "doc_all_in_range") then - mode = "v" - end - if mapping then - vim.api.nvim_buf_set_keymap(bufnr, mode, mapping, string.format(":lua require 'nvim-tree-docs.internal'.%s()", _fn), {silent = true}) - end - end - return nil - end - v_0_0 = attach0 - _0_["attach"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["attach"] = v_0_ - attach = v_0_ +_2amodule_2a["get-docs-at-range"] = get_docs_at_range +local function get_docs_from_selection() + local _, start, _0, _1 = unpack(vim.fn.getpos("'<")) + local _2, _end, _3, _4 = unpack(vim.fn.getpos("'>")) + return get_docs_in_range({["start-line"] = (start - 1), ["end-line"] = (_end - 1)}) end -local detach -do - local v_0_ +_2amodule_2a["get-docs-from-selection"] = get_docs_from_selection +local function doc_all_in_range() + return generate_docs(get_docs_from_selection()) +end +_2amodule_2a["doc-all-in-range"] = doc_all_in_range +local function edit_doc_at_cursor() + local _let_15_ = vim.api.nvim_win_get_cursor(0) + local row = _let_15_[1] + local doc_data = get_docs_at_range({["start-line"] = (row - 1), ["end-line"] = (row - 1)}) + local bufnr = vim.api.nvim_get_current_buf() + local lang = vim.api.nvim_buf_get_option(bufnr, "ft") + local spec_name = get_spec_for_lang(lang) + local spec = templates["get-spec"](lang, spec_name) + local doc_lang = spec["doc-lang"] + local doc_entry do - local v_0_0 - local function detach0(bufnr_3f) - local bufnr = utils["get-bufnr"](bufnr_3f) - local config = configs.get_module("tree_docs") - for _fn, mapping in pairs(config.keymaps) do - local mode = "n" - if (_fn == "doc_all_in_range") then - mode = "v" - end - if mapping then - vim.api.nvim_buf_del_keymap(bufnr, mode, mapping) - end + local _16_ = doc_data + if (nil ~= _16_) then + local _17_ = (_16_)[1] + if (nil ~= _17_) then + doc_entry = (_17_).doc + else + doc_entry = _17_ end - return nil + else + doc_entry = _16_ end - v_0_0 = detach0 - _0_["detach"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["detach"] = v_0_ - detach = v_0_ -end -local doc_node_at_cursor0 -do - local v_0_ - do - local v_0_0 = doc_node_at_cursor - _0_["doc_node_at_cursor"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc_node_at_cursor"] = v_0_ - doc_node_at_cursor0 = v_0_ -end -local doc_node0 -do - local v_0_ - do - local v_0_0 = doc_node - _0_["doc_node"] = v_0_0 - v_0_ = v_0_0 + if (core["table?"](doc_entry) and doc_entry.node and doc_lang) then + return editing["edit-doc"]({lang = lang, ["spec-name"] = spec_name, bufnr = bufnr, ["doc-lang"] = doc_lang, node = doc_entry.node}) + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc_node"] = v_0_ - doc_node0 = v_0_ end -local doc_all_in_range0 -do - local v_0_ - do - local v_0_0 = doc_all_in_range - _0_["doc_all_in_range"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["edit-doc-at-cursor"] = edit_doc_at_cursor +local function attach(bufnr_3f) + local bufnr = utils["get-bufnr"](bufnr_3f) + local config = configs.get_module("tree_docs") + for _fn, mapping in pairs(config.keymaps) do + local mode = "n" + if (_fn == "doc_all_in_range") then + mode = "v" + else + end + if mapping then + vim.api.nvim_buf_set_keymap(bufnr, mode, mapping, string.format(":lua require 'nvim-tree-docs.internal'.%s()", _fn), {silent = true}) + else + end end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["doc_all_in_range"] = v_0_ - doc_all_in_range0 = v_0_ + return nil end -local edit_doc_at_cursor0 -do - local v_0_ - do - local v_0_0 = edit_doc_at_cursor - _0_["edit_doc_at_cursor"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["attach"] = attach +local function detach(bufnr_3f) + local bufnr = utils["get-bufnr"](bufnr_3f) + local config = configs.get_module("tree_docs") + for _fn, mapping in pairs(config.keymaps) do + local mode = "n" + if (_fn == "doc_all_in_range") then + mode = "v" + else + end + if mapping then + vim.api.nvim_buf_del_keymap(bufnr, mode, mapping) + else + end end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["edit_doc_at_cursor"] = v_0_ - edit_doc_at_cursor0 = v_0_ + return nil end -return nil \ No newline at end of file +_2amodule_2a["detach"] = detach +local doc_node_at_cursor0 = doc_node_at_cursor +_2amodule_2a["doc_node_at_cursor"] = doc_node_at_cursor0 +local doc_node0 = doc_node +_2amodule_2a["doc_node"] = doc_node0 +local doc_all_in_range0 = doc_all_in_range +_2amodule_2a["doc_all_in_range"] = doc_all_in_range0 +local edit_doc_at_cursor0 = edit_doc_at_cursor +_2amodule_2a["edit_doc_at_cursor"] = edit_doc_at_cursor0 +return _2amodule_2a \ No newline at end of file diff --git a/lua/nvim-tree-docs/main.lua b/lua/nvim-tree-docs/main.lua index 0bdc7cf..06854fc 100644 --- a/lua/nvim-tree-docs/main.lua +++ b/lua/nvim-tree-docs/main.lua @@ -1,63 +1,24 @@ local _2afile_2a = "fnl/nvim-tree-docs/main.fnl" -local _0_ +local _2amodule_name_2a = "nvim-tree-docs.main" +local _2amodule_2a do - local name_0_ = "nvim-tree-docs.main" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _1_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("nvim-treesitter.query"), autoload("nvim-treesitter")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {queries = "nvim-treesitter.query", ts = "nvim-treesitter"}} - return val_0_ - else - return print(val_0_) - end + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local _local_0_ = _2_(...) -local queries = _local_0_[1] -local ts = _local_0_[2] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.main" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local init +local _2amodule_locals_2a do - local v_0_ - do - local v_0_0 - local function init0() - local function _3_(_241) - return (queries.get_query(_241, "docs") ~= nil) - end - return ts.define_modules({tree_docs = {is_supported = _3_, keymaps = {doc_all_in_range = "gdd", doc_node_at_cursor = "gdd", edit_doc_at_cursor = "gde"}, module_path = "nvim-tree-docs.internal"}}) - end - v_0_0 = init0 - _0_["init"] = v_0_0 - v_0_ = v_0_0 + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local queries, ts = autoload("nvim-treesitter.query"), autoload("nvim-treesitter") +do end (_2amodule_locals_2a)["queries"] = queries +_2amodule_locals_2a["ts"] = ts +local function init() + local function _1_(_241) + return (queries.get_query(_241, "docs") ~= nil) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["init"] = v_0_ - init = v_0_ + return ts.define_modules({tree_docs = {module_path = "nvim-tree-docs.internal", keymaps = {doc_node_at_cursor = "gdd", doc_all_in_range = "gdd", edit_doc_at_cursor = "gde"}, is_supported = _1_}}) end -return nil \ No newline at end of file +_2amodule_2a["init"] = init +return _2amodule_2a \ No newline at end of file diff --git a/lua/nvim-tree-docs/specs/base/base.lua b/lua/nvim-tree-docs/specs/base/base.lua index f40f136..a61847f 100644 --- a/lua/nvim-tree-docs/specs/base/base.lua +++ b/lua/nvim-tree-docs/specs/base/base.lua @@ -1,29 +1,30 @@ local _2afile_2a = "fnl/nvim-tree-docs/specs/base/base.fnl" local _1_ do - local mod_name_0_ = ("base" .. "." .. "base") - local template_mod_0_ = require("nvim-tree-docs.template") - local module_0_ = {["doc-lang"] = "nil", __build = template_mod_0_["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {}), inherits = nil, lang = "base", module = mod_name_0_, processors = {}, spec = "base", templates = {}, utils = {}} - template_mod_0_["extend-spec"](module_0_, "base.base") - template_mod_0_["extend-spec"](module_0_) - do end ((template_mod_0_)["loaded-specs"])[mod_name_0_] = module_0_ - _1_ = module_0_ + local mod_name_1_auto = ("base" .. "." .. "base") + local template_mod_2_auto = require("nvim-tree-docs.template") + local module_3_auto = {__build = template_mod_2_auto["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {}), ["doc-lang"] = "nil", inherits = nil, lang = "base", module = mod_name_1_auto, processors = {}, spec = "base", templates = {}, utils = {}} + template_mod_2_auto["extend-spec"](module_3_auto, "base.base") + template_mod_2_auto["extend-spec"](module_3_auto) + do end ((template_mod_2_auto)["loaded-specs"])[mod_name_1_auto] = module_3_auto + _1_ = module_3_auto end local function _2_(slot_indexes, slot_config) local expanded = {} for ps_name, enabled in pairs(slot_config) do if (enabled and not slot_indexes[ps_name]) then table.insert(expanded, ps_name) + else end end return expanded end (_1_).processors["%rest%"] = {expand = _2_, implicit = true} -local function _3_(_241) +local function _4_(_241) return _241.content end -local function _4_() +local function _5_() return 0 end -(_1_).processors["%content%"] = {build = _3_, implicit = true, indent = _4_} +(_1_).processors["%content%"] = {build = _4_, implicit = true, indent = _5_} return nil \ No newline at end of file diff --git a/lua/nvim-tree-docs/specs/javascript/jsdoc.lua b/lua/nvim-tree-docs/specs/javascript/jsdoc.lua index 6f1fd56..517611b 100644 --- a/lua/nvim-tree-docs/specs/javascript/jsdoc.lua +++ b/lua/nvim-tree-docs/specs/javascript/jsdoc.lua @@ -1,13 +1,13 @@ local _2afile_2a = "fnl/nvim-tree-docs/specs/javascript/jsdoc.fnl" local _1_ do - local mod_name_0_ = ("javascript" .. "." .. "jsdoc") - local template_mod_0_ = require("nvim-tree-docs.template") - local module_0_ = {["doc-lang"] = "jsdoc", __build = template_mod_0_["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {empty_line_after_description = false, include_types = true, slots = {["function"] = {["function"] = true, example = false, export = true, generator = true, param = true, returns = true, template = true, yields = true}, class = {class = true, example = false, export = true, extends = true}, member = {memberof = true, type = true}, method = {example = false, generator = true, memberof = true, param = true, returns = true, yields = true}, module = {module = true}, variable = {export = true, type = true}}}), inherits = nil, lang = "javascript", module = mod_name_0_, processors = {}, spec = "jsdoc", templates = {}, utils = {}} - template_mod_0_["extend-spec"](module_0_, "base.base") - template_mod_0_["extend-spec"](module_0_) - do end ((template_mod_0_)["loaded-specs"])[mod_name_0_] = module_0_ - _1_ = module_0_ + local mod_name_1_auto = ("javascript" .. "." .. "jsdoc") + local template_mod_2_auto = require("nvim-tree-docs.template") + local module_3_auto = {__build = template_mod_2_auto["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {include_types = true, slots = {["function"] = {param = true, returns = true, ["function"] = true, generator = true, template = true, yields = true, export = true, example = false}, variable = {type = true, export = true}, class = {class = true, export = true, extends = true, example = false}, member = {memberof = true, type = true}, method = {memberof = true, yields = true, generator = true, param = true, returns = true, example = false}, module = {module = true}}, empty_line_after_description = false}), ["doc-lang"] = "jsdoc", inherits = nil, lang = "javascript", module = mod_name_1_auto, processors = {}, spec = "jsdoc", templates = {}, utils = {}} + template_mod_2_auto["extend-spec"](module_3_auto, "base.base") + template_mod_2_auto["extend-spec"](module_3_auto) + do end ((template_mod_2_auto)["loaded-specs"])[mod_name_1_auto] = module_3_auto + _1_ = module_3_auto end (_1_).templates["function"] = {"doc-start", "description", "function", "generator", "yields", "%rest%", "param", "returns", "example", "doc-end", "%content%"} (_1_).templates["variable"] = {"doc-start", "description", "%rest%", "doc-end", "%content%"} @@ -81,9 +81,9 @@ end (_1_).processors["yields"] = {build = _17_, when = _18_} local function _19_(_241, _242) local description = (_1_).__build(" * ", {content = ("The " .. _241["get-text"]((_241).name) .. " " .. _242.name), mark = "tabstop"}) - local _let_0_ = _242 - local index = _let_0_["index"] - local processors = _let_0_["processors"] + local _let_20_ = _242 + local processors = _let_20_["processors"] + local index = _let_20_["index"] local next_ps = processors[(index + 1)] if ((next_ps == "doc-end") or not _241.conf("empty_line_after_description")) then return description @@ -92,19 +92,19 @@ local function _19_(_241, _242) end end (_1_).processors["description"] = {build = _19_, implicit = true} -local function _20_(_241) +local function _22_(_241) local type_str = ((_1_).utils)["get-marked-type"](_241, " ") return (_1_).__build(" * @type", type_str) end -local function _21_(_241) +local function _23_(_241) return _241.type end -(_1_).processors["type"] = {build = _20_, when = _21_} -local function _22_(_241) +(_1_).processors["type"] = {build = _22_, when = _23_} +local function _24_(_241) return _241.export end -(_1_).processors["export"] = {when = _22_} -local function _23_(_241) +(_1_).processors["export"] = {when = _24_} +local function _25_(_241) local result = {} for param in _241.iter(_241.parameters) do local param_name = ((_1_).utils)["get-param-name"](_241, param.entry) @@ -114,38 +114,38 @@ local function _23_(_241) end return result end -local function _24_(_241) +local function _26_(_241) return (_241.parameters and not _241["empty?"](_241.parameters)) end -(_1_).processors["param"] = {build = _23_, when = _24_} -local function _25_(_241) +(_1_).processors["param"] = {build = _25_, when = _26_} +local function _27_(_241) return (_1_).__build(" * @memberof ", _241["get-text"]((_241).class)) end -local function _26_(_241) +local function _28_(_241) return _241.class end -(_1_).processors["memberof"] = {build = _25_, when = _26_} -local function _27_(_241, _242) +(_1_).processors["memberof"] = {build = _27_, when = _28_} +local function _29_(_241, _242) return (_1_).__build(" * @", _242.name) end -(_1_).processors["__default"] = {build = _27_} -local function _28_(_24, param) +(_1_).processors["__default"] = {build = _29_} +local function _30_(_24, param) if param.default_value then return string.format("%s=%s", _24["get-text"](param.name), _24["get-text"](param.default_value)) else return _24["get-text"](param.name) end end -(_1_).utils["get-param-name"] = _28_ -local function _29_(_24, not_found_3f) +(_1_).utils["get-param-name"] = _30_ +local function _32_(_24, not_found_3f) if _24.conf("include_types") then return " {any} " else return (not_found_3f or "") end end -(_1_).utils["get-marked-type"] = _29_ -local function _30_(_24, tag) +(_1_).utils["get-marked-type"] = _32_ +local function _34_(_24, tag) local result = {} for generic in _24.iter(_24.generics) do local name = _24["get-text"](generic.entry.name) @@ -153,5 +153,5 @@ local function _30_(_24, tag) end return result end -(_1_).utils["build-generics"] = _30_ +(_1_).utils["build-generics"] = _34_ return nil \ No newline at end of file diff --git a/lua/nvim-tree-docs/specs/lua/luadoc.lua b/lua/nvim-tree-docs/specs/lua/luadoc.lua index 2691763..30c1bed 100644 --- a/lua/nvim-tree-docs/specs/lua/luadoc.lua +++ b/lua/nvim-tree-docs/specs/lua/luadoc.lua @@ -1,13 +1,13 @@ local _2afile_2a = "fnl/nvim-tree-docs/specs/lua/luadoc.fnl" local _1_ do - local mod_name_0_ = ("lua" .. "." .. "luadoc") - local template_mod_0_ = require("nvim-tree-docs.template") - local module_0_ = {["doc-lang"] = "nil", __build = template_mod_0_["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {slots = {["function"] = {param = true, returns = true}, variable = {}}}), inherits = nil, lang = "lua", module = mod_name_0_, processors = {}, spec = "luadoc", templates = {}, utils = {}} - template_mod_0_["extend-spec"](module_0_, "base.base") - template_mod_0_["extend-spec"](module_0_) - do end ((template_mod_0_)["loaded-specs"])[mod_name_0_] = module_0_ - _1_ = module_0_ + local mod_name_1_auto = ("lua" .. "." .. "luadoc") + local template_mod_2_auto = require("nvim-tree-docs.template") + local module_3_auto = {__build = template_mod_2_auto["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {slots = {["function"] = {param = true, returns = true}, variable = {}}}), ["doc-lang"] = "nil", inherits = nil, lang = "lua", module = mod_name_1_auto, processors = {}, spec = "luadoc", templates = {}, utils = {}} + template_mod_2_auto["extend-spec"](module_3_auto, "base.base") + template_mod_2_auto["extend-spec"](module_3_auto) + do end ((template_mod_2_auto)["loaded-specs"])[mod_name_1_auto] = module_3_auto + _1_ = module_3_auto end (_1_).templates["function"] = {"description", "param", "returns"} (_1_).templates["variable"] = {"description"} diff --git a/lua/nvim-tree-docs/specs/typescript/tsdoc.lua b/lua/nvim-tree-docs/specs/typescript/tsdoc.lua index 1476d5c..e0f9271 100644 --- a/lua/nvim-tree-docs/specs/typescript/tsdoc.lua +++ b/lua/nvim-tree-docs/specs/typescript/tsdoc.lua @@ -1,12 +1,12 @@ local _2afile_2a = "fnl/nvim-tree-docs/specs/typescript/tsdoc.fnl" local _1_ do - local mod_name_0_ = ("typescript" .. "." .. "tsdoc") - local template_mod_0_ = require("nvim-tree-docs.template") - local module_0_ = {["doc-lang"] = "nil", __build = template_mod_0_["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {empty_line_after_description = true, include_types = false, slots = {["function"] = {["function"] = false, export = false, generator = false}, class = {class = false, export = false, extends = false}, member = {memberof = false, type = false}, method = {memberof = false}, variable = {export = false, type = false}}}), inherits = nil, lang = "typescript", module = mod_name_0_, processors = {}, spec = "tsdoc", templates = {}, utils = {}} - template_mod_0_["extend-spec"](module_0_, "base.base") - template_mod_0_["extend-spec"](module_0_, "javascript.jsdoc") - do end ((template_mod_0_)["loaded-specs"])[mod_name_0_] = module_0_ - _1_ = module_0_ + local mod_name_1_auto = ("typescript" .. "." .. "tsdoc") + local template_mod_2_auto = require("nvim-tree-docs.template") + local module_3_auto = {__build = template_mod_2_auto["build-line"], config = vim.tbl_deep_extend("force", {processors = {}, slots = {}}, {empty_line_after_description = true, slots = {["function"] = {generator = false, export = false, ["function"] = false}, variable = {export = false, type = false}, class = {extends = false, export = false, class = false}, member = {memberof = false, type = false}, method = {memberof = false}}, include_types = false}), ["doc-lang"] = "nil", inherits = nil, lang = "typescript", module = mod_name_1_auto, processors = {}, spec = "tsdoc", templates = {}, utils = {}} + template_mod_2_auto["extend-spec"](module_3_auto, "base.base") + template_mod_2_auto["extend-spec"](module_3_auto, "javascript.jsdoc") + do end ((template_mod_2_auto)["loaded-specs"])[mod_name_1_auto] = module_3_auto + _1_ = module_3_auto end return nil \ No newline at end of file diff --git a/lua/nvim-tree-docs/template.lua b/lua/nvim-tree-docs/template.lua index 39c2c52..f366fd0 100644 --- a/lua/nvim-tree-docs/template.lua +++ b/lua/nvim-tree-docs/template.lua @@ -1,580 +1,340 @@ local _2afile_2a = "fnl/nvim-tree-docs/template.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.template" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _2_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _2_ -local function _3_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _3_() - return {autoload("nvim-tree-docs.collector"), autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-treesitter.ts_utils"), autoload("nvim-tree-docs.utils")} - end - ok_3f_0_, val_0_ = pcall(_3_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {["ts-utils"] = "nvim-treesitter.ts_utils", collectors = "nvim-tree-docs.collector", core = "nvim-tree-docs.aniseed.core", utils = "nvim-tree-docs.utils"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _3_(...) -local collectors = _local_0_[1] -local core = _local_0_[2] -local ts_utils = _local_0_[3] -local utils = _local_0_[4] -local _2amodule_2a = _0_ local _2amodule_name_2a = "nvim-tree-docs.template" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local loaded_specs +local _2amodule_2a do - local v_0_ - do - local v_0_0 = {} - _0_["loaded-specs"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["loaded-specs"] = v_0_ - loaded_specs = v_0_ + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] end -local get_text +local _2amodule_locals_2a do - local v_0_ - do - local v_0_0 - local function get_text0(context, node, default, multi) - local default_value = (default or "") - if (node and (type(node) == "table")) then - local tsnode - if node.node then - tsnode = node.node - else - tsnode = node - end - local lines = ts_utils.get_node_text(tsnode) - if multi then - return lines - else - local line = lines[1] - if (line ~= "") then - return line - else - return default_value - end - end + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local collectors, core, ts_utils, utils = autoload("nvim-tree-docs.collector"), autoload("nvim-tree-docs.aniseed.core"), autoload("nvim-treesitter.ts_utils"), autoload("nvim-tree-docs.utils") +do end (_2amodule_locals_2a)["collectors"] = collectors +_2amodule_locals_2a["core"] = core +_2amodule_locals_2a["ts-utils"] = ts_utils +_2amodule_locals_2a["utils"] = utils +local loaded_specs = {} +_2amodule_2a["loaded-specs"] = loaded_specs +local function get_text(context, node, default, multi) + local default_value = (default or "") + if (node and (type(node) == "table")) then + local tsnode + if node.node then + tsnode = node.node + else + tsnode = node + end + local lines = ts_utils.get_node_text(tsnode) + if multi then + return lines + else + local line = lines[1] + if (line ~= "") then + return line else return default_value end end - v_0_0 = get_text0 - _0_["get-text"] = v_0_0 - v_0_ = v_0_0 + else + return default_value end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-text"] = v_0_ - get_text = v_0_ end -local iter -do - local v_0_ - do - local v_0_0 - local function iter0(collector) - if collector then - return collectors["iterate-collector"](collector) +_2amodule_2a["get-text"] = get_text +local function iter(collector) + if collector then + return collectors["iterate-collector"](collector) + else + local function _6_() + return nil + end + return _6_ + end +end +_2amodule_2a["iter"] = iter +local function conf(context, path, default_3f) + return utils.get(path, context.config, default_3f) +end +_2amodule_2a["conf"] = conf +local function empty_3f(collector) + return collectors["is-collector-empty"](collector) +end +_2amodule_2a["empty?"] = empty_3f +local function build_line(...) + local result = {content = "", marks = {}} + local add_content + local function _8_(_241) + result.content = (result.content .. _241) + return nil + end + add_content = _8_ + for _, value in ipairs({...}) do + if core["string?"](value) then + add_content(value) + elseif (core["table?"](value) and core["string?"](value.content)) then + if value.mark then + local start = #result.content + add_content(value.content) + table.insert(result.marks, {kind = value.mark, stop = (#value.content + start), start = start}) else - local function _4_() - return nil - end - return _4_ + add_content(value.content) end + else end - v_0_0 = iter0 - _0_["iter"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["iter"] = v_0_ - iter = v_0_ + return result end -local conf -do - local v_0_ - do - local v_0_0 - local function conf0(context, path, default_3f) - return utils.get(path, context.config, default_3f) - end - v_0_0 = conf0 - _0_["conf"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["build-line"] = build_line +local function new_template_context(collector, options_3f) + local options = (options_3f or {}) + local context = vim.tbl_extend("keep", {iter = iter, ["empty?"] = empty_3f, build = build_line, config = options.config, kind = options.kind, ["start-line"] = (options["start-line"] or 0), ["start-col"] = (options["start-col"] or 0), content = (options.content or {}), bufnr = utils["get-bufnr"](options.bufnr)}, collector) + local function _11_(...) + return get_text(context, ...) + end + context["get-text"] = _11_ + local function _12_(...) + return conf(context, ...) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["conf"] = v_0_ - conf = v_0_ + context.conf = _12_ + return context end -local empty_3f -do - local v_0_ - do - local v_0_0 - local function empty_3f0(collector) - return collectors["is-collector-empty"](collector) - end - v_0_0 = empty_3f0 - _0_["empty?"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["new-template-context"] = new_template_context +local function get_spec(lang, spec) + local key = (lang .. "." .. spec) + if not loaded_specs[key] then + require(string.format("nvim-tree-docs.specs.%s.%s", lang, spec)) + else end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["empty?"] = v_0_ - empty_3f = v_0_ + return loaded_specs[key] end -local build_line -do - local v_0_ - do - local v_0_0 - local function build_line0(...) - local result = {content = "", marks = {}} - local add_content - local function _4_(_241) - result.content = (result.content .. _241) - return nil - end - add_content = _4_ - for _, value in ipairs({...}) do - if core["string?"](value) then - add_content(value) - elseif (core["table?"](value) and core["string?"](value.content)) then - if value.mark then - local start = #result.content - add_content(value.content) - table.insert(result.marks, {kind = value.mark, start = start, stop = (#value.content + start)}) - else - add_content(value.content) - end - end - end - return result - end - v_0_0 = build_line0 - _0_["build-line"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get-spec"] = get_spec +local function normalize_processor(processor) + if utils["func?"](processor) then + return {build = processor} + else + return processor end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["build-line"] = v_0_ - build_line = v_0_ end -local new_template_context -do - local v_0_ - do - local v_0_0 - local function new_template_context0(collector, options_3f) - local options = (options_3f or {}) - local context = vim.tbl_extend("keep", {["empty?"] = empty_3f, ["start-col"] = (options["start-col"] or 0), ["start-line"] = (options["start-line"] or 0), bufnr = utils["get-bufnr"](options.bufnr), build = build_line, config = options.config, content = (options.content or {}), iter = iter, kind = options.kind}, collector) - local function _4_(...) - return get_text(context, ...) - end - context["get-text"] = _4_ - local function _5_(...) - return conf(context, ...) - end - context.conf = _5_ - return context - end - v_0_0 = new_template_context0 - _0_["new-template-context"] = v_0_0 - v_0_ = v_0_0 +_2amodule_locals_2a["normalize-processor"] = normalize_processor +local function get_processor(processors, name, aliased_from_3f) + local processor_config = processors[name] + if core["string?"](processor_config) then + return get_processor(processors, processor_config, (aliased_from_3f or name)) + else + local result = normalize_processor((processor_config or processors.__default)) + return {processor = result, name = name, ["aliased-from"] = aliased_from_3f} end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["new-template-context"] = v_0_ - new_template_context = v_0_ end -local get_spec -do - local v_0_ - do - local v_0_0 - local function get_spec0(lang, spec) - local key = (lang .. "." .. spec) - if not loaded_specs[key] then - require(string.format("nvim-tree-docs.specs.%s.%s", lang, spec)) +_2amodule_locals_2a["get-processor"] = get_processor +local function get_expanded_slots(ps_list, slot_config, processors) + local result = {unpack(ps_list)} + local i = 1 + while (i <= #result) do + local ps_name = result[i] + local _let_16_ = get_processor(processors, ps_name) + local processor = _let_16_["processor"] + if (processor and processor.expand) then + local expanded = processor.expand(utils["make-inverse-list"](result), slot_config) + table.remove(result, i) + for j, expanded_ps in ipairs(expanded) do + table.insert(result, ((i + j) - 1), expanded_ps) end - return loaded_specs[key] + else end - v_0_0 = get_spec0 - _0_["get-spec"] = v_0_0 - v_0_ = v_0_0 + i = (i + 1) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-spec"] = v_0_ - get_spec = v_0_ + return result end -local normalize_processor -do - local v_0_ - local function normalize_processor0(processor) - if utils["func?"](processor) then - return {build = processor} +_2amodule_2a["get-expanded-slots"] = get_expanded_slots +local function get_filtered_slots(ps_list, processors, slot_config, context) + local function _18_(_241) + return (_241 ~= nil) + end + local function _19_(_241) + local include_ps + if utils["method?"](_241.processor, "when") then + include_ps = _241.processor.when(context) else - return processor + include_ps = core["table?"](_241.processor) end - end - v_0_ = normalize_processor0 - local t_0_ = (_0_)["aniseed/locals"] - t_0_["normalize-processor"] = v_0_ - normalize_processor = v_0_ -end -local get_processor -do - local v_0_ - local function get_processor0(processors, name, aliased_from_3f) - local processor_config = processors[name] - if core["string?"](processor_config) then - return get_processor0(processors, processor_config, (aliased_from_3f or name)) + if include_ps then + return _241.name else - local result = normalize_processor((processor_config or processors.__default)) - return {["aliased-from"] = aliased_from_3f, name = name, processor = result} + return nil end end - v_0_ = get_processor0 - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-processor"] = v_0_ - get_processor = v_0_ -end -local get_expanded_slots -do - local v_0_ - do - local v_0_0 - local function get_expanded_slots0(ps_list, slot_config, processors) - local result = {unpack(ps_list)} - local i = 1 - while (i <= #result) do - local ps_name = result[i] - local _let_0_ = get_processor(processors, ps_name) - local processor = _let_0_["processor"] - if (processor and processor.expand) then - local expanded = processor.expand(utils["make-inverse-list"](result), slot_config) - table.remove(result, i) - for j, expanded_ps in ipairs(expanded) do - table.insert(result, ((i + j) - 1), expanded_ps) - end - end - i = (i + 1) - end - return result - end - v_0_0 = get_expanded_slots0 - _0_["get-expanded-slots"] = v_0_0 - v_0_ = v_0_0 + local function _22_(_241) + return (_241.processor and (_241.processor.implicit or slot_config[(_241["aliased-from"] or _241.name)])) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-expanded-slots"] = v_0_ - get_expanded_slots = v_0_ + local function _23_(_241) + return get_processor(processors, _241) + end + return core.filter(_18_, core.map(_19_, core.filter(_22_, core.map(_23_, ps_list)))) end -local get_filtered_slots -do - local v_0_ - do - local v_0_0 - local function get_filtered_slots0(ps_list, processors, slot_config, context) - local function _4_(_241) - return (_241 ~= nil) - end - local function _5_(_241) - local include_ps - if utils["method?"](_241.processor, "when") then - include_ps = _241.processor.when(context) - else - include_ps = core["table?"](_241.processor) - end - if include_ps then - return _241.name +_2amodule_2a["get-filtered-slots"] = get_filtered_slots +local function normalize_build_output(output) + if core["string?"](output) then + return {{content = output, marks = {}}} + elseif core["table?"](output) then + if core["string?"](output.content) then + return {output} + else + local function _24_(_241) + if core["string?"](_241) then + return {content = _241, marks = {}} else - return nil + return _241 end end - local function _6_(_241) - return (_241.processor and (_241.processor.implicit or slot_config[(_241["aliased-from"] or _241.name)])) - end - local function _7_(_241) - return get_processor(processors, _241) - end - return core.filter(_4_, core.map(_5_, core.filter(_6_, core.map(_7_, ps_list)))) + return core.map(_24_, output) end - v_0_0 = get_filtered_slots0 - _0_["get-filtered-slots"] = v_0_0 - v_0_ = v_0_0 + else + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-filtered-slots"] = v_0_ - get_filtered_slots = v_0_ end -local normalize_build_output -do - local v_0_ - do - local v_0_0 - local function normalize_build_output0(output) - if core["string?"](output) then - return {{content = output, marks = {}}} - elseif core["table?"](output) then - if core["string?"](output.content) then - return {output} - else - local function _4_(_241) - if core["string?"](_241) then - return {content = _241, marks = {}} - else - return _241 - end - end - return core.map(_4_, output) - end - end +_2amodule_2a["normalize-build-output"] = normalize_build_output +local function indent_lines(lines, indenter, context) + local indentation_amount + if utils["func?"](indenter) then + indentation_amount = indenter(lines, context) + else + indentation_amount = context["start-col"] + end + local function _29_(line) + local function _30_(_241) + return vim.tbl_extend("force", _241, {start = (_241.start + indentation_amount), stop = (_241.stop + indentation_amount)}) end - v_0_0 = normalize_build_output0 - _0_["normalize-build-output"] = v_0_0 - v_0_ = v_0_0 + return vim.tbl_extend("force", {}, {content = (string.rep(" ", indentation_amount) .. line.content), marks = core.map(_30_, line.marks)}) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["normalize-build-output"] = v_0_ - normalize_build_output = v_0_ + return core.map(_29_, lines) end -local indent_lines -do - local v_0_ - do - local v_0_0 - local function indent_lines0(lines, indenter, context) - local indentation_amount - if utils["func?"](indenter) then - indentation_amount = indenter(lines, context) +_2amodule_2a["indent-lines"] = indent_lines +local function build_slots(ps_list, processors, context) + local result = {} + for i, ps_name in ipairs(ps_list) do + local _let_31_ = get_processor(processors, ps_name) + local processor = _let_31_["processor"] + local default_processor = processors.__default + local build_fn + local function _32_() + local _33_ = processor + if (nil ~= _33_) then + return (_33_).build else - indentation_amount = context["start-col"] + return _33_ end - local function _5_(line) - local function _6_(_241) - return vim.tbl_extend("force", _241, {start = (_241.start + indentation_amount), stop = (_241.stop + indentation_amount)}) - end - return vim.tbl_extend("force", {}, {content = (string.rep(" ", indentation_amount) .. line.content), marks = core.map(_6_, line.marks)}) + end + local function _35_() + local _36_ = default_processor + if (nil ~= _36_) then + return (_36_).build + else + return _36_ end - return core.map(_5_, lines) end - v_0_0 = indent_lines0 - _0_["indent-lines"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["indent-lines"] = v_0_ - indent_lines = v_0_ -end -local build_slots -do - local v_0_ - do - local v_0_0 - local function build_slots0(ps_list, processors, context) - local result = {} - for i, ps_name in ipairs(ps_list) do - local _let_0_ = get_processor(processors, ps_name) - local processor = _let_0_["processor"] - local default_processor = processors.__default - local build_fn - local _5_ - do - local _4_ = processor - if _4_ then - _5_ = (_4_).build - else - _5_ = _4_ - end - end - local function _7_() - local _6_ = default_processor - if _6_ then - return (_6_).build - else - return _6_ - end - end - build_fn = (_5_ or _7_()) - local indent_fn - local _9_ - do - local _8_ = processor - if _8_ then - _9_ = (_8_).indent - else - _9_ = _8_ - end - end - local function _11_() - local _10_ = default_processor - if _10_ then - return (_10_).indent - else - return _10_ - end - end - indent_fn = (_9_ or _11_()) - local function _12_() - if utils["func?"](build_fn) then - return indent_lines(normalize_build_output(build_fn(context, {index = i, name = ps_name, processors = ps_list})), indent_fn, context) - else - return {} - end - end - table.insert(result, _12_()) + build_fn = (_32_() or _35_()) + local indent_fn + local function _38_() + local _39_ = processor + if (nil ~= _39_) then + return (_39_).indent + else + return _39_ end - return result end - v_0_0 = build_slots0 - _0_["build-slots"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["build-slots"] = v_0_ - build_slots = v_0_ -end -local output_to_lines -do - local v_0_ - do - local v_0_0 - local function output_to_lines0(output) - local function _4_(_241, _242) - return vim.list_extend(_241, _242) + local function _41_() + local _42_ = default_processor + if (nil ~= _42_) then + return (_42_).indent + else + return _42_ end - return core.reduce(_4_, {}, output) end - v_0_0 = output_to_lines0 - _0_["output-to-lines"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["output-to-lines"] = v_0_ - output_to_lines = v_0_ -end -local package_build_output -do - local v_0_ - do - local v_0_0 - local function package_build_output0(output, context) - local result = {content = {}, marks = {}} - for i, entry in ipairs(output) do - for j, line in ipairs(entry) do - local lnum = (#result.content + 1) - table.insert(result.content, line.content) - local function _4_(_241) - return vim.tbl_extend("force", {}, _241, {line = (lnum + (context["start-line"] or 0))}) - end - vim.list_extend(result.marks, core.map(_4_, line.marks)) - end + indent_fn = (_38_() or _41_()) + local function _44_() + if utils["func?"](build_fn) then + return indent_lines(normalize_build_output(build_fn(context, {processors = ps_list, index = i, name = ps_name})), indent_fn, context) + else + return {} end - return result end - v_0_0 = package_build_output0 - _0_["package-build-output"] = v_0_0 - v_0_ = v_0_0 + table.insert(result, _44_()) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["package-build-output"] = v_0_ - package_build_output = v_0_ + return result end -local process_template -do - local v_0_ - do - local v_0_0 - local function process_template0(collector, config) - local _let_0_ = config - local spec_conf = _let_0_["config"] - local kind = _let_0_["kind"] - local spec = _let_0_["spec"] - local ps_list - local _5_ - do - local _4_ = spec_conf - if _4_ then - local _6_ = (_4_).templates - if _6_ then - _5_ = (_6_)[kind] - else - _5_ = _6_ - end - else - _5_ = _4_ - end - end - ps_list = (_5_ or spec.templates[kind]) - local processors = vim.tbl_extend("force", spec.processors, (spec_conf.processors or {})) - local slot_config - local _7_ - do - local _6_ = spec_conf.slots - if _6_ then - _7_ = (_6_)[kind] - else - _7_ = _6_ - end +_2amodule_2a["build-slots"] = build_slots +local function output_to_lines(output) + local function _45_(_241, _242) + return vim.list_extend(_241, _242) + end + return core.reduce(_45_, {}, output) +end +_2amodule_2a["output-to-lines"] = output_to_lines +local function package_build_output(output, context) + local result = {content = {}, marks = {}} + for i, entry in ipairs(output) do + for j, line in ipairs(entry) do + local lnum = (#result.content + 1) + table.insert(result.content, line.content) + local function _46_(_241) + return vim.tbl_extend("force", {}, _241, {line = (lnum + (context["start-line"] or 0))}) end - slot_config = (_7_ or {}) - local context = new_template_context(collector, config) - return package_build_output(build_slots(get_filtered_slots(get_expanded_slots(ps_list, slot_config, processors), processors, slot_config, context), processors, context), context) + vim.list_extend(result.marks, core.map(_46_, line.marks)) end - v_0_0 = process_template0 - _0_["process-template"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["process-template"] = v_0_ - process_template = v_0_ + return result end -local extend_spec -do - local v_0_ - do - local v_0_0 - local function extend_spec0(mod, spec) - if (spec and (mod.module ~= spec)) then - require(("nvim-tree-docs.specs." .. spec)) - local inherited_spec = loaded_specs[spec] - mod["templates"] = vim.tbl_extend("force", mod.templates, loaded_specs[spec].templates) - do end (mod)["utils"] = vim.tbl_extend("force", mod.utils, loaded_specs[spec].utils) - do end (mod)["inherits"] = inherited_spec - mod["processors"] = vim.tbl_extend("force", mod.processors, inherited_spec.processors) - do end (mod)["config"] = vim.tbl_deep_extend("force", inherited_spec.config, mod.config) - return nil +_2amodule_2a["package-build-output"] = package_build_output +local function process_template(collector, config) + local _let_47_ = config + local spec = _let_47_["spec"] + local kind = _let_47_["kind"] + local spec_conf = _let_47_["config"] + local ps_list + local function _48_() + local _49_ = spec_conf + if (nil ~= _49_) then + local _50_ = (_49_).templates + if (nil ~= _50_) then + return (_50_)[kind] + else + return _50_ end + else + return _49_ + end + end + ps_list = (_48_() or spec.templates[kind]) + local processors = vim.tbl_extend("force", spec.processors, (spec_conf.processors or {})) + local slot_config + local function _53_() + local _54_ = spec_conf.slots + if (nil ~= _54_) then + return (_54_)[kind] + else + return _54_ end - v_0_0 = extend_spec0 - _0_["extend-spec"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["extend-spec"] = v_0_ - extend_spec = v_0_ + slot_config = (_53_() or {}) + local context = new_template_context(collector, config) + return package_build_output(build_slots(get_filtered_slots(get_expanded_slots(ps_list, slot_config, processors), processors, slot_config, context), processors, context), context) +end +_2amodule_2a["process-template"] = process_template +local function extend_spec(mod, spec) + if (spec and (mod.module ~= spec)) then + require(("nvim-tree-docs.specs." .. spec)) + local inherited_spec = loaded_specs[spec] + mod["templates"] = vim.tbl_extend("force", mod.templates, loaded_specs[spec].templates) + do end (mod)["utils"] = vim.tbl_extend("force", mod.utils, loaded_specs[spec].utils) + do end (mod)["inherits"] = inherited_spec + mod["processors"] = vim.tbl_extend("force", mod.processors, inherited_spec.processors) + do end (mod)["config"] = vim.tbl_deep_extend("force", inherited_spec.config, mod.config) + return nil + else + return nil + end end -return nil \ No newline at end of file +_2amodule_2a["extend-spec"] = extend_spec +return _2amodule_2a \ No newline at end of file diff --git a/lua/nvim-tree-docs/utils.lua b/lua/nvim-tree-docs/utils.lua index ad36579..24e5f70 100644 --- a/lua/nvim-tree-docs/utils.lua +++ b/lua/nvim-tree-docs/utils.lua @@ -1,404 +1,207 @@ local _2afile_2a = "fnl/nvim-tree-docs/utils.fnl" -local _0_ -do - local name_0_ = "nvim-tree-docs.utils" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ +local _2amodule_name_2a = "nvim-tree-docs.utils" +local _2amodule_2a +do + package.loaded[_2amodule_name_2a] = {} + _2amodule_2a = package.loaded[_2amodule_name_2a] +end +local _2amodule_locals_2a +do + _2amodule_2a["aniseed/locals"] = {} + _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] +end +local autoload = (require("nvim-tree-docs.aniseed.autoload")).autoload +local core = autoload("nvim-tree-docs.aniseed.core") +do end (_2amodule_locals_2a)["core"] = core +local ns = vim.api.nvim_create_namespace("blorg") +do end (_2amodule_2a)["ns"] = ns +local function get_start_node(entry) + local function _2_() + local _3_ = entry + if (nil ~= _3_) then + local _4_ = (_3_).start_point + if (nil ~= _4_) then + return (_4_).node + else + return _4_ + end else - module_0_ = {} + return _3_ end end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end -local autoload -local function _2_(...) - return (require("nvim-tree-docs.aniseed.autoload")).autoload(...) -end -autoload = _2_ -local function _3_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _3_() - return {autoload("nvim-tree-docs.aniseed.core")} - end - ok_3f_0_, val_0_ = pcall(_3_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {core = "nvim-tree-docs.aniseed.core"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _3_(...) -local core = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "nvim-tree-docs.utils" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local ns -do - local v_0_ - do - local v_0_0 = vim.api.nvim_create_namespace("blorg") - do end (_0_)["ns"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["ns"] = v_0_ - ns = v_0_ -end -local get_start_node -do - local v_0_ - do - local v_0_0 - local function get_start_node0(entry) - local _5_ - do - local _4_ = entry - if _4_ then - local _6_ = (_4_).start_point - if _6_ then - _5_ = (_6_).node - else - _5_ = _6_ - end - else - _5_ = _4_ - end - end - local function _7_() - local _6_ = entry - if _6_ then - local _8_ = (_6_).definition - if _8_ then - return (_8_).node - else - return _8_ - end - else - return _6_ - end + local function _7_() + local _8_ = entry + if (nil ~= _8_) then + local _9_ = (_8_).definition + if (nil ~= _9_) then + return (_9_).node + else + return _9_ end - return (_5_ or _7_()) + else + return _8_ end - v_0_0 = get_start_node0 - _0_["get-start-node"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-start-node"] = v_0_ - get_start_node = v_0_ + return (_2_() or _7_()) end -local get_end_node -do - local v_0_ - do - local v_0_0 - local function get_end_node0(entry) - local _5_ - do - local _4_ = entry - if _4_ then - local _6_ = (_4_).end_point - if _6_ then - _5_ = (_6_).node - else - _5_ = _6_ - end - else - _5_ = _4_ - end - end - local function _7_() - local _6_ = entry - if _6_ then - local _8_ = (_6_).definition - if _8_ then - return (_8_).node - else - return _8_ - end - else - return _6_ - end +_2amodule_2a["get-start-node"] = get_start_node +local function get_end_node(entry) + local function _12_() + local _13_ = entry + if (nil ~= _13_) then + local _14_ = (_13_).end_point + if (nil ~= _14_) then + return (_14_).node + else + return _14_ end - return (_5_ or _7_()) + else + return _13_ end - v_0_0 = get_end_node0 - _0_["get-end-node"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-end-node"] = v_0_ - get_end_node = v_0_ -end -local get_position -do - local v_0_ - do - local v_0_0 - local function get_position0(keys, default_position, entry) - local i = 1 - local result = nil - while (not result and (i <= #keys)) do - do - local key = keys[i] - local match_3f = entry[key] - local has_match_3f = (core["table?"](match_3f) and match_3f.node) - local position_3f - if has_match_3f then - position_3f = (match_3f.position or default_position) - else - position_3f = nil - end - if has_match_3f then - if (position_3f == "start") then - result = {(match_3f.node):start()} - else - result = {(match_3f.node):end_()} - end - end + local function _17_() + local _18_ = entry + if (nil ~= _18_) then + local _19_ = (_18_).definition + if (nil ~= _19_) then + return (_19_).node + else + return _19_ + end + else + return _18_ + end + end + return (_12_() or _17_()) +end +_2amodule_2a["get-end-node"] = get_end_node +local function get_position(keys, default_position, entry) + local i = 1 + local result = nil + while (not result and (i <= #keys)) do + do + local key = keys[i] + local match_3f = entry[key] + local has_match_3f = (core["table?"](match_3f) and match_3f.node) + local position_3f + if has_match_3f then + position_3f = (match_3f.position or default_position) + else + position_3f = nil + end + if has_match_3f then + if (position_3f == "start") then + result = {(match_3f.node):start()} + else + result = {(match_3f.node):end_()} end - i = core.inc(i) + else end - return unpack(result) end - v_0_0 = get_position0 - _0_["get-position"] = v_0_0 - v_0_ = v_0_0 + i = core.inc(i) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-position"] = v_0_ - get_position = v_0_ + return unpack(result) end +_2amodule_2a["get-position"] = get_position local get_start_position do - local v_0_ - do - local v_0_0 - local function _4_(...) - return get_position({"start_point", "definition"}, "start", ...) - end - v_0_0 = _4_ - _0_["get-start-position"] = v_0_0 - v_0_ = v_0_0 + local _25_ = {"start_point", "definition"} + local function _26_(...) + return get_position(_25_, "start", ...) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-start-position"] = v_0_ - get_start_position = v_0_ + get_start_position = _26_ end +_2amodule_2a["get-start-position"] = get_start_position local get_end_position do - local v_0_ - do - local v_0_0 - local function _4_(...) - return get_position({"end_point", "definition"}, "end", ...) - end - v_0_0 = _4_ - _0_["get-end-position"] = v_0_0 - v_0_ = v_0_0 + local _27_ = {"end_point", "definition"} + local function _28_(...) + return get_position(_27_, "end", ...) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-end-position"] = v_0_ - get_end_position = v_0_ + get_end_position = _28_ end +_2amodule_2a["get-end-position"] = get_end_position local get_edit_start_position do - local v_0_ - do - local v_0_0 - local function _4_(...) - return get_position({"edit_start_point", "start_point", "definition"}, "start", ...) - end - v_0_0 = _4_ - _0_["get-edit-start-position"] = v_0_0 - v_0_ = v_0_0 + local _29_ = {"edit_start_point", "start_point", "definition"} + local function _30_(...) + return get_position(_29_, "start", ...) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-edit-start-position"] = v_0_ - get_edit_start_position = v_0_ + get_edit_start_position = _30_ end +_2amodule_2a["get-edit-start-position"] = get_edit_start_position local get_edit_end_position do - local v_0_ - do - local v_0_0 - local function _4_(...) - return get_position({"edit_end_point", "end_point", "definition"}, "end", ...) - end - v_0_0 = _4_ - _0_["get-edit-end-position"] = v_0_0 - v_0_ = v_0_0 + local _31_ = {"edit_end_point", "end_point", "definition"} + local function _32_(...) + return get_position(_31_, "end", ...) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-edit-end-position"] = v_0_ - get_edit_end_position = v_0_ + get_edit_end_position = _32_ end -local get_bufnr -do - local v_0_ - do - local v_0_0 - local function get_bufnr0(bufnr) - return (bufnr or vim.api.nvim_get_current_buf()) - end - v_0_0 = get_bufnr0 - _0_["get-bufnr"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-bufnr"] = v_0_ - get_bufnr = v_0_ +_2amodule_2a["get-edit-end-position"] = get_edit_end_position +local function get_bufnr(bufnr) + return (bufnr or vim.api.nvim_get_current_buf()) end -local get_buf_content -do - local v_0_ - do - local v_0_0 - local function get_buf_content0(start_row, start_col, end_row, end_col, bufnr) - return vim.api.nvim_buf_get_lines(bufnr, start_row, (end_row + 1), false) - end - v_0_0 = get_buf_content0 - _0_["get-buf-content"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-buf-content"] = v_0_ - get_buf_content = v_0_ +_2amodule_2a["get-bufnr"] = get_bufnr +local function get_buf_content(start_row, start_col, end_row, end_col, bufnr) + return vim.api.nvim_buf_get_lines(bufnr, start_row, (end_row + 1), false) end -local get -do - local v_0_ - do - local v_0_0 - local function get0(path, tbl, default_3f) - local segments - if (type(path) == "string") then - segments = vim.split(path, "%.") - else - segments = path - end - local result = tbl - for _, segment in ipairs(segments) do - if (type(result) == "table") then - result = result[segment] - else - result = nil - end - end - if (result == nil) then - return default_3f - else - return result - end - end - v_0_0 = get0 - _0_["get"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get-buf-content"] = get_buf_content +local function get(path, tbl, default_3f) + local segments + if (type(path) == "string") then + segments = vim.split(path, "%.") + else + segments = path end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get"] = v_0_ - get = v_0_ -end -local make_inverse_list -do - local v_0_ - do - local v_0_0 - local function make_inverse_list0(tbl) - local result = {} - for i, v in ipairs(tbl) do - result[v] = i - end - return result + local result = tbl + for _, segment in ipairs(segments) do + if (type(result) == "table") then + result = result[segment] + else + result = nil end - v_0_0 = make_inverse_list0 - _0_["make-inverse-list"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["make-inverse-list"] = v_0_ - make_inverse_list = v_0_ -end -local get_all_truthy_keys -do - local v_0_ - do - local v_0_0 - local function get_all_truthy_keys0(tbl) - local result = {} - for k, v in pairs(tbl) do - if v then - table.insert(result, k) - end - end - return result - end - v_0_0 = get_all_truthy_keys0 - _0_["get-all-truthy-keys"] = v_0_0 - v_0_ = v_0_0 + if (result == nil) then + return default_3f + else + return result end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-all-truthy-keys"] = v_0_ - get_all_truthy_keys = v_0_ end -local func_3f -do - local v_0_ - do - local v_0_0 - local function func_3f0(v) - return (type(v) == "function") - end - v_0_0 = func_3f0 - _0_["func?"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get"] = get +local function make_inverse_list(tbl) + local result = {} + for i, v in ipairs(tbl) do + result[v] = i end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["func?"] = v_0_ - func_3f = v_0_ + return result end -local method_3f -do - local v_0_ - do - local v_0_0 - local function method_3f0(v, key) - return ((type(v) == "table") and (type(v[key]) == "function")) +_2amodule_2a["make-inverse-list"] = make_inverse_list +local function get_all_truthy_keys(tbl) + local result = {} + for k, v in pairs(tbl) do + if v then + table.insert(result, k) + else end - v_0_0 = method_3f0 - _0_["method?"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["method?"] = v_0_ - method_3f = v_0_ + return result end -local highlight_marks -do - local v_0_ - do - local v_0_0 - local function highlight_marks0(marks, bufnr) - for _, mark in ipairs(marks) do - local line = (mark.line - 1) - vim.highlight.range(bufnr, ns, "Visual", {line, mark.start}, {line, mark.stop}) - end - return nil - end - v_0_0 = highlight_marks0 - _0_["highlight-marks"] = v_0_0 - v_0_ = v_0_0 +_2amodule_2a["get-all-truthy-keys"] = get_all_truthy_keys +local function func_3f(v) + return (type(v) == "function") +end +_2amodule_2a["func?"] = func_3f +local function method_3f(v, key) + return ((type(v) == "table") and (type(v[key]) == "function")) +end +_2amodule_2a["method?"] = method_3f +local function highlight_marks(marks, bufnr) + for _, mark in ipairs(marks) do + local line = (mark.line - 1) + vim.highlight.range(bufnr, ns, "Visual", {line, mark.start}, {line, mark.stop}) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["highlight-marks"] = v_0_ - highlight_marks = v_0_ + return nil end -return nil \ No newline at end of file +_2amodule_2a["highlight-marks"] = highlight_marks +return _2amodule_2a \ No newline at end of file