tree-sitter-scrii — editor grammar
tree-sitter is an incremental
parsing framework used by editors for syntax highlighting, indentation,
folding, and code navigation. tree-sitter-scrii is the grammar for Scrii.
Adding the grammar to a tree-sitter editor gives you accurate, structural highlighting (as opposed to the regex highlighting a naive syntax bundle provides).
Build
Plain Makefile, no CMake:
make # produces scrii.so (shared parser library)
make generate # regenerate src/parser.c from grammar.js
make test # run the corpus tests
make clean
The grammar also ships bindings for other tree-sitter consumers: a
package.json (Node addon) and a Cargo.toml/build.rs (Rust).
Regenerating the parser
After changing grammar.js:
tree-sitter generate
This rewrites src/parser.c, src/grammar.json and src/node-types.json.
Testing
tree-sitter test # runs test/corpus/statements.txt (24 cases)
tree-sitter parse file.scr
The corpus covers declarations, control flow, switch, arrays/objects,
member access and method calls (obj:method(...) — Scrii deliberately
rejects obj.method(...) calls), operators, comments, escapes, and numeric
literals.
Highlighting
queries/highlights.scm maps the grammar to standard capture names. Notable:
SCREAMING_CASE identifiers are captured as @constant regardless of how they
were declared — a code-convention rule that mirrors what the LSP's semantic
tokens report. Because tree-sitter resolves overlapping captures with
last-match-wins, this rule sits at the end of the file so it outranks
@variable / @function.
queries/locals.scm provides symbol scoping for editors that use it.
Configuring the highlight
Install the tree-sitter grammar for the scrii filetype (file extensions
.scr, scrii, scope source.scrii). With Neovim's
nvim-treesitter:
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.scrii = {
install_info = {
url = "/path/to/tree-sitter-scrii",
files = { "src/parser.c" },
},
filetype = "scrii",
}
Then run :TSInstall scrii (or point url at the local checkout and
re-source the config). See the upstream
nvim-treesitter docs
for other editors.