This is Yet Another perl tree-sitter module.
To get started, install the dependencies for this repo
npm i
That should get you set up with tree-sitter's cli locally.
In this project, the generated C source code (stored in the src
directory) is
.gitignored. In order to generate it, run
npx tree-sitter generate
You'll need to do this after any changes to the grammar.
Tests are stored in the /test/corpus
directory, as txt files. A little reference on the
syntax can be found here.
You can run the tests with
npx tree-sitter test
See the help output (-h
) for that command for some more details on using the test
runner.
If you'd like to contribute, Pull Requests are welcome! The plan is to build the grammar from the bottom up, from simple statements with solid code coverage, eventually building up to full, complex syntax.
You can see a reference of the grammar's DSL here. It's fairly straigthforward, and makes for pleasant reading. It is stored in grammar.js
at the root of this repo.
For subtle points in the grammar implementation, PLEASE leave comments. The extra bytes spent on the comments in dev will go a long way in the big picture.
You can install these bindings in neovim by using the following snippet. Hopefully soon we'll get upstreamed + you won't need this patchery.
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.perl = {
install_info = {
url = 'https://github.com/tree-sitter-perl/tree-sitter-perl',
revision = 'release',
files = { "src/parser.c", "src/scanner.c" },
}
}
Then you just :TSInstall perl
. You'll need to copy the queries in the queries
directory of this repo into a queries/perl
directory somewhere in you rtp
.
As of version 29, Emacs can be built with tree-sitter support. This version is not yet released, so you need to build it yourself from the Emacs source repository. You need to have tree-sitter itself available to do this.
Once this is done, you can install the Perl bindings by executing two Emacs lisp forms:
(setq treesit-language-source-alist
'((perl . ("https://github.com/tree-sitter-perl/tree-sitter-perl" "release"))))
(treesit-install-language-grammar 'perl)
Alternatively, you can run the command interactively:
M-x treesit-install-language-grammar <RET>
Then answer the prompts accordingly. Enter perl
for the language, the
repository URL is https://github.com/tree-sitter-perl/tree-sitter-perl
and the branch is release
.
An Emacs major mode which makes use of these binding ... is yet to be written.
You can get the built files off of the release
branch in this repo. If you have specific
instructions for a particular editor, PRs are welcome.