Showing preview only (373K chars total). Download the full file or copy to clipboard to get everything.
Repository: nvim-treesitter/nvim-tree-docs
Branch: master
Commit: 5db023d783da
Files: 54
Total size: 353.9 KB
Directory structure:
gitextract_uscgubcz/
├── .gitignore
├── Makefile
├── README.md
├── fnl/
│ └── nvim-tree-docs/
│ ├── collector.fnl
│ ├── editing.fnl
│ ├── internal.fnl
│ ├── macros.fnl
│ ├── main.fnl
│ ├── specs/
│ │ ├── base/
│ │ │ └── base.fnl
│ │ ├── javascript/
│ │ │ └── jsdoc.fnl
│ │ ├── lua/
│ │ │ └── luadoc.fnl
│ │ └── typescript/
│ │ └── tsdoc.fnl
│ ├── template.fnl
│ └── utils.fnl
├── lua/
│ └── nvim-tree-docs/
│ ├── aniseed/
│ │ ├── autoload.lua
│ │ ├── compile.lua
│ │ ├── core.lua
│ │ ├── deps/
│ │ │ ├── fennel.lua
│ │ │ ├── fennelview.lua
│ │ │ └── nvim.lua
│ │ ├── env.lua
│ │ ├── eval.lua
│ │ ├── fennel.lua
│ │ ├── fs.lua
│ │ ├── macros.fnl
│ │ ├── nvim/
│ │ │ └── util.lua
│ │ ├── nvim.lua
│ │ ├── string.lua
│ │ ├── test.lua
│ │ └── view.lua
│ ├── collector.lua
│ ├── editing.lua
│ ├── internal.lua
│ ├── macros.fnl
│ ├── main.lua
│ ├── specs/
│ │ ├── base/
│ │ │ └── base.lua
│ │ ├── javascript/
│ │ │ └── jsdoc.lua
│ │ ├── lua/
│ │ │ └── luadoc.lua
│ │ └── typescript/
│ │ └── tsdoc.lua
│ ├── template.lua
│ └── utils.lua
├── plugin/
│ └── nvim-tree-docs.vim
├── queries/
│ ├── ecma/
│ │ └── docs.scm
│ ├── javascript/
│ │ └── docs.scm
│ ├── javascriptreact/
│ │ └── docs.scm
│ ├── jsdoc/
│ │ └── edits.scm
│ ├── jsx/
│ │ └── docs.scm
│ ├── lua/
│ │ └── docs.scm
│ ├── python/
│ │ └── docs.scm
│ ├── tsx/
│ │ └── docs.scm
│ ├── typescript/
│ │ └── docs.scm
│ └── typescriptreact/
│ └── docs.scm
├── scripts/
│ └── dep.sh
└── test/
└── fnl/
└── example/
└── main-test.fnl
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/deps/
/test/results.txt
/test/lua/
/doc/tags
================================================
FILE: Makefile
================================================
.PHONY: deps compile test
default: deps compile test
deps:
scripts/dep.sh Olical aniseed origin/master
compile:
rm -rf lua
deps/aniseed/scripts/compile.sh
## Uncomment and set CHANGEME to your project prefix if you need access to
## Aniseed at runtime, instead of just compile time.
## If your project modules are like myplugin.some-thing, you'd use myplugin
## in place of CHANGEME.
deps/aniseed/scripts/embed.sh aniseed nvim-tree-docs
test:
rm -rf test/lua
deps/aniseed/scripts/test.sh
================================================
FILE: README.md
================================================
nvim-tree-docs
==============
Highly configurable documentation generator using treesitter.
This plugin is experimental!
## Setup
nvim-tree-docs is a module for the `nvim-treesitter` plugin. You can install both by doing (vim-plug):
```vim
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-treesitter/nvim-tree-docs'
```
You can configure `nvim-tree-docs` as part of your `nvim-treesitter` configuration.
```lua
require "nvim-treesitter.configs".setup {
tree_docs = {enable = true}
}
```
## Usage
There are two key bindings provided by default:
- `doc_node_at_cursor`: `gdd`
- `doc_all_in_range`: `gdd` (Visual)
These can be configured through the `keymap` option in the config.
## Advanced configuration
This plugin is extremely configurable. Most documentation is standardized, but our
projects and personal preferences for documentation vary. This plugin aims to add total
customization to the user.
### Core concepts
There three key components to how this plugin operates.
- `processors` -> Processors generate lines of content within a template.
- `slots` -> Slots are positions where a processor can output it's content.
- `templates` -> Templates are a list of slots, basically the ordering of processors.
These are by `kind` (Ex: function).
- `specs` -> Specs are a collection of templates and processors (Ex: jsdoc).
### Basic example
Here is a basic example of how this works (psuedo code).
```lua
local processors = {
my_processor = function() -- The processor
return "Output!!!"
end
}
local template = { -- template
"my_processor", -- slot
"my_processor" -- slot
}
```
This example would generate the lines
```
Output!!!
Output!!!
```
You get the idea... The above code doesn't actually do anything, but is just to illustrate the point.
### Configuring slots
The key advantage is they can be toggled on and off.
For example, lets say you like to include an `@author` tag on all your jsdoc classes.
You can enable the `author` slot to generate an author tag.
This is done in the configuration for the spec.
```lua
require "nvim-treesitter.configs".setup {
tree_docs = {
enable = true,
spec_config = {
jsdoc = {
slots = {
class = {author = true}
}
}
}
}
}
```
This will generate the following output.
```javascript
/**
* The person class
* @author
*/
class Person {}
```
Pretty cool... but this is using the default processor for the spec, which in the case
of jsdoc, just generates a tag. What if we could modify the behavior of that processor?
We can configure author processor in the same config.
```lua
require "nvim-treesitter.configs".setup {
tree_docs = {
enable = true,
spec_config = {
jsdoc = {
slots = {
class = {author = true}
},
processors = {
author = function()
return " * @author Steven Sojka"
end
}
}
}
}
}
```
This will generate.
```javascript
/**
* The person class
* @author Steven Sojka
*/
class Person {}
```
Processors can return a single line or multiple lines.
Here's an advanced sample that will prompt the user for
an issue ticket number. If the user doesn't enter anything
the tag won't get generated.
```lua
require "nvim-treesitter.configs".setup {
tree_docs = {
enable = true,
spec_config = {
jsdoc = {
slots = {
class = {see = true, author = true}
},
processors = {
author = function() return " * @author Steven Sojka" end
see = function()
local ticket = vim.fn.input("Ticket: ")
return ticket ~= "" and (" * @see " .. ticket) or []
end
}
}
}
}
}
```
This will result in the following (assuming PROJ-X-123456 was inputted).
```javascript
/**
* The person class
* @author Steven Sojka
* @see PROJ-X-123456
*/
class Person {}
```
### Configuring templates
Templates aren't traditional templates. It's basically just a set of slots in a specific order.
You can configure the template in the config.
```lua
require "nvim-treesitter.configs".setup {
tree_docs = {
enable = true,
spec_config = {
jsdoc = {
slots = {
class = {custom = true, author = true}
},
templates = {
class = {
"doc-start" -- Note, these are implicit slots and can't be turned off and vary between specs.
"custom"
"author"
"doc-end"
"%content%"
}
}
}
}
}
}
```
This will generate.
```javascript
/**
* The person class
* @custom
* @author
*/
class Person {}
```
Note, in the above example, if we would have left out the `custom` slot in the template, it would not have output anything.
#### Builtin processors
There are some builtin processors that work across all specs (unless overridden, which is possible).
- `%content%` -> This will output the content line, in our case above it would be the class declaration line.
This makes it possible to wrap or put the documentation below the content line.
- `%rest%` -> This will output all slots that are enabled, but do not have an explicit slot in the template.
### Template context
This still needs to be documented...
## Writing language queries
Queries contain a couple conventions that are shared amongst all languages.
Query tag syntax is `@<kind>.<property>`
The `<kind>` tag corresponds with a template in the language specific template file.
Properties can be accessed within a processor as the first argument.
For example, a simple processor that gets the name of a nod
```lua
function(ctx) return ctx.get_text(ctx.name.node) end
```
This would correspond to a tag `@<kind>.name`.
Properties are not predefined and can differ from language to language, but there a couple
that have special behavior.
### `@<kind>.definition`
This is the most important one and is required for each `<kind>`.
This defines the node that defines the `<kind>`. If multiple queries
match the same definition node, those entries will be merged together.
This is very important for function parameters where multiple matches
need to be grouped under the same function definition.
For example, that this javascript query.
```scheme
(function_declaration
name: (identifier) @function.name
body: (statement_block
(return_statement)? @function.return)) @function.definition
(export_statement
(function_declaration) @function.definition) @function.export
```
This will match both these functions.
```javascript
function test() {}
export function test() {}
```
The key difference is one will have an `export` node associated with it. Both queries
match the function that is exported but they get merged into a single data model
because both `@function.definition` tags match the same node at the same position.
### `@<kind>.<kind>.definition`
Kind queries can be nested to define multiple different node merge points. This can be done
by providing multiple, nested definition tags. For example in function parameters. A nested `<kind>`
can be thought of as a list of similiar items.
### `@<kind>.start_point`
When docs are inserted into the document, it will insert the docs at the indentation and position
of the definition node (`@<kind>.definition`). This can be changed, if you need to keep the same definition
node, but need a different start point to insert.
For example, that this javascript query.
```scheme
(function_declaration
name: (identifier) @function.name
body: (statement_block
(return_statement)? @function.return_statement)) @function.definition
(export_statement
(function_declaration) @function.definition) @function.start_point @function.export
```
If we doc'ed the following functions WITHOUT the root tag, we would get this:
```javascript
/**
* test
*/
function test() {}
/**
* test
*/
export function test() {}
```
Including the start_point tag flags the export_statement node as the root node INSTEAD of the definition node.
### `@<kind>.end_point`
This flags the end node that document can be triggered from. For example, the end of a function signature.
This is important, because it allows us to trigger docs on a multiline signature.
For example, that this javascript query.
```scheme
(
(comment)+? @function.doc
(function_declaration
name: (identifier) @function.name
parameters: (formal_parameters) @function.end_point
body: (statement_block
(return_statement)? @function.return)) @function.definition
)
```
This flags the parameters node as the end node for the signature. This allows us
to doc signatures that look like this.
```javascript
function test(
someVeryLongNameThatRequiresUsToWrap,
blorg, // <- We can trigger here to generate docs with no problem
boom
) {
return;
}
```
The furtherest end node will be used if there are overlapping end_points.
You should always have an end_point defined in order to avoid unwanted document triggers.
### `@<kind>.doc`
The doc references the current doc that is preceding the definition node. This gives access to existing
documentation to either parse, update, or remove with updated information.
# Roadmap
- Filetype aliases
- Template marks
- More doc specs
- Doc commands that don't require a treesitter node (jsdoc modules)
- Predifined processors that can be swapped in... (think promptable descriptions?)
================================================
FILE: fnl/nvim-tree-docs/collector.fnl
================================================
(module nvim-tree-docs.collector
{autoload {core nvim-tree-docs.aniseed.core}})
(def- collector-metatable
{:__index (fn [tbl key]
(if (= (type key) :number)
(let [id (. tbl.__order key)]
(if id (. tbl.__entries id) nil))
(rawget tbl key)))})
(defn new-collector []
(setmetatable {:__entries {}
:__order {}}
collector-metatable))
(defn is-collector [value]
(and (= (type value) :table)
(= (type value.__entries) :table)))
(defn is-collector-empty [collector]
(= (length collector.__order) 0))
(defn iterate-collector [collector]
(var i 1)
(fn []
(let [id (. collector.__order i)]
(if id
(do
(set i (+ i 1))
{:index (- i 1)
:entry (. collector.__entries id)})
nil))))
(defn get-node-id [node]
(let [(srow scol erow ecol) (node:range)]
(string.format "%d_%d_%d_%d" srow scol erow ecol)))
(defn collect_ [collector entry _match key add-fn]
(if _match.definition
(do
(when (not (. entry key))
(tset entry key (new-collector)))
(-> (. entry key)
(add-fn key _match collect)))
(not (. entry key))
(tset entry key _match)
(and (= key :start_point) _match.node)
(let [(_ _ current-start) (-> (. entry key) (. :node) (: :start))
(_ _ new-start) (-> (. _match :node) (: :start))]
(when (< new-start current-start)
(tset entry key _match)))
(and (= key :end_point) _match.node)
(let [(_ _ current-end) (-> (. entry key) (. :node) (: :end_))
(_ _ new-end) (-> (. _match :node) (: :end_))]
(when (> new-end current-end)
(tset entry key _match)))))
(defn add-match [collector kind _match]
(if (and _match _match.definition)
(let [_def _match.definition
def-node _def.node
node-id (get-node-id def-node)]
(when (not (. collector.__entries node-id))
(var order-index 1)
(let [(_ _ def-start-byte) (def-node:start)
entry-keys (core.keys collector.__entries)]
(var done false)
(var i 1)
(while (not done)
(local entry (-?>> (. entry-keys i)
(. collector.__entries)))
(if (not entry)
(set done true)
(let [(_ _ start-byte) (entry.definition.node:start)]
(if (< def-start-byte start-byte)
(set done true)
(do
(set order-index (+ order-index 1))
(set i (+ i 1)))))))
(table.insert collector.__order order-index node-id)
(tset collector.__entries node-id {:kind kind :definition _def})))
(each [key submatch (pairs _match)]
(when (not= key :definition)
(collect_ collector (. collector.__entries node-id) submatch key add-match))))))
================================================
FILE: fnl/nvim-tree-docs/editing.fnl
================================================
(module nvim-tree-docs.editing
{autoload {ts-utils nvim-treesitter.ts_utils
tsq vim.treesitter.query}})
(def- ns (vim.api.nvim_create_namespace "doc-edit"))
(defn get-doc-comment-data [args]
(let [{: lang
: doc-lang
: node
: bufnr} args
doc-lines (ts-utils.get_node_text node bufnr)
doc-string (table.concat doc-lines "\n")
parser (vim.treesitter.get_string_parser doc-string doc-lang)
query (tsq.get_query doc-lang :edits)
iter (query:iter_matches
(-> (parser:parse) (: :root))
doc-string
1
(+ (length doc-string) 1))
result {}]
(var item [(iter)])
(while (. item 1)
(let [[pattern-id matches] item]
(each [id match-node (pairs matches)]
(let [match-name (. query.captures id)]
(when (not (. result match-name))
(tset result match-name []))
(table.insert (. result match-name) match-node)))
(set item [(iter)])))
result))
(defn edit-doc [args]
(let [{: bufnr :node doc-node} args
{: edit} (get-doc-comment-data args)
(sr) (doc-node:range)]
(vim.api.nvim_buf_clear_namespace bufnr ns 0 -1)
(each [_ node (ipairs edit)]
(let [(dsr dsc der dec) (node:range)]
(ts-utils.highlight_range
[(+ dsr sr ) dsc (+ der sr) dec]
bufnr
ns
:Visual)))))
================================================
FILE: fnl/nvim-tree-docs/internal.fnl
================================================
(module nvim-tree-docs.internal
{autoload {utils nvim-tree-docs.utils
core nvim-tree-docs.aniseed.core
templates nvim-tree-docs.template
collectors nvim-tree-docs.collector
editing nvim-tree-docs.editing
configs nvim-treesitter.configs
queries nvim-treesitter.query
ts-utils nvim-treesitter.ts_utils}})
(def- language-specs {:javascript :jsdoc
:lua :luadoc
:typescript :tsdoc})
(def- doc-cache {})
(defn get-spec-for-lang [lang]
(let [spec (. language-specs lang)]
(when (not spec)
(error (string.format "No language spec configured for %s" lang)))
spec))
(defn get-spec-config [lang spec]
(let [spec-def (templates.get-spec lang spec)
module-config (configs.get_module :tree_docs)
spec-default-config spec-def.config
lang-config (utils.get [:lang_config lang spec] module-config {})
spec-config (utils.get [:spec_config spec] module-config {})]
(vim.tbl_deep_extend :force spec-default-config spec-config lang-config)))
(defn get-spec-for-buf [bufnr?]
(let [bufnr (or bufnr? (vim.api.nvim_get_current_buf))]
(get-spec-for-lang (vim.api.nvim_buf_get_option bufnr :ft))))
(defn generate-docs [data-list bufnr? lang?]
(let [bufnr (utils.get-bufnr bufnr?)
lang (or lang? (vim.api.nvim_buf_get_option bufnr :ft))
spec-name (get-spec-for-lang lang)
spec (templates.get-spec lang spec-name)
spec-config (get-spec-config lang spec-name)
edits []
marks []]
; Guarantee that docs are from the top down.
(table.sort data-list #(let [(_ _ start-byte-a) (utils.get-start-position $1)
(_ _ start-byte-b) (utils.get-start-position $2)]
(< start-byte-a start-byte-b)))
(var line-offset 0)
(each [_ doc-data (ipairs data-list)]
(let [(node-sr node-sc) (utils.get-start-position doc-data)
(node-er node-ec) (utils.get-end-position doc-data)
content-lines (utils.get-buf-content node-sr node-sc node-er node-ec bufnr)
replaced-count (- (+ node-er 1) node-sr)
result (templates.process-template
doc-data
{: spec
: 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)
(set line-offset (- (+ line-offset (length result.content)) replaced-count))))
(vim.lsp.util.apply_text_edits edits bufnr)))
; Uncomment to test marks
;(utils.highlight-marks marks bufnr)))
(defn collect-docs [bufnr?]
(let [bufnr (utils.get-bufnr bufnr?)]
(if (= (utils.get [bufnr :tick] doc-cache)
(vim.api.nvim_buf_get_changedtick bufnr))
(utils.get [bufnr :docs] doc-cache)
(let [collector (collectors.new-collector)
doc-matches (queries.collect_group_results bufnr :docs)]
(each [_ item (ipairs doc-matches)]
(each [kind _match (pairs item)]
(collectors.add-match collector kind _match)))
(tset doc-cache bufnr {:tick (vim.api.nvim_buf_get_changedtick bufnr)
:docs collector})
collector))))
(defn get-doc-data-for-node [node bufnr?]
(var current nil)
(var last-start nil)
(var last-end nil)
(let [doc-data (collect-docs bufnr?)
(_ _ node-start) (node:start)]
(each [iter-item (collectors.iterate-collector doc-data)]
(var is-more-specific true)
(let [{:entry doc-def} iter-item
(_ _ start) (utils.get-start-position doc-def)
(_ _ end) (utils.get-end-position doc-def)
is-in-range (and (>= node-start start)
(< node-start end))]
(when (and last-start last-end)
(set is-more-specific (and (>= start last-start) (<= end last-end))))
(when (and is-in-range is-more-specific)
(do
(set last-start start)
(set last-end end)
(set current doc-def)))))
current))
(defn doc-node [node bufnr? lang?]
(if node
(let [doc-data (get-doc-data-for-node node bufnr?)]
(generate-docs [doc-data] bufnr? lang?))))
(defn doc-node-at-cursor []
(doc-node (ts-utils.get_node_at_cursor)))
(defn get-docs-from-position [args]
(let [{: start-line
: end-line
: position
:inclusion inclusion?
:bufnr bufnr?} args
is-edit-type? (= position :edit)
doc-data (collect-docs bufnr?)
result []]
(each [item (collectors.iterate-collector doc-data)]
(let [{:entry _def} item
start-r (if is-edit-type?
(utils.get-edit-start-position _def)
(utils.get-start-position _def))
end-r (if is-edit-type?
(utils.get-edit-end-position _def)
(utils.get-end-position _def))]
(when (if inclusion?
(and (>= start-line start-r) (<= end-line end-r))
(and (>= start-r start-line) (<= end-r end-line)))
(table.insert result _def))))
result))
(defn get-docs-in-range [args]
(get-docs-from-position (vim.tbl_extend
"force"
args
{:inclusion false :position nil})))
(defn get-docs-at-range [args]
(get-docs-from-position (vim.tbl_extend
"force"
args
{:inclusion true :position :edit})))
(defn get-docs-from-selection []
(let [(_ start _ _) (unpack (vim.fn.getpos "'<"))
(_ end _ _) (unpack (vim.fn.getpos "'>"))]
(get-docs-in-range {:start-line (- start 1)
:end-line (- end 1)})))
(defn doc-all-in-range []
(-> (get-docs-from-selection)
(generate-docs)))
(defn edit-doc-at-cursor []
(let [[row] (vim.api.nvim_win_get_cursor 0)
doc-data (get-docs-at-range {:start-line (- row 1)
:end-line (- row 1)})
bufnr (vim.api.nvim_get_current_buf)
lang (vim.api.nvim_buf_get_option bufnr :ft)
spec-name (get-spec-for-lang lang)
spec (templates.get-spec lang spec-name)
doc-lang spec.doc-lang
doc-entry (-?> doc-data (. 1) (. :doc))]
(when (and (core.table? doc-entry) doc-entry.node doc-lang)
(editing.edit-doc {: lang
: spec-name
: bufnr
: doc-lang
:node doc-entry.node}))))
(defn attach [bufnr?]
(let [bufnr (utils.get-bufnr bufnr?)
config (configs.get_module :tree_docs)]
(each [_fn mapping (pairs config.keymaps)]
(var mode :n)
(when (= _fn :doc_all_in_range)
(set mode :v))
(when mapping
(vim.api.nvim_buf_set_keymap
bufnr
mode
mapping
(string.format ":lua require 'nvim-tree-docs.internal'.%s()<CR>" _fn)
{:silent true})))))
(defn detach [bufnr?]
(let [bufnr (utils.get-bufnr bufnr?)
config (configs.get_module :tree_docs)]
(each [_fn mapping (pairs config.keymaps)]
(var mode :n)
(when (= _fn :doc_all_in_range)
(set mode :v))
(when mapping
(vim.api.nvim_buf_del_keymap bufnr mode mapping)))))
; Export these as snake case for configuration purposes.
(def doc_node_at_cursor doc-node-at-cursor)
(def doc_node doc-node)
(def doc_all_in_range doc-all-in-range)
(def edit_doc_at_cursor edit-doc-at-cursor)
================================================
FILE: fnl/nvim-tree-docs/macros.fnl
================================================
(local modsym (gensym))
(fn doc-spec [config]
"Defines a documentation specification"
(assert config.lang "A language is required")
(assert config.spec "A specification name is required")
`(local ,modsym
(let [mod-name# (.. ,(tostring config.lang) "." ,(tostring config.spec))
template-mod# (require "nvim-tree-docs.template")
module# {:templates {}
:utils {}
:processors {}
:doc-lang ,(tostring config.doc-lang)
:config (vim.tbl_deep_extend
"force"
{:slots {}
:processors {}}
,(or config.config {}))
:inherits nil
:spec ,(tostring config.spec)
:lang ,(tostring config.lang)
:module mod-name#
:__build template-mod#.build-line}]
(template-mod#.extend-spec module# :base.base)
(template-mod#.extend-spec module# ,(if config.extends (tostring config.extends) nil))
(tset (. template-mod# :loaded-specs)
mod-name#
module#)
module#)))
(fn util [name parameters ...]
"Defines a util function as part of this specification.
These can be used in templates as well as any specification
That extends this specification."
`(tset (. ,modsym :utils) ,(tostring name) (fn ,parameters ,...)))
(fn template [kind ...]
"Defines a template for a given 'kind'.
The kind correlates with the query matches."
(let [slots (let [results []]
(each [_ slot (ipairs [...])]
(table.insert results (tostring slot)))
results)]
`(tset (. ,modsym :templates) ,(tostring kind) ,slots)))
(fn %= [key tbl default]
"Get a nodes text content. A key is provided and will
access the root context or the provided table."
`($.get-text (. ,(or tbl `$) ,(tostring key)) ,default))
(fn %- [...]
"Builds a line of output."
`((. ,modsym :__build) ,...))
(fn %^ [content kind]
"Marks content for the builder"
`{:content ,content :mark ,kind})
(fn %! [content]
"Marks a tab stop for the builder"
`{:content ,content :mark :tabstop})
(fn %> [util-name ...]
"Invokes a util function on this specification.
This will invoke any inherited utils as well."
`((. (. ,modsym :utils) ,(tostring util-name)) ,...))
(fn processor [...]
(let [processor {}
forms [...]
has-name (not= (% (length forms) 2) 0)]
(var hook nil)
(var callback nil)
(var name :__default)
(when has-name
(do
(set name (. forms 1))
(table.remove forms 1)))
(each [_ form (ipairs forms)]
(if hook
(set callback form)
(set hook (tostring form)))
(if (and hook callback)
(do
(tset processor hook form)
(set hook nil)
(set callback nil))))
`(tset (. ,modsym :processors) ,(tostring name) ,processor)))
(fn post-processor [name bindings ...]
`(tset (. ,modsym :post-processors) ,name (fn ,bindings ,...)))
(fn log [...]
`(let [result# ,...]
(print (vim.inspect result#))
result#))
{: template
: util
: %=
: %>
: %-
: %^
: %!
: log
: post-processor
: processor
: doc-spec}
================================================
FILE: fnl/nvim-tree-docs/main.fnl
================================================
(module nvim-tree-docs.main
{autoload {queries nvim-treesitter.query
ts nvim-treesitter}})
(defn init []
(->> {: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 #(not= (queries.get_query $1 :docs) nil)}}
(ts.define_modules)))
================================================
FILE: fnl/nvim-tree-docs/specs/base/base.fnl
================================================
(require-macros "nvim-tree-docs.macros")
(doc-spec
{:spec base
:lang base})
(processor %rest%
implicit true
expand (fn [slot-indexes slot-config]
(let [expanded []]
(each [ps-name enabled (pairs slot-config)]
(when (and enabled (not (. slot-indexes ps-name)))
(table.insert expanded ps-name)))
expanded)))
(processor %content%
implicit true
build #$.content
indent #0)
================================================
FILE: fnl/nvim-tree-docs/specs/javascript/jsdoc.fnl
================================================
(require-macros "nvim-tree-docs.macros")
(doc-spec
{:spec jsdoc
:lang javascript
:doc-lang jsdoc
:config {:include_types true
:empty_line_after_description false
:slots {:function {:param true
:example false
:returns true
:function true
:generator true
:template true
:yields true
:export true}
:variable {:type true
:export true}
:class {:class true
:example false
:export true
:extends true}
:member {:memberof true
:type true}
:method {:memberof true
:example false
:yields true
:generator true
:param true
:returns true}
:module {:module true}}}})
(template function
doc-start
description
function
generator
yields
%rest%
param
returns
example
doc-end
%content%)
(template variable
doc-start
description
%rest%
doc-end
%content%)
(template method
doc-start
description
memberof
%rest%
param
returns
example
doc-end
%content%)
(template class
doc-start
description
class
extends
%rest%
example
doc-end
%content%)
(template member
doc-start
description
memberof
%rest%
doc-end
%content%)
(template module
doc-start
description
module
%rest%
doc-end)
(processor doc-start
implicit true
build #"/**")
(processor doc-end
implicit true
build #" */")
(processor returns
when #$.return_statement
build #(let [type-str (%> get-marked-type $ " ")]
(%- " * @returns" type-str (%! "The result"))))
(processor function
when #(not $.generator)
build #(%- " * @function " (%= name)))
(processor module
build #(let [filename (vim.fn.expand "%:t:r")]
(%- " * @module " (%! filename))))
(processor template
when #$.generics
build #(%> build-generics $ :template))
(processor typeParam
when #$.generics
build #(%> build-generics $ :typeParam))
(processor extends
when #$.extends
build #(%- " * @extends " (%= extends)))
(processor class
build #(%- " * @class " (%= name)))
(processor generator
when #$.generator)
(processor yields
when #$.yields
build #(%- " * @yields" (%> get-marked-type $ "")))
(processor description
implicit true
build #(let [description (%- " * " (%! (.. "The " (%= name) " " $2.name)))
{: processors : index} $2
next-ps (. processors (+ index 1))]
(if (or (= next-ps :doc-end)
(not ($.conf :empty_line_after_description)))
description
[description " *"])))
(processor type
when #$.type
build #(let [type-str (%> get-marked-type $ " ")]
(%- " * @type" type-str)))
(processor export
when #$.export)
(processor param
when #(and $.parameters
(not ($.empty? $.parameters)))
build #(let [result []]
(each [param ($.iter $.parameters)]
(let [param-name (%> get-param-name $ param.entry)
type-str (%> get-marked-type $ " ")
name (%= name param.entry)]
(table.insert
result
(%- " * @param"
type-str
param-name
" - "
(%! (.. "The " name " param"))))))
result))
(processor memberof
when #$.class
build #(%- " * @memberof " (%= class)))
(processor
build #(%- " * @" $2.name))
(util get-param-name [$ param]
(if param.default_value
(string.format "%s=%s"
($.get-text param.name)
($.get-text param.default_value))
($.get-text param.name)))
(util get-marked-type [$ not-found?]
(if ($.conf :include_types)
" {any} "
(or not-found? "")))
(util build-generics [$ tag]
(let [result []]
(each [generic ($.iter $.generics)]
(let [name (%= name generic.entry)]
(table.insert result
(%- " * @" tag " " name " " (%! (.. "The " name " type"))))))
result))
================================================
FILE: fnl/nvim-tree-docs/specs/lua/luadoc.fnl
================================================
(require-macros "nvim-tree-docs.macros")
(doc-spec
{:spec luadoc
:lang lua
:config {:slots {:function {:param true
:returns true}
:variable {}}}})
(template function
description
param
returns)
(template variable
description)
(processor description
implicit true
build #"--- Description")
(processor param
when #(and $.parameters
(not ($.empty? $.parameters)))
build #(let [result []]
(each [param ($.iter $.parameters)]
(let [name (%= name param.entry)]
(table.insert
result
(.. "-- @param " name " The " name))))
result))
================================================
FILE: fnl/nvim-tree-docs/specs/typescript/tsdoc.fnl
================================================
(require-macros "nvim-tree-docs.macros")
(doc-spec
{:spec tsdoc
:lang typescript
:extends javascript.jsdoc
:config {:include_types false
:empty_line_after_description true
:slots {:function {:export false
:generator false
:function false}
:variable {:type false
:export false}
:class {:class false
:export false
:extends false}
:member {:memberof false
:type false}
:method {:memberof false}}}})
================================================
FILE: fnl/nvim-tree-docs/template.fnl
================================================
(module nvim-tree-docs.template
{autoload {core nvim-tree-docs.aniseed.core
utils nvim-tree-docs.utils
collectors nvim-tree-docs.collector
ts-utils nvim-treesitter.ts_utils}})
(import-macros {: log} "nvim-tree-docs.macros")
(def loaded-specs {})
(defn get-text [context node default multi]
(let [default-value (or default "")]
(if (and node (= (type node) :table))
(let [tsnode (if node.node node.node node)
lines (ts-utils.get_node_text tsnode)]
(if multi
lines
(let [line (. lines 1)]
(if (not= line "") line default-value))))
default-value)))
(defn iter [collector]
(if collector (collectors.iterate-collector collector) #nil))
(defn conf [context path default?]
(utils.get path context.config default?))
(defn empty? [collector]
(collectors.is-collector-empty collector))
(defn build-line [...]
"Builds a line of content while capturing any marks that are defined"
(let [result {:content "" :marks []}
add-content #(set result.content (.. result.content $))]
(each [_ value (ipairs [...])]
(if (core.string? value)
(add-content value)
(and (core.table? value) (core.string? value.content))
(if value.mark
(let [start (length result.content)]
(add-content value.content)
(table.insert result.marks {:kind value.mark
:stop (+ (length value.content) start)
: start}))
(add-content value.content))))
result))
(defn new-template-context [collector options?]
(let [options (or options? {})
context (vim.tbl_extend
"keep"
{: iter
: empty?
:build build-line
:config options.config
:kind options.kind
:start-line (or options.start-line 0)
:start-col (or options.start-col 0)
:content (or options.content [])
:bufnr (utils.get-bufnr options.bufnr)}
collector)]
(set context.get-text (partial get-text context))
(set context.conf (partial conf context))
context))
(defn get-spec [lang spec]
(let [key (.. lang "." spec)]
(when (not (. loaded-specs key))
(require (string.format "nvim-tree-docs.specs.%s.%s" lang spec)))
(. loaded-specs key)))
(defn- normalize-processor [processor]
(if (utils.func? processor)
{:build processor}
processor))
(defn- get-processor [processors name aliased-from?]
(let [processor-config (. processors name)]
(if (core.string? processor-config)
(get-processor processors processor-config (or aliased-from? name))
(let [result (-> (or processor-config processors.__default)
(normalize-processor))]
{:processor result :name name :aliased-from aliased-from?}))))
(defn get-expanded-slots [ps-list slot-config processors]
(let [result [(unpack ps-list)]]
(var i 1)
(while (<= i (length result))
(let [ps-name (. result i)
{: processor} (get-processor processors ps-name)]
(if (and processor processor.expand)
(let [expanded (processor.expand
(utils.make-inverse-list result)
slot-config)]
(table.remove result i)
(each [j expanded-ps (ipairs expanded)]
(table.insert result (- (+ i j) 1) expanded-ps))))
(set i (+ i 1))))
result))
(defn get-filtered-slots [ps-list processors slot-config context]
(->>
(core.map #(get-processor processors $) ps-list)
(core.filter #(and $.processor
(or $.processor.implicit
(. slot-config (or $.aliased-from $.name)))))
(core.map #(let [include-ps (if (utils.method? $.processor :when)
($.processor.when context)
(core.table? $.processor))]
(if include-ps $.name nil)))
(core.filter #(not= $ nil))))
(defn normalize-build-output [output]
(if (core.string? output)
[{:content output :marks []}]
(core.table? output)
(if (core.string? output.content)
[output]
(core.map #(if (core.string? $)
{:content $ :marks []}
$)
output))))
(defn indent-lines [lines indenter context]
(let [indentation-amount (if (utils.func? indenter)
(indenter lines context)
context.start-col)]
(core.map (fn [line]
(vim.tbl_extend
"force"
{}
{:content (.. (string.rep " " indentation-amount) line.content)
:marks (core.map
#(vim.tbl_extend
"force"
$
{:start (+ $.start indentation-amount)
:stop (+ $.stop indentation-amount)})
line.marks)}))
lines)))
(defn build-slots [ps-list processors context]
(let [result []]
(each [i ps-name (ipairs ps-list)]
(let [{: processor} (get-processor processors ps-name)
default-processor processors.__default
build-fn (or (-?> processor (. :build))
(-?> default-processor (. :build)))
indent-fn (or (-?> processor (. :indent))
(-?> default-processor (. :indent)))]
(table.insert
result
(if (utils.func? build-fn)
(-> (build-fn context {:processors ps-list
:index i
:name ps-name})
(normalize-build-output)
(indent-lines indent-fn context))
[]))))
result))
(defn output-to-lines [output]
(core.reduce #(vim.list_extend $1 $2) [] output))
(defn package-build-output [output context]
(let [result {:content [] :marks []}]
(each [i entry (ipairs output)]
(each [j line (ipairs entry)]
(let [lnum (+ (length result.content) 1)]
(table.insert result.content line.content)
(vim.list_extend result.marks (core.map #(vim.tbl_extend
"force"
{}
$
{:line (+ lnum
(or context.start-line 0))})
line.marks)))))
result))
(defn process-template [collector config]
(let [{: spec : kind :config spec-conf} config
ps-list (or (-?> spec-conf (. :templates) (. kind))
(. spec.templates kind))
processors (vim.tbl_extend
"force"
spec.processors
(or spec-conf.processors {}))
slot-config (or (-?> spec-conf.slots (. kind)) {})
context (new-template-context collector config)]
(-> ps-list
(get-expanded-slots slot-config processors)
(get-filtered-slots processors slot-config context)
(build-slots processors context)
(package-build-output context))))
(defn extend-spec [mod spec]
(when (and spec (not= mod.module spec))
(do
(require (.. "nvim-tree-docs.specs." spec))
(let [inherited-spec (. loaded-specs spec)]
(tset mod :templates (vim.tbl_extend "force"
mod.templates
(-> loaded-specs (. spec) (. :templates))))
(tset mod :utils (vim.tbl_extend "force"
mod.utils
(-> loaded-specs (. spec) (. :utils))))
(tset mod :inherits inherited-spec)
(tset mod :processors (vim.tbl_extend "force" mod.processors inherited-spec.processors))
(tset mod :config (vim.tbl_deep_extend "force" inherited-spec.config mod.config))))))
================================================
FILE: fnl/nvim-tree-docs/utils.fnl
================================================
(module nvim-tree-docs.utils
{autoload {core nvim-tree-docs.aniseed.core}})
(def ns (vim.api.nvim_create_namespace "blorg"))
(defn get-start-node [entry]
(or (-?> entry (. :start_point) (. :node))
(-?> entry (. :definition) (. :node))))
(defn get-end-node [entry]
(or (-?> entry (. :end_point) (. :node))
(-?> entry (. :definition) (. :node))))
(defn get-position [keys default-position entry]
(var i 1)
(var result nil)
(while (and (not result) (<= i (length keys)))
(let [key (. keys i)
match? (. entry key)
has-match? (and (core.table? match?) match?.node)
position? (if has-match? (or match?.position default-position) nil)]
(if has-match?
(set result (if (= position? :start)
[(match?.node:start)]
[(match?.node:end_)]))))
(set i (core.inc i)))
(unpack result))
(def get-start-position (partial get-position [:start_point :definition] :start))
(def get-end-position (partial get-position [:end_point :definition] :end))
(def get-edit-start-position (partial get-position [:edit_start_point :start_point :definition] :start))
(def get-edit-end-position (partial get-position [:edit_end_point :end_point :definition] :end))
(defn get-bufnr [bufnr]
(or bufnr (vim.api.nvim_get_current_buf)))
(defn get-buf-content [start-row start-col end-row end-col bufnr]
(vim.api.nvim_buf_get_lines bufnr start-row (+ end-row 1) false))
(defn get [path tbl default?]
(let [segments (if (= (type path) :string)
(vim.split path "%.")
path)]
(var result tbl)
(each [_ segment (ipairs segments)]
(if (= (type result) :table)
(set result (. result segment))
(set result nil)))
(if (= result nil) default? result)))
(defn make-inverse-list [tbl]
(let [result {}]
(each [i v (ipairs tbl)]
(tset result v i))
result))
(defn get-all-truthy-keys [tbl]
(let [result []]
(each [k v (pairs tbl)]
(when v (table.insert result k)))
result))
(defn func? [v] (= (type v) :function))
(defn method? [v key] (and (= (type v) :table)
(= (type (. v key)) :function)))
(defn highlight-marks [marks bufnr]
(each [_ mark (ipairs marks)]
(let [line (- mark.line 1)]
(vim.highlight.range bufnr ns "Visual" [line mark.start] [line mark.stop]))))
================================================
FILE: lua/nvim-tree-docs/aniseed/autoload.lua
================================================
local _2afile_2a = "fnl/aniseed/autoload.fnl"
local _0_
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_
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
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["autoload"] = v_0_
autoload0 = v_0_
end
return nil
================================================
FILE: lua/nvim-tree-docs/aniseed/compile.lua
================================================
local _2afile_2a = "fnl/aniseed/compile.fnl"
local _0_
do
local name_0_ = "nvim-tree-docs.aniseed.compile"
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.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)
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_
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["str"] = v_0_
str = v_0_
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
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
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_
end
return nil
================================================
FILE: lua/nvim-tree-docs/aniseed/core.lua
================================================
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
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_
end
local string_3f
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_
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_
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_
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_
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_
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_
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_
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_
end
local inc
do
local v_0_
do
local v_0_0
local function inc0(n)
return (n + 1)
end
v_0_0 = inc0
_0_["inc"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["inc"] = v_0_
inc = v_0_
end
local dec
do
local v_0_
do
local v_0_0
local function dec0(n)
return (n - 1)
end
v_0_0 = dec0
_0_["dec"] = v_0_0
v_0_ = v_0_0
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_
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
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
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
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_
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
end
v_0_0 = run_210
_0_["run!"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["run!"] = v_0_
run_21 = v_0_
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
end
v_0_0 = filter0
_0_["filter"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["filter"] = v_0_
filter = v_0_
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_())
end
run_21(_3_, xs)
return result
end
v_0_0 = map0
_0_["map"] = v_0_0
v_0_ = v_0_0
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["map-indexed"] = v_0_
map_indexed = v_0_
end
local identity
do
local v_0_
do
local v_0_0
local function identity0(x)
return x
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_
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)
return nil
end
run_21(_3_, xs)
return result
end
v_0_0 = reduce0
_0_["reduce"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["reduce"] = v_0_
reduce = v_0_
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_
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_
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["rest"] = v_0_
rest = v_0_
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
end
v_0_0 = concat0
_0_["concat"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["concat"] = v_0_
concat = v_0_
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["mapcat"] = v_0_
mapcat = v_0_
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["pr-str"] = v_0_
pr_str = v_0_
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_, {...}))
end
v_0_0 = str0
_0_["str"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["str"] = v_0_
str = v_0_
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_
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
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
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_
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
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_
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
end
return reduce(_3_, (base or {}), {...})
end
v_0_0 = merge_210
_0_["merge!"] = v_0_0
v_0_ = v_0_0
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["merge!"] = v_0_
merge_21 = v_0_
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_
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)
else
return {}
end
end
v_0_0 = select_keys0
_0_["select-keys"] = v_0_0
v_0_ = v_0_0
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
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
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
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
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
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
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)))
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_
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
end
local t_0_ = (_0_)["aniseed/locals"]
t_0_["constantly"] = v_0_
constantly = v_0_
end
return nil
================================================
FILE: lua/nvim-tree-docs/aniseed/deps/fennel.lua
================================================
package.preload["nvim-tree-docs.aniseed.fennel.repl"] = package.preload["nvim-tree-docs.aniseed.fennel.repl"] or function(...)
local utils = require("nvim-tree-docs.aniseed.fennel.utils")
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 function default_read_chunk(parser_state)
local function _0_()
if (0 < parser_state["stack-size"]) then
return ".."
else
return ">> "
end
end
io.write(_0_())
io.flush()
local input = io.read()
return (input and (input .. "\n"))
end
local function default_on_values(xs)
io.write(table.concat(xs, "\9"))
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
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
return (compiler.traceback(tostring(err), 4) .. "\n")
else
local _ = _0_0
return ("%s error: %s\n"):format(errtype, tostring(err))
end
end
return io.write(_1_())
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)
end
for name in pairs(env.___replLocals___) do
table.insert(spliced_source, 1, bind:format(name, name))
end
if ((1 < #spliced_source) and (spliced_source[#spliced_source]):match("^ *return .*$")) then
table.insert(spliced_source, #spliced_source, save_source)
end
return table.concat(spliced_source, "\n")
end
local commands = {}
local function command_3f(input)
return input:match("^%s*,")
end
local function command_docs()
local _0_
do
local tbl_0_ = {}
for name, f in pairs(commands) do
tbl_0_[(#tbl_0_ + 1)] = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented"))
end
_0_ = tbl_0_
end
return table.concat(_0_, "\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")})
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
package.loaded[module_name] = nil
_ = nil
local ok, new = pcall(require, module_name)
local new0 = nil
if not ok then
on_values({new})
new0 = old
else
new0 = new
end
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
old[k] = nil
end
end
package.loaded[module_name] = old
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
end
return on_error("Runtime", _3_())
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))
end
end
do end (compiler.metadata):set(commands.reload, "fnl/docstring", "Reload the specified module.")
commands.reset = function(env, _, on_values)
env.___replLocals___ = {}
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)
end
end
end
return nil
end
end
local function run_command(input, read, loop, env, on_values, on_error)
load_plugin_commands()
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
if ("exit" ~= command_name) then
on_values({"Unknown command", command_name})
end
end
end
if ("exit" ~= command_name) then
return loop()
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]
else
k0 = k
end
if ((#matches < 2000) and (type(k0) == "string") and (input == k0:sub(0, #input))) then
table.insert(matches, (prefix .. k0))
end
end
return nil
end
local function add_matches(input, tbl, prefix)
local prefix0 = nil
if prefix then
prefix0 = (prefix .. ".")
else
prefix0 = ""
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]
else
raw_head = head
end
if (type(tbl[raw_head]) == "table") then
return add_matches(tail, tbl[raw_head], (prefix0 .. head))
end
end
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 old_root_options = utils.root.options
local env = nil
if options.env then
env = specials["wrap-env"](options.env)
else
env = setmetatable({}, {__index = (rawget(_G, "_ENV") or _G)})
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 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 byte_stream, clear_stream = parser.granulate(read_chunk)
local chars = {}
local read, reset = nil, nil
local function _1_(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)
if (opts.allowedGlobals == nil) then
opts.allowedGlobals = specials["current-global-names"](opts.env)
end
if opts.registerCompleter then
local function _3_(...)
return completer(env, scope, ...)
end
opts.registerCompleter(_3_)
end
local function print_values(...)
local vals = {...}
local out = {}
env._, env.__ = vals[1], vals
for i = 1, select("#", ...) do
table.insert(out, pp(vals[i]))
end
return on_values(out)
end
local function loop()
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
if not ok then
on_error("Parse", parse_ok_3f)
clear_stream()
reset()
return loop()
elseif command_3f(src_string) then
return run_command(src_string, read, loop, env, on_values, on_error)
else
if parse_ok_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
clear_stream()
on_error("Compile", msg)
elseif ((_4_0 == true) and (nil ~= _5_0)) then
local src = _5_0
local src0 = nil
if save_locals_3f then
src0 = splice_save_locals(env, src)
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
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_()
return print_values(chunk())
end
local function _10_(...)
return on_error("Runtime", ...)
end
xpcall(_9_, _10_)
end
end
end
utils.root.options = old_root_options
return loop()
end
end
end
return loop()
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
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
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
else
return assert(load(code, filename, "t", environment0))
end
end
local function doc_2a(tgt, name)
if not tgt then
return (name .. " not found")
else
local docstring = (((compiler.metadata):get(tgt, "fnl/docstring") or "#<undocumented>")):gsub("\n$", ""):gsub("\n", "\n ")
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 {"#<unknown-arguments>"}), " ")
local _0_
if (#arglist > 0) then
_0_ = " "
else
_0_ = ""
end
return string.format("(%s%s%s)\n %s", name, _0_, 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}
return nil
end
local function compile_do(ast, scope, parent, start)
local start0 = (start or 2)
local len = #ast
local sub_scope = compiler["make-scope"](scope)
for i = start0, 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 {})
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})
else
for i = start0, 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)
if (i ~= len) then
compiler["keep-side-effects"](subexprs, parent, nil, ast[i])
end
end
end
compiler.emit(parent, chunk0, ast)
compiler.emit(parent, "end", ast)
return (outer_retexprs or retexprs)
end
if (opts.target or (opts.nval == 0) or opts.tail) then
compiler.emit(parent, "do", ast)
return compile_body(opts.target, opts.tail)
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
retexprs[i] = utils.expr(s, "sym")
end
local outer_target = table.concat(syms, ", ")
compiler.emit(parent, string.format("local %s", outer_target), ast)
compiler.emit(parent, "do", ast)
return compile_body(outer_target, opts.tail)
else
local fname = compiler.gensym(scope)
local fargs = nil
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
doc_special("do", {"..."}, "Evaluate multiple forms; return last value.", true)
SPECIALS.values = function(ast, scope, parent)
local len = #ast
local exprs = {}
for i = 2, len do
local subexprs = compiler.compile1(ast[i], scope, parent, {nval = ((i ~= len) and 1)})
table.insert(exprs, subexprs[1])
if (i == len) then
for j = 2, #subexprs do
table.insert(exprs, subexprs[j])
end
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))
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
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))
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
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, ", ")))
end
end
local function get_fn_name(ast, scope, fn_name, multi)
if (fn_name and (fn_name[1] ~= "nil")) then
local _0_
if not multi then
_0_ = compiler["declare-local"](fn_name, {}, scope, ast)
else
_0_ = compiler["symbol-to-expression"](fn_name, scope)[1]
end
return _0_, 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)
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_
if local_3f then
_0_ = "local function %s(%s)"
else
_0_ = "%s = function(%s)"
end
compiler.emit(parent, string.format(_0_, 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)
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 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)
end
SPECIALS.fn = function(ast, scope, parent)
local f_scope = nil
do
local _0_0 = compiler["make-scope"](scope)
_0_0["vararg"] = false
f_scope = _0_0
end
local f_chunk = {}
local fn_sym = utils["sym?"](ast[2])
local multi = (fn_sym and utils["multi-sym?"](fn_sym[1]))
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
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
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
else
return compiler.assert(false, ("expected symbol for function parameter: %s"):format(tostring(arg)), ast[2])
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
end
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)
else
return compile_anonymous_fn(ast, f_scope, f_chunk, parent, index0, arg_name_list, arg_list, docstring, 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)
SPECIALS.lua = function(ast, _, parent)
compiler.assert(((#ast == 2) or (#ast == 3)), "expected 1 or 2 arguments", ast)
if (ast[2] ~= nil) then
table.insert(parent, {ast = ast, leaf = tostring(ast[2])})
end
if (ast[3] ~= nil) then
return tostring(ast[3])
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))
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]))
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]
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
table.insert(indices, ("." .. index))
else
local _1_ = compiler.compile1(index, scope, parent, {nval = 1})
local index0 = _1_[1]
table.insert(indices, ("[" .. tostring(index0) .. "]"))
end
end
if (tostring(lhs):find("[{\"0-9]") or ("nil" == tostring(lhs))) then
return ("(" .. tostring(lhs) .. ")" .. table.concat(indices))
else
return (tostring(lhs) .. table.concat(indices))
end
end
end
SPECIALS["."] = dot
doc_special(".", {"tbl", "key1", "..."}, "Look up key1 in tbl table. If more args are provided, do a nested lookup.")
SPECIALS.global = function(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
compiler.destructure(ast[2], ast[3], ast, scope, parent, {forceglobal = true, nomulti = true, symtype = "global"})
return nil
end
doc_special("global", {"name", "val"}, "Set name as a global with val.")
SPECIALS.set = function(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
compiler.destructure(ast[2], ast[3], ast, scope, parent, {noundef = true, symtype = "set"})
return nil
end
doc_special("set", {"name", "val"}, "Set a local variable to a new value. Only works on locals using var.")
local function set_forcibly_21_2a(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
compiler.destructure(ast[2], ast[3], ast, scope, parent, {forceset = true, symtype = "set"})
return nil
end
SPECIALS["set-forcibly!"] = set_forcibly_21_2a
local function local_2a(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
compiler.destructure(ast[2], ast[3], ast, scope, parent, {declaration = true, nomulti = true, symtype = "local"})
return nil
end
SPECIALS["local"] = local_2a
doc_special("local", {"name", "val"}, "Introduce new top-level immutable local.")
SPECIALS.var = function(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
compiler.destructure(ast[2], ast[3], ast, scope, parent, {declaration = true, isvar = true, nomulti = true, symtype = "var"})
return nil
end
doc_special("var", {"name", "val"}, "Introduce new mutable local.")
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(((#bindings % 2) == 0), "expected even number of name/value bindings", ast[2])
compiler.assert((#ast >= 3), "expected body expression", ast[1])
for _ = 1, (opts.nval or 0) do
table.insert(pre_syms, compiler.gensym(scope))
end
local sub_scope = compiler["make-scope"](scope)
local sub_chunk = {}
for i = 1, #bindings, 2 do
compiler.destructure(bindings[i], bindings[(i + 1)], ast, sub_scope, sub_chunk, {declaration = true, nomulti = true, symtype = "let"})
end
return SPECIALS["do"](ast, scope, parent, opts, 3, sub_chunk, sub_scope, pre_syms)
end
doc_special("let", {"[name1 val1 ... nameN valN]", "..."}, "Introduces a new scope in which a given set of local bindings are used.", true)
local function get_prev_line(parent)
if ("table" == type(parent)) then
return get_prev_line((parent.leaf or parent[#parent]))
else
return (parent or "")
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
return prev_line:match("%)$")
end
end
return (rootstr:match("^{") or _1_())
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]
local keys = {}
for i = 3, (#ast - 1) do
local _0_ = compiler.compile1(ast[i], scope, parent, {nval = 1})
local key = _0_[1]
table.insert(keys, tostring(key))
end
local value = compiler.compile1(ast[#ast], scope, parent, {nval = 1})[1]
local rootstr = tostring(root)
local fmtstr = nil
if disambiguate_3f(rootstr, parent) then
fmtstr = "do end (%s)[%s] = %s"
else
fmtstr = "%s[%s] = %s"
end
return compiler.emit(parent, fmtstr:format(rootstr, table.concat(keys, "]["), tostring(value)), ast)
end
doc_special("tset", {"tbl", "key1", "...", "keyN", "val"}, "Set the value of a table field. Can take additional keys to set\nnested values, but all parents must contain an existing table.")
local function calculate_target(scope, opts)
if not (opts.tail or opts.target or opts.nval) then
return "iife", true, nil
elseif (opts.nval and (opts.nval ~= 0) and not opts.target) then
local accum = {}
local target_exprs = {}
for i = 1, opts.nval do
local s = compiler.gensym(scope)
accum[i] = s
target_exprs[i] = utils.expr(s, "sym")
end
return "target", opts.tail, table.concat(accum, ", "), target_exprs
else
return "none", opts.tail, opts.target
end
end
local function if_2a(ast, scope, parent, opts)
local do_scope = compiler["make-scope"](scope)
local branches = {}
local wrapper, inner_tail, inner_target, target_exprs = calculate_target(scope, opts)
local body_opts = {nval = opts.nval, tail = inner_tail, target = inner_target}
local function compile_body(i)
local chunk = {}
local cscope = compiler["make-scope"](do_scope)
compiler["keep-side-effects"](compiler.compile1(ast[i], cscope, chunk, body_opts), chunk, nil, ast[i])
return {chunk = chunk, scope = cscope}
end
for i = 2, (#ast - 1), 2 do
local condchunk = {}
local res = compiler.compile1(ast[i], do_scope, condchunk, {nval = 1})
local cond = res[1]
local branch = compile_body((i + 1))
branch.cond = cond
branch.condchunk = condchunk
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 s = compiler.gensym(scope)
local buffer = {}
local last_buffer = buffer
for i = 1, #branches do
local branch = branches[i]
local fstr = nil
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
if branch.nested then
compiler.emit(last_buffer, branch.condchunk, ast)
else
for _, v in ipairs(branch.condchunk) do
compiler.emit(last_buffer, v, ast)
end
end
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, "end", ast)
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
end
end
if (wrapper == "iife") then
local iifeargs = ((scope.vararg and "...") or "")
compiler.emit(parent, ("local function %s(%s)"):format(tostring(s), iifeargs), ast)
compiler.emit(parent, buffer, ast)
compiler.emit(parent, "end", ast)
return utils.expr(("%s(%s)"):format(tostring(s), iifeargs), "statement")
elseif (wrapper == "none") then
for i = 1, #buffer do
compiler.emit(parent, buffer[i], ast)
end
return {returned = true}
else
compiler.emit(parent, ("local %s"):format(inner_target), ast)
for i = 1, #buffer do
compiler.emit(parent, buffer[i], ast)
end
return target_exprs
end
end
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
table.remove(bindings, (#bindings - 1))
return table.remove(bindings)
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)
end
end
SPECIALS.each = function(ast, scope, parent)
compiler.assert((#ast >= 3), "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)
local iter = table.remove(binding, #binding)
local destructures = {}
local new_manglings = {}
local sub_scope = compiler["make-scope"](scope)
local function destructure_binding(v)
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
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 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)
for raw, args in utils.stablepairs(destructures) do
compiler.destructure(args, raw, ast, sub_scope, chunk, {declaration = true, nomulti = true, symtype = "each"})
end
compiler["apply-manglings"](sub_scope, new_manglings, ast)
compile_until(until_condition, sub_scope, chunk)
compile_do(ast, sub_scope, chunk, 3)
compiler.emit(parent, chunk, ast)
return compiler.emit(parent, "end", ast)
end
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 len2 = #parent
local sub_chunk = {}
if (len1 ~= len2) then
for i = (len1 + 1), len2 do
table.insert(sub_chunk, parent[i])
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)
else
compiler.emit(parent, ("while " .. tostring(condition) .. " do"), ast)
end
compile_do(ast, compiler["make-scope"](scope), sub_chunk, 3)
compiler.emit(parent, sub_chunk, ast)
return compiler.emit(parent, "end", ast)
end
SPECIALS["while"] = while_2a
doc_special("while", {"condition", "..."}, "The classic while loop. Evaluates body until a condition is non-truthy.", true)
local function for_2a(ast, scope, parent)
local ranges = compiler.assert(utils["table?"](ast[2]), "expected binding table", ast)
local until_condition = remove_until_condition(ast[2])
local binding_sym = table.remove(ast[2], 1)
local sub_scope = compiler["make-scope"](scope)
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])
for i = 1, math.min(#ranges, 3) do
range_args[i] = tostring(compiler.compile1(ranges[i], sub_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)
compile_do(ast, sub_scope, chunk, 3)
compiler.emit(parent, chunk, ast)
return compiler.emit(parent, "end", ast)
end
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
call_string = "(%s):%s(%s)"
else
call_string = "%s:%s(%s)"
end
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 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 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 args = {}
for i = 4, #ast do
local subexprs = nil
local _1_
if (i ~= #ast) then
_1_ = 1
else
_1_ = nil
end
subexprs = compiler.compile1(ast[i], scope, parent, {nval = _1_})
utils.map(subexprs, tostring, args)
end
if ((type(ast[3]) == "string") 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)
else
return double_eval_protected_method_call(ast, scope, parent, target, args)
end
end
SPECIALS[":"] = method_call
doc_special(":", {"tbl", "method-name", "..."}, "Call the named method on tbl with the provided args.\nMethod name doesn't have to be known at compile-time; if it is, use\n(tbl:method-name ...) instead.")
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_())
end
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
if f_scope.symmeta[("$" .. i)].used then
max0 = i
else
max0 = max
end
if (i < 9) then
return hashfn_max_used(f_scope, (i + 1), max0)
else
return max0
end
end
SPECIALS.hashfn = function(ast, scope, parent)
compiler.assert((#ast == 2), "expected one argument", ast)
local f_scope = nil
do
local _0_0 = compiler["make-scope"](scope)
_0_0["vararg"] = false
_0_0["hashfn"] = true
f_scope = _0_0
end
local f_chunk = {}
local name = compiler.gensym(scope)
local symbol = utils.sym(name)
local args = {}
compiler["declare-local"](symbol, {}, scope, ast)
for i = 1, 9 do
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
parent_node[idx] = utils.varg()
f_scope.vararg = true
return nil
else
return (utils["list?"](node) or utils["table?"](node))
end
end
utils["walk-tree"](ast[2], walker)
compiler.compile1(ast[2], f_scope, f_chunk, {tail = true})
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)
end
local arg_str = nil
if f_scope.vararg then
arg_str = utils.deref(utils.varg())
else
arg_str = table.concat(args, ", ", 1, max_used)
end
compiler.emit(parent, string.format("local function %s(%s)", name, arg_str), ast)
compiler.emit(parent, f_chunk, ast)
compiler.emit(parent, "end", ast)
return utils.expr(name, "sym")
end
doc_special("hashfn", {"..."}, "Function literal shorthand; args are either $... OR $1, $2, etc.")
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_})
utils.map(subexprs, tostring, operands)
end
if (#operands == 1) then
if unary_prefix then
return ("(" .. unary_prefix .. padded_op .. operands[1] .. ")")
else
return operands[1]
end
else
return ("(" .. table.concat(operands, padded_op) .. ")")
end
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, ...)
end
SPECIALS[name] = _0_
return doc_special(name, {"a", "b", "..."}, "Arithmetic operator; works the same as Lua but accepts more arguments.")
end
define_arithmetic_special("+", "0")
define_arithmetic_special("..", "''")
define_arithmetic_special("^")
define_arithmetic_special("-", nil, "")
define_arithmetic_special("*", "1")
define_arithmetic_special("%")
define_arithmetic_special("/", nil, "1")
define_arithmetic_special("//", nil, "1")
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)
else
local len = #ast
local operands = {}
local padded_native_name = (" " .. native_name .. " ")
local prefixed_lib_name = ("bit." .. lib_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_})
utils.map(subexprs, tostring, operands)
end
if (#operands == 1) then
if utils.root.options.useBitLib then
return (prefixed_lib_name .. "(" .. unary_prefix .. ", " .. operands[1] .. ")")
else
return ("(" .. unary_prefix .. padded_native_name .. operands[1] .. ")")
end
else
if utils.root.options.useBitLib then
return (prefixed_lib_name .. "(" .. table.concat(operands, ", ") .. ")")
else
return ("(" .. table.concat(operands, padded_native_name) .. ")")
end
end
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, ...)
end
SPECIALS[name] = _0_
return nil
end
define_bitop_special("lshift", nil, "1", "<<")
define_bitop_special("rshift", nil, "1", ">>")
define_bitop_special("band", "0", "0", "&")
define_bitop_special("bor", "0", "0", "|")
define_bitop_special("bxor", "0", "0", "~")
doc_special("lshift", {"x", "n"}, "Bitwise logical left shift of x by n bits.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.")
doc_special("rshift", {"x", "n"}, "Bitwise logical right shift of x by n bits.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.")
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]
return string.format("(%s %s %s)", tostring(lhs), op, tostring(rhs))
end
local function double_eval_protected_comparator(op, chain_op, ast, scope, parent)
local arglist = {}
local comparisons = {}
local vals = {}
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]))
end
for i = 1, (#arglist - 1) do
table.insert(comparisons, string.format("(%s %s %s)", arglist[i], op, arglist[(i + 1)]))
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)
do
local op = (lua_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)
else
return double_eval_protected_comparator(op, chain_op, ast, scope, parent)
end
end
SPECIALS[name] = opfn
end
return doc_special(name, {"a", "b", "..."}, "Comparison operator; works the same as Lua but accepts more arguments.")
end
define_comparator_special(">")
define_comparator_special("<")
define_comparator_special(">=")
define_comparator_special("<=")
define_comparator_special("=", "==")
define_comparator_special("not=", "~=", "or")
local function define_unary_special(op, realop)
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]))
end
SPECIALS[op] = opfn
return nil
end
define_unary_special("not", "not ")
doc_special("not", {"x"}, "Logical operator; works the same as Lua.")
define_unary_special("bnot", "~")
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="]
SPECIALS["#"] = SPECIALS.length
SPECIALS.quote = function(ast, scope, parent)
compiler.assert((#ast == 2), "expected one argument")
local runtime, this_scope = true, scope
while this_scope do
this_scope = this_scope.parent
if (this_scope == compiler.scopes.compiler) then
runtime = false
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 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
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_})
end
local function make_compiler_env(ast, scope, parent, strict_3f)
local function _1_()
return compiler.scopes.macro
end
local function _2_(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)
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
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_})
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 function escapepat(str)
return string.gsub(str, "[^%w]", "%%%1")
end
local function search_module(modulename, pathstring)
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 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
file:close()
return filename
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)))
end
end
return find_in_path(1)
end
local function make_searcher(options)
local function _1_(module_name)
local opts = utils.copy(utils.root.options)
for k, v in pairs((options 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, ...)
end
return _3_, filename
end
end
return _1_
end
local function macro_globals(env, globals)
local allowed = current_global_names(env)
for _, k in pairs((globals or {})) do
table.insert(allowed, k)
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"}, ...)
end
return _2_, filename
end
end
local macro_searchers = {default_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
return loader, _3ffilename
else
local _ = _2_0
return search_macro_module(modname, (n + 1))
end
end
end
local macro_loaded = {}
local function metadata_only_fennel(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}
end
end
local function _1_(modname)
local function _2_()
local loader, filename = search_macro_module(modname, 1)
compiler.assert(loader, (modname .. " module not found."))
macro_loaded[modname] = loader(modname, filename)
return macro_loaded[modname]
end
return (macro_loaded[modname] or metadata_only_fennel(modname) or _2_())
end
safe_require = _1_
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
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))
if not macro_loaded[modname] then
local env = make_compiler_env(ast, scope, parent)
local loader, filename0 = search_macro_module(modname, 1)
compiler.assert(loader, (modname .. " module not found."), ast)
macro_loaded[modname] = loader(modname, filename0)
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)
local subscope = compiler["make-scope"](utils.root.scope.parent)
local forms = {}
if utils.root.options.requireAsInclude then
subscope.specials.require = compiler["require-include"]
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
if (i == #forms) then
subopts = {tail = true}
else
subopts = {nval = 0}
end
utils["propagate-options"](opts, subopts)
compiler.compile1(forms[i], subscope, sub_chunk, subopts)
end
return nil
end
local function include_path(ast, opts, path, mod, fennel_3f)
utils.root.scope.includes[mod] = "fnl/loading"
local src = nil
do
local f = assert(io.open(path))
local function close_handlers_0_(ok_0_, ...)
f:close()
if ok_0_ then
return ...
else
return error(..., 0)
end
end
local function _2_()
return f:read("*all"):gsub("[\13\n]*$", "")
end
src = close_handlers_0_(xpcall(_2_, (package.loaded.fennel or debug).traceback))
end
local ret = utils.expr(("require(\"" .. mod .. "\")"), "statement")
local target = ("package.preload[%q]"):format(mod)
local preload_str = (target .. " = " .. target .. " or function(...)")
local temp_chunk, sub_chunk = {}, {}
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)
end
if fennel_3f then
emit_included_fennel(src, path, opts, sub_chunk)
else
compiler.emit(sub_chunk, src, ast)
end
utils.root.scope.includes[mod] = ret
return ret
end
local function include_circular_fallback(mod, modexpr, fallback, ast)
if (utils.root.scope.includes[mod] == "fnl/loading") then
compiler.assert(fallback, "circular include detected", ast)
return fallback(modexpr)
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]
if ((modexpr.type ~= "literal") or ((modexpr[1]):byte() ~= 34)) then
if opts.fallback then
return opts.fallback(modexpr)
else
return compiler.assert(false, "module name must be string literal", ast)
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
return include_path(ast, opts, fennel_path, mod, true)
else
local _ = _2_0
local lua_path = search_module(mod, package.path)
if lua_path then
return include_path(ast, opts, lua_path, mod, false)
elseif opts.fallback then
return opts.fallback(modexpr)
else
return compiler.assert(false, ("module not found " .. mod), ast)
end
end
end
return (include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _3_())
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.")
local function eval_compiler_2a(ast, scope, parent)
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)
end
SPECIALS.macros = function(ast, scope, parent)
compiler.assert((#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.")
SPECIALS["eval-compiler"] = function(ast, scope, parent)
local old_first = ast[1]
ast[1] = utils.sym("do")
local val = eval_compiler_2a(ast, scope, parent)
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}
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")
local parser = require("nvim-tree-docs.aniseed.fennel.parser")
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)
else
_0_ = 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)}
end
local function assert_msg(ast, msg)
local ast_tbl = nil
if ("table" == type(ast)) then
ast_tbl = ast
else
ast_tbl = {}
end
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)
end
local function assert_compile(condition, msg, 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)
else
friend["assert-compile"](condition, msg, ast, source)
end
end
return condition
end
scopes.global = make_scope()
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 function serialize_string(str)
local function _0_(_241)
return ("\\" .. _241:byte())
end
return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _0_)
end
local function global_mangling(str)
if utils["valid-lua-identifier?"](str) then
return str
else
local function _0_(_241)
return string.format("_%02x", _241:byte())
end
return ("__fnl_global__" .. str:gsub("[^%w]", _0_))
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)
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
return identifier
end
end
local allowed_globals = nil
local function global_allowed_3f(name)
return (not allowed_globals or utils["member?"](name, allowed_globals))
end
local function unique_mangling(original, mangling, scope, append)
if (scope.unmanglings[mangling] and not scope.gensyms[mangling]) then
return unique_mangling(original, (original .. append), scope, (append + 1))
else
return mangling
end
end
local function local_mangling(str, scope, ast, temp_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
raw = ("_" .. str)
else
raw = str
end
local mangling = nil
local function _1_(_241)
return string.format("_%02x", _241:byte())
end
mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _1_)
local unique = unique_mangling(mangling, mangling, scope, 0)
scope.unmanglings[unique] = str
do
local manglings = (temp_manglings or scope.manglings)
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
end
return nil
end
local function combine_parts(parts, scope)
local ret = (scope.manglings[parts[1]] or global_mangling(parts[1]))
for i = 2, #parts do
if utils["valid-lua-identifier?"](parts[i]) then
if (parts["multi-sym-method-call"] and (i == #parts)) then
ret = (ret .. ":" .. parts[i])
else
ret = (ret .. "." .. parts[i])
end
else
ret = (ret .. "[" .. serialize_string(parts[i]) .. "]")
end
end
return ret
end
local function gensym(scope, base)
local append, mangling = 0, ((base or "") .. "_0_")
while scope.unmanglings[mangling] do
mangling = ((base or "") .. "_" .. append .. "_")
append = (append + 1)
end
scope.unmanglings[mangling] = (base or true)
scope.gensyms[mangling] = true
return mangling
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
return mangling
end
return (scope.autogensyms[base] or _1_())
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"))
end
assert_compile(not (scope.specials[name] or 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)
check_binding_valid(symbol, scope, ast)
local name = utils.deref(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)
end
local function hashfn_arg_name(name, multi_sym_parts, scope)
if not scope.hashfn then
return nil
elseif (name == "$") then
return "$1"
elseif multi_sym_parts then
if (multi_sym_parts and (multi_sym_parts[1] == "$")) then
multi_sym_parts[1] = "$1"
end
return table.concat(multi_sym_parts, ".")
end
end
local function symbol_to_expression(symbol, scope, reference_3f)
utils.hook("symbol-to-expression", symbol, scope, reference_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 local_3f = scope.manglings[parts[1]]
if (local_3f and scope.symmeta[parts[1]]) then
scope.symmeta[parts[1]]["used"] = true
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
end
return utils.expr(combine_parts(parts, scope), etype)
end
local function emit(chunk, out, ast)
if (type(out) == "table") then
return table.insert(chunk, out)
else
return table.insert(chunk, {ast = ast, 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
local kid = peephole(chunk[(#chunk - 1)])
local new_chunk = {ast = chunk.ast}
for i = 1, (#chunk - 3) do
table.insert(new_chunk, peephole(chunk[i]))
end
for i = 1, #kid do
table.insert(new_chunk, kid[i])
end
return new_chunk
else
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
if chunk.leaf then
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 (file == source.filename) then
last_line0 = math.max(last_line0, (source.line or 0))
end
last_line0 = flatten(subchunk, out, last_line0, file)
end
end
end
return last_line0
end
local out = {}
local last = flatten(main_chunk, out, 1, options.filename)
for i = 1, last do
if (out[i] == nil) then
out[i] = ""
end
end
return table.concat(out, "\n")
end
local function flatten_chunk(sm, 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
else
local tab0 = nil
do
local _0_0 = tab
if (_0_0 == true) then
tab0 = " "
elseif (_0_0 == false) then
tab0 = ""
elseif (_0_0 == tab) then
tab0 = tab
elseif (_0_0 == nil) then
tab0 = ""
else
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
return (tab0 .. sub:gsub("\n", ("\n" .. tab0)))
else
return sub
end
end
end
return table.concat(utils.map(chunk, parter), "\n")
end
end
local fennel_sourcemap = {}
local function make_short_src(source)
local source0 = source:gsub("\n", " ")
if (#source0 <= 49) then
return ("[fennel \"" .. source0 .. "\"]")
else
return ("[fennel \"" .. source0:sub(1, 46) .. "...\"]")
end
end
local function flatten(chunk, options)
local chunk0 = peephole(chunk)
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
end
return ret, sm
end
end
local function make_metadata()
local function _0_(self, tgt, key)
if self[tgt] then
return self[tgt][key]
end
end
local function _1_(self, tgt, key, value)
self[tgt] = (self[tgt] or {})
self[tgt][key] = value
return tgt
end
local function _2_(self, tgt, ...)
local kv_len = select("#", ...)
local kvs = {...}
if ((kv_len % 2) ~= 0) then
error("metadata:setall() expected even number of k/v pairs")
end
self[tgt] = (self[tgt] or {})
for i = 1, kv_len, 2 do
self[tgt][kvs[i]] = kvs[(i + 1)]
end
return tgt
end
return setmetatable({}, {__index = {get = _0_, set = _1_, setall = _2_}, __mode = "k"})
end
local function exprs1(exprs)
return table.concat(utils.map(exprs, 1), ", ")
end
local function keep_side_effects(exprs, chunk, start, ast)
local start0 = (start or 1)
for j = start0, #exprs do
local se = exprs[j]
if ((se.type == "expression") and (se[1] ~= "nil")) then
emit(chunk, string.format("do local _ = %s end", tostring(se)), ast)
elseif (se.type == "statement") then
local code = tostring(se)
local disambiguated = nil
if (code:byte() == 40) then
disambiguated = ("do end " .. code)
else
disambiguated = code
end
emit(chunk, disambiguated, ast)
end
end
return nil
end
local function handle_compile_opts(exprs, parent, opts, ast)
if opts.nval then
local n = opts.nval
local len = #exprs
if (n ~= len) then
if (len > n) then
keep_side_effects(exprs, parent, (n + 1), ast)
for i = (n + 1), len do
exprs[i] = nil
end
else
for i = (#exprs + 1), n do
exprs[i] = utils.expr("nil", "literal")
end
end
end
end
if opts.tail then
emit(parent, string.format("return %s", exprs1(exprs)), ast)
end
if opts.target then
local result = exprs1(exprs)
local function _2_()
if (result == "") then
return "nil"
else
return result
end
end
emit(parent, string.format("%s = %s", opts.target, _2_()), ast)
end
if (opts.tail or opts.target) then
return {returned = true}
else
local _3_0 = exprs
_3_0["returned"] = true
return _3_0
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))
else
return t
end
end
local macro_2a = (utils["sym?"](ast[1]) and scope.macros[utils.deref(ast[1])])
if (not macro_2a and multi_sym_parts) then
local nested_macro = find_in_table(scope.macros, 1)
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
if utils["list?"](ast) then
_0_0 = find_macro(ast, scope, utils["multi-sym?"](ast[1]))
else
_0_0 = nil
end
if (_0_0 == false) then
return ast
elseif (nil ~= _0_0) then
local macro_2a = _0_0
local old_scope = scopes.macro
local _ = nil
scopes.macro = scope
_ = nil
local ok, transformed = nil, nil
local function _2_()
return macro_2a(unpack(ast, 2))
end
ok, transformed = xpcall(_2_, debug.traceback)
scopes.macro = old_scope
assert_compile(ok, transformed, ast)
if (once or not transformed) then
return transformed
else
return macroexpand_2a(transformed, scope)
end
else
local _ = _0_0
return ast
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
exprs0 = utils.expr(exprs, "expression")
else
exprs0 = exprs
end
local exprs2 = nil
if utils["expr?"](exprs0) then
exprs2 = {exprs0}
else
exprs2 = exprs0
end
if not exprs2.returned then
return handle_compile_opts(exprs2, parent, opts, ast)
elseif (opts.tail or opts.target) then
return {returned = true}
else
return exprs2
end
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)
for i = 2, len do
local subexprs = nil
local _0_
if (i ~= len) then
_0_ = 1
else
_0_ = nil
end
subexprs = compile1(ast[i], scope, parent, {nval = _0_})
table.insert(fargs, (subexprs[1] or utils.expr("nil", "literal")))
if (i == len) then
for j = 2, #subexprs do
table.insert(fargs, subexprs[j])
end
else
keep_side_effects(subexprs, parent, 2, ast[i])
end
end
local pat = nil
if ("string" == type(ast[1])) then
pat = "(%s)(%s)"
else
pat = "%s(%s)"
end
local call = string.format(pat, tostring(fcallee), exprs1(fargs))
return handle_compile_opts({utils.expr(call, "statement")}, parent, opts, ast)
end
local function compile_call(ast, scope, parent, opts, compile1)
utils.hook("call", ast, scope)
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)
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)))
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)
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
if (ast[1] == "nil") then
e = utils.expr("nil", "literal")
else
e = symbol_to_expression(ast, scope, true)
end
return handle_compile_opts({e}, parent, opts, ast)
end
local function serialize_number(n)
local _0_0 = string.gsub(tostring(n), ",", ".")
return _0_0
end
local function compile_scalar(ast, _scope, parent, opts)
local serialize = nil
do
local _0_0 = type(ast)
if (_0_0 == "nil") then
serialize = tostring
elseif (_0_0 == "boolean") then
serialize = tostring
elseif (_0_0 == "string") then
serialize = serialize_string
elseif (_0_0 == "number") then
serialize = serialize_number
else
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}
else
local _0_ = compile1(k, scope, parent, {nval = 1})
local compiled = _0_[1]
local kstr = ("[" .. tostring(compiled) .. "]")
return {kstr, k}
end
end
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])
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 ast0 = macroexpand_2a(ast, scope)
if utils["list?"](ast0) then
return compile_call(ast0, scope, parent, opts0, compile1)
elseif utils["varg?"](ast0) then
return compile_varg(ast0, scope, parent, opts0)
elseif utils["sym?"](ast0) then
return compile_sym(ast0, scope, parent, opts0)
elseif (type(ast0) == "table") then
return compile_table(ast0, scope, parent, opts0, 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)
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 symtype0 = ("_" .. (symtype or "dst"))
local setter = nil
if declaration then
setter = "local %s = %s"
else
setter = "%s = %s"
end
local new_manglings = {}
local function getname(symbol, up1)
local raw = symbol[1]
assert_compile(not (opts0.nomulti and utils["multi-sym?"](raw)), ("unexpected multi symbol " .. raw), up1)
if declaration then
return declare_local(symbol, nil, scope, symbol, new_manglings)
else
local parts = (utils["multi-sym?"](raw) or {raw})
local meta = scope.symmeta[parts[1]]
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)
end
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
if allowed_globals then
table.insert(allowed_globals, raw)
end
end
return symbol_to_expression(symbol, scope)[1]
end
end
local function compile_top_target(lvalues)
local inits = nil
local function _2_(_241)
if scope.manglings[_241] then
return _241
else
return "nil"
end
end
inits = utils.map(lvalues, _2_)
local init = table.concat(inits, ", ")
local lvalue = table.concat(lvalues, ", ")
local plen, plast = #parent, parent[#parent]
local ret = compile1(from, scope, parent, {target = lvalue})
if declaration then
for pi = plen, #parent do
if (parent[pi] == plast) then
plen = pi
end
end
if ((#parent == (plen + 1)) and parent[#parent].leaf) then
parent[#parent]["leaf"] = ("local " .. parent[#parent].leaf)
elseif (init == "nil") then
table.insert(parent, (plen + 1), {ast = ast, leaf = ("local " .. lvalue)})
else
table.insert(parent, (plen + 1), {ast = ast, leaf = ("local " .. lvalue .. " = " .. init)})
end
end
return ret
end
local function destructure_sym(left, rightexprs, up1, top_3f)
local lname = getname(left, up1)
check_binding_valid(left, scope, left)
if top_3f then
compile_top_target({lname})
else
emit(parent, setter:format(lname, exprs1(rightexprs)), left)
end
if declaration then
scope.symmeta[utils.deref(left)] = {var = isvar}
return nil
end
end
local function destructure_table(left, rightexprs, top_3f, destructure1)
local s = gensym(scope, symtype0)
local right = nil
do
local _2_0 = nil
if top_3f then
_2_0 = exprs1(compile1(from, scope, parent))
else
_2_0 = exprs1(rightexprs)
end
if (_2_0 == "") then
right = "nil"
elseif (nil ~= _2_0) then
local right0 = _2_0
right = right0
else
right = nil
end
end
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
destructure_sym(v, {utils.expr(tostring(s))}, left)
elseif (utils["sequence?"](left) and (utils.deref(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
if (type(k) == "string") then
key = serialize_string(k)
else
key = k
end
local subexpr = utils.expr(string.format("%s[%s]", s, key), "expression")
destructure1(v, {subexpr}, left)
end
end
end
return nil
end
local function destructure_values(left, up1, top_3f, destructure1)
local left_names, tables = {}, {}
for i, name in ipairs(left) do
if utils["sym?"](name) then
table.insert(left_names, getname(name, up1))
else
local symname = gensym(scope, symtype0)
table.insert(left_names, symname)
tables[i] = {name, utils.expr(symname, "sym")}
end
end
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}
end
end
end
for _, pair in utils.stablepairs(tables) do
destructure1(pair[1], {pair[2]}, left)
end
return nil
end
local function destructure1(left, rightexprs, up1, top_3f)
if (utils["sym?"](left) and (left[1] ~= "nil")) then
destructure_sym(left, rightexprs, up1, top_3f)
elseif utils["table?"](left) then
destructure_table(left, rightexprs, top_3f, destructure1)
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))
end
if top_3f then
return {returned = true}
end
end
local ret = destructure1(to, nil, ast, true)
utils.hook("destructure", from, to, scope)
apply_manglings(scope, new_manglings, ast)
return ret
end
local function require_include(ast, scope, parent, opts)
opts.fallback = function(e)
return utils.expr(string.format("require(%s)", tostring(e)), "statement")
end
return scopes.global.specials.include(ast, scope, parent, opts)
end
local function compile_stream(strm, options)
local opts = utils.copy(options)
local old_globals = allowed_globals
local scope = (opts.scope or make_scope(scopes.global))
local vals = {}
local chunk = {}
local _0_ = utils.root
_0_["set-reset"](_0_)
allowed_globals = opts.allowedGlobals
if (opts.indent == nil) then
opts.indent = " "
end
if opts.requireAsInclude then
scope.specials.require = require_include
end
utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts
for _, val in parser.parser(strm, opts.filename, opts) do
table.insert(vals, val)
end
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])
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 {}))
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_)
allowed_globals = opts0.allowedGlobals
if (opts0.indent == nil) then
opts0.indent = " "
end
if opts0.requireAsInclude then
scope.specials.require = require_include
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)
allowed_globals = old_globals
utils.root.reset()
return flatten(chunk, opts0)
end
local function traceback_frame(info)
if ((info.what == "C") and info.name) then
return string.format(" [C]: in function '%s'", info.name)
elseif (info.what == "C") then
return " [C]: in ?"
else
local remap = fennel_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
else
info.short_src = remap.short_src
end
info.currentline = (remap[info.currentline][2] or -1)
end
if (info.what == "Lua") then
local function _1_()
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_())
elseif (info.short_src == "(tail call)") then
return " (tail call)"
else
return string.format(" %s:%d: in main chunk", info.short_src, info.currentline)
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
else
local lines = {}
if (msg0:find("^Compile error") or msg0:find("^Parse error")) then
table.insert(lines, msg0)
else
local newmsg = msg0:gsub("^[^:]*:%d+:%s+", "runtime error: ")
table.insert(lines, newmsg)
end
table.insert(lines, "stack traceback:")
local done_3f, level = false, (start or 2)
while not done_3f do
do
local _1_0 = debug.getinfo(level, "Sln")
if (_1_0 == nil) then
done_3f = true
elseif (nil ~= _1_0) then
local info = _1_0
table.insert(lines, traceback_frame(info))
end
end
level = (level + 1)
end
return table.concat(lines, "\n")
end
end
local function entry_transform(fk, fv)
local function _0_(k, v)
if (type(k) == "number") then
return k, fv(v)
else
return fk(k), fv(v)
end
end
return _0_
end
local function mixed_concat(t, joiner)
local seen = {}
local ret, s = "", ""
for k, v in ipairs(t) do
table.insert(seen, k)
ret = (ret .. s .. v)
s = joiner
end
for k, v in utils.stablepairs(t) do
if not seen[k] then
ret = (ret .. s .. "[" .. k .. "]" .. "=" .. v)
s = joiner
end
end
return ret
end
local function do_quote(form, scope, parent, runtime_3f)
local function q(x)
return do_quote(x, scope, parent, runtime_3f)
end
if utils["varg?"](form) then
assert_compile(not runtime_3f, "quoted ... may only be used at compile time", form)
return "_VARARG"
elseif utils["sym?"](form) then
local filename = nil
if form.filename then
filename = string.format("%q", form.filename)
else
filename = "nil"
end
local symstr = utils.deref(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
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_()
return nil
end
mapped = utils.kvmap(form, entry_transform(_0_, q))
local filename = nil
if form.filename then
filename = string.format("%q", form.filename)
else
filename = "nil"
end
assert_compile(not runtime_3f, "lists may only be used at compile time", form)
return string.format(("setmetatable({filename=%s, line=%s, bytestart=%s, %s}" .. ", getmetatable(list()))"), filename, (form.line or "nil"), (form.bytestart or "nil"), mixed_concat(mapped, ", "))
elseif utils["sequence?"](form) then
local mapped = utils.kvmap(form, entry_transform(q, q))
local source = getmetatable(form)
local filename = nil
if source.filename then
filename = string.format("%q", source.filename)
else
filename = "nil"
end
local _1_
if source then
_1_ = source.line
else
_1_ = "nil"
end
return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _1_, "(getmetatable(sequence()))['sequence']")
elseif (type(form) == "table") then
local mapped = utils.kvmap(form, entry_transform(q, q))
local source = getmetatable(form)
local filename = nil
if source.filename then
filename = string.format("%q", source.filename)
else
filename = "nil"
end
local function _1_()
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_())
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}
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 unpack = (table.unpack or _G.unpack)
local function suggest(msg)
local suggestion = nil
for pat, sug in pairs(suggestions) do
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)))
end
suggestion = out
else
suggestion = sug(matches)
end
end
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())
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)
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))
end
end
return table.concat(out, "\n")
end
local function assert_compile(condition, msg, ast, source)
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)
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)
end
return {["assert-compile"] = assert_compile, ["parse-error"] = parse_error}
end
package.preload["nvim-tree-docs.aniseed.fennel.parser"] = package.preload["nvim-tree-docs.aniseed.fennel.parser"] or function(...)
local utils = require("nvim-tree-docs.aniseed.fennel.utils")
local friend = require("nvim-tree-docs.aniseed.fennel.friend")
local unpack = (table.unpack or _G.unpack)
local function granulate(getchunk)
local c, index, done_3f = "", 1, false
local function _0_(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 ~= ""))
end
if _4_ then
local char = _1_0
c = char
index = 2
return c:byte()
else
local _ = _1_0
done_3f = true
return nil
end
end
end
end
local function _1_()
c = ""
return nil
end
return _0_, _1_
end
local function string_stream(str)
local str0 = str:gsub("^#!", ";;")
local index = 1
local function _0_()
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)))
end
local function sym_char_3f(b)
local b0 = nil
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))
end
local prefixes = {[35] = "hashfn", [39] = "quote", [44] = "unquote", [96] = "quote"}
local function parser(getbyte, filename, options)
local stack = {}
local line = 1
local byteindex = 0
local lastb = nil
local function ungetb(ub)
if (ub == 10) then
line = (line - 1)
end
byteindex = (byteindex - 1)
lastb = ub
return nil
end
local function getb()
local r = nil
if lastb then
r, lastb = lastb, nil
else
r = getbyte({["stack-size"] = #stack})
end
byteindex = (byteindex + 1)
if (r == 10) then
line = (line + 1)
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)
else
return friend["parse-error"](msg, (filename or "unknown"), (line or "?"), (byteindex_override or byteindex), source)
end
end
local function parse_stream()
local whitespace_since_dispatch, done_3f, retval = true
local function dispatch(v)
local _0_0 = stack[#stack]
if (_0_0 == 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
do
local _1_0 = table.remove(stack)
_1_0["byteend"] = byteindex
source = _1_0
end
local list = utils.list(utils.sym(prefix, source), v)
for k, v0 in pairs(source) do
list[k] = v0
end
return dispatch(list)
elseif (nil ~= _0_0) then
local top = _0_0
whitespace_since_dispatch = false
return table.insert(top, v)
end
end
local function badend()
local accum = utils.map(stack, "closer")
local _0_
if (#stack == 1) then
_0_ = ""
else
_0_ = "s"
end
return parse_error(string.format("expected closing delimiter%s %s", _0_, 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
return badend()
else
return b
end
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
end
return parse_comment(getb(), _1_())
elseif (options and options.comments) then
return dispatch(utils.comment(table.concat(contents), {filename = filename, line = (line - 1)}))
else
return b
end
end
local function open_table(b)
if not whitespace_since_dispatch then
parse_error(("expected whitespace before opening delimiter " .. string.char(b)))
end
return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = filename, line = line})
end
local function close_list(list)
return dispatch(setmetatable(list, getmetatable(utils.list())))
end
local function close_sequence(tbl)
local val = utils.sequence(unpack(tbl))
for k, v in pairs(tbl) do
getmetatable(val)[k] = v
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
return table.insert(existing, node)
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))
else
return tbl[i]
end
end
local function extract_comments(tbl)
local comments = {keys = {}, last = {}, values = {}}
while utils["comment?"](tbl[#tbl]) do
table.insert(comments.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)
else
add_comment_at(comments.keys, next_noncomment(tbl, i), node)
end
end
for i = #tbl, 1, -1 do
if utils["comment?"](tbl[i]) then
table.remove(tbl, i)
end
end
return comments
end
local function close_curly_table(tbl)
local comments = 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")
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)])
end
val[tbl[i]] = tbl[(i + 1)]
table.insert(keys, tbl[i])
end
tbl.comments = comments
tbl.keys = keys
return dispatch(val)
end
local function close_table(b)
local top = table.remove(stack)
if (top == nil) then
parse_error(("unexpected closing delimiter " .. string.char(b)))
end
if (top.closer and (top.closer ~= b)) then
parse_error(("mismatched closing delimiter " .. string.char(b) .. ", expected " .. string.char(top.closer)))
end
top.byteend = byteindex
if (b == 41) then
return close_list(top)
elseif (b == 93) then
return close_sequence(top)
else
return close_curly_table(top)
end
end
local function parse_string_loop(chars, b, state)
table.insert(chars, b)
local state0 = nil
do
local _0_0 = {state, b}
if ((type(_0_0) == "table") and (_0_0[1] == "base") and (_0_0[2] == 92)) then
state0 = "backslash"
elseif ((type(_0_0) == "table") and (_0_0[1] == "base") and (_0_0[2] == 34)) then
state0 = "done"
else
local _ = _0_0
state0 = "base"
end
end
if (b and (state0 ~= "done")) then
return parse_string_loop(chars, getb(), state0)
else
return b
end
end
local function escape_char(c)
return ({nil, nil, nil, nil, nil, nil, "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\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()
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
return dispatch(load_fn())
elseif (_1_0 == nil) then
return parse_error(("Invalid string: " .. raw))
end
end
local function parse_prefix(b)
table.insert(stack, {bytestart = byteindex, filename = filename, line = line, prefix = prefixes[b]})
local nextb = getb()
if (whitespace_3f(nextb) or (true == delims[nextb])) then
if (b ~= 35) then
parse_error("invalid whitespace after quoting prefix")
end
table.remove(stack)
dispatch(utils.sym("#"))
end
return ungetb(nextb)
end
local function parse_sym_loop(chars, b)
if (b and sym_char_3f(b)) then
table.insert(chars, b)
return parse_sym_loop(chars, getb())
else
if b then
ungetb(b)
end
return chars
end
end
local function parse_number(rawstr)
local number_with_stripped_underscores = (not rawstr:find("^_") and rawstr:gsub("_", ""))
if rawstr:match("^%d") then
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
dispatch(x)
return true
else
local _ =
gitextract_uscgubcz/
├── .gitignore
├── Makefile
├── README.md
├── fnl/
│ └── nvim-tree-docs/
│ ├── collector.fnl
│ ├── editing.fnl
│ ├── internal.fnl
│ ├── macros.fnl
│ ├── main.fnl
│ ├── specs/
│ │ ├── base/
│ │ │ └── base.fnl
│ │ ├── javascript/
│ │ │ └── jsdoc.fnl
│ │ ├── lua/
│ │ │ └── luadoc.fnl
│ │ └── typescript/
│ │ └── tsdoc.fnl
│ ├── template.fnl
│ └── utils.fnl
├── lua/
│ └── nvim-tree-docs/
│ ├── aniseed/
│ │ ├── autoload.lua
│ │ ├── compile.lua
│ │ ├── core.lua
│ │ ├── deps/
│ │ │ ├── fennel.lua
│ │ │ ├── fennelview.lua
│ │ │ └── nvim.lua
│ │ ├── env.lua
│ │ ├── eval.lua
│ │ ├── fennel.lua
│ │ ├── fs.lua
│ │ ├── macros.fnl
│ │ ├── nvim/
│ │ │ └── util.lua
│ │ ├── nvim.lua
│ │ ├── string.lua
│ │ ├── test.lua
│ │ └── view.lua
│ ├── collector.lua
│ ├── editing.lua
│ ├── internal.lua
│ ├── macros.fnl
│ ├── main.lua
│ ├── specs/
│ │ ├── base/
│ │ │ └── base.lua
│ │ ├── javascript/
│ │ │ └── jsdoc.lua
│ │ ├── lua/
│ │ │ └── luadoc.lua
│ │ └── typescript/
│ │ └── tsdoc.lua
│ ├── template.lua
│ └── utils.lua
├── plugin/
│ └── nvim-tree-docs.vim
├── queries/
│ ├── ecma/
│ │ └── docs.scm
│ ├── javascript/
│ │ └── docs.scm
│ ├── javascriptreact/
│ │ └── docs.scm
│ ├── jsdoc/
│ │ └── edits.scm
│ ├── jsx/
│ │ └── docs.scm
│ ├── lua/
│ │ └── docs.scm
│ ├── python/
│ │ └── docs.scm
│ ├── tsx/
│ │ └── docs.scm
│ ├── typescript/
│ │ └── docs.scm
│ └── typescriptreact/
│ └── docs.scm
├── scripts/
│ └── dep.sh
└── test/
└── fnl/
└── example/
└── main-test.fnl
Condensed preview — 54 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (384K chars).
[
{
"path": ".gitignore",
"chars": 46,
"preview": "/deps/\n/test/results.txt\n/test/lua/\n/doc/tags\n"
},
{
"path": "Makefile",
"chars": 502,
"preview": ".PHONY: deps compile test\n\ndefault: deps compile test\n\ndeps:\n\tscripts/dep.sh Olical aniseed origin/master\n\ncompile:\n\trm "
},
{
"path": "README.md",
"chars": 9478,
"preview": "nvim-tree-docs\n==============\n\nHighly configurable documentation generator using treesitter.\n\nThis plugin is experimenta"
},
{
"path": "fnl/nvim-tree-docs/collector.fnl",
"chars": 2930,
"preview": "(module nvim-tree-docs.collector\n {autoload {core nvim-tree-docs.aniseed.core}})\n\n(def- collector-metatable\n {:__index"
},
{
"path": "fnl/nvim-tree-docs/editing.fnl",
"chars": 1455,
"preview": "(module nvim-tree-docs.editing\n {autoload {ts-utils nvim-treesitter.ts_utils\n tsq vim.treesitter.query}})\n\n"
},
{
"path": "fnl/nvim-tree-docs/internal.fnl",
"chars": 8080,
"preview": "(module nvim-tree-docs.internal\n {autoload {utils nvim-tree-docs.utils\n core nvim-tree-docs.aniseed.core\n "
},
{
"path": "fnl/nvim-tree-docs/macros.fnl",
"chars": 3330,
"preview": "(local modsym (gensym))\n\n(fn doc-spec [config]\n \"Defines a documentation specification\"\n (assert config.lang \"A langua"
},
{
"path": "fnl/nvim-tree-docs/main.fnl",
"chars": 450,
"preview": "(module nvim-tree-docs.main\n {autoload {queries nvim-treesitter.query\n ts nvim-treesitter}})\n\n(defn init []"
},
{
"path": "fnl/nvim-tree-docs/specs/base/base.fnl",
"chars": 456,
"preview": "(require-macros \"nvim-tree-docs.macros\")\n\n(doc-spec\n {:spec base\n :lang base})\n\n(processor %rest%\n implicit true\n e"
},
{
"path": "fnl/nvim-tree-docs/specs/javascript/jsdoc.fnl",
"chars": 4498,
"preview": "(require-macros \"nvim-tree-docs.macros\")\n\n(doc-spec\n {:spec jsdoc\n :lang javascript\n :doc-lang jsdoc\n :config {:i"
},
{
"path": "fnl/nvim-tree-docs/specs/lua/luadoc.fnl",
"chars": 700,
"preview": "(require-macros \"nvim-tree-docs.macros\")\n\n(doc-spec\n {:spec luadoc\n :lang lua\n :config {:slots {:function {:param t"
},
{
"path": "fnl/nvim-tree-docs/specs/typescript/tsdoc.fnl",
"chars": 690,
"preview": "(require-macros \"nvim-tree-docs.macros\")\n\n(doc-spec\n {:spec tsdoc\n :lang typescript\n :extends javascript.jsdoc\n :"
},
{
"path": "fnl/nvim-tree-docs/template.fnl",
"chars": 8288,
"preview": "(module nvim-tree-docs.template\n {autoload {core nvim-tree-docs.aniseed.core\n utils nvim-tree-docs.utils\n "
},
{
"path": "fnl/nvim-tree-docs/utils.fnl",
"chars": 2390,
"preview": "(module nvim-tree-docs.utils\n {autoload {core nvim-tree-docs.aniseed.core}})\n\n(def ns (vim.api.nvim_create_namespace \"b"
},
{
"path": "lua/nvim-tree-docs/aniseed/autoload.lua",
"chars": 2023,
"preview": "local _2afile_2a = \"fnl/aniseed/autoload.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.autoload\"\n local m"
},
{
"path": "lua/nvim-tree-docs/aniseed/compile.lua",
"chars": 3949,
"preview": "local _2afile_2a = \"fnl/aniseed/compile.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.compile\"\n local mod"
},
{
"path": "lua/nvim-tree-docs/aniseed/core.lua",
"chars": 18024,
"preview": "local _2afile_2a = \"fnl/aniseed/core.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.core\"\n local module_0_"
},
{
"path": "lua/nvim-tree-docs/aniseed/deps/fennel.lua",
"chars": 166084,
"preview": "package.preload[\"nvim-tree-docs.aniseed.fennel.repl\"] = package.preload[\"nvim-tree-docs.aniseed.fennel.repl\"] or functio"
},
{
"path": "lua/nvim-tree-docs/aniseed/deps/fennelview.lua",
"chars": 10557,
"preview": "local type_order = {[\"function\"] = 5, boolean = 2, number = 1, string = 3, table = 4, thread = 7, userdata = 6}\nlocal fu"
},
{
"path": "lua/nvim-tree-docs/aniseed/deps/nvim.lua",
"chars": 7391,
"preview": "-- Bring vim into local scope.\nlocal vim = vim\nlocal api = vim.api\nlocal inspect = vim.inspect\n\nlocal function extend(t,"
},
{
"path": "lua/nvim-tree-docs/aniseed/env.lua",
"chars": 3246,
"preview": "local _2afile_2a = \"fnl/aniseed/env.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.env\"\n local module_0_\n "
},
{
"path": "lua/nvim-tree-docs/aniseed/eval.lua",
"chars": 2068,
"preview": "local _2afile_2a = \"fnl/aniseed/eval.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.eval\"\n local module_0_"
},
{
"path": "lua/nvim-tree-docs/aniseed/fennel.lua",
"chars": 2862,
"preview": "local _2afile_2a = \"fnl/aniseed/fennel.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.fennel\"\n local modul"
},
{
"path": "lua/nvim-tree-docs/aniseed/fs.lua",
"chars": 3636,
"preview": "local _2afile_2a = \"fnl/aniseed/fs.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.fs\"\n local module_0_\n d"
},
{
"path": "lua/nvim-tree-docs/aniseed/macros.fnl",
"chars": 4475,
"preview": ";; All of Aniseed's macros in one place.\n;; Can't be compiled to Lua directly.\n\n;; Automatically loaded through require-"
},
{
"path": "lua/nvim-tree-docs/aniseed/nvim/util.lua",
"chars": 3082,
"preview": "local _2afile_2a = \"fnl/aniseed/nvim/util.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.nvim.util\"\n local"
},
{
"path": "lua/nvim-tree-docs/aniseed/nvim.lua",
"chars": 1106,
"preview": "local _2afile_2a = \"fnl/aniseed/nvim.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.nvim\"\n local module_0_"
},
{
"path": "lua/nvim-tree-docs/aniseed/string.lua",
"chars": 3976,
"preview": "local _2afile_2a = \"fnl/aniseed/string.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.string\"\n local modul"
},
{
"path": "lua/nvim-tree-docs/aniseed/test.lua",
"chars": 6890,
"preview": "local _2afile_2a = \"fnl/aniseed/test.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.test\"\n local module_0_"
},
{
"path": "lua/nvim-tree-docs/aniseed/view.lua",
"chars": 1400,
"preview": "local _2afile_2a = \"fnl/aniseed/view.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.aniseed.view\"\n local module_0_"
},
{
"path": "lua/nvim-tree-docs/collector.lua",
"chars": 6494,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/collector.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.collector\"\n local "
},
{
"path": "lua/nvim-tree-docs/editing.lua",
"chars": 3501,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/editing.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.editing\"\n local modu"
},
{
"path": "lua/nvim-tree-docs/internal.lua",
"chars": 15489,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/internal.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.internal\"\n local mo"
},
{
"path": "lua/nvim-tree-docs/macros.fnl",
"chars": 3330,
"preview": "(local modsym (gensym))\n\n(fn doc-spec [config]\n \"Defines a documentation specification\"\n (assert config.lang \"A langua"
},
{
"path": "lua/nvim-tree-docs/main.lua",
"chars": 1787,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/main.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.main\"\n local module_0_\n"
},
{
"path": "lua/nvim-tree-docs/specs/base/base.lua",
"chars": 1123,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/specs/base/base.fnl\"\nlocal _1_\ndo\n local mod_name_0_ = (\"base\" .. \".\" .. \"base\")"
},
{
"path": "lua/nvim-tree-docs/specs/javascript/jsdoc.lua",
"chars": 6445,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/specs/javascript/jsdoc.fnl\"\nlocal _1_\ndo\n local mod_name_0_ = (\"javascript\" .. \""
},
{
"path": "lua/nvim-tree-docs/specs/lua/luadoc.lua",
"chars": 1344,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/specs/lua/luadoc.fnl\"\nlocal _1_\ndo\n local mod_name_0_ = (\"lua\" .. \".\" .. \"luadoc"
},
{
"path": "lua/nvim-tree-docs/specs/typescript/tsdoc.lua",
"chars": 1012,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/specs/typescript/tsdoc.fnl\"\nlocal _1_\ndo\n local mod_name_0_ = (\"typescript\" .. \""
},
{
"path": "lua/nvim-tree-docs/template.lua",
"chars": 15878,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/template.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.template\"\n local mo"
},
{
"path": "lua/nvim-tree-docs/utils.lua",
"chars": 9021,
"preview": "local _2afile_2a = \"fnl/nvim-tree-docs/utils.fnl\"\nlocal _0_\ndo\n local name_0_ = \"nvim-tree-docs.utils\"\n local module_0"
},
{
"path": "plugin/nvim-tree-docs.vim",
"chars": 65,
"preview": "if has(\"nvim\")\n lua require(\"nvim-tree-docs.main\").init()\nendif\n"
},
{
"path": "queries/ecma/docs.scm",
"chars": 3238,
"preview": "; ECMAScript base\n\n; ---- Functions\n\n[\n (function_declaration name: (identifier) @function.name)\n (generator_function_"
},
{
"path": "queries/javascript/docs.scm",
"chars": 1923,
"preview": "; inherits: ecma\n; Javascript\n\n; ---- Functions\n\n; Function param name\n[\n (function_declaration\n parameters: (formal"
},
{
"path": "queries/javascriptreact/docs.scm",
"chars": 23,
"preview": "; inherits: javascript\n"
},
{
"path": "queries/jsdoc/edits.scm",
"chars": 39,
"preview": "(tag (type) @edit)\n(description) @edit\n"
},
{
"path": "queries/jsx/docs.scm",
"chars": 23,
"preview": "; inherits: javascript\n"
},
{
"path": "queries/lua/docs.scm",
"chars": 719,
"preview": "; Nonlocal functions `function M.test() end`\n; Local functions `local function test() end`\n(function_declaration\n name:"
},
{
"path": "queries/python/docs.scm",
"chars": 245,
"preview": "(function_definition\n name: (identifier) @function.name) @function.definition\n\n(function_definition\n parameters: (para"
},
{
"path": "queries/tsx/docs.scm",
"chars": 23,
"preview": "; inherits: typescript\n"
},
{
"path": "queries/typescript/docs.scm",
"chars": 5979,
"preview": "; inherits: ecma\n\n; ---- Functions\n\n; Function generics\n(function_declaration\n type_parameters: (type_parameters\n (t"
},
{
"path": "queries/typescriptreact/docs.scm",
"chars": 23,
"preview": "; inherits: typescript\n"
},
{
"path": "scripts/dep.sh",
"chars": 465,
"preview": "#!/usr/bin/env bash\n\n# Clones a GitHub repo into deps/{name} if it's not there already.\n# Will update the repository eac"
},
{
"path": "test/fnl/example/main-test.fnl",
"chars": 95,
"preview": "(module example.main-test)\n\n(deftest something-simple\n (t.= 1 1 \"1 should equal 1, I hope!\"))\n"
}
]
About this extraction
This page contains the full source code of the nvim-treesitter/nvim-tree-docs GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 54 files (353.9 KB), approximately 109.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.