#tree-sitter #parser #incremental #rslox

tree-sitter-rslox

lox(rust) grammar for the tree-sitter parsing library

2 releases

0.1.1 Jul 4, 2023
0.1.0 Jul 4, 2023

#350 in Text editors

MIT license

165KB
6.5K SLoC

C 6K SLoC JavaScript 153 SLoC // 0.1% comments Scheme 90 SLoC // 0.2% comments Rust 33 SLoC // 0.4% comments

tree-sitter-rslox

适配 Lox programming language 的语法高亮解析器

Local setup

先安装 tree-sitter-cli:

cargo install tree-sitter-cli

通过以下命令生成 bindings:

tree-sitter generate

更改语法后,只需再次运行 tree-sitter generate 即可

运行测试:

tree-sitter test

生成 wasm

如果想要生成 wasm,执行:

npm run build:wasm

注:打包成 wasm 需要依赖 emscripten 或者 docker 环境

查看效果:

npm install
node main.js

参考


lib.rs:

This crate provides rslox language support for the tree-sitter parsing library.

Typically, you will use the language function to add this language to a tree-sitter Parser, and then use the parser to parse some code:

let code = "";
let mut parser = tree_sitter::Parser::new();
parser.set_language(tree_sitter_rslox::language()).expect("Error loading rslox grammar");
let tree = parser.parse(code, None).unwrap();

Dependencies

~2.8–4MB
~76K SLoC