Merge branch 'osa1-dart'

Closes #166
pull/185/head
Wilfred Hughes 2022-03-20 11:41:08 +07:00
commit e2d1a80235
43 changed files with 137198 additions and 0 deletions

@ -1,5 +1,9 @@
## 0.24 (unreleased)
### Parsing
Added support for Dart.
## 0.23.1 (released 19th March 2022)
Fixed crash where the 'shrink unchanged' logic would not set the

@ -61,6 +61,7 @@ Difftastic supports the following languages:
* Clojure
* Common Lisp
* CSS
* Dart
* Elixir
* Emacs Lisp
* Go

@ -89,6 +89,11 @@ fn main() {
src_dir: "vendor/tree-sitter-css-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-dart",
src_dir: "vendor/tree-sitter-dart-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-elisp",
src_dir: "vendor/tree-sitter-elisp-src",

@ -10,6 +10,7 @@ tool that understands syntax. It supports the following languages:
* Clojure
* Common Lisp
* CSS
* Dart
* Elixir
* Emacs Lisp
* Go

@ -11,6 +11,7 @@ Difftastic uses the following tree-sitter parsers:
| Clojure | [sogaiu/tree-sitter-clojure](https://github.com/sogaiu/tree-sitter-clojure) |
| Common Lisp | [theHamsta/tree-sitter-commonlisp](https://github.com/theHamsta/tree-sitter-commonlisp) |
| CSS | [tree-sitter/tree-sitter-css](https://github.com/tree-sitter/tree-sitter-css) |
| Dart | [UserNobody14/tree-sitter-dart](https://github.com/UserNobody14/tree-sitter-dart) |
| Elixir | [elixir-lang/tree-sitter-elixir](https://github.com/elixir-lang/tree-sitter-elixir) |
| Emacs Lisp | [wilfred/tree-sitter-elisp](https://github.com/Wilfred/tree-sitter-elisp) |
| Go | [tree-sitter/tree-sitter-go](https://github.com/tree-sitter/tree-sitter-go) |

@ -19,6 +19,9 @@ b5e718eb8328f8df8aff0eddf4e46d1a -
sample_files/css_before.css sample_files/css_after.css
a110f9a9ab8586f2f307df3cc9997ead -
sample_files/dart_before.dart sample_files/dart_after.dart
aeed85d8cb8905197268309894a2945e -
sample_files/elisp_before.el sample_files/elisp_after.el
c2871ec588ad8dd1e8c482efc4662f42 -

@ -0,0 +1,5 @@
void test() {
Object()..a()..b();
expect(a.b.c.d()!.x);
}

@ -0,0 +1,7 @@
void test() {
if (x) {
Object().a().b();
}
expect(a.b(c.d()).x);
}

@ -25,6 +25,7 @@ pub enum Language {
CPlusPlus,
CSharp,
Css,
Dart,
Elixir,
EmacsLisp,
Go,
@ -87,6 +88,7 @@ fn from_emacs_mode_header(src: &str) -> Option<Language> {
"clojure" => Some(Clojure),
"csharp" => Some(CSharp),
"css" => Some(Css),
"dart" => Some(Dart),
"c++" => Some(CPlusPlus),
"elixir" => Some(Elixir),
"emacs-lisp" => Some(EmacsLisp),
@ -181,6 +183,7 @@ fn from_extension(extension: &OsStr, src: &str) -> Option<Language> {
"lisp" | "lsp" | "asd" => Some(CommonLisp),
"cs" => Some(CSharp),
"css" => Some(Css),
"dart" => Some(Dart),
"el" => Some(EmacsLisp),
"ex" | "exs" => Some(Elixir),
"go" => Some(Go),

@ -50,6 +50,7 @@ extern "C" {
fn tree_sitter_cpp() -> ts::Language;
fn tree_sitter_commonlisp() -> ts::Language;
fn tree_sitter_css() -> ts::Language;
fn tree_sitter_dart() -> ts::Language;
fn tree_sitter_elisp() -> ts::Language;
fn tree_sitter_elixir() -> ts::Language;
fn tree_sitter_go() -> ts::Language;
@ -190,6 +191,20 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
.unwrap(),
}
}
Dart => {
let language = unsafe { tree_sitter_dart() };
TreeSitterConfig {
name: "Dart",
language,
atom_nodes: (vec!["string_literal"]).into_iter().collect(),
delimiter_tokens: (vec![("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")]),
highlight_query: ts::Query::new(
language,
include_str!("../vendor/highlights/dart.scm"),
)
.unwrap(),
}
}
EmacsLisp => {
let language = unsafe { tree_sitter_elisp() };
TreeSitterConfig {

@ -0,0 +1 @@
../tree-sitter-dart/queries/highlights.scm

@ -0,0 +1 @@
tree-sitter-dart/src

@ -0,0 +1,15 @@
node_modules
.node-version
build
*.log
/test.js
/examples/npm
package-lock.json
/parser.exp
/parser.lib
/parser.obj
/scanner.obj
/.idea/
.dart_tool
.packages
pubspec.lock

@ -0,0 +1,26 @@
[package]
name = "tree-sitter-dart"
description = "dart grammar for the tree-sitter parsing library"
version = "0.0.1"
keywords = ["incremental", "parsing", "dart"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-javascript"
edition = "2018"
license = "MIT"
build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
[lib]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "0.17"
[build-dependencies]
cc = "1.0"

@ -0,0 +1,18 @@
# tree-sitter-dart
This is a tree-sitter grammar written for the dart programming language. I attempted to adhere as closely as possible to the dart language spec. Initially I 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`

@ -0,0 +1,19 @@
{
"targets": [
{
"target_name": "tree_sitter_dart_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"src/parser.c",
"bindings/node/binding.cc",
"src/scanner.c"
],
"cflags_c": [
"-std=c99",
]
}
]
}

@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_dart();
namespace {
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_dart());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("dart").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_dart_binding, Init)
} // namespace

@ -0,0 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_dart_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_dart_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}

@ -0,0 +1,40 @@
fn main() {
let src_dir = std::path::Path::new("src");
let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
// If your language uses an external scanner written in C,
// then include this block of code:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C++,
// then include this block of code:
/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}

@ -0,0 +1,52 @@
//! This crate provides dart language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] 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();
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter::Language;
extern "C" {
fn tree_sitter_dart() -> Language;
}
/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_dart() }
}
/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading dart language");
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,13 @@
try {
module.exports = require("./build/Release/tree_sitter_dart_binding");
} catch (error) {
try {
module.exports = require("./build/Debug/tree_sitter_dart_binding");
} catch (_) {
throw error
}
}
try {
module.exports.nodeTypeInfo = require("./src/node-types.json");
} catch (_) {}

@ -0,0 +1,57 @@
{
"name": "tree-sitter-dart",
"version": "1.0.0",
"description": "Dart grammar attempt for tree-sitter",
"main": "bindings/node",
"keywords": [
"tree-sitter",
"parser",
"dart"
],
"author": "Benjamin Sobel",
"license": "ISC",
"dependencies": {
"nan": "^2.14.2"
},
"devDependencies": {
"node-gyp": "^7.1.2",
"npm-watch": "^0.7.0",
"tree-sitter-cli": "^0.19.2"
},
"watch": {
"test": {
"patterns": [
"corpus"
],
"extensions": "dart",
"quiet": true
},
"build-test": {
"patterns": [
"./"
],
"extensions": [
"js",
"scm",
"txt"
],
"quiet": true
}
},
"scripts": {
"build_init": "tree-sitter generate && node-gyp configure && node-gyp build",
"build": "tree-sitter generate && node-gyp build",
"test": "tree-sitter test",
"build-test": "tree-sitter generate && node-gyp build && tree-sitter test",
"watch-test": "npm-watch test",
"watch-grammar": "npm-watch build-test"
},
"tree-sitter": [
{
"scope": "source.dart",
"file-types": [
"dart"
]
}
]
}

@ -0,0 +1,228 @@
(dotted_identifier_list) @string
; Methods
; --------------------
;; TODO: does not work
;(function_type
;name: (identifier) @method)
(super) @function
; Annotations
; --------------------
(annotation
name: (identifier) @attribute)
(marker_annotation
name: (identifier) @attribute)
; Operators and Tokens
; --------------------
(template_substitution
"$" @punctuation.special
"{" @punctuation.special
"}" @punctuation.special
) @none
(template_substitution
"$" @punctuation.special
(identifier_dollar_escaped) @variable
) @none
(escape_sequence) @string.escape
[
"@"
"=>"
".."
"??"
"=="
"?"
":"
"&&"
"%"
"<"
">"
"="
">="
"<="
"||"
(increment_operator)
(is_operator)
(prefix_operator)
(equality_operator)
(additive_operator)
] @operator
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
; Delimiters
; --------------------
[
";"
"."
","
] @punctuation.delimiter
; Types
; --------------------
(class_definition
name: (identifier) @type)
(constructor_signature
name: (identifier) @type)
;; TODO: does not work
;(type_identifier
;(identifier) @type)
(scoped_identifier
scope: (identifier) @type)
(function_signature
name: (identifier) @method)
(getter_signature
(identifier) @method)
(setter_signature
name: (identifier) @method)
(enum_declaration
name: (identifier) @type)
(enum_constant
name: (identifier) @type)
(type_identifier) @type
(void_type) @type
((scoped_identifier
scope: (identifier) @type
name: (identifier) @type)
(#match? @type "^[a-zA-Z]"))
(type_identifier) @type
; Variables
; --------------------
; var keyword
(inferred_type) @keyword
(const_builtin) @constant.builtin
(final_builtin) @constant.builtin
((identifier) @type
(#match? @type "^_?[A-Z]"))
("Function" @type)
; properties
; TODO: add method/call_expression to grammar and
; distinguish method call from variable access
(unconditional_assignable_selector
(identifier) @property)
;; https://github.com/UserNobody14/tree-sitter-dart/issues/24
;; (assignable_selector
;; (identifier) @property)
; assignments
(assignment_expression
left: (assignable_expression) @variable)
(this) @variable.builtin
; Parameters
; --------------------
(formal_parameter
name: (identifier) @parameter)
(named_argument
(label (identifier) @parameter))
; Literals
; --------------------
[
(hex_integer_literal)
(decimal_integer_literal)
(decimal_floating_point_literal)
; TODO: inaccessbile nodes
; (octal_integer_literal)
; (hex_floating_point_literal)
] @number
(symbol_literal) @symbol
(string_literal) @string
(true) @boolean
(false) @boolean
(null_literal) @constant.builtin
(documentation_comment) @comment
(comment) @comment
; Keywords
; --------------------
["import" "library" "export"] @include
; Reserved words (cannot be used as identifiers)
; TODO: "rethrow" @keyword
[
; "assert"
(case_builtin)
"extension"
"on"
"class"
"enum"
"extends"
"in"
"is"
"new"
"return"
"super"
"with"
] @keyword
; Built in identifiers:
; alone these are marked as keywords
[
"abstract"
"as"
"async"
"async*"
"yield"
"sync*"
"await"
"covariant"
"deferred"
"dynamic"
"external"
"factory"
"get"
"implements"
"interface"
"library"
"operator"
"mixin"
"part"
"set"
"show"
"static"
"typedef"
] @keyword
; when used as an identifier:
((identifier) @variable.builtin
(#vim-match? @variable.builtin "^(abstract|as|covariant|deferred|dynamic|export|external|factory|Function|get|implements|import|interface|library|operator|mixin|part|set|static|typedef)$"))
["if" "else" "switch" "default"] @conditional
[
"try"
"throw"
"catch"
"finally"
(break_statement)
] @exception
["do" "while" "continue" "for"] @repeat
; Error
(ERROR) @error

@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_dart();
namespace {
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_dart());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("dart").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_dart_binding, Init)
} // namespace

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,172 @@
#include <tree_sitter/parser.h>
#include <wctype.h>
enum TokenType {
AUTOMATIC_SEMICOLON,
TEMPLATE_CHARS_SINGLE,
TEMPLATE_CHARS_DOUBLE,
TEMPLATE_CHARS_SINGLE_SINGLE,
TEMPLATE_CHARS_DOUBLE_SINGLE,
TEMPLATE_CHARS_RAW_SLASH
};
void *tree_sitter_dart_external_scanner_create() { return NULL; }
void tree_sitter_dart_external_scanner_destroy(void *p) {}
void tree_sitter_dart_external_scanner_reset(void *p) {}
unsigned tree_sitter_dart_external_scanner_serialize(void *p, char *buffer) { return 0; }
void tree_sitter_dart_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
static void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
static bool scan_whitespace_and_comments(TSLexer *lexer) {
for (;;) {
while (iswspace(lexer->lookahead)) {
advance(lexer);
}
if (lexer->lookahead == '/') {
advance(lexer);
if (lexer->lookahead == '/') {
advance(lexer);
while (lexer->lookahead != 0 && lexer->lookahead != '\n') {
advance(lexer);
}
} else if (lexer->lookahead == '*') {
advance(lexer);
while (lexer->lookahead != 0) {
if (lexer->lookahead == '*') {
advance(lexer);
if (lexer->lookahead == '/') {
advance(lexer);
break;
}
} else {
advance(lexer);
}
}
} else {
return false;
}
} else {
return true;
}
}
}
bool tree_sitter_dart_external_scanner_scan(void *payload, TSLexer *lexer,
const bool *valid_symbols) {
if (valid_symbols[TEMPLATE_CHARS_DOUBLE] ||
valid_symbols[TEMPLATE_CHARS_SINGLE] ||
valid_symbols[TEMPLATE_CHARS_DOUBLE_SINGLE] ||
valid_symbols[TEMPLATE_CHARS_SINGLE_SINGLE]) {
if (valid_symbols[AUTOMATIC_SEMICOLON]) return false;
if(valid_symbols[TEMPLATE_CHARS_DOUBLE]) {
lexer->result_symbol = TEMPLATE_CHARS_DOUBLE;
} else if (valid_symbols[TEMPLATE_CHARS_SINGLE]) {
lexer->result_symbol = TEMPLATE_CHARS_SINGLE;
} else if (valid_symbols[TEMPLATE_CHARS_SINGLE_SINGLE]) {
lexer->result_symbol = TEMPLATE_CHARS_SINGLE_SINGLE;
} else {
lexer->result_symbol = TEMPLATE_CHARS_DOUBLE_SINGLE;
}
for (bool has_content = false;; has_content = true) {
lexer->mark_end(lexer);
switch (lexer->lookahead) {
case '\'':
case '"':
return has_content;
case '\n':
if (valid_symbols[TEMPLATE_CHARS_DOUBLE_SINGLE] || valid_symbols[TEMPLATE_CHARS_SINGLE_SINGLE]) return false;
advance(lexer);
break;
case '\0':
return false;
case '$':
// advance(lexer);
// if (lexer->lookahead == '{') return has_content;
// break;
return has_content;
case '\\':
if (valid_symbols[TEMPLATE_CHARS_RAW_SLASH]) {
lexer->result_symbol = TEMPLATE_CHARS_RAW_SLASH;
advance(lexer);
} else {
return has_content;
}
break;
default:
advance(lexer);
}
}
} else {
lexer->result_symbol = AUTOMATIC_SEMICOLON;
lexer->mark_end(lexer);
for (;;) {
if (lexer->lookahead == 0) return true;
if (lexer->lookahead == '}') return true;
if (lexer->is_at_included_range_start(lexer)) return true;
if (!iswspace(lexer->lookahead)) return false;
if (lexer->lookahead == '\n') break;
advance(lexer);
}
advance(lexer);
if (!scan_whitespace_and_comments(lexer)) return false;
switch (lexer->lookahead) {
case ',':
case '.':
case ':':
case ';':
case '*':
case '%':
case '>':
case '<':
case '=':
case '[':
case '(':
case '?':
case '^':
case '|':
case '&':
case '/':
return false;
// Insert a semicolon before `--` and `++`, but not before binary `+` or `-`.
case '+':
advance(lexer);
return lexer->lookahead == '+';
case '-':
advance(lexer);
return lexer->lookahead == '-';
// Don't insert a semicolon before `!=`, but do insert one before a unary `!`.
case '!':
advance(lexer);
return lexer->lookahead != '=';
// Don't insert a semicolon before `in` or `instanceof`, but do insert one
// before an identifier.
case 'i':
advance(lexer);
if (lexer->lookahead != 'n') return true;
advance(lexer);
if (!iswalpha(lexer->lookahead)) return false;
for (unsigned i = 0; i < 8; i++) {
if (lexer->lookahead != "stanceof"[i]) return true;
advance(lexer);
}
if (!iswalpha(lexer->lookahead)) return false;
break;
}
return true;
}
}

@ -0,0 +1,223 @@
#ifndef TREE_SITTER_PARSER_H_
#define TREE_SITTER_PARSER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define ts_builtin_sym_error ((TSSymbol)-1)
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
#endif
typedef struct {
TSFieldId field_id;
uint8_t child_index;
bool inherited;
} TSFieldMapEntry;
typedef struct {
uint16_t index;
uint16_t length;
} TSFieldMapSlice;
typedef struct {
bool visible;
bool named;
bool supertype;
} TSSymbolMetadata;
typedef struct TSLexer TSLexer;
struct TSLexer {
int32_t lookahead;
TSSymbol result_symbol;
void (*advance)(TSLexer *, bool);
void (*mark_end)(TSLexer *);
uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *);
};
typedef enum {
TSParseActionTypeShift,
TSParseActionTypeReduce,
TSParseActionTypeAccept,
TSParseActionTypeRecover,
} TSParseActionType;
typedef union {
struct {
uint8_t type;
TSStateId state;
bool extra;
bool repetition;
} shift;
struct {
uint8_t type;
uint8_t child_count;
TSSymbol symbol;
int16_t dynamic_precedence;
uint16_t production_id;
} reduce;
uint8_t type;
} TSParseAction;
typedef struct {
uint16_t lex_state;
uint16_t external_lex_state;
} TSLexMode;
typedef union {
TSParseAction action;
struct {
uint8_t count;
bool reusable;
} entry;
} TSParseActionEntry;
struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
uint32_t alias_count;
uint32_t token_count;
uint32_t external_token_count;
uint32_t state_count;
uint32_t large_state_count;
uint32_t production_id_count;
uint32_t field_count;
uint16_t max_alias_sequence_length;
const uint16_t *parse_table;
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map;
const uint16_t *alias_map;
const TSSymbol *alias_sequences;
const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token;
struct {
const bool *states;
const TSSymbol *symbol_map;
void *(*create)(void);
void (*destroy)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
};
/*
* Lexer Macros
*/
#define START_LEXER() \
bool result = false; \
bool skip = false; \
bool eof = false; \
int32_t lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead;
#define ADVANCE(state_value) \
{ \
state = state_value; \
goto next_state; \
}
#define SKIP(state_value) \
{ \
skip = true; \
state = state_value; \
goto next_state; \
}
#define ACCEPT_TOKEN(symbol_value) \
result = true; \
lexer->result_symbol = symbol_value; \
lexer->mark_end(lexer);
#define END_STATE() return result;
/*
* Parse Table Macros
*/
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define STATE(id) id
#define ACTIONS(id) id
#define SHIFT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value \
} \
}}
#define SHIFT_REPEAT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value, \
.repetition = true \
} \
}}
#define SHIFT_EXTRA() \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.extra = true \
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
}, \
}}
#define RECOVER() \
{{ \
.type = TSParseActionTypeRecover \
}}
#define ACCEPT_INPUT() \
{{ \
.type = TSParseActionTypeAccept \
}}
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_PARSER_H_

@ -0,0 +1,74 @@
====
comment
====
// This is a comment
/* This is also a comment */
/* this comment /* // /** ends here: */
---
(program (comment) (comment) (comment))
======================
comments and literals
======================
123;
// comment
---
(program
(expression_statement (decimal_integer_literal))
(comment))
======================
documentation comment
======================
/// * [defaultSchedulingStrategy], the default [SchedulingStrategy] for [SchedulerBinding.schedulingStrategy].
---
(program (documentation_comment))
======================
documentation comment 1
======================
/**
* Is [:true:] if this comment is a documentation comment.
*
* That is, that the comment is either enclosed in [: /** ... */ :] or starts
* with [: /// :].
*/
---
======================
documentation comment 2
======================
/**
* Is [:true:] if this comment is a documentation comment.
*
* That is, that the comment is either enclosed in [: /** ... */ :] or starts
*/
---
======================
documentation comment 3
======================
/*
* Is [:true:] if this comment is a documentation comment.
*
* That is, that the comment is either enclosed in /* var ... */ var or starts
*/
---

@ -0,0 +1,360 @@
========================================
dart if statements
========================================
if (z) return n;
---
(program
(if_statement
(parenthesized_expression (identifier))
(return_statement (identifier))))
=========================================
dart string literals
=========================================
get a => "";
get a => "\"";
get a => "This' is a string $mystring";
get a => '''This" is a
string ${mystring}''';
get a => 'Also a string';
---
(program
(getter_signature (identifier)) (function_body (string_literal))
(getter_signature (identifier)) (function_body (string_literal (escape_sequence)))
(getter_signature (identifier)) (function_body (string_literal (template_substitution (identifier_dollar_escaped))))
(getter_signature (identifier)) (function_body (string_literal (template_substitution (identifier))))
(getter_signature (identifier)) (function_body (string_literal)))
=========================================
dart string literals 2
=========================================
get a => "";
get a => "\"";
get a => """This' is a string $mystring""";
get a => '''This" is a $
string mystring''';
get a => '''Also a string''';
---
(program
(getter_signature (identifier)) (function_body (string_literal))
(getter_signature (identifier)) (function_body (string_literal (escape_sequence)))
(getter_signature (identifier)) (function_body (string_literal (template_substitution (identifier_dollar_escaped))))
(getter_signature (identifier)) (function_body (string_literal))
(getter_signature (identifier)) (function_body (string_literal)))
=========================================
dart string literals raw
=========================================
get a => "";
get a => r"\";
get a => """This' is a string $mystring""";
get a => '''This" is a $
string mystring''';
get a => r'''Also a string''';
---
(program
(getter_signature (identifier)) (function_body (string_literal))
(getter_signature (identifier)) (function_body (string_literal))
(getter_signature (identifier)) (function_body (string_literal (template_substitution (identifier_dollar_escaped))))
(getter_signature (identifier)) (function_body (string_literal))
(getter_signature (identifier)) (function_body (string_literal)))
==================================================
dart identifier name r (used to conflict/error with raw string literal)
==================================================
String hello(r) => 'hello';
---
(program
(function_signature (type_identifier) (identifier)
(formal_parameter_list (formal_parameter (identifier)))) (function_body (string_literal)))
==================================================
dart set literals
==================================================
class A {
int b() {
var c = {vala};
var c = {vala: 'g'};
}
}
---
(program
(class_definition
name: (identifier)
body: (class_body
(method_signature (function_signature
(type_identifier)
name: (identifier)
(formal_parameter_list)))
(function_body (block
(local_variable_declaration
(initialized_variable_definition
(inferred_type)
name: (identifier)
value: (set_or_map_literal (identifier))
))
(local_variable_declaration
(initialized_variable_definition
(inferred_type)
name: (identifier)
value: (set_or_map_literal (pair key: (identifier) value: (string_literal)))
)
))
))))
==================================================
embedded control flow for collections
==================================================
class A {
int b() {
var c = {if (z) vala};
var c = {vala: 'g'};
}
}
---
(program
(class_definition
name: (identifier)
body: (class_body
(method_signature (function_signature
(type_identifier)
name: (identifier)
(formal_parameter_list)))
(function_body (block
(local_variable_declaration
(initialized_variable_definition
(inferred_type)
name: (identifier)
value: (set_or_map_literal (if_element
condition: (parenthesized_expression (identifier))
consequence: (identifier)
))
)
)
(local_variable_declaration
(initialized_variable_definition
(inferred_type)
name: (identifier)
value: (set_or_map_literal (pair key: (identifier) value: (string_literal)))
)
))
)
)))
===================
Positional Parameters
===================
class Beyonce {
void calculateAnswer(double wingSpan, int numberOfEngines,
[double length, double grossTons]) {
//do the calculation here
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature (function_signature
(void_type)
(identifier)
(formal_parameter_list
(formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier))
(optional_formal_parameters
(formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier))))))
(function_body (block (comment))))))
==================================================
collection trailing commas
==================================================
final map = {"hello": "world",};
final set = {"hello", "world"};
---
(program
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier)
(set_or_map_literal (pair (string_literal) (string_literal)))))
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier)
(set_or_map_literal (string_literal) (string_literal)))))
==================================================
collection literal type parameters
==================================================
final dynamic opts = <dynamic, dynamic>{
'transports': ['websocket'],
'forceNew': true,
};
---
(program (final_builtin) (type_identifier) (static_final_declaration_list (static_final_declaration (identifier)
(set_or_map_literal (type_arguments (type_identifier) (type_identifier)) (pair (string_literal)
(list_literal (string_literal))) (pair (string_literal) (true))))))
==================================================
extensions on integer literals
==================================================
void main() {
await Future.delayed(10.milliseconds, () {});
}
---
(program
(function_signature (void_type) (identifier) (formal_parameter_list))
(function_body (block (expression_statement (unary_expression
(await_expression (identifier) (selector (unconditional_assignable_selector (identifier))) (selector (argument_part
(arguments (argument (decimal_integer_literal) (selector (unconditional_assignable_selector (identifier))))
(argument (function_expression (formal_parameter_list) (function_expression_body (block)))))))))))))
==================================================
part directive
==================================================
part 'hello.dart';
---
(program (part_directive (uri (string_literal))))
==================================================
part of directive
==================================================
part of 'hello.dart';
---
(program (part_of_directive (uri (string_literal))))
==================================================
extension methods
==================================================
extension Hello on String {
String get hello => 'hello';
}
---
(program
(extension_declaration (identifier) (type_identifier) (extension_body
(method_signature (getter_signature (type_identifier) (identifier))) (function_body (string_literal)))))
==================================================
library directive
==================================================
library myLibrary;
---
(program (library_name (dotted_identifier_list (identifier))))
==================================================
scoped library directive
==================================================
library myLibrary.a.cool.library;
---
(program (library_name (dotted_identifier_list (identifier) (identifier) (identifier) (identifier))))
==================================================
redirecting factories
==================================================
@freezed
abstract class MyDataClass implements _$MyDataClass {
const factory MyDataClass.initialize({@Default(false) bool debug}) = _MyDataClassInitialize;
factory MyDataClass.debug() => MyDataClass.initialize(debug: true);
}
---
(program
(marker_annotation (identifier))
(class_definition (identifier) (interfaces (type_identifier))
(class_body
(declaration (redirecting_factory_constructor_signature (const_builtin) (identifier) (identifier) (formal_parameter_list
(optional_formal_parameters (formal_parameter
(annotation (identifier) (arguments (argument (false)))) (type_identifier) (identifier)))) (type_identifier)))
(method_signature (factory_constructor_signature (identifier) (identifier) (formal_parameter_list)))
(function_body (identifier) (selector (unconditional_assignable_selector (identifier)))
(selector (argument_part (arguments (named_argument (label (identifier)) (true)))))))))
======================================
setter expressions
======================================
class MyClass {
set editing(bool value) {
_editing = value;
}
}
---
(program (class_definition (identifier)
(class_body (method_signature
(setter_signature (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier)))))
(function_body (block (expression_statement (assignment_expression (assignable_expression (identifier)) (identifier))))))))
======================================
Basic selector
======================================
void main() {
f(a.b);
}
---
(program
(function_signature (void_type) (identifier) (formal_parameter_list))
(function_body (block
(expression_statement
(identifier)
(selector (argument_part
(arguments
(argument
(identifier)
(selector (unconditional_assignable_selector (identifier)))))))))))

@ -0,0 +1,673 @@
===============
local variable
===============
class A {
int b() {
int c = 5;
}
}
---
(program
(class_definition
name: (identifier)
body: (class_body
(method_signature (function_signature
(type_identifier)
name: (identifier)
(formal_parameter_list))
)
(function_body (block
(local_variable_declaration (initialized_variable_definition
(type_identifier)
name: (identifier)
value: (decimal_integer_literal))))))))
===============================
single type import declaration
===============================
import 'package:dektor/catalog.dart';
---
(program (import_or_export (library_import (import_specification (configurable_uri (uri (string_literal)))))))
===========================
type_import_on_declaraction
===========================
import 'package:dektor/catalog.dart';
---
(program (import_or_export (library_import (import_specification (configurable_uri (uri (string_literal)))))))
=================================
single static import declaration
=================================
import 'package:dektor/catalog.dart';
---
(program (import_or_export (library_import (import_specification (configurable_uri (uri (string_literal)))))))
===================================
static import on demand declaration
===================================
import 'package:dektor/catalog.dart';
---
(program (import_or_export (library_import (import_specification (configurable_uri (uri (string_literal)))))))
=================
class declaration
=================
class Point {
}
---
(program
(class_definition
(identifier)
(class_body)))
=====================================================================
class declaration involving public, private, abstract and superclass
=====================================================================
class Point {
}
class Point {
}
abstract class ColoredPoint extends Point {
}
---
(program
(class_definition (identifier) (class_body))
(class_definition (identifier) (class_body))
(class_definition (identifier) (superclass (type_identifier)) (class_body)))
==================================
class declaration with implements
==================================
class Dog implements ISpeak {
}
---
(program
(class_definition
(identifier)
(interfaces (type_identifier)) (class_body)))
============================
class declaration with body
============================
class Point {
var x;
var s = 'g';
void bar() {
x = 2;
}
}
---
(program
(class_definition
(identifier)
(class_body
(declaration
(inferred_type)
(initialized_identifier_list (initialized_identifier (identifier))))
(declaration
(inferred_type)
(initialized_identifier_list
(initialized_identifier
(identifier)
(string_literal))))
(method_signature (function_signature
(void_type)
(identifier)
(formal_parameter_list)))
(function_body
(block
(expression_statement
(assignment_expression (assignable_expression (identifier)) (decimal_integer_literal))))))))
===================
method declaration
===================
class Beyonce {
void calculateAnswer(double wingSpan, int numberOfEngines,
double length, double grossTons) {
//do the calculation here
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature (function_signature
(void_type)
(identifier)
(formal_parameter_list
(formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier))))
)
(function_body
(block (comment))))))
========================
constructor declaration
========================
class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
Point.json() {
this(0, 0);
}
Point.json(this.x, this.y);
}
---
(program
(class_definition
name: (identifier)
body: (class_body
(declaration
(type_identifier)
(initialized_identifier_list
(initialized_identifier (identifier))
(initialized_identifier (identifier))
)
)
(method_signature (constructor_signature
name: (identifier)
parameters: (formal_parameter_list
(formal_parameter
(type_identifier)
name: (identifier))
(formal_parameter
(type_identifier)
name: (identifier)))))
(function_body
(block (expression_statement (assignment_expression
left: (assignable_expression
(this)
(unconditional_assignable_selector (identifier))
)
right: (identifier))
)
(expression_statement (assignment_expression
left: (assignable_expression
(this)
(unconditional_assignable_selector (identifier))
)
right: (identifier))
)
))
(method_signature (constructor_signature
name: (identifier)
name: (identifier)
parameters: (formal_parameter_list)))
(function_body
(block
(expression_statement
(this)
(selector
(argument_part
(arguments
(argument (decimal_integer_literal))
(argument (decimal_integer_literal))
)
)
)
)
)
)
(declaration
(constructor_signature
name: (identifier)
name: (identifier)
parameters: (formal_parameter_list
(formal_parameter (constructor_param (this) (identifier)))
(formal_parameter (constructor_param (this) (identifier)))
)
)
)
)
)
)
======================
object instantiation
======================
class Point {
double Foo() {
new BufferedWriter();
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature (function_signature
(type_identifier)
(identifier)
(formal_parameter_list))
)
(function_body (block
(expression_statement
(new_expression
(type_identifier)
(arguments)))
)))))
=====================
variable declaration
=====================
class JayZ {
void Beyonce() {
int blue_ivy_carter;
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature (function_signature
(void_type)
(identifier)
(formal_parameter_list)))
(function_body
(block
(local_variable_declaration (initialized_variable_definition
(type_identifier)
(identifier))))))))
=================
enum declaration
=================
enum HandSign {
SCISSOR, PAPER, STONE
}
---
(program
(enum_declaration
name: (identifier)
body: (enum_body
(enum_constant name: (identifier))
(enum_constant name: (identifier))
(enum_constant name: (identifier)))))
=================
variable inferred type declaration
=================
var x = 0;
---
(program (inferred_type)
(initialized_identifier_list (initialized_identifier (identifier) (decimal_integer_literal))))
=================
top level annotated declaration
=================
@annotation
final y = 0;
---
(program
(marker_annotation (identifier))
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier) (decimal_integer_literal))))
=================
static final top level declaration
=================
final y = 1.0;
final double y1 = 1.0;
const z = "100";
const String z1 = "100";
---
(program
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier) (decimal_floating_point_literal)))
(final_builtin)
(type_identifier) (static_final_declaration_list (static_final_declaration (identifier) (decimal_floating_point_literal)))
(const_builtin)
(static_final_declaration_list (static_final_declaration (identifier) (string_literal)))
(const_builtin)
(type_identifier) (static_final_declaration_list (static_final_declaration (identifier) (string_literal))))
=================
identifier with dollar signs
=================
final $y$ = 0;
---
(program
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier) (decimal_integer_literal))))
=================
typedefs
=================
typedef CreateCallback = void Function(String);
typedef void EndCallback(String endValue);
typedef Future<String> Handler(String method, Map<String, String> parameters);
typedef MyFunction<T> = T Function();
typedef DismissMethod = Future<void> Function(WidgetTester tester, Finder finder, {@required AxisDirection gestureDirection});
---
(program
(type_alias (type_identifier)
(function_type
(void_type)
(parameter_type_list (normal_parameter_type (type_identifier)))))
(type_alias
(void_type)
(type_identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier))))
(type_alias
(type_identifier) (type_arguments (type_identifier))
(type_identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier)) (formal_parameter (type_identifier) (type_arguments (type_identifier) (type_identifier)) (identifier))))
(type_alias
(type_identifier) (type_parameters (type_parameter (type_identifier)))
(function_type (type_identifier) (parameter_type_list)))
(type_alias
(type_identifier)
(function_type (type_identifier) (type_arguments (void_type))
(parameter_type_list (normal_parameter_type (typed_identifier (type_identifier) (identifier))) (normal_parameter_type (typed_identifier (type_identifier) (identifier)))
(optional_parameter_types (named_parameter_types (typed_identifier (marker_annotation (identifier)) (type_identifier) (identifier))))))))
=================
script tag
=================
#! /usr/bin/env dshell
import 'package:dshell/dshell.dart';
---
(program
(script_tag)
(import_or_export (library_import (import_specification (configurable_uri (uri (string_literal)))))))
================================================================
non final and final declarations
================================================================
List<String> animations = ['1', '2', '3', '4', 'Default'];
final String assetFile = "assets/myasset.flr";
class MyClass {
}
---
(program
(type_identifier) (type_arguments (type_identifier))
(initialized_identifier_list (initialized_identifier (identifier) (list_literal (string_literal) (string_literal) (string_literal) (string_literal) (string_literal))))
(final_builtin)
(type_identifier) (static_final_declaration_list (static_final_declaration (identifier) (string_literal)))
(class_definition (identifier) (class_body)))
==================================
Nullable Function Parameter
==================================
void callback(Future<void> Function(String?) handler) {
}
---
(program
(function_signature (void_type) (identifier)
(formal_parameter_list
(formal_parameter
(function_type
(type_identifier)
(type_arguments (void_type))
(parameter_type_list (normal_parameter_type (type_identifier)))) (identifier))))
(function_body (block)))
==================================
Type with Library Prefix
==================================
const my.MyType newMyType = my.MyType();
---
(program
(const_builtin)
(type_identifier) (type_identifier)
(static_final_declaration_list
(static_final_declaration
(identifier)
(identifier) (selector
(unconditional_assignable_selector (identifier))
)
(selector (argument_part (arguments)))
)
)
)
==================================
Type with Library Prefix Plus
==================================
const my.MyType newMyType;
const my.MyType newMytype;
---
(program
(local_variable_declaration (initialized_variable_definition (const_builtin) (type_identifier) (type_identifier) (identifier)))
(local_variable_declaration (initialized_variable_definition (const_builtin) (type_identifier) (type_identifier) (identifier)))
)
==================================
Type with Library Prefix Plus Final
==================================
final my.MyType newMyType = my.MyType();
final my.MyType newMytype;
if (blah) {
const my.myType newMyType = ggg;
const mytype = 2;
}
---
(program
(local_variable_declaration (initialized_variable_definition (final_builtin) (type_identifier) (type_identifier) (identifier) (identifier) (selector
(unconditional_assignable_selector (identifier))) (selector (argument_part (arguments)))))
(local_variable_declaration (initialized_variable_definition (final_builtin) (type_identifier) (type_identifier) (identifier)))
(if_statement (parenthesized_expression (identifier))
(block
(local_variable_declaration (initialized_variable_definition (const_builtin) (type_identifier) (type_identifier) (identifier) (identifier)))
(local_variable_declaration (initialized_variable_definition (const_builtin) (identifier) (decimal_integer_literal)))
)
)
)
==================================
Null function argument
==================================
void _invoke(void callback()?, Zone? zone) {
}
---
(program
(function_signature (void_type) (identifier)
(formal_parameter_list
(formal_parameter (void_type) (identifier) (formal_parameter_list))
(formal_parameter (type_identifier) (identifier))))
(function_body (block)))
==================================
Get and set methods (not keyword)
==================================
// Interesting issue of conflict between dart grammar itself and actual value of elements?
String get(String hello) => 'A string $hello';
class MyClass {
void set(String name, Object value) {}
}
---
(program
(comment)
(function_signature (type_identifier) (identifier) (formal_parameter_list (formal_parameter (type_identifier) (identifier))))
(function_body (string_literal (template_substitution (identifier_dollar_escaped))))
(class_definition (identifier)
(class_body
(method_signature
(function_signature (void_type) (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier)) (formal_parameter (type_identifier) (identifier)))))
(function_body (block)))))
==================================
Get and set methods (functional?)
==================================
String get myGetterName => 'A string hello';
class MyClass {
void set myValue(String name, Object value) {}
}
---
(program
(getter_signature (type_identifier) (identifier))
(function_body (string_literal))
(class_definition (identifier)
(class_body
(method_signature
(setter_signature (void_type) (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier)))))
(function_body (block)))))
======================================
Get and set identifiers
======================================
class Tree {
Set toSet() {
Set set = Set();
set._count = _count;
set._root = _root;
return set;
}
}
---
==================================
void types
==================================
class MyClass {
void mySet(String name, Object value) {}
}
---
(program
(class_definition (identifier)
(class_body
(method_signature
(function_signature (void_type) (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier))
(formal_parameter (type_identifier) (identifier)))))
(function_body (block)))))
==================================
external factories
==================================
class LinkedHashMap {
external factory LinkedHashMap();
external factory LinkedHashMap.identity();
}
---
(program
(class_definition (identifier)
(class_body
(declaration (factory_constructor_signature (identifier) (formal_parameter_list)))
(declaration (factory_constructor_signature (identifier) (identifier) (formal_parameter_list))))))

@ -0,0 +1,617 @@
==================================
standalone assignment expression
==================================
x = 3;
---
(program
(expression_statement
(assignment_expression (assignable_expression (identifier)) (decimal_integer_literal))
)
)
==================================
standalone binary expression
==================================
a > b;
a < b;
a == b;
a >= b;
a <= b;
a != b;
a && b;
a || b;
a & b;
a | b;
a ^ b;
a % b;
a << b;
a >> b;
a >>> b;
3 + 2;
3 - 2;
3 * 2;
9 / 3;
---
(program
(expression_statement (relational_expression (identifier) (relational_operator) (identifier)))
(expression_statement (relational_expression (identifier) (relational_operator) (identifier)))
(expression_statement (equality_expression (identifier) (equality_operator) (identifier)))
(expression_statement (relational_expression (identifier) (relational_operator) (identifier)))
(expression_statement (relational_expression (identifier) (relational_operator) (identifier)))
(expression_statement (equality_expression (identifier) (equality_operator) (identifier)))
(expression_statement (logical_and_expression (identifier) (identifier)))
(expression_statement (logical_or_expression (identifier) (identifier)))
(expression_statement (bitwise_and_expression (identifier) (identifier)))
(expression_statement (bitwise_or_expression (identifier) (identifier)))
(expression_statement (bitwise_xor_expression (identifier) (identifier)))
(expression_statement (multiplicative_expression (identifier) (multiplicative_operator) (identifier)))
(expression_statement (shift_expression (identifier) (shift_operator) (identifier)))
(expression_statement (shift_expression (identifier) (shift_operator) (identifier)))
(expression_statement (shift_expression (identifier) (shift_operator) (identifier)))
(expression_statement (additive_expression (decimal_integer_literal) (additive_operator) (decimal_integer_literal)))
(expression_statement (additive_expression (decimal_integer_literal) (additive_operator) (decimal_integer_literal)))
(expression_statement (multiplicative_expression (decimal_integer_literal) (multiplicative_operator) (decimal_integer_literal)))
(expression_statement (multiplicative_expression (decimal_integer_literal) (multiplicative_operator) (decimal_integer_literal)))
)
==================================
instanceof expressions
==================================
a is C.D;
a is List<B>;
c is C;
---
(program
(expression_statement
(type_test_expression
(identifier)
(type_test (is_operator) (type_identifier) (type_identifier))
)
)
(expression_statement
(type_test_expression
(identifier)
(type_test (is_operator) (type_identifier)
(type_arguments (type_identifier))
)
)
)
(expression_statement
(type_test_expression
(identifier)
(type_test (is_operator) (type_identifier))
)
)
)
===========================================================
if statements
===========================================================
if (x)
y;
---
(program
(if_statement
condition: (parenthesized_expression (identifier))
consequence: (expression_statement (identifier))))
===========================================================
if statements with braces
===========================================================
if (x) {
y;
}
---
(program
(if_statement
condition: (parenthesized_expression (identifier))
consequence: (block (expression_statement (identifier)))))
===========================================================
if statements with assignment without braces
===========================================================
if (x != 3)
y = 2;
---
(program
(if_statement
condition: (parenthesized_expression
(equality_expression (identifier) (equality_operator)
(decimal_integer_literal)))
consequence: (expression_statement
(assignment_expression
left: (assignable_expression (identifier))
right: (decimal_integer_literal)))))
==================================
if then else statement
==================================
if (x == 3) {
y = 9;
} else {
y = 0;
}
---
(program
(if_statement
condition: (parenthesized_expression
(equality_expression (identifier) (equality_operator)
(decimal_integer_literal)))
consequence: (block
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (decimal_integer_literal))))
alternative: (block
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (decimal_integer_literal))))))
==================================
nested if then else statements
==================================
if (a)
if (b)
c();
else
d();
---
(program
(if_statement
(parenthesized_expression (identifier))
(if_statement
(parenthesized_expression (identifier))
(expression_statement
(identifier)
(selector (argument_part (arguments)))
)
(expression_statement
(identifier)
(selector (argument_part (arguments)))
))))
==================================
ternary expressions
==================================
max = (a > b) ? a : b;
---
(program
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (conditional_expression
(relational_expression (identifier) (relational_operator) (identifier))
consequence: (identifier)
alternative: (identifier)))))
==================================
for statement
==================================
for(int i = 1; i < 11; i++) {
System.out.println("Count is: " + i);
}
for (j.init(i); j.check(); j.update()) {
System.out.println(j);
}
---
(program
(for_statement
init: (local_variable_declaration (initialized_variable_definition
(type_identifier)
name: (identifier)
value: (decimal_integer_literal)))
condition: (relational_expression
(identifier)
(relational_operator)
(decimal_integer_literal))
update: (postfix_expression (assignable_expression (identifier)) (postfix_operator (increment_operator)))
body: (block
(expression_statement
(identifier)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(argument_part
(arguments
(argument
(additive_expression
(string_literal)
(additive_operator)
(identifier)
)
)
)
)
)
)
)
)
(for_statement
init: (identifier)
init: (selector (unconditional_assignable_selector (identifier)))
init: (selector (argument_part (arguments (argument (identifier)))))
condition: (identifier)
condition: (selector (unconditional_assignable_selector (identifier)))
condition: (selector (argument_part (arguments)))
update: (identifier)
update: (selector (unconditional_assignable_selector (identifier)))
update: (selector (argument_part (arguments)))
body: (block
(expression_statement
(identifier)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(argument_part
(arguments
(argument
(identifier))
)
)
)
)
)
)
)
================================
enhanced for statements
================================
for (A b in c) {
d(b);
}
---
(program
(for_statement
(type_identifier)
(identifier)
(identifier)
(block
(expression_statement (identifier) (selector (argument_part (arguments (argument (identifier)))))))))
================================
await expressions
================================
void main() async {
final id = await Future.delayed(const Duration(seconds: 100));
}
---
(program (function_signature (void_type) (identifier) (formal_parameter_list))
(function_body (block
(local_variable_declaration (initialized_variable_definition (final_builtin) (identifier) (unary_expression
(await_expression (identifier) (selector (unconditional_assignable_selector (identifier)))
(selector (argument_part (arguments (argument
(const_object_expression (const_builtin) (type_identifier)
(arguments (named_argument (label (identifier)) (decimal_integer_literal)))))))))))))))
================================
unary negation expression
================================
void main() {
final remote = false;
if (!remote) {
server = localUrl;
}
}
---
(program (function_signature (void_type) (identifier) (formal_parameter_list))
(function_body (block
(local_variable_declaration (initialized_variable_definition (final_builtin) (identifier) (false)))
(if_statement (parenthesized_expression (unary_expression (prefix_operator (negation_operator)) (identifier)))
(block (expression_statement (assignment_expression (assignable_expression (identifier)) (identifier))))))))
================================
assert statement
================================
assert(x != null);
---
(program
(assert_statement (assertion (equality_expression (identifier) (equality_operator) (null_literal)))))
===========================
Type cast in if statement
===========================
if (data['frame_count'] as int < 5) {
}
---
(program
(if_statement
(parenthesized_expression
(relational_expression
(type_cast_expression
(identifier) (selector
(unconditional_assignable_selector (string_literal))
)
(type_cast (as_operator) (type_identifier))
)
(relational_operator)
(decimal_integer_literal)
)
)
(block)
)
)
===========================
Type cast in if statement parenthesized
===========================
if ((data['frame_count'] as int) < 5) {
}
---
(program
(if_statement
(parenthesized_expression
(relational_expression
(type_cast_expression
(identifier) (selector
(unconditional_assignable_selector (string_literal))
)
(type_cast (as_operator) (type_identifier))
)
(relational_operator)
(decimal_integer_literal)
)
)
(block)
)
)
==========================
Simple non-null assertion
==========================
my!.size = 1;
---
(program
(expression_statement
(assignment_expression
(assignable_expression (identifier)
(selector)
(unconditional_assignable_selector (identifier))
)
(decimal_integer_literal)
)
)
)
==========================
Simple non-null assertion alternative-test
==========================
my!.size += 1;
---
(program
(expression_statement
(assignment_expression
(assignable_expression (identifier)
(selector)
(unconditional_assignable_selector (identifier))
)
(decimal_integer_literal)
)
)
)
==========================
Additional non-null assertion
==========================
my.size!.run();
---
(program
(expression_statement (identifier)
(selector
(unconditional_assignable_selector (identifier))) (selector)
(selector (unconditional_assignable_selector (identifier)))
(selector (argument_part (arguments))))
)
============================
Simple assertion w/o nonnull
============================
my.size.whatever = 1;
---
(program
(expression_statement
(assignment_expression
(assignable_expression (identifier)
(selector
(unconditional_assignable_selector (identifier)))
(unconditional_assignable_selector (identifier))
)
(decimal_integer_literal)
)
)
)
============================
Complex type cast in function call
============================
printStream(args['json'] as bool ? '' : 'hi');
---
(program
(expression_statement
(identifier)
(selector
(argument_part
(arguments
(argument
(conditional_expression
(type_cast_expression (identifier)
(selector (unconditional_assignable_selector (string_literal)))
(type_cast (as_operator) (type_identifier))
)
(string_literal)
(string_literal)
)
)
)
)
)
)
)
============================
Complex (parenthesized) type cast in function call
============================
printStream((args['json'] as bool) ? '' : 'hi');
---
(program
(expression_statement
(identifier)
(selector
(argument_part
(arguments
(argument
(conditional_expression
(type_cast_expression (identifier)
(selector (unconditional_assignable_selector (string_literal)))
(type_cast (as_operator) (type_identifier))
)
(string_literal)
(string_literal)
)
)
)
)
)
)
)
==================================
typecast in expression
==================================
a['json'] as BigB > b;
a < b['json'] as BigB;
a == b as BigB;
a as BigB >= b;
a <= b;
a as BigB != b;
a && b as BigB;
a as BigB || b as BigB;
if (a['json'] as BigB < b as BigB) {
}
a as BigB | b as BigB;
---
(program
(expression_statement
(relational_expression
(type_cast_expression (identifier)
(selector (unconditional_assignable_selector (string_literal)))
(type_cast (as_operator) (type_identifier)))
(relational_operator)
(identifier)))
(expression_statement
(relational_expression (identifier) (relational_operator)
(type_cast_expression (identifier)
(selector (unconditional_assignable_selector (string_literal)))
(type_cast (as_operator) (type_identifier)))))
(expression_statement (equality_expression (identifier) (equality_operator) (type_cast_expression (identifier) (type_cast (as_operator) (type_identifier)))))
(expression_statement (relational_expression (type_cast_expression (identifier) (type_cast (as_operator) (type_identifier))) (relational_operator) (identifier)))
(expression_statement (relational_expression (identifier) (relational_operator) (identifier)))
(expression_statement (equality_expression (type_cast_expression (identifier) (type_cast (as_operator) (type_identifier))) (equality_operator) (identifier)))
(expression_statement (logical_and_expression (identifier) (type_cast_expression (identifier) (type_cast (as_operator) (type_identifier)))))
(expression_statement (logical_or_expression (type_cast_expression (identifier) (type_cast (as_operator) (type_identifier))) (type_cast_expression (identifier) (type_cast (as_operator) (type_identifier)))))
(if_statement
(parenthesized_expression
(relational_expression
(type_cast_expression (identifier)
(selector (unconditional_assignable_selector (string_literal)))
(type_cast (as_operator) (type_identifier)))
(relational_operator)
(type_cast_expression (identifier) (type_cast (as_operator) (type_identifier))))) (block))
(expression_statement
(bitwise_or_expression
(type_cast_expression (identifier) (type_cast (as_operator) (type_identifier)))
(type_cast_expression (identifier) (type_cast (as_operator) (type_identifier))))))
=============================
Non-null assignable selector
=============================
parameters?["charset"];
---
(program
(expression_statement (identifier)
(selector (unconditional_assignable_selector (string_literal)))))

@ -0,0 +1,220 @@
========================================
simple flutter example
========================================
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container();
}
}
---
(program
(import_or_export
(library_import (import_specification (configurable_uri (uri (string_literal))))))
(function_signature (void_type) (identifier) (formal_parameter_list))
(function_body (block (expression_statement (identifier) (selector (argument_part
(arguments (argument (identifier) (selector (argument_part (arguments))))))))))
(class_definition (identifier) (superclass (type_identifier))
(class_body
(declaration (constant_constructor_signature (const_builtin) (qualified (identifier))
(formal_parameter_list (optional_formal_parameters (formal_parameter (type_identifier) (identifier)))))
(initializers (initializer_list_entry (arguments (named_argument (label (identifier)) (identifier))))))
(marker_annotation (identifier))
(method_signature (function_signature (type_identifier) (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier)))))
(function_body (block (return_statement (identifier) (selector (argument_part (arguments)))))))))
===============================================
ben's flutter error testing
===============================================
class CatalogThumbnailUI extends StatelessWidget {
static const routeName = '/catalog';
CatalogThumbnailUI(this.thread);
final ThreadModel thread;
@override
Widget build(BuildContext context) {
// TODO: implement build
var op = thread.posts.first;
var remainingPosts = thread.posts.getRange(1, thread.posts.length);
var previewRemaining = remainingPosts.map((f) => Column(
children: <Widget>[
Divider(),
Row(children: <Widget>[
Text(f.utc.difference(DateTime.now()).inHours.toString()),
Text(f.text),
Text('...')
],)
],
));
return Card(
child: Column(
children: <Widget>[
Expanded(child: PostUI(op, true)),
...previewRemaining
],
),
);
}
}
------------------------------
(program
(class_definition (identifier) (superclass (type_identifier))
(class_body
(declaration (const_builtin) (static_final_declaration_list (static_final_declaration (identifier) (string_literal))))
(declaration (constructor_signature (identifier)
(formal_parameter_list (formal_parameter (constructor_param (this) (identifier))))))
(declaration (final_builtin) (type_identifier) (initialized_identifier_list (initialized_identifier (identifier))))
(marker_annotation (identifier))
(method_signature
(function_signature (type_identifier) (identifier)
(formal_parameter_list (formal_parameter (type_identifier) (identifier)))))
(function_body
(block (comment)
(local_variable_declaration
(initialized_variable_definition (inferred_type) (identifier) (identifier)
(selector (unconditional_assignable_selector (identifier)))
(selector (unconditional_assignable_selector (identifier)))))
(local_variable_declaration
(initialized_variable_definition (inferred_type) (identifier) (identifier)
(selector (unconditional_assignable_selector (identifier)))
(selector (unconditional_assignable_selector (identifier)))
(selector (argument_part (arguments (argument (decimal_integer_literal)) (argument (identifier)
(selector (unconditional_assignable_selector (identifier)))
(selector (unconditional_assignable_selector (identifier)))))))))
(local_variable_declaration
(initialized_variable_definition (inferred_type) (identifier) (identifier)
(selector (unconditional_assignable_selector (identifier)))
(selector
(argument_part
(arguments
(argument
(function_expression
(formal_parameter_list (formal_parameter (identifier)))
(function_expression_body (identifier)
(selector
(argument_part
(arguments
(named_argument (label (identifier))
(list_literal
(type_arguments (type_identifier)) (identifier)
(selector (argument_part (arguments))) (identifier)
(selector
(argument_part
(arguments
(named_argument (label (identifier))
(list_literal
(type_arguments (type_identifier))
(identifier)
(selector
(argument_part
(arguments (argument (identifier)
(selector
(unconditional_assignable_selector
(identifier)))
(selector
(unconditional_assignable_selector
(identifier)))
(selector
(argument_part
(arguments (argument (identifier)
(selector
(unconditional_assignable_selector (identifier)))
(selector (argument_part (arguments)))))))
(selector
(unconditional_assignable_selector (identifier)))
(selector
(unconditional_assignable_selector (identifier)))
(selector (argument_part (arguments)))))))
(identifier)
(selector
(argument_part
(arguments (argument (identifier)
(selector
(unconditional_assignable_selector (identifier)))))))
(identifier)
(selector
(argument_part
(arguments (argument
(string_literal)))))
))))))))))))))))))
(return_statement
(identifier)
(selector
(argument_part
(arguments
(named_argument
(label (identifier))
(identifier)
(selector
(argument_part
(arguments
(named_argument (label (identifier))
(list_literal
(type_arguments (type_identifier))
(identifier)
(selector
(argument_part
(arguments
(named_argument (label (identifier))
(identifier)
(selector
(argument_part (arguments (argument (identifier)) (argument (true)))))))))
(spread_element (identifier))))))))))))
)))))
======================
Const list constructors
======================
import 'package:flutter/material.dart';
class AWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: const [
Flexible(child: ColoredBox(color: Colors.white)),
Flexible(child: ColoredBox(color: Colors.blue))
],
);
}
}
---
(program
(import_or_export (library_import (import_specification (configurable_uri (uri (string_literal))))))
(class_definition (identifier) (superclass (type_identifier))
(class_body (marker_annotation (identifier))
(method_signature (function_signature (type_identifier) (identifier) (formal_parameter_list (formal_parameter (type_identifier) (identifier)))))
(function_body (block
(return_statement (identifier)
(selector (argument_part (arguments (named_argument (label (identifier))
(list_literal (const_builtin) (identifier)
(selector (argument_part (arguments (named_argument (label (identifier)) (identifier)
(selector (argument_part (arguments (named_argument (label (identifier)) (identifier)
(selector (unconditional_assignable_selector (identifier))))))))))) (identifier)
(selector (argument_part (arguments (named_argument (label (identifier)) (identifier)
(selector (argument_part (arguments (named_argument (label (identifier)) (identifier)
(selector (unconditional_assignable_selector (identifier))))))))))))))))))))))

@ -0,0 +1,185 @@
========================
decimal integer literals
========================
123;
4;
50;
---
(program
(expression_statement (decimal_integer_literal))
(expression_statement (decimal_integer_literal))
(expression_statement (decimal_integer_literal)))
====================
hex integer literals
====================
0xa_bcd_ef0;
0Xa_bcd_ef0;
0X8000;
---
(program
(expression_statement (hex_integer_literal))
(expression_statement (hex_integer_literal))
(expression_statement (hex_integer_literal)))
===============================
floating point literals
===============================
4.23e9;
4.23e-9;
4.23e+9;
40.3e6;
40.3e-6;
1.234;
0.123456;
.12345;
1e4;
0.2e-2;
0.0e-4;
.2e-2;
5.4;
5.4e-10;
---
(program
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal))
(expression_statement (decimal_floating_point_literal)))
================
boolean literals
================
true;
false;
---
(program
(expression_statement (true))
(expression_statement (false)))
===============
string literals
===============
"";
"\"";
"This is a string";
"'";
'\n';
---
(program
(expression_statement (string_literal))
(expression_statement (string_literal (escape_sequence)))
(expression_statement (string_literal))
(expression_statement (string_literal))
(expression_statement (string_literal (escape_sequence))))
=============
null literals
=============
null;
---
(program
(expression_statement (null_literal)))
=============
multiline string literals with single quotes of same type inside
=============
'''
# * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')
''';
---
(program (expression_statement (string_literal)))
=============
adjacent string concatentation
=============
final str = 'a string'
'another string';
final mixedStr = r'''(["'])((?:\\{2})*|(?:.*?[^\\](?:\\{2})*))\2|''' // with quotes.
r'([^ ]+))';
---
(program
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier) (string_literal)))
(final_builtin)
(static_final_declaration_list (static_final_declaration (identifier) (string_literal (comment)))))
=============
complex string interpolation
=============
'ERROR: $error${'\n$stackTrace' ?? ''}';
---
(program
(expression_statement (string_literal
(template_substitution (identifier_dollar_escaped))
(template_substitution
(if_null_expression
(string_literal (escape_sequence) (template_substitution (identifier_dollar_escaped)))
(string_literal))))))
=============
raw strings single
=============
r'\';
r'''\''';
---
(program
(expression_statement (string_literal))
(expression_statement (string_literal))
)
=============
raw strings double
=============
r"\";
r"""\""";
---
(program
(expression_statement (string_literal))
(expression_statement (string_literal))
)

@ -0,0 +1,550 @@
==================================
while statement
==================================
class WhileDemo {
void main(String args){
int count = 1;
while (count < 11) {
System.out.println("Count is: " + count);
count++;
}
}
}
---
(program
(class_definition
name: (identifier)
body: (class_body
(method_signature
(function_signature
(void_type)
name: (identifier)
(formal_parameter_list
(formal_parameter
(type_identifier)
name: (identifier)))
)
)
(function_body
(block
(local_variable_declaration (initialized_variable_definition
(type_identifier)
name: (identifier)
value: (decimal_integer_literal)))
(while_statement
condition: (parenthesized_expression
(relational_expression
(identifier)
(relational_operator)
(decimal_integer_literal)))
body: (block
(expression_statement
(identifier)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(argument_part (arguments
(argument (additive_expression
(string_literal)
(additive_operator)
(identifier)
))
))
)
)
(expression_statement
(postfix_expression (assignable_expression (identifier)) (postfix_operator (increment_operator)))
)
)
)
)
)
)
)
)
==================================
try-with-resources statements
==================================
get a {
var a;
try {
int data = input.read();
} on Exception catch (e) {
a();
}
}
---
(program
(getter_signature
name: (identifier))
(function_body
(block
(local_variable_declaration (initialized_variable_definition (inferred_type) name: (identifier)))
(try_statement
body: (block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
name: (identifier)
value: (identifier)
value:
(selector
(unconditional_assignable_selector (identifier))
)
value:
(selector
(argument_part
(arguments)
)
)
)
)
)
(type_identifier)
(catch_clause
(identifier))
(block
(expression_statement
(identifier)
(selector
(argument_part
(arguments)
)
)
)
)
)
)
)
)
==================================
return statement
==================================
return x;
return x * y;
return x + 2;
return fire(x);
---
(program
(return_statement (identifier))
(return_statement (multiplicative_expression (identifier) (multiplicative_operator) (identifier)))
(return_statement (additive_expression (identifier) (additive_operator) (decimal_integer_literal)))
(return_statement (identifier) (selector (argument_part (arguments (argument (identifier)))))))
==================================
annotation
==================================
@SuppressWarnings(value = "unchecked")
@GwtCompatible(emulated = true)
class Duck {
}
---
(program
(annotation
(identifier)
(arguments (argument (assignment_expression (assignable_expression (identifier)) (string_literal))))
)
(annotation
(identifier)
(arguments (argument (assignment_expression (assignable_expression (identifier)) (true))))
)
(class_definition
(identifier)
(class_body)
)
)
==================================
marker annotation
==================================
@Override
class Quack {
@bar
void foo() {
}
}
---
(program
(marker_annotation (identifier))
(class_definition
(identifier)
(class_body
(marker_annotation (identifier))
(method_signature
(function_signature
(void_type)
(identifier)
(formal_parameter_list)
))
(function_body
(block))
)))
==================================
single element annotation
==================================
@Duck(waddle.swim)
@SuppressWarnings("unchecked")
class Quack {
}
---
(program
(annotation (identifier)
(arguments (argument (identifier) (selector (unconditional_assignable_selector (identifier)))))
)
(annotation (identifier) (arguments (argument (string_literal))))
(class_definition
(identifier)
(class_body)))
==================================
lambda expression
==================================
class LambdaTest {
void singleton() {
var b = (Str version) => create;
var d = (Str a) {
int destinysChild = 2;
};
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature (function_signature
(void_type)
(identifier)
(formal_parameter_list)))
(function_body
(block
(local_variable_declaration
(initialized_variable_definition (inferred_type) (identifier)
(function_expression
(formal_parameter_list (formal_parameter (type_identifier) (identifier)))
(function_expression_body (identifier))
)
)
)
(local_variable_declaration
(initialized_variable_definition
(inferred_type) (identifier) (function_expression
(formal_parameter_list (formal_parameter (type_identifier) (identifier)) )
(function_expression_body
(block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
(decimal_integer_literal)))
)))
)
))
))))
==================================
switch statement
==================================
class SwitchDemo {
static void main(String args) {
int destinysChild = 2;
String destinysChildString;
switch (destinysChild) {
case 1: destinysChildString = "Beyonce";
break;
case 2: destinysChildString = "Kelly";
break;
case 3: destinysChildString = "Michelle";
break;
default: destinysChildString = "Invalid";
break;
}
System.out.println(destinysChildString);
}
}
---
(program
(class_definition
name: (identifier)
body: (class_body
(method_signature (function_signature
(void_type)
name: (identifier)
(formal_parameter_list
(formal_parameter
(type_identifier)
name: (identifier)
)
)
))
(function_body (block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
name: (identifier)
value: (decimal_integer_literal)
)
)
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
name: (identifier)
)
)
(switch_statement
condition: (parenthesized_expression (identifier))
body: (switch_block
(switch_label (case_builtin) (decimal_integer_literal))
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (string_literal)))
(break_statement)
(switch_label (case_builtin) (decimal_integer_literal))
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (string_literal)))
(break_statement)
(switch_label (case_builtin) (decimal_integer_literal))
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (string_literal)))
(break_statement)
(switch_label)
(expression_statement (assignment_expression
left: (assignable_expression (identifier))
right: (string_literal)))
(break_statement)))
(expression_statement
(identifier)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(argument_part (arguments (argument (identifier))))
)
)
)
)
)
)
)
==================================
type arguments
==================================
class Box <T> {
T theObject;
Box( T arg) { theObject = arg; }
// more code
}
---
(program
(class_definition
(identifier)
(type_parameters
(type_parameter
(type_identifier)))
(class_body
(declaration
(type_identifier)
(initialized_identifier_list (initialized_identifier (identifier)))
)
(method_signature (constructor_signature
(identifier)
(formal_parameter_list
(formal_parameter
(type_identifier)
(identifier)))))
(function_body
(block (expression_statement (assignment_expression
(assignable_expression (identifier))
(identifier)))))
(comment))))
==================================
wildcard
==================================
class WildcardDemo {
List<B> a;
}
---
(program
(class_definition
(identifier)
(class_body
(declaration
(type_identifier)
(type_arguments
(type_identifier))
(initialized_identifier_list (initialized_identifier (identifier)))
))))
==================================
type arguments with generic types
==================================
class someClass <T> {
List<T> someMethod() {
List< T > list = Collections.emptyList<S>();
emptyList<S, H>(g);
return list;
}
void anotherMethod<T>(S arg) {
List< S > list = Collections.emptyList<S>();
}
}
---
(program
(class_definition
(identifier)
(type_parameters
(type_parameter
(type_identifier)))
(class_body
(method_signature (function_signature
(type_identifier)
(type_arguments (type_identifier))
(identifier)
(formal_parameter_list)
))
(function_body (block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(type_arguments (type_identifier))
(identifier)
(identifier)
(selector
(unconditional_assignable_selector (identifier))
)
(selector
(argument_part
(type_arguments
(type_identifier)
)
(arguments)
)
)
)
)
(expression_statement
(identifier)
(selector
(argument_part
(type_arguments
(type_identifier)
(type_identifier)
)
(arguments (argument (identifier)))
)
)
)
(return_statement (identifier))))
(method_signature (function_signature
(void_type)
(identifier)
(type_parameters
(type_parameter
(type_identifier)))
(formal_parameter_list
(formal_parameter
(type_identifier)
(identifier)))
))
(function_body (block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(type_arguments (type_identifier))
(identifier)
(identifier)
(selector
(unconditional_assignable_selector
(identifier)
)
)
(selector
(argument_part
(type_arguments
(type_identifier)
) (arguments)
)
)
)
)
)
)
)
)
)
==================================
empty type arguments
==================================
Box<Integer> integerBox = new Box<>();
---
(program
(type_identifier) (type_arguments (type_identifier))
(initialized_identifier_list
(initialized_identifier (identifier)
(new_expression (type_identifier) (type_arguments) (arguments)))))

@ -0,0 +1,104 @@
===============
integral types
===============
class Beyonce {
int formation() {
int x;
byte x;
short x;
long x;
char x;
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature
(function_signature
(type_identifier)
(identifier)
(formal_parameter_list)
)
)
(function_body
(block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)))
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
))
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
))
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
))
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
))
)
)
)
)
)
=====================
floating point types
=====================
class Beyonce {
int formation() {
float x;
double x;
}
}
---
(program
(class_definition
(identifier)
(class_body
(method_signature
(function_signature
(type_identifier)
(identifier)
(formal_parameter_list)
)
)
(function_body
(block
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
))
(local_variable_declaration
(initialized_variable_definition
(type_identifier)
(identifier)
))))
)))

@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container();
}
}
Future<void> hello() async {
// <- keyword
}
Stream<String> helloStream() async* {
// <- keyword
}
Iterable<String> helloIter() sync* {
// <- keyword
}

@ -0,0 +1,43 @@
enum Material {
// ^ type
DENIM,
CANVAS
}
class Person {
// ^ type
String name;
Person(String name) {
// <- type
// ^ type
this.name = name;
this.pants = new Pants<Pocket>();
// ^ type
// ^ type
}
String getName() {
// <- type
// ^ function.method
return this.name;
return Material.DENIM;
}
}
class Collections {
static List<T> emptyList<T>() {
return [];
}
}
class someClass<T> {
List<T> someMethod() {
List<T> list = Collections.emptyList<T>();
return list;
}
void anotherMethod<S>(S arg) {
List<S> list = Collections.emptyList<S>();
}
}

@ -0,0 +1,8 @@
#!/bin/bash
dart tester/test.dart $1
## USAGE
# ./test_all.sh ~/flutter
# Or whatever directory you want to find all errors in
# Edit test.dart to change how many error lines it prints
# Default maximum is 100 lines, so you don't get endless errors printing out

@ -0,0 +1,8 @@
name: tree_sitter_dart_tester
dependencies:
path: any
dev_dependencies:
derry: any
dshell: any

@ -0,0 +1,54 @@
#! /usr/bin/env dshell
import 'dart:io';
import 'package:dshell/dshell.dart';
/// dshell script generated by:
/// dshell create test.dart
///
/// See
/// https://pub.dev/packages/dshell#-installing-tab-
///
/// For details on installing dshell.
///
var lines = 0;
final sectionSize = 100;
final maxPrint = 500;
var linesPrinted = 0;
var errorLines = 0;
void main(List<String> args) async {
if (args.length < 1) {
print("Usage: dart test.dart /path/to/directory/for/testing");
}
final files = <String>[];
find('*.dart', root: args[0], includeHidden: false).forEach((file) {
files.add(file);
});
final results = <Future<void>>[];
for (var i = 0; i < files.length; i += sectionSize) {
final sublist = files.sublist(
i, i + sectionSize < files.length ? i + sectionSize : files.length);
results.add(runTreeSitter(sublist));
}
await Future.wait(results);
print('Processed $lines lines of tree-sitter output');
print('Error lines $errorLines');
print('Error percentage ${errorLines * 100 / lines}%');
}
Future<void> runTreeSitter(List<String> files) async {
final result = await Process.run(
absolute('node_modules/tree-sitter-cli/tree-sitter'),
['parse', ...files]);
for (final line in result.stdout.split('\n')) {
lines++;
if (line.contains('ERROR')) {
errorLines++;
if (linesPrinted < maxPrint) {
linesPrinted++;
print(line);
}
}
}
}