tree_sitter 0.1.2 copy "tree_sitter: ^0.1.2" to clipboard
tree_sitter: ^0.1.2 copied to clipboard

A tree sitter parsing library

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');

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);
}

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

1
likes
105
pub points
0%
popularity

Publisher

unverified uploader

A tree sitter parsing library

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

args, dylib, ffi, freezed_annotation, json_annotation, path

More

Packages that depend on tree_sitter