0 purchases
tree sitter
Tree Sitter Dart Library #
This library provides Dart bindings for the Tree Sitter c parsing library. It allows parsing source code into a syntax tree that you can traverse and query.
Installation #
You must have the tree sitter library available as a dynamic library on your system.
Then set the library location using:
TreeSitterConfig.setLibraryPath('/path/to/libtree-sitter.so');
copied to clipboard
Next create a parser for your language by first creating a dynamic library for your language's grammar.
Then load and use the parser:
import 'package:ffi/ffi.dart';
import 'package:tree_sitter/tree_sitter.dart';
void main() {
final parser =
Parser(sharedLibrary: 'libdart.dylib', entryPoint: 'tree_sitter_dart');
final program = "class A {}";
final tree = parser.parse(program);
print(tree.root.string);
}
copied to clipboard
You can access other apis via the top level treeSitterApi ffi wrapper
Or you can help contribute to an idiomatic dart api on top of the ffi wrapper.
Many of the apis are started but not complete.
Expect breaking changes while we figure out the best api
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.