Documentation ¶
Overview ¶
Package forest makes all the parsers, queries and filetype detection.
This includes every single parser, as long as it is not pending (even new/experimental, etc.).
The parsers, queries and filetype detection work in tandem: the exact same language returned by filetype detection, can be used to pull in the language parser as well as the corresponding queries.
Index ¶
- Constants
- func DetectLanguage(fpath string) string
- func GetLanguage(lang string) (l *sitter.Language)
- func GetQuery(lang, kind string, opts ...byte) (out []byte)
- func Info(lang string) (gr *grammar.Grammar)
- func RegisterLanguage(pat, lang string) error
- func SupportedLanguage(lang string) bool
- func SupportedLanguages() []string
Examples ¶
Constants ¶
const ( NvimFirst byte // Fetch both, prefer nvim. NativeFirst // Fetch both, prefer native. NvimOnly // Fetch only from nvim. NativeOnly // Fetch only from sitter repo. )
Query fetching preference.
Variables ¶
This section is empty.
Functions ¶
func DetectLanguage ¶ added in v1.5.105
DetectLanguage detects the language name based on given file path. The given fpath should preferably be the absolute path as that guarantees that all the detectors can be used. It can however work with relative paths, the filename or even with just the file extension (including leading dot) alone. However the success rate will correspondingly be reduced due to the inability to use all the detectors available.
func GetLanguage ¶ added in v1.5.11
GetLanguage returns the corresponding TS language function for given lang, and caches it so that language copies are not created unnecessarily.
Example ¶
package main import ( "context" "fmt" "github.com/alexaandru/go-sitter-forest/lua" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { content := []byte("print('It works!')\n") node, err := sitter.Parse(context.TODO(), content, sitter.NewLanguage(lua.GetLanguage())) if err != nil { panic(err) } // Do something interesting with the parsed tree... fmt.Println(node) }
Output: (chunk (function_call name: (identifier) arguments: (arguments (string content: (string_content)))))
func GetQuery ¶ added in v1.5.89
GetQuery returns (if it exists) the `kind`.scm query for `lang` language, using the DefaultPreference, resolving "inherits" directives, recursively. You should omit the ".scm" extension.
func Info ¶
Info returns the language parser (grammar) related information. TODO: Hmm, now that we also have queries, should it include info about them too? Or offer a similar function?
Example ¶
This is still an example for GetLanguage, but I cannot have two ExampleGetLanguage in the same package.
package main import ( "context" "fmt" forest "github.com/alexaandru/go-sitter-forest" sitter "github.com/alexaandru/go-tree-sitter-bare" ) func main() { content := []byte("print('It works!')") parser := sitter.NewParser() parser.SetLanguage(forest.GetLanguage("lua")) tree, err := parser.ParseString(context.TODO(), nil, content) if err != nil { panic(err) } // Do something interesting with the parsed tree... fmt.Println(tree.RootNode()) }
Output: (chunk (function_call name: (identifier) arguments: (arguments (string content: (string_content)))))
func RegisterLanguage ¶ added in v1.5.107
RegisterLanguage allows end users to register their own mappings, potentially overriding existing ones. Typical use would be for languages not maintained by this library, or overriding ambiguous ones (i.e. v vs verilog for `v`, ldg or ledger for `ldg`, etc.).
The pattern pat can be a glob, a path, a filename or a file extension (including the leading dot).
func SupportedLanguage ¶ added in v1.5.119
SupportedLanguage checks if the given language is supported.
func SupportedLanguages ¶ added in v1.5.11
func SupportedLanguages() []string
SupportedLanguages returns the list of supported languages' names.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
abap
module
|
|
abl
module
|
|
ada
module
|
|
agda
module
|
|
aiken
module
|
|
al
module
|
|
alcha
module
|
|
amber
module
|
|
angular
module
|
|
animationtxt
module
|
|
ansible
module
|
|
anzu
module
|
|
apex
module
|
|
applesoft
module
|
|
arduino
module
|
|
asciidoc
module
|
|
asciidoc_inline
module
|
|
asm
module
|
|
astro
module
|
|
august
module
|
|
authzed
module
|
|
awa5_rs
module
|
|
awatalk
module
|
|
awk
module
|
|
bara
module
|
|
bash
module
|
|
bass
module
|
|
beancount
module
|
|
bend
module
|
|
bibtex
module
|
|
bicep
module
|
|
bitbake
module
|
|
blade
module
|
|
blueprint
module
|
|
bluespec
module
|
|
bond
module
|
|
bp
module
|
|
bqn
module
|
|
brightscript
module
|
|
bruno
module
|
|
c
module
|
|
c3
module
|
|
c_sharp
module
|
|
ca65
module
|
|
cairo
module
|
|
calc
module
|
|
capnp
module
|
|
carbon
module
|
|
cds
module
|
|
cedar
module
|
|
cel
module
|
|
cerium
module
|
|
cfengine
module
|
|
cg
module
|
|
cgsql
module
|
|
chatito
module
|
|
circom
module
|
|
clarity
module
|
|
cleancopy
module
|
|
clingo
module
|
|
clojure
module
|
|
cloudflare
module
|
|
cmake
module
|
|
cmdl
module
|
|
cobol
module
|
|
cognate
module
|
|
comment
module
|
|
commonlisp
module
|
|
context
module
|
|
cooklang
module
|
|
core
module
|
|
corn
module
|
|
cpon
module
|
|
cpp
module
|
|
crystal
module
|
|
css
module
|
|
csv
module
|
|
cuda
module
|
|
cue
module
|
|
cylc
module
|
|
d
module
|
|
d2
module
|
|
dale
module
|
|
dart
module
|
|
dataweave
module
|
|
dbml
module
|
|
desktop
module
|
|
devicetree
module
|
|
dezyne
module
|
|
dhall
module
|
|
diff
module
|
|
disassembly
module
|
|
djot
module
|
|
djot_inline
module
|
|
dockerfile
module
|
|
dot
module
|
|
dotenv
module
|
|
doxygen
module
|
|
dtd
module
|
|
dune
module
|
|
earthfile
module
|
|
ebnf
module
|
|
editorconfig
module
|
|
eds
module
|
|
eex
module
|
|
effekt
module
|
|
eiffel
module
|
|
elisp
module
|
|
elixir
module
|
|
elm
module
|
|
elsa
module
|
|
elvish
module
|
|
embedded_template
module
|
|
epics_cmd
module
|
|
epics_db
module
|
|
epics_msi_substitution
module
|
|
epics_msi_template
module
|
|
erlang
module
|
|
facility
module
|
|
familymarkup
module
|
|
fastbuild
module
|
|
faust
module
|
|
fe
module
|
|
fennel
module
|
|
fidl
module
|
|
fin
module
|
|
firrtl
module
|
|
fish
module
|
|
flamingo
module
|
|
fluentbit
module
|
|
foam
module
|
|
forth
module
|
|
fortran
module
|
|
fsh
module
|
|
fsharp
module
|
|
fsharp_signature
module
|
|
func
module
|
|
fusion
module
|
|
gab
module
|
|
galvan
module
|
|
gap
module
|
|
gaptst
module
|
|
gdscript
module
|
|
gdshader
module
|
|
gemfilelock
module
|
|
gherkin
module
|
|
git_config
module
|
|
git_rebase
module
|
|
gitattributes
module
|
|
gitcommit
module
|
|
gitignore
module
|
|
gleam
module
|
|
glimmer
module
|
|
glimmer_javascript
module
|
|
glimmer_typescript
module
|
|
glint
module
|
|
glsl
module
|
|
gn
module
|
|
gnuplot
module
|
|
go
module
|
|
gobra
module
|
|
goctl
module
|
|
godot_resource
module
|
|
gomod
module
|
|
gooscript
module
|
|
gosum
module
|
|
gotmpl
module
|
|
gowork
module
|
|
gpg
module
|
|
gram
module
|
|
graphql
module
|
|
gren
module
|
|
gritql
module
|
|
groovy
module
|
|
gstlaunch
module
|
|
hack
module
|
|
haml
module
|
|
hare
module
|
|
haskell
module
|
|
haskell_persistent
module
|
|
haxe
module
|
|
hcl
module
|
|
heex
module
|
|
helm
module
|
|
hjson
module
|
|
hl7
module
|
|
hlsl
module
|
|
hlsplaylist
module
|
|
hocon
module
|
|
hoon
module
|
|
html
module
|
|
htmlaskama
module
|
|
htmldjango
module
|
|
http
module
|
|
http2
module
|
|
hungarian
module
|
|
hurl
module
|
|
hy
module
|
|
hygen_template
module
|
|
hylo
module
|
|
hyprlang
module
|
|
i3config
module
|
|
idl
module
|
|
idris
module
|
|
ignis
module
|
|
ini
module
|
|
ink
module
|
|
inko
module
|
|
integerbasic
module
|
|
internal
|
|
automation/grammar
Package grammar holds the main structure that the automation operates with: the Grammar.
|
Package grammar holds the main structure that the automation operates with: the Grammar. |
automation/util
Package util holds a few useful functions both for the forest package as well as for automation.
|
Package util holds a few useful functions both for the forest package as well as for automation. |
ispc
module
|
|
jai
module
|
|
janet
module
|
|
janet_simple
module
|
|
jasmin
module
|
|
java
module
|
|
javascript
module
|
|
jinja
module
|
|
jinja_inline
module
|
|
jq
module
|
|
jsdoc
module
|
|
json
module
|
|
json5
module
|
|
jsonc
module
|
|
jsonnet
module
|
|
jule
module
|
|
julia
module
|
|
just
module
|
|
kamailio_cfg
module
|
|
kanshi
module
|
|
kappa
module
|
|
kcl
module
|
|
kconfig
module
|
|
kdl
module
|
|
koan
module
|
|
koka
module
|
|
kon
module
|
|
kos
module
|
|
kotlin
module
|
|
koto
module
|
|
kusto
module
|
|
lalrpop
module
|
|
lart
module
|
|
lat
module
|
|
latex
module
|
|
latte
module
|
|
ldg
module
|
|
ledger
module
|
|
leo
module
|
|
lexc
module
|
|
lexd
module
|
|
lilypond
module
|
|
lilypond_scheme
module
|
|
linkerscript
module
|
|
liquid
module
|
|
liquidsoap
module
|
|
lithia
module
|
|
llvm
module
|
|
lookml
module
|
|
lox
module
|
|
lua
module
|
|
luadoc
module
|
|
luap
module
|
|
luau
module
|
|
m68k
module
|
|
magik
module
|
|
make
module
|
|
mandbconfig
module
|
|
markdown
module
|
|
markdown_inline
module
|
|
marte
module
|
|
matlab
module
|
|
mcfuncx
module
|
|
menhir
module
|
|
merlin6502
module
|
|
mermaid
module
|
|
meson
module
|
|
mlir
module
|
|
modelica
module
|
|
moonbit
module
|
|
moonscript
module
|
|
motoko
module
|
|
move
module
|
|
move_on_aptos
module
|
|
mustache
module
|
|
muttrc
module
|
|
mxml
module
|
|
mylang
module
|
|
nasm
module
|
|
nelua
module
|
|
nesfab
module
|
|
nftables
module
|
|
nginx
module
|
|
nickel
module
|
|
nim
module
|
|
nim_format_string
module
|
|
ninja
module
|
|
nix
module
|
|
norg
module
|
|
note
module
|
|
nqc
module
|
|
nu
module
|
|
objc
module
|
|
objdump
module
|
|
ocaml
module
|
|
ocaml_interface
module
|
|
ocamllex
module
|
|
odin
module
|
|
org
module
|
|
ott
module
|
|
pact
module
|
|
pascal
module
|
|
passwd
module
|
|
pdxinfo
module
|
|
pem
module
|
|
perl
module
|
|
perm
module
|
|
pgn
module
|
|
php
module
|
|
php_only
module
|
|
phpdoc
module
|
|
pic
module
|
|
pint
module
|
|
pioasm
module
|
|
pkl
module
|
|
plantuml
module
|
|
po
module
|
|
pod
module
|
|
poe_filter
module
|
|
pony
module
|
|
postscript
module
|
|
poweron
module
|
|
powershell
module
|
|
printf
module
|
|
prisma
module
|
|
problog
module
|
|
prolog
module
|
|
promql
module
|
|
properties
module
|
|
proto
module
|
|
proxima
module
|
|
prql
module
|
|
psv
module
|
|
pug
module
|
|
puppet
module
|
|
purescript
module
|
|
pymanifest
module
|
|
pyrope
module
|
|
python
module
|
|
qbe
module
|
|
ql
module
|
|
qmldir
module
|
|
qmljs
module
|
|
quakec
module
|
|
query
module
|
|
quint
module
|
|
r
module
|
|
racket
module
|
|
ralph
module
|
|
rasi
module
|
|
rbs
module
|
|
rcl
module
|
|
re2c
module
|
|
readline
module
|
|
regex
module
|
|
rego
module
|
|
requirements
module
|
|
rescript
module
|
|
risor
module
|
|
rnoweb
module
|
|
robot
module
|
|
robots
module
|
|
roc
module
|
|
ron
module
|
|
rstml
module
|
|
rsx
module
|
|
rtx
module
|
|
ruby
module
|
|
runescript
module
|
|
rust
module
|
|
rust_with_rstml
module
|
|
sage
module
|
|
scala
module
|
|
scfg
module
|
|
scheme
module
|
|
scss
module
|
|
sdml
module
|
|
sflog
module
|
|
simula
module
|
|
sincere
module
|
|
slang
module
|
|
slim
module
|
|
slint
module
|
|
smali
module
|
|
smith
module
|
|
smithy
module
|
|
sml
module
|
|
snakemake
module
|
|
snl
module
|
|
sol
module
|
|
solidity
module
|
|
sop
module
|
|
soql
module
|
|
sosl
module
|
|
sourcepawn
module
|
|
sparql
module
|
|
spicy
module
|
|
sql
module
|
|
sql_bigquery
module
|
|
sqlite
module
|
|
squirrel
module
|
|
ssh_client_config
module
|
|
ssh_config
module
|
|
starlark
module
|
|
strace
module
|
|
streamdevice_proto
module
|
|
structurizr
module
|
|
styled
module
|
|
supercollider
module
|
|
superhtml
module
|
|
surface
module
|
|
surrealql
module
|
|
sus
module
|
|
svelte
module
|
|
sway
module
|
|
swift
module
|
|
sxhkdrc
module
|
|
syphon
module
|
|
systemtap
module
|
|
systemverilog
module
|
|
t32
module
|
|
tablegen
module
|
|
tact
module
|
|
talon
module
|
|
tcl
module
|
|
teal
module
|
|
templ
module
|
|
tera
module
|
|
terra
module
|
|
test
module
|
|
textproto
module
|
|
thrift
module
|
|
tiger
module
|
|
tlaplus
module
|
|
tmux
module
|
|
tnsl
module
|
|
todolang
module
|
|
todotxt
module
|
|
toml
module
|
|
tort
module
|
|
tsv
module
|
|
tsx
module
|
|
tup
module
|
|
turtle
module
|
|
twig
module
|
|
twolc
module
|
|
typescript
module
|
|
typespec
module
|
|
typoscript
module
|
|
typst
module
|
|
udev
module
|
|
uiua
module
|
|
ungrammar
module
|
|
unison
module
|
|
ursa
module
|
|
usd
module
|
|
uxntal
module
|
|
v
module
|
|
vala
module
|
|
vento
module
|
|
verilog
module
|
|
vhdl
module
|
|
vhs
module
|
|
vim
module
|
|
vimdoc
module
|
|
virdant
module
|
|
virgil
module
|
|
vrl
module
|
|
vue
module
|
|
walnut
module
|
|
wbproto
module
|
|
wgsl
module
|
|
wgsl_bevy
module
|
|
wing
module
|
|
wit
module
|
|
woml
module
|
|
wtf
module
|
|
xcompose
module
|
|
xfst
module
|
|
xml
module
|
|
xresources
module
|
|
yadl
module
|
|
yaml
module
|
|
yang
module
|
|
yaral
module
|
|
yarnlock
module
|
|
yuck
module
|
|
zathurarc
module
|
|
zeek
module
|
|
zig
module
|
|
ziggy
module
|
|
ziggy_schema
module
|
|
zoomba
module
|