This monorepo contains two folders: packages
and scripts
.
Packages contain a list of prebuild tree-sitter grammars to use with the @ast-grep/napi
package.
Typical usage:
- Install the language package in your project
pnpm install @ast-grep/lang-{name}
pnpm install @ast-grep/napi
# install the tree-sitter-cli if no prebuild is available
pnpm install @tree-sitter/cli --save-dev
- Use the language package in your project
import lang from '@ast-grep/lang-{name}'
import { registerDynamicLanguage, parse } from '@ast-grep/napi'
registerDynamicLanguage({ [langName]: lang })
const sg = parse(langName, `your code`)
sg.root().kind()
Scripts contain a list of scripts to help with the development of the packages.
You can use pnpm create @ast-grep/lang
to create a new language package.
# create a new language package in current directory
pnpm create @ast-grep/lang
# create package in a specific directory
pnpm create @ast-grep/lang some-dir
You will be prompted to enter the language name, the language file extension, package name and tree-sitter grammar package.
Note the tree-sitter grammar package is different from the package name. package name is the repo you create, tree-sitter package should be a package already published on npm.
After the package is created, you can use these commands:
pnpm source # copy tree-sitter grammar files to the src folder
pnpm build # build the tree-sitter grammar files to dynamic lib
pnpm test # test the tree-sitter grammar files
You can edit nursery.js
to add test case for your language.
A build-time dependency for the @ast-grep/lang-*
packages.
It is used to copy and test the tree-sitter grammars.
A postinstall script to setup parser dynamic library for the @ast-grep/lang-*
packages.
If there is prebuild available, it will copy the dynamic library according to the platform and architecture.
If there is no prebuild available, it will build the dynamic library from the tree-sitter grammar files.