Skip to content

TreeSitter

module TreeSitter
AssemblyNacara.Plugin.Highlight.TreeSitter
Attributes[<RequireQualifiedAccess>]

Declared inside

TreeSitterHighlighterA highlighter backed by tree-sitter grammars compiled to wasm

Functions and values

aliases (names: string list) (grammar: TreeSitterGrammar) : TreeSitterGrammar

Names this grammar answers to besides its own.

Parameter
namesThe other names a fence may write.
grammarThe grammar so far.
autoBuild (value: bool) (options: TreeSitterOptions) : TreeSitterOptions

Build a grammar named by repository when it is not already built.

Parameter
valueThe value to use.
optionsThe options so far.
browser (value: string list) (options: TreeSitterOptions) : TreeSitterOptions

The languages <nacara-highlight> can colour in the browser.

Parameter
valueThe value to use.
optionsThe options so far.
browserAssets (languages: string list) : Result<TreeSitterBrowserAssets,string>

Everything a browser needs to colour these languages, with the grammars this package ships.

Parameter
languagesThe languages to emit a grammar for.
browserAssetsWith (options: TreeSitterOptions) (languages: string list) : Result<TreeSitterBrowserAssets,string>

Everything a browser needs to colour these languages itself.

The wasm build of tree-sitter is fetched once per machine, and a grammar is read from wherever the options say it comes from - the same place the build reads it.

Parameter
optionsWhich grammar is which, and what may be fetched or built.
languagesThe languages to emit a grammar for.

Returns. What to emit and what the browser can ask for, or why none of it could be had.

bundled (language: string) : TreeSitterGrammar

One of the grammars this package ships.

bundledGrammar (language: string) : byte array

The parse tables of a shipped language, gzipped as they are stored.

Parameter
languageThe language whose grammar is wanted.
bundledLanguages: Lazy<string list>

The languages this package ships a grammar for.

Inside the assembly, so the first site built on a machine colours its F#, its shell commands and its configuration files without compiling anything.

bundledQueries (language: string) : byte array

The queries a shipped language is coloured by, with any it builds on.

What the language adds comes last: a later pattern wins the bytes it covers, so a node both queries claim is coloured the way the more specific one asked.

Parameter
languageThe language whose queries are wanted.
classMap (queries: string) : (string * string) list

Every capture the queries use, paired with the class the build would give it.

Read out of the queries and answered by className, so a browser colours a block the way the build coloured the one above it. Deriving it beats copying the table into JavaScript, where the two would drift apart the first time a capture was added.

Parameter
queriesThe highlights query of a grammar.
className (capture: string) : string option

What a capture name means to the theme.

Capture names are a convention rather than a standard, and they nest: variable.parameter falls back to variable when nothing claims the whole of it. What comes out is the vocabulary the stylesheet is written against.

cliSource (value: string) (options: TreeSitterOptions) : TreeSitterOptions

Where the tree-sitter CLI is published, with {version} and {platform} in it.

Parameter
valueThe value to use.
optionsThe options so far.
continuedFrom (text: string) (grammar: TreeSitterGrammar) : TreeSitterGrammar

What a snippet of this language continues from, when it is a fragment.

Parameter
textWhat to parse ahead of the snippet, so a fragment stands alone.
grammarThe grammar so far.
create () : IPlugin

The plugin, with the grammars this package ships.

createWith (configure: TreeSitterOptions -> TreeSitterOptions) : IPlugin

The plugin, configured.

fromGitHub (language: string) (repository: string) (reference: string) : TreeSitterGrammar

A grammar, from the repository it lives in.

Fetched and compiled to wasm the first time, then kept. Nothing has to be installed, and nothing installed is used.

Parameter
languageWhat a fence writes after its backticks.
repositoryThe repository, as its web address.
referenceA branch, a tag or a commit. A commit is the one that cannot move under a site.
grammar (language: string) (wasm: string) (queries: string) : TreeSitterGrammar

A grammar, from the two files it takes.

Parameter
languageThe name a fence writes to ask for it.
wasmThe compiled grammar.
queriesThe highlights query saying what its nodes mean.
grammars (value: TreeSitterGrammar list) (options: TreeSitterOptions) : TreeSitterOptions

The grammars to load, one per language.

Parameter
valueThe value to use.
optionsThe options so far.
inDirectory (subdirectory: string) (grammar: TreeSitterGrammar) : TreeSitterGrammar

Which directory of the repository holds the grammar, when it is not the top one.

Parameter
subdirectoryWhere in the repository the grammar lives.
grammarThe grammar so far.
namesOf (grammar: TreeSitterGrammar) : Set<string>

Every name a grammar answers to: its own, the ones it lists, and their family.

queriesAt (path: string) (grammar: TreeSitterGrammar) : TreeSitterGrammar

Which file of the repository says what the nodes mean, when it is not where they usually are.

Parameter
pathWhere the highlights query is, inside the repository.
grammarThe grammar so far.
register (site: Site) : Site

Colour code blocks with the grammars this package ships.

registerWith (configure: TreeSitterOptions -> TreeSitterOptions) (site: Site) : Site

Colour code blocks with tree-sitter, with languages of your own.

Parameter
configureGiven the defaults, the options to use.
siteThe site you are describing.
runtimePath (value: string option) (options: TreeSitterOptions) : TreeSitterOptions

Where the two native libraries are: tree-sitter and wasmtime.

Parameter
valueThe value to use.
optionsThe options so far.
runtimeSource (value: string) (options: TreeSitterOptions) : TreeSitterOptions

Where that pair is published, with {version} and {rid} in it.

Parameter
valueThe value to use.
optionsThe options so far.
useBundledGrammars (value: bool) (options: TreeSitterOptions) : TreeSitterOptions

Fall back to the grammars this package ships.

Parameter
valueThe value to use.
optionsThe options so far.
wasiSdkSource (value: string) (options: TreeSitterOptions) : TreeSitterOptions

Where the wasi-sdk is published, with {major}, {version} and {platform} in it.

Parameter
valueThe value to use.
optionsThe options so far.