#dart #parser #incremental

tree-sitter-dart-latest

dart grammar for the tree-sitter parsing library

1 unstable release

0.0.1 Jul 21, 2023

#36 in #dart

MIT license

6MB
198K SLoC

C 195K SLoC JavaScript 2.5K SLoC // 0.1% comments Scheme 154 SLoC // 0.2% comments Rust 31 SLoC // 0.5% comments C++ 19 SLoC

tree-sitter-dart

This is a tree-sitter grammar written for the dart programming language. We attempt to adhere as closely as possible to the dart language spec. Initially it was started with a copy of the tree-sitter Java grammar which is why there may be a few relics included in here. For the sake of simplifying the syntax tree, many items were made inlined with tree-sitter's "underscore" method of writing rules.

Getting Started

  • Go to the project directory
  • run npm install (first time)
  • run npm run build_init (first time) npm run build (subsequent times)
  • run npm run test

To test a single highlight file

  • run tree-sitter highlight test/highlight/types.dart

To test a single test file

  • run tree-sitter test -f 'testcasefilter'
  • for example tree-sitter test -f 'dart string literals'

To show the output of a parse for a sample file (for example while debugging highlight issues)

  • run tree-sitter parse path/to/file.dart

lib.rs:

This crate provides dart 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_dart::language()).expect("Error loading dart grammar");
let tree = parser.parse(code, None).unwrap();

Dependencies

~2.7–4MB
~75K SLoC