Use tree-sitter-c-sharp from crates.io

pull/795/head
Wilfred Hughes 2024-12-19 23:21:26 +07:00
parent de6e6707d2
commit 2bbed44664
66 changed files with 229 additions and 1588921 deletions

@ -10,7 +10,7 @@ with YAML.
Improved language detection when one argument is a named pipe.
Updated to the latest tree-sitter parser for Haskell, Objective-C,
Updated to the latest tree-sitter parser for C#, Haskell, Objective-C,
OCaml, Ruby and Scala.
### Syntax Highlighting

11
Cargo.lock generated

@ -249,6 +249,7 @@ dependencies = [
"strsim",
"strum",
"tree-sitter",
"tree-sitter-c-sharp",
"tree-sitter-haskell",
"tree-sitter-language",
"tree-sitter-objc",
@ -1006,6 +1007,16 @@ dependencies = [
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-c-sharp"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67f06accca7b45351758663b8215089e643d53bd9a660ce0349314263737fcb0"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-haskell"
version = "0.23.1"

@ -83,6 +83,7 @@ tree-sitter-ruby = "0.23.1"
tree-sitter-scala = "0.23.3"
tree-sitter-objc = "3.0.2"
tree-sitter-ocaml = "0.23.2"
tree-sitter-c-sharp = "0.23.1"
[dev-dependencies]
# assert_cmd 2.0.10 requires predicates 3.

@ -93,11 +93,6 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-cpp-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-c-sharp",
src_dir: "vendored_parsers/tree-sitter-c-sharp-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-clojure",
src_dir: "vendored_parsers/tree-sitter-clojure-src",

@ -65,7 +65,6 @@ extern "C" {
fn tree_sitter_apex() -> ts::Language;
fn tree_sitter_bash() -> ts::Language;
fn tree_sitter_c() -> ts::Language;
fn tree_sitter_c_sharp() -> ts::Language;
fn tree_sitter_clojure() -> ts::Language;
fn tree_sitter_cmake() -> ts::Language;
fn tree_sitter_cpp() -> ts::Language;
@ -262,7 +261,8 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig {
}
}
CSharp => {
let language = unsafe { tree_sitter_c_sharp() };
let language_fn = tree_sitter_c_sharp::LANGUAGE;
let language = tree_sitter::Language::new(language_fn);
TreeSitterConfig {
language: language.clone(),
atom_nodes: vec![

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

@ -0,0 +1,214 @@
;; https://github.com/tree-sitter/tree-sitter-c-sharp/blob/4bf615f8d688f50d69fc5677187dc35f22e03ad6/queries/highlights.scm
;; MIT license
(identifier) @variable
;; Methods
(method_declaration name: (identifier) @function)
(local_function_statement name: (identifier) @function)
;; Types
(interface_declaration name: (identifier) @type)
(class_declaration name: (identifier) @type)
(enum_declaration name: (identifier) @type)
(struct_declaration (identifier) @type)
(record_declaration (identifier) @type)
(namespace_declaration name: (identifier) @module)
(generic_name (identifier) @type)
(type_parameter (identifier) @property.definition)
(parameter type: (identifier) @type)
(type_argument_list (identifier) @type)
(as_expression right: (identifier) @type)
(is_expression right: (identifier) @type)
(constructor_declaration name: (identifier) @constructor)
(destructor_declaration name: (identifier) @constructor)
(_ type: (identifier) @type)
(base_list (identifier) @type)
(predefined_type) @type.builtin
;; Enum
(enum_member_declaration (identifier) @property.definition)
;; Literals
[
(real_literal)
(integer_literal)
] @number
[
(character_literal)
(string_literal)
(raw_string_literal)
(verbatim_string_literal)
(interpolated_string_expression)
(interpolation_start)
(interpolation_quote)
] @string
(escape_sequence) @string.escape
[
(boolean_literal)
(null_literal)
] @constant.builtin
;; Comments
(comment) @comment
;; Tokens
[
";"
"."
","
] @punctuation.delimiter
[
"--"
"-"
"-="
"&"
"&="
"&&"
"+"
"++"
"+="
"<"
"<="
"<<"
"<<="
"="
"=="
"!"
"!="
"=>"
">"
">="
">>"
">>="
">>>"
">>>="
"|"
"|="
"||"
"?"
"??"
"??="
"^"
"^="
"~"
"*"
"*="
"/"
"/="
"%"
"%="
":"
] @operator
[
"("
")"
"["
"]"
"{"
"}"
(interpolation_brace)
] @punctuation.bracket
;; Keywords
[
(modifier)
"this"
(implicit_type)
] @keyword
[
"add"
"alias"
"as"
"base"
"break"
"case"
"catch"
"checked"
"class"
"continue"
"default"
"delegate"
"do"
"else"
"enum"
"event"
"explicit"
"extern"
"finally"
"for"
"foreach"
"global"
"goto"
"if"
"implicit"
"interface"
"is"
"lock"
"namespace"
"notnull"
"operator"
"params"
"return"
"remove"
"sizeof"
"stackalloc"
"static"
"struct"
"switch"
"throw"
"try"
"typeof"
"unchecked"
"using"
"while"
"new"
"await"
"in"
"yield"
"get"
"set"
"when"
"out"
"ref"
"from"
"where"
"select"
"record"
"init"
"with"
"let"
] @keyword
;; Attribute
(attribute name: (identifier) @attribute)
;; Parameters
(parameter
name: (identifier) @variable.parameter)
;; Type constraints
(type_parameter_constraints_clause (identifier) @property.definition)
;; Method calls
(invocation_expression (member_access_expression name: (identifier) @function))

@ -1 +0,0 @@
tree-sitter-c-sharp/src

@ -1,4 +0,0 @@
/src/** linguist-vendored
/script/** text eol=lf
/src/parser.c -diff
/src/grammar.json -diff

@ -1,36 +0,0 @@
name: build
on:
push:
pull_request:
branches:
- "**" # Don't trust forks because miners
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install
- run: npm test
build-windows:
runs-on: windows-latest
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install
- run: npm run-script test-windows

@ -1,33 +0,0 @@
name: Publish on crates.io
on:
push:
tags:
- v*
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable
run: |
rustup toolchain install stable --profile minimal --no-self-update
- name: Verify publish crate
uses: katyo/publish-crates@v1
with:
dry-run: true
- name: Publish crate
uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

@ -1,13 +0,0 @@
Cargo.lock
node_modules
build
npm-debug.log
package-lock.json
parser.exp
parser.lib
parser.obj
examples
!examples/.gitkeep
scanner.obj
/target/
.build/

@ -1,6 +0,0 @@
examples
corpus
build
.travis.yml
appveyor.yml
target

@ -1,36 +0,0 @@
[package]
name = "tree-sitter-c-sharp"
description = "C# grammar for the tree-sitter parsing library"
version = "0.20.0"
authors = [
"Damien Guard <damieng@gmail.com>",
"Max Brunsfeld <maxbrunsfeld@gmail.com>",
"Martin Midtgaard <martin.midtgaard@gmail.com>",
"Sjoerd Langkemper <sjoerd-github@linuxonly.nl>",
"Patrick Thomson <patrickt@github.com>",
"Noelle Caldwell <noelle.caldwell@microsoft.com>",
"Douglas Creager <dcreager@dcreager.net>",
]
license = "MIT"
readme = "bindings/rust/README.md"
keywords = ["incremental", "parsing", "c-sharp"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-c-sharp"
edition = "2018"
build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
[lib]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = ">= 0.19, < 0.21"
[build-dependencies]
cc = "1.0"

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014-2023 Max Brunsfeld, Damien Guard, and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,38 +0,0 @@
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "TreeSitterCSharp",
products: [
.library(name: "TreeSitterCSharp", targets: ["TreeSitterCSharp"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterCSharp",
path: ".",
exclude: [
"binding.gyp",
"bindings",
"Cargo.toml",
"corpus",
"grammar.js",
"index.js",
"LICENSE",
"Makefile",
"package.json",
"README.md",
"script",
"src/grammar.json",
"src/node-types.json",
],
sources: [
"src/parser.c",
"src/scanner.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
]
)

@ -1,48 +0,0 @@
# tree-sitter-c-sharp
[![Build Status](https://github.com/tree-sitter/tree-sitter-c-sharp/workflows/build/badge.svg)](https://github.com/tree-sitter/tree-sitter-c-sharp/actions?query=workflow%3Abuild)
C# grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter) based upon the Roslyn grammar with changes in order to:
- Deal with differences between the parsing technologies
- Work around some bugs in that grammar
- Handle `#if`, `#else`, `#elif`, `#endif` blocks
- Support syntax highlighting/parsing of fragments
- Simplify the output tree
### Status
Comprehensive supports C# 1 through 10.0 with the following exceptions:
- [ ] `async`, `var` and `await` cannot be used as identifiers everywhere they are valid
#### C# 10.0
- [x] global using directives
- [x] File-scoped namespace declaration
- [x] Extended property patterns
- [x] Allow const interpolated strings
- [x] Record types can seal ToString()
- [x] Allow both assignment and declaration in the same deconstruction
- [x] Allow AsyncMethodBuilder attribute on methods
- [x] Record structs
- [x] Lambda improvements
#### C# 11.0 (under development)
- [x] Generic attributes
- [x] Static abstract members in interfaces
- [x] Newlines in string interpolations
- [x] List patterns
- [x] Slice pattern
- [x] Required members
- [x] File scoped classes
- [ ] Raw string literals
- [x] File scoped types
- [x] Scoped ref
### References
- [Official C# 6 Language Spec](https://github.com/dotnet/csharplang/blob/master/spec/) provides chapters that formally define the language grammar.
- [Roslyn C# language grammar export](https://github.com/dotnet/roslyn/blob/master/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4)
- [SharpLab](https://sharplab.io) (web-based syntax tree playground based on Roslyn)

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

@ -1,28 +0,0 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_c_sharp();
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_c_sharp());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("c_sharp").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_c_sharp_binding, Init)
} // namespace

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

@ -1,37 +0,0 @@
# tree-sitter-c-sharp
This crate provides a C# grammar for the [tree-sitter][] parsing library. To
use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
file. (Note that you will probably also need to depend on the
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
way.)
``` toml
[dependencies]
tree-sitter = "0.17"
tree-sitter-c-sharp = "0.16"
```
Typically, you will use the [language][language func] function to add this
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
``` rust
let code = r#"
class Test {
int double(int x) => x * 2;
}
"#;
let mut parser = Parser::new();
parser.set_language(tree_sitter_c_sharp::language()).expect("Error loading C# grammar");
let parsed = parser.parse(code, None);
```
If you have any questions, please reach out to us in the [tree-sitter
discussions] page.
[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
[language func]: https://docs.rs/tree-sitter-c-sharp/*/tree_sitter_c_sharp/fn.language.html
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
[tree-sitter]: https://tree-sitter.github.io/
[tree-sitter crate]: https://crates.io/crates/tree-sitter
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions

@ -1,19 +0,0 @@
use std::path::Path;
extern crate cc;
fn main() {
let src_dir = 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);
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
c_config.compile("parser-scanner");
}

@ -1,69 +0,0 @@
// -*- coding: utf-8 -*-
// ------------------------------------------------------------------------------------------------
// Copyright © 2020, tree-sitter-c-sharp authors.
// See the LICENSE file in this repo for license details.
// ------------------------------------------------------------------------------------------------
//! This crate provides a C# grammar for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this grammar to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! use tree_sitter::Parser;
//!
//! let code = r#"
//! class Test {
//! int double(int x) => x * 2;
//! }
//! "#;
//! let mut parser = Parser::new();
//! parser.set_language(tree_sitter_c_sharp::language()).expect("Error loading C# grammar");
//! let parsed = parser.parse(code, None);
//! # let parsed = parsed.unwrap();
//! # let root = parsed.root_node();
//! # assert!(!root.has_error());
//! ```
//!
//! [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_c_sharp() -> Language;
}
/// Returns 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_c_sharp() }
}
/// The source of the C# tree-sitter grammar description.
pub const GRAMMAR: &'static str = include_str!("../../grammar.js");
/// 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");
/// The symbol tagging query for this language.
pub const TAGGING_QUERY: &'static str = include_str!("../../queries/tags.scm");
/// The syntax highlighting query for this language.
pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");
#[cfg(test)]
mod tests {
#[test]
fn can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading C# grammar");
}
}

@ -1,16 +0,0 @@
#ifndef TREE_SITTER_CSHARP_H_
#define TREE_SITTER_CSHARP_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
extern TSLanguage *tree_sitter_c_sharp();
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_CSHARP_H_

@ -1,481 +0,0 @@
================================================================================
Global attributes
================================================================================
[assembly: Single]
[module: A, C()]
--------------------------------------------------------------------------------
(compilation_unit
(global_attribute_list
(attribute
(identifier)))
(global_attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list))))
================================================================================
Attributes with arguments
================================================================================
[A(B.C)]
class D {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(attribute_list
(attribute
(identifier)
(attribute_argument_list
(attribute_argument
(member_access_expression
(identifier)
(identifier))))))
(identifier)
(declaration_list)))
================================================================================
Attributes with qualified name
================================================================================
[NS.A(B.C)]
class D {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(attribute_list
(attribute
(qualified_name
(identifier)
(identifier))
(attribute_argument_list
(attribute_argument
(member_access_expression
(identifier)
(identifier))))))
(identifier)
(declaration_list)))
================================================================================
Attributes on classes
================================================================================
[Single]
class A { }
[One][Two]
[Three]
class A { }
[One]
[Two,Three()]
class A { }
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(attribute_list
(attribute
(identifier)))
(identifier)
(declaration_list))
(class_declaration
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier)))
(identifier)
(declaration_list))
(class_declaration
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(identifier)
(declaration_list)))
================================================================================
Attributes on structs
================================================================================
[A,B()][C]
struct A { }
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(attribute_list
(attribute
(identifier)))
(identifier)
(declaration_list)))
================================================================================
Attributes on fields
================================================================================
class Zzz {
[A,B()][C]
public int Z;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(attribute_list
(attribute
(identifier)))
(modifier)
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)))))))
================================================================================
Attributes on methods
================================================================================
class Methods {
[ValidatedContract]
int Method1() { return 0; }
[method: ValidatedContract]
int Method2() { return 0; }
[return: ValidatedContract]
int Method3() { return 0; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(attribute_list
(attribute
(identifier)))
(predefined_type)
(identifier)
(parameter_list)
(block
(return_statement
(integer_literal))))
(method_declaration
(attribute_list
(attribute_target_specifier)
(attribute
(identifier)))
(predefined_type)
(identifier)
(parameter_list)
(block
(return_statement
(integer_literal))))
(method_declaration
(attribute_list
(attribute_target_specifier)
(attribute
(identifier)))
(predefined_type)
(identifier)
(parameter_list)
(block
(return_statement
(integer_literal)))))))
================================================================================
Attributes on enums
================================================================================
[Single]
enum A { B, C }
[One][Two]
[Three]
enum A { B, C }
[One]
[Two,Three()]
enum A { B, C }
--------------------------------------------------------------------------------
(compilation_unit
(enum_declaration
(attribute_list
(attribute
(identifier)))
(identifier)
(enum_member_declaration_list
(enum_member_declaration
(identifier))
(enum_member_declaration
(identifier))))
(enum_declaration
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier)))
(identifier)
(enum_member_declaration_list
(enum_member_declaration
(identifier))
(enum_member_declaration
(identifier))))
(enum_declaration
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(identifier)
(enum_member_declaration_list
(enum_member_declaration
(identifier))
(enum_member_declaration
(identifier)))))
================================================================================
Attributes on events
================================================================================
class Zzz {
[A,B()][C]
public event EventHandler SomeEvent { add { } remove { } }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(event_declaration
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(attribute_list
(attribute
(identifier)))
(modifier)
(identifier)
(identifier)
(accessor_list
(accessor_declaration
(block))
(accessor_declaration
(block)))))))
================================================================================
Attributes on type parameters
================================================================================
class Class<[A, B][C()]T1> {
void Method<[E] [F, G(1)] T2>() {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(type_parameter_list
(type_parameter
(attribute_list
(attribute
(identifier))
(attribute
(identifier)))
(attribute_list
(attribute
(identifier)
(attribute_argument_list)))
(identifier)))
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(type_parameter_list
(type_parameter
(attribute_list
(attribute
(identifier)))
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list
(attribute_argument
(integer_literal)))))
(identifier)))
(parameter_list)
(block)))))
================================================================================
Attributes on event accessors
================================================================================
class Zzz {
public event EventHandler SomeEvent {
[A,B()][C] add { }
[A,B()][C] remove { }
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(event_declaration
(modifier)
(identifier)
(identifier)
(accessor_list
(accessor_declaration
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(attribute_list
(attribute
(identifier)))
(block))
(accessor_declaration
(attribute_list
(attribute
(identifier))
(attribute
(identifier)
(attribute_argument_list)))
(attribute_list
(attribute
(identifier)))
(block)))))))
================================================================================
Attributes with trailing comma
================================================================================
[Theory,]
void A() { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(attribute_list
(attribute
(identifier)))
(predefined_type)
(identifier)
(parameter_list)
(block))))
================================================================================
Generic attribute
================================================================================
[Theory<About,Life>]
void A() { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(attribute_list
(attribute
(generic_name
(identifier)
(type_argument_list
(identifier)
(identifier)))))
(predefined_type)
(identifier)
(parameter_list)
(block))))
================================================================================
Lambda with attribute
================================================================================
var greeting = [Hello] () => Console.WriteLine("hello");
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(lambda_expression
(attribute_list
(attribute
(identifier)))
(parameter_list)
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list
(argument
(string_literal
(string_literal_fragment))))))))))))

@ -1,663 +0,0 @@
================================================================================
Global empty class
================================================================================
public class F {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
body: (declaration_list)))
================================================================================
Class base is dynamic
================================================================================
public class F : dynamic { }
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
bases: (base_list
(identifier))
body: (declaration_list)))
================================================================================
Class base is object with interfaces
================================================================================
public class F : object, IAlpha, IOmega { }
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
bases: (base_list
(predefined_type)
(identifier)
(identifier))
body: (declaration_list)))
================================================================================
Partial class
================================================================================
public partial class F {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(modifier)
(identifier)
(declaration_list)))
================================================================================
Class with a single type parameter
================================================================================
class F<T> {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(declaration_list)))
================================================================================
Class with multiple type parameters
================================================================================
internal class F<T1, T2> {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(declaration_list)))
================================================================================
Class with co-variant and contra-variant type parameters
================================================================================
internal class F<in T1, out T2> {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(declaration_list)))
================================================================================
Class with a type parameter struct constraint
================================================================================
public class F<T> where T:struct {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Class with a type parameter unmanaged constraint
================================================================================
public class F<T> where T:unmanaged {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Class with a type parameter class constraint
================================================================================
public class F<T> where T:class {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Class with a type parameter and nullable constraints
================================================================================
public class F<T> where T:class?, notnull, Mine? {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint)
(type_parameter_constraint)
(type_parameter_constraint
(type_constraint
(nullable_type
(identifier)))))
(declaration_list)))
================================================================================
Class with type parameter new constraint
================================================================================
public class F<T> where T: new() {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(constructor_constraint)))
(declaration_list)))
================================================================================
Class with type parameter identifier constraint
================================================================================
public class F<T> where T: I {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier))))
(declaration_list)))
================================================================================
Class with type parameter identifier and new constraints
================================================================================
public class F<T> where T: I, new() {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(constructor_constraint)))
(declaration_list)))
================================================================================
Class with multiple type parameter constraints
================================================================================
private class F<T1,T2> where T1 : I1, I2, new() where T2 : I2 { }
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier))))
(declaration_list)))
================================================================================
Class with public constructor
================================================================================
class Foo {
public Foo() {}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(constructor_declaration
(modifier)
(identifier)
(parameter_list)
(block)))))
================================================================================
Class with expression bodied constructor
================================================================================
class Foo {
public Foo(string name) => Name = name;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(constructor_declaration
(modifier)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(arrow_expression_clause
(assignment_expression
(identifier)
(assignment_operator)
(identifier)))))))
================================================================================
Class with static constructor
================================================================================
class Foo {
static Foo() {}
static extern Foo() {}
extern static Foo() {}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(constructor_declaration
(modifier)
(identifier)
(parameter_list)
(block))
(constructor_declaration
(modifier)
(modifier)
(identifier)
(parameter_list)
(block))
(constructor_declaration
(modifier)
(modifier)
(identifier)
(parameter_list)
(block)))))
================================================================================
Class with extern destructor
================================================================================
class Foo {
extern ~Foo() {}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(destructor_declaration
(identifier)
(parameter_list)
(block)))))
================================================================================
Class with expression bodied destructor
================================================================================
class Foo {
~Foo() => DoSomething();
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(destructor_declaration
(identifier)
(parameter_list)
(arrow_expression_clause
(invocation_expression
(identifier)
(argument_list)))))))
================================================================================
Class with constants
================================================================================
class Foo {
private const int a = 1;
const string b = $"hello";
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal)))))
(field_declaration
(modifier)
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(interpolated_string_expression
(interpolated_string_text)))))))))
================================================================================
Class with indexer
================================================================================
class Foo {
public bool this[int index] {
get { return a; }
set { a = value; }
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(indexer_declaration
(modifier)
(predefined_type)
(bracketed_parameter_list
(parameter
(predefined_type)
(identifier)))
(accessor_list
(accessor_declaration
(block
(return_statement
(identifier))))
(accessor_declaration
(block
(expression_statement
(assignment_expression
(identifier)
(assignment_operator)
(identifier))))))))))
================================================================================
Class with expression bodied indexer
================================================================================
class Foo {
public bool this[int index] => a[index];
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(indexer_declaration
(modifier)
(predefined_type)
(bracketed_parameter_list
(parameter
(predefined_type)
(identifier)))
(arrow_expression_clause
(element_access_expression
(identifier)
(bracketed_argument_list
(argument
(identifier)))))))))
================================================================================
Class with expression bodied indexer accessors
================================================================================
class Foo {
public string this[int index]
{
get => a[index];
set => a[index] = value;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(indexer_declaration
(modifier)
(predefined_type)
(bracketed_parameter_list
(parameter
(predefined_type)
(identifier)))
(accessor_list
(accessor_declaration
(arrow_expression_clause
(element_access_expression
(identifier)
(bracketed_argument_list
(argument
(identifier))))))
(accessor_declaration
(arrow_expression_clause
(assignment_expression
(element_access_expression
(identifier)
(bracketed_argument_list
(argument
(identifier))))
(assignment_operator)
(identifier)))))))))
================================================================================
Class with varargs indexer
================================================================================
class A {
public int this[params string[] arguments] {
get { return 1; }
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(indexer_declaration
(modifier)
(predefined_type)
(bracketed_parameter_list
(array_type
(predefined_type)
(array_rank_specifier))
(identifier))
(accessor_list
(accessor_declaration
(block
(return_statement
(integer_literal)))))))))
================================================================================
Method with qualified return type
================================================================================
class A {
B.C d() {
return null;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (qualified_name
(identifier)
(identifier))
name: (identifier)
parameters: (parameter_list)
body: (block
(return_statement
(null_literal)))))))
================================================================================
Class and methods with Unicode identifiers
================================================================================
class Ωµ {
B.C d() {
return null;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (qualified_name
(identifier)
(identifier))
name: (identifier)
parameters: (parameter_list)
body: (block
(return_statement
(null_literal)))))))
================================================================================
File scoped class
================================================================================
file class A {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
body: (declaration_list)))

@ -1,612 +0,0 @@
================================================================================
From keyword can be a variable
================================================================================
var a = Assert.Range(from, to);
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list
(argument
(identifier))
(argument
(identifier))))))))))
================================================================================
File keyword in invocation
================================================================================
file.Method(1, 2);
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(expression_statement
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list
(argument
(integer_literal))
(argument
(integer_literal)))))))
================================================================================
File contextual keyword
================================================================================
void file() { }
void m(file p) { }
void m(int file) { }
void m()
{
file v = null;
int file = file;
file();
m(file);
var x = file + 1;
}
file class file { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(identifier)
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(identifier)))))
(expression_statement
(invocation_expression
(identifier)
(argument_list)))
(expression_statement
(invocation_expression
(identifier)
(argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(binary_expression
(identifier)
(integer_literal)))))))))
(class_declaration
(modifier)
(identifier)
(declaration_list)))
================================================================================
Scoped contextual keyword
================================================================================
void scoped() { }
void m(scoped p) { }
void m(scoped ref int p) { }
void m(scoped ref scoped p) { }
void m(int scoped) { }
void m()
{
scoped v = null;
scoped ref int v = null;
scoped ref scoped v = null;
int scoped = null;
scoped();
m(scoped);
var x = scoped + 1;
var l = scoped => null;
var l = (scoped i) => null;
var l = (scoped, i) => null;
var l = scoped (int i, int j) => null;
}
class scoped { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
(predefined_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
(identifier)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(identifier)
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(scoped_type
(ref_type
(predefined_type)))
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(scoped_type
(ref_type
(identifier)))
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(expression_statement
(invocation_expression
(identifier)
(argument_list)))
(expression_statement
(invocation_expression
(identifier)
(argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(binary_expression
(identifier)
(integer_literal))))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(lambda_expression
(identifier)
(null_literal))))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(lambda_expression
(parameter_list
(parameter
(identifier)
(identifier)))
(null_literal))))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(lambda_expression
(parameter_list
(parameter
(identifier))
(parameter
(identifier)))
(null_literal))))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(lambda_expression
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier)))
(null_literal)))))))))
(class_declaration
(identifier)
(declaration_list)))
================================================================================
Set contextual keyword
================================================================================
void set() { }
void m(set p) { }
void m(int set) { }
void m()
{
set v = null;
int set = set;
set();
m(set);
var x = set + 1;
}
class set { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(identifier)
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(identifier)))))
(expression_statement
(invocation_expression
(identifier)
(argument_list)))
(expression_statement
(invocation_expression
(identifier)
(argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(binary_expression
(identifier)
(integer_literal)))))))))
(class_declaration
(identifier)
(declaration_list)))
================================================================================
Var contextual keyword
================================================================================
void var() { }
void m(var p) { }
void m(int var) { }
void m()
{
var v = null;
int var = var;
var var = 1;
var();
m(var);
var x = var + 1;
}
class var { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(implicit_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(identifier)))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal)))))
(expression_statement
(invocation_expression
(identifier)
(argument_list)))
(expression_statement
(invocation_expression
(identifier)
(argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(binary_expression
(identifier)
(integer_literal)))))))))
(class_declaration
(identifier)
(declaration_list)))
================================================================================
Nameof contextual keyword
================================================================================
void nameof() { }
void m(nameof p) { }
void m(int nameof) { }
void m()
{
nameof v = null;
int nameof = nameof;
nameof();
nameof(a, b);
m(nameof);
var x = nameof + 1;
}
class nameof { }
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block)))
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(identifier)
(variable_declarator
(identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(identifier)))))
(expression_statement
(invocation_expression
(identifier)
(argument_list)))
(expression_statement
(invocation_expression
(identifier)
(argument_list
(argument
(identifier))
(argument
(identifier)))))
(expression_statement
(invocation_expression
(identifier)
(argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(binary_expression
(identifier)
(integer_literal)))))))))
(class_declaration
(identifier)
(declaration_list)))

@ -1,59 +0,0 @@
================================================================================
global enum with one option
================================================================================
enum A { One }
--------------------------------------------------------------------------------
(compilation_unit
(enum_declaration
name: (identifier)
body: (enum_member_declaration_list
(enum_member_declaration
name: (identifier)))))
================================================================================
enum with integer values
================================================================================
enum B { Ten = 10, Twenty = 20 }
--------------------------------------------------------------------------------
(compilation_unit
(enum_declaration
name: (identifier)
body: (enum_member_declaration_list
(enum_member_declaration
name: (identifier)
value: (integer_literal))
(enum_member_declaration
name: (identifier)
value: (integer_literal)))))
================================================================================
enum with byte base
================================================================================
namespace A {
enum B : byte { Five = 0x05, Fifteen = 0x0F }
}
--------------------------------------------------------------------------------
(compilation_unit
(namespace_declaration
name: (identifier)
body: (declaration_list
(enum_declaration
name: (identifier)
bases: (base_list
(predefined_type))
body: (enum_member_declaration_list
(enum_member_declaration
name: (identifier)
value: (integer_literal))
(enum_member_declaration
name: (identifier)
value: (integer_literal)))))))

File diff suppressed because it is too large Load Diff

@ -1,134 +0,0 @@
================================================================================
basic indentifiers
================================================================================
int x = y;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(identifier)))))))
================================================================================
indentifiers with keyword names
================================================================================
int @var = @const;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(identifier)))))))
================================================================================
identifiers with contextual keyword names
================================================================================
int nint = 0;
int nuint = 0;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal)))))))
================================================================================
unicode identifiers
================================================================================
var under_score = 0;
var with1number = 0;
var varæble = 0;
var Переменная = 0;
var first‿letter = 0;
var ග්‍රහලෝකය = 0;
var _كوكبxxx = 0;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal)))))))

@ -1,335 +0,0 @@
================================================================================
Global empty interface
================================================================================
public interface IOne {};
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(declaration_list)))
================================================================================
Interface with properties
================================================================================
interface IOne {
byte Get { get; }
char Set { set; }
uint GetSet { get; set; }
long SetGet { set; get; }
};
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration)))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Interface with methods
================================================================================
interface IOne {
void Nothing();
int Output();
void Input(string a);
int InputOutput(string a);
};
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list))
(method_declaration
(predefined_type)
(identifier)
(parameter_list))
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier))))
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))))))
================================================================================
Interface base single
================================================================================
private interface IOne : ITwo { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(base_list
(identifier))
(declaration_list)))
================================================================================
Interface base multiple
================================================================================
private interface IOne : ITwo, IThree { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(base_list
(identifier)
(identifier))
(declaration_list)))
================================================================================
Interface generic
================================================================================
private interface IOne<T1> : ITwo { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(base_list
(identifier))
(declaration_list)))
================================================================================
Interface generic single constraint
================================================================================
private interface IOne<T1> : ITwo where T1:T2 { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(base_list
(identifier))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier))))
(declaration_list)))
================================================================================
Interface generic multiple constraints
================================================================================
private interface IOne<T1, T3> : ITwo where T1:T2 where T3:new() { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(base_list
(identifier))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier))))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(constructor_constraint)))
(declaration_list)))
================================================================================
Interface in namespace
================================================================================
namespace A {
interface IOne : ITwo { }
}
--------------------------------------------------------------------------------
(compilation_unit
(namespace_declaration
(identifier)
(declaration_list
(interface_declaration
(identifier)
(base_list
(identifier))
(declaration_list)))))
================================================================================
Interface event declarations
================================================================================
interface A {
event EventHandler<T> SomeEvent;
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(identifier)
(declaration_list
(event_field_declaration
(variable_declaration
(generic_name
(identifier)
(type_argument_list
(identifier)))
(variable_declarator
(identifier)))))))
================================================================================
Interface with indexer
================================================================================
interface A {
bool this[int index] { get; set; }
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(identifier)
(declaration_list
(indexer_declaration
(predefined_type)
(bracketed_parameter_list
(parameter
(predefined_type)
(identifier)))
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Interface with default method
================================================================================
interface MyDefault {
void Log(string message) {
Console.WriteLine(message);
}
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block
(expression_statement
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list
(argument
(identifier))))))))))
================================================================================
Static abstract members
================================================================================
public interface IGetNext<T> where T : IGetNext<T>
{
static abstract T operator ++(T other);
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(generic_name
(identifier)
(type_argument_list
(identifier))))))
(declaration_list
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))))))

File diff suppressed because it is too large Load Diff

@ -1,307 +0,0 @@
================================================================================
If, elif and else directives
================================================================================
#if WIN32
string os = "Win32";
#elif MACOS
string os = "MacOS";
#else
string os = "Unknown";
#endif
--------------------------------------------------------------------------------
(compilation_unit
(if_directive
(identifier))
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(string_literal
(string_literal_fragment)))))))
(elif_directive
(identifier))
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(string_literal
(string_literal_fragment)))))))
(else_directive)
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)
(equals_value_clause
(string_literal
(string_literal_fragment)))))))
(endif_directive))
================================================================================
Complex if conditions
================================================================================
#if !MACOS
#if WIN32==true
#if !MACOS!=false
#if A && B || C
#if (A)
#if (A || B)
#if (A && B) || C
--------------------------------------------------------------------------------
(compilation_unit
(if_directive
(prefix_unary_expression
(identifier)))
(if_directive
(binary_expression
(identifier)
(boolean_literal)))
(if_directive
(binary_expression
(prefix_unary_expression
(identifier))
(boolean_literal)))
(if_directive
(binary_expression
(binary_expression
(identifier)
(identifier))
(identifier)))
(if_directive
(parenthesized_expression
(identifier)))
(if_directive
(parenthesized_expression
(binary_expression
(identifier)
(identifier))))
(if_directive
(binary_expression
(parenthesized_expression
(binary_expression
(identifier)
(identifier)))
(identifier))))
================================================================================
Region directives
================================================================================
#region Here, there, everywhere
// something fast
#endregion
--------------------------------------------------------------------------------
(compilation_unit
(region_directive
(preproc_message))
(comment)
(endregion_directive))
================================================================================
Define and undefine directives
================================================================================
#define SOMETHING
#undef BAD
--------------------------------------------------------------------------------
(compilation_unit
(define_directive
(identifier))
(undef_directive
(identifier)))
================================================================================
Warning and error directives
================================================================================
class Of1879 {
#warning This class is bad.
#error Okay, just stop.
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(warning_directive
(preproc_message))
(error_directive
(preproc_message)))))
================================================================================
Line directives
================================================================================
class Of1879 {
void AMethod() {
#line 2001 "A Space" // Comment
#line hidden
#line default
#line (1, 1) - (1, 3) 1 "a.cs"
#line (2, 1) - (2, 3) "a.cs"
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list)
(block
(line_directive
(preproc_integer_literal)
(preproc_string_literal))
(comment)
(line_directive)
(line_directive)
(line_directive
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_string_literal))
(line_directive
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_integer_literal)
(preproc_string_literal)))))))
================================================================================
Spaces in directives
================================================================================
class Of1879 {
void AMethod() {
# line 2001 "A Space"
# line hidden
# line default
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list)
(block
(line_directive
(preproc_integer_literal)
(preproc_string_literal))
(line_directive)
(line_directive))))))
================================================================================
Pragmas
================================================================================
#pragma warning disable 660,661,nullable
--------------------------------------------------------------------------------
(compilation_unit
(pragma_directive
(integer_literal)
(integer_literal)
(identifier)))
================================================================================
Directives not in strings or comments
================================================================================
class Of1879 {
void AMethod() {
var s = @"Only a string
#if NOPE
";
/* Only a comment
#if NOPE
*/
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(verbatim_string_literal)))))
(comment))))))
================================================================================
Reference (r) directive
================================================================================
#r "Microsoft.WindowsAzure.Storage"
--------------------------------------------------------------------------------
(compilation_unit
(reference_directive
(preproc_string_literal)))
================================================================================
Load directive
================================================================================
#load "mylogger.csx"
--------------------------------------------------------------------------------
(compilation_unit
(load_directive
(preproc_string_literal)))
================================================================================
Shebang directive
================================================================================
#!/usr/bin/env scriptcs
--------------------------------------------------------------------------------
(compilation_unit
(shebang_directive))

@ -1,436 +0,0 @@
================================================================================
Query from select
================================================================================
var x = from a in source select a.B;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(select_clause
(member_access_expression
(identifier)
(identifier))))))))))
================================================================================
Query from select with operator
================================================================================
var x = from a in source select a * 2;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(select_clause
(binary_expression
(identifier)
(integer_literal))))))))))
================================================================================
Query from select with method call
================================================================================
var x = from a in source select a.B();
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(select_clause
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list))))))))))
================================================================================
Query from select with conditional operator
================================================================================
var x = from a in source select a ? 0 : 1;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(select_clause
(conditional_expression
(identifier)
(integer_literal)
(integer_literal))))))))))
================================================================================
Query from select with assignment
================================================================================
var x = from a in source select somevar = a;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(select_clause
(assignment_expression
(identifier)
(assignment_operator)
(identifier))))))))))
================================================================================
Query from select projection
================================================================================
var x = from a in source select new { Name = a.B };
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(select_clause
(anonymous_object_creation_expression
(name_equals
(identifier))
(member_access_expression
(identifier)
(identifier)))))))))))
================================================================================
Query from select with where
================================================================================
var x = from a in source
where a.B == "A"
select a;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(where_clause
(binary_expression
(member_access_expression
(identifier)
(identifier))
(string_literal
(string_literal_fragment))))
(select_clause
(identifier)))))))))
================================================================================
Query from select with where and projection
================================================================================
var x = from a in source
where a.B == "A" && a.C == "D"
select new { Name = a.B };
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(where_clause
(binary_expression
(binary_expression
(member_access_expression
(identifier)
(identifier))
(string_literal
(string_literal_fragment)))
(binary_expression
(member_access_expression
(identifier)
(identifier))
(string_literal
(string_literal_fragment)))))
(select_clause
(anonymous_object_creation_expression
(name_equals
(identifier))
(member_access_expression
(identifier)
(identifier)))))))))))
================================================================================
Query from select with orderby
================================================================================
var x = from a in source
orderby a.A descending
orderby a.C ascending
orderby 1
select a;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(order_by_clause
(member_access_expression
(identifier)
(identifier)))
(order_by_clause
(member_access_expression
(identifier)
(identifier)))
(order_by_clause
(integer_literal))
(select_clause
(identifier)))))))))
================================================================================
Query from select with let
================================================================================
var x = from a in source
let z = new { a.A, a.B }
select z;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(let_clause
(identifier)
(anonymous_object_creation_expression
(member_access_expression
(identifier)
(identifier))
(member_access_expression
(identifier)
(identifier))))
(select_clause
(identifier)))))))))
================================================================================
Query from select with join
================================================================================
var x = from a in sourceA
join b in sourceB on a.FK equals b.PK
select new { A.A, B.B };
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(join_clause
(identifier)
(identifier)
(member_access_expression
(identifier)
(identifier))
(member_access_expression
(identifier)
(identifier)))
(select_clause
(anonymous_object_creation_expression
(member_access_expression
(identifier)
(identifier))
(member_access_expression
(identifier)
(identifier)))))))))))
================================================================================
Query from select with multiple from
================================================================================
var x = from a in sourceA
from b in sourceB
where a.FK == b.FK
select new { A.A, B.B };
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(from_clause
(identifier)
(identifier))
(where_clause
(binary_expression
(member_access_expression
(identifier)
(identifier))
(member_access_expression
(identifier)
(identifier))))
(select_clause
(anonymous_object_creation_expression
(member_access_expression
(identifier)
(identifier))
(member_access_expression
(identifier)
(identifier)))))))))))
================================================================================
Query from select with group by & continuation
================================================================================
var x = from a in sourceA
group a by a.Country into g
select new { Country = g.Key, Population = g.Sum(p => p.Population) };
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(query_expression
(from_clause
(identifier)
(identifier))
(group_clause
(identifier)
(member_access_expression
(identifier)
(identifier)))
(query_continuation
(identifier)
(select_clause
(anonymous_object_creation_expression
(name_equals
(identifier))
(member_access_expression
(identifier)
(identifier))
(name_equals
(identifier))
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list
(argument
(lambda_expression
(identifier)
(member_access_expression
(identifier)
(identifier))))))))))))))))

@ -1,525 +0,0 @@
================================================================================
Basic record declaration
================================================================================
record F {
int Age { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Basic record struct declaration
================================================================================
record struct F {
int Age { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(record_struct_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Record class with optional `class` specification
================================================================================
record class F {
int Age { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Record with a type parameter struct constraint
================================================================================
public record F<T> where T:struct {}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Record with a type parameter class constraint
================================================================================
public record F<T> where T:class {}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Record with type parameter new constraint
================================================================================
public record F<T> where T: new() {}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(constructor_constraint)))
(declaration_list)))
================================================================================
Record with interface
================================================================================
public record A : ISomething { }
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
(identifier)
(base_list
(identifier))
(declaration_list)))
================================================================================
Record with multiple type parameter constraints
================================================================================
[Nice]
private record F<T1,T2> where T1 : I1, I2, new() where T2 : I2 { }
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(attribute_list
(attribute
(identifier)))
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier))))
(declaration_list)))
================================================================================
Record with constructor
================================================================================
record Person(string FirstName, string LastName);
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier)))))
================================================================================
Record inheritance with constructor overload
================================================================================
record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName);
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier)))
(base_list
(primary_constructor_base_type
(identifier)
(argument_list
(argument
(identifier))
(argument
(identifier)))))))
================================================================================
Record inheritance with constructor overload and interfaces
================================================================================
record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName), I1, I2;
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier)))
(base_list
(primary_constructor_base_type
(identifier)
(argument_list
(argument
(identifier))
(argument
(identifier))))
(identifier)
(identifier))))
================================================================================
Record inheritance with generic base
================================================================================
record Teacher() : Entity<Person>(), I1;
record A : System.IEquatable<A>;
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(parameter_list)
(base_list
(primary_constructor_base_type
(generic_name
(identifier)
(type_argument_list
(identifier)))
(argument_list))
(identifier)))
(record_declaration
(identifier)
(base_list
(qualified_name
(identifier)
(generic_name
(identifier)
(type_argument_list
(identifier)))))))
================================================================================
Record types can end with a semicolon
================================================================================
public record Person { };
public record struct Person2 { };
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
(identifier)
(declaration_list))
(record_struct_declaration
(modifier)
(identifier)
(declaration_list)))
================================================================================
Record types can seal ToString()
================================================================================
record A {
public sealed override string ToString(){
return "";
}
}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(identifier)
(declaration_list
(method_declaration
(modifier)
(modifier)
(modifier)
(predefined_type)
(identifier)
(parameter_list)
(block
(return_statement
(string_literal)))))))
================================================================================
With expression typical basic form
================================================================================
void A() {
var newFriend = friend with { LastName = "Edwards" };
}
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(with_expression
(identifier)
(with_initializer_expression
(simple_assignment_expression
(identifier)
(string_literal
(string_literal_fragment)))))))))))))
================================================================================
With expression using expressions
================================================================================
void A() {
var friend = GetAFriend() with {
ForeName = RandomFirstName(),
LastName = RandomLastName()
};
}
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_function_statement
(predefined_type)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(with_expression
(invocation_expression
(identifier)
(argument_list))
(with_initializer_expression
(simple_assignment_expression
(identifier)
(invocation_expression
(identifier)
(argument_list)))
(simple_assignment_expression
(identifier)
(invocation_expression
(identifier)
(argument_list)))))))))))))
================================================================================
Precedence between with and cast
================================================================================
var x = (Point) p1 with {X = 3};
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(with_expression
(cast_expression
(identifier)
(identifier))
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))))))))
================================================================================
Precedence between with and switch
================================================================================
var x = p1 with {X = 3} switch { _ => 3 };
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(switch_expression
(with_expression
(identifier)
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))
(switch_expression_arm
(discard)
(integer_literal)))))))))
================================================================================
Precedence between with and equals
================================================================================
var x = p1 with {X = 3} == p1 with {X = 4};
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(binary_expression
(with_expression
(identifier)
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))
(with_expression
(identifier)
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal)))))))))))
================================================================================
Associativity of with expression
================================================================================
var x = p1 with {X = 3} with {X = 4} with {X = 5};
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(with_expression
(with_expression
(with_expression
(identifier)
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))))))))

@ -1,273 +0,0 @@
================================================================================
Using directives
================================================================================
using A;
using B.C;
using global::E.F;
using G = H.I;
using static J.K;
--------------------------------------------------------------------------------
(compilation_unit
(using_directive
(identifier))
(using_directive
(qualified_name
(identifier)
(identifier)))
(using_directive
(qualified_name
(alias_qualified_name
(identifier)
(identifier))
(identifier)))
(using_directive
(name_equals
(identifier))
(qualified_name
(identifier)
(identifier)))
(using_directive
(qualified_name
(identifier)
(identifier))))
================================================================================
Nested using directives
================================================================================
namespace Foo {
using A;
}
--------------------------------------------------------------------------------
(compilation_unit
(namespace_declaration
(identifier)
(declaration_list
(using_directive
(identifier)))))
================================================================================
Global using directives
================================================================================
global using A;
global using static A.B;
--------------------------------------------------------------------------------
(compilation_unit
(using_directive
(identifier))
(using_directive
(qualified_name
(identifier)
(identifier))))
================================================================================
Comments
================================================================================
// I'm a single-line comment
/*
* I'm a block comment: a * b / c
*/
--------------------------------------------------------------------------------
(compilation_unit
(comment)
(comment))
================================================================================
Comment with double asterisk
================================================================================
/** test **/
--------------------------------------------------------------------------------
(compilation_unit
(comment))
================================================================================
Namespaces
================================================================================
namespace A {
namespace B.C.D {
}
namespace E.F {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(namespace_declaration
(identifier)
(declaration_list
(namespace_declaration
(qualified_name
(qualified_name
(identifier)
(identifier))
(identifier))
(declaration_list))
(namespace_declaration
(qualified_name
(identifier)
(identifier))
(declaration_list)))))
================================================================================
File scoped namespaces
================================================================================
namespace A;
class B {
}
--------------------------------------------------------------------------------
(compilation_unit
(file_scoped_namespace_declaration
(identifier)
(class_declaration
(identifier)
(declaration_list))))
================================================================================
Interfaces
================================================================================
public interface IFoo {
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
(identifier)
(declaration_list)))
================================================================================
Externs
================================================================================
extern alias A;
--------------------------------------------------------------------------------
(compilation_unit
(extern_alias_directive
(identifier)))
================================================================================
Delegates
================================================================================
public delegate int Global(ref char a = '\n');
public delegate ref int Global(ref char a = '\n');
public delegate ref readonly int Global(ref char a = '\n');
delegate void A<T>() where T:class;
delegate void A(params int [] test);
class Z {
delegate void Zed();
}
--------------------------------------------------------------------------------
(compilation_unit
(delegate_declaration
(modifier)
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(predefined_type)
(identifier)
(equals_value_clause
(character_literal
(escape_sequence))))))
(delegate_declaration
(modifier)
(ref_type
(predefined_type))
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(predefined_type)
(identifier)
(equals_value_clause
(character_literal
(escape_sequence))))))
(delegate_declaration
(modifier)
(ref_type
(predefined_type))
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(predefined_type)
(identifier)
(equals_value_clause
(character_literal
(escape_sequence))))))
(delegate_declaration
(predefined_type)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(parameter_list)
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint)))
(delegate_declaration
(predefined_type)
(identifier)
(parameter_list
(array_type
(predefined_type)
(array_rank_specifier))
(identifier)))
(class_declaration
(identifier)
(declaration_list
(delegate_declaration
(predefined_type)
(identifier)
(parameter_list)))))
================================================================================
Var declared equal to integer literal
================================================================================
var a = 1;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(integer_literal)))))))

File diff suppressed because it is too large Load Diff

@ -1,140 +0,0 @@
================================================================================
Struct with a type parameter struct constraint
================================================================================
public struct F<T> where T:struct {}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Struct with a type parameter class constraint
================================================================================
public struct F<T> where T:class {}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint))
(declaration_list)))
================================================================================
Struct with type parameter new constraint
================================================================================
public struct F<T> where T: new() {}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(constructor_constraint)))
(declaration_list)))
================================================================================
Struct with interface
================================================================================
public struct A : ISomething { }
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(base_list
(identifier))
(declaration_list)))
================================================================================
Struct with multiple type parameter constraints
================================================================================
private struct F<T1,T2> where T1 : I1, I2, new() where T2 : I2 { }
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier))))
(declaration_list)))
================================================================================
Struct with readonly modifier
================================================================================
readonly struct Test {
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(declaration_list)))
================================================================================
Struct with ref modifier
================================================================================
ref struct Test {
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(declaration_list)))

@ -1,83 +0,0 @@
================================================================================
Class event declarations
================================================================================
class A {
public event EventHandler<T> SomeEvent { add { } remove { } }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(event_declaration
(modifier)
(generic_name
(identifier)
(type_argument_list
(identifier)))
(identifier)
(accessor_list
(accessor_declaration
(block))
(accessor_declaration
(block)))))))
================================================================================
Struct event declarations
================================================================================
struct A {
public event EventHandler<T> SomeEvent { add { } remove { } }
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(identifier)
(declaration_list
(event_declaration
(modifier)
(generic_name
(identifier)
(type_argument_list
(identifier)))
(identifier)
(accessor_list
(accessor_declaration
(block))
(accessor_declaration
(block)))))))
================================================================================
Class event declarations with expression bodies
================================================================================
class A {
public event EventHandler SomeEvent { add => addSomething(); remove => removeSomething(); }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(event_declaration
(modifier)
(identifier)
(identifier)
(accessor_list
(accessor_declaration
(arrow_expression_clause
(invocation_expression
(identifier)
(argument_list))))
(accessor_declaration
(arrow_expression_clause
(invocation_expression
(identifier)
(argument_list)))))))))

@ -1,382 +0,0 @@
================================================================================
Class field declarations
================================================================================
class A {
public readonly int _B;
Int64 D_e_f, g;
Tuple<char, Nullable<int>> z;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
(predefined_type)
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(identifier)
(variable_declarator
(identifier))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(generic_name
(identifier)
(type_argument_list
(predefined_type)
(generic_name
(identifier)
(type_argument_list
(predefined_type)))))
(variable_declarator
(identifier)))))))
================================================================================
Struct field declarations
================================================================================
struct A {
private readonly int c_;
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(identifier)
(declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)))))))
================================================================================
Class field nullable type
================================================================================
class A {
public readonly int? i;
private Byte? b;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
(nullable_type
(predefined_type))
(variable_declarator
(identifier))))
(field_declaration
(modifier)
(variable_declaration
(nullable_type
(identifier))
(variable_declarator
(identifier)))))))
================================================================================
Class field pointer type
================================================================================
class A {
public readonly int* i;
private Byte* b;
private void* c;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
(pointer_type
(predefined_type))
(variable_declarator
(identifier))))
(field_declaration
(modifier)
(variable_declaration
(pointer_type
(identifier))
(variable_declarator
(identifier))))
(field_declaration
(modifier)
(variable_declaration
(pointer_type
(predefined_type))
(variable_declarator
(identifier)))))))
================================================================================
Function pointer type
================================================================================
class A {
// Function pointer equivalent without calling convention
delegate*<string, int> a;
delegate*<delegate*<in string, int>, delegate*<ref string, ref readonly int>> b;
// Function pointer equivalent with calling convention
delegate* managed<string, int> c;
delegate*<delegate* unmanaged[MyCallConv, YourCallConv]<string, int>, delegate*<string, int>> d;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(comment)
(field_declaration
(variable_declaration
(function_pointer_type
(function_pointer_parameter
(predefined_type))
(function_pointer_parameter
(predefined_type)))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(function_pointer_type
(function_pointer_parameter
(function_pointer_type
(function_pointer_parameter
(parameter_modifier)
(predefined_type))
(function_pointer_parameter
(predefined_type))))
(function_pointer_parameter
(function_pointer_type
(function_pointer_parameter
(parameter_modifier)
(predefined_type))
(function_pointer_parameter
(ref_type
(predefined_type))))))
(variable_declarator
(identifier))))
(comment)
(field_declaration
(variable_declaration
(function_pointer_type
(function_pointer_calling_convention)
(function_pointer_parameter
(predefined_type))
(function_pointer_parameter
(predefined_type)))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(function_pointer_type
(function_pointer_parameter
(function_pointer_type
(function_pointer_calling_convention
(function_pointer_unmanaged_calling_convention_list
(function_pointer_unmanaged_calling_convention
(identifier))
(function_pointer_unmanaged_calling_convention
(identifier))))
(function_pointer_parameter
(predefined_type))
(function_pointer_parameter
(predefined_type))))
(function_pointer_parameter
(function_pointer_type
(function_pointer_parameter
(predefined_type))
(function_pointer_parameter
(predefined_type)))))
(variable_declarator
(identifier)))))))
================================================================================
Ref readonly
================================================================================
class A {
ref readonly Point Origin => ref origin;
ref readonly Point* Origin;
ref readonly Point[] Origin;
ref readonly Point? Origin;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(ref_type
(identifier))
(identifier)
(arrow_expression_clause
(ref_expression
(identifier))))
(field_declaration
(variable_declaration
(ref_type
(pointer_type
(identifier)))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(ref_type
(array_type
(identifier)
(array_rank_specifier)))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(ref_type
(nullable_type
(identifier)))
(variable_declarator
(identifier)))))))
================================================================================
Nullable reference types
================================================================================
class A {
string? a;
A? a;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(variable_declaration
(nullable_type
(predefined_type))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(nullable_type
(identifier))
(variable_declarator
(identifier)))))))
================================================================================
Tuple types
================================================================================
class A {
(int, string str) a;
(B b, C c, D d) a;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(variable_declaration
(tuple_type
(tuple_element
(predefined_type))
(tuple_element
(predefined_type)
(identifier)))
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(tuple_type
(tuple_element
(identifier)
(identifier))
(tuple_element
(identifier)
(identifier))
(tuple_element
(identifier)
(identifier)))
(variable_declarator
(identifier)))))))
================================================================================
Native integer types
================================================================================
class A {
nint a;
nuint b;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(variable_declaration
(predefined_type)
(variable_declarator
(identifier))))
(field_declaration
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)))))))
================================================================================
Required fields
================================================================================
class A {
public required int B;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
(predefined_type)
(variable_declarator
(identifier)))))))

@ -1,457 +0,0 @@
================================================================================
Class method with single parameter
================================================================================
class A {
private int GetBack(int b) {
return b;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(modifier)
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block
(return_statement
(identifier)))))))
================================================================================
Class method with multiple parameters
================================================================================
class A {
void DoSomething(A a, B b) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block)))))
================================================================================
Class generic method
================================================================================
class A {
void Accept<T>(T accept) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(parameter_list
(parameter
(identifier)
(identifier)))
(block)))))
================================================================================
Class generic method with new type constraint
================================================================================
class A {
void Accept<T>(T accept) where T: new() {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(type_parameter_list
(type_parameter
(identifier)))
(parameter_list
(parameter
(identifier)
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(constructor_constraint)))
(block)))))
================================================================================
Class generic method with multiple type constraints
================================================================================
class A {
void Accept<T1, T2>(T1 accept, T2 from)
where T1: new()
where T2: T1, new() {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(type_parameter_list
(type_parameter
(identifier))
(type_parameter
(identifier)))
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
(identifier)
(type_parameter_constraint
(type_constraint
(identifier)))
(type_parameter_constraint
(constructor_constraint)))
(block)))))
================================================================================
Class method with out parameter
================================================================================
class A {
void HasAnOut(out int a) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(predefined_type)
(identifier)))
(block)))))
================================================================================
Class method with in parameter
================================================================================
class A {
void HasAnOut(in int a) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(predefined_type)
(identifier)))
(block)))))
================================================================================
Class method with ref parameter
================================================================================
class A {
void HasAnOut(ref int a) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(predefined_type)
(identifier)))
(block)))))
================================================================================
Class method with contextually-reserved keyword named parameters
================================================================================
class A {
void HasAnOut(int from, string partial) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier))
(parameter
(predefined_type)
(identifier)))
(block)))))
================================================================================
Class method with default parameter
================================================================================
class A {
void HasAnOut(int a = 5) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)
(equals_value_clause
(integer_literal))))
(block)))))
================================================================================
Class static method with single parameter
================================================================================
class A {
static int GetBack(int b) {
return b;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(modifier)
(predefined_type)
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block
(return_statement
(identifier)))))))
================================================================================
Class method with explicit interface specifier
================================================================================
class A : ISomething {
int ISomething.GetBack(int b) {
return b;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(base_list
(identifier))
(declaration_list
(method_declaration
(predefined_type)
(explicit_interface_specifier
(identifier))
(identifier)
(parameter_list
(parameter
(predefined_type)
(identifier)))
(block
(return_statement
(identifier)))))))
================================================================================
Class method with readonly method
================================================================================
class A {
public readonly double Add => x + y;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(modifier)
(modifier)
(predefined_type)
(identifier)
(arrow_expression_clause
(binary_expression
(identifier)
(identifier)))))))
================================================================================
Class method with nullable parameter list
================================================================================
class A {
public int Zero(params int[]? ints) => 0;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(method_declaration
(modifier)
(predefined_type)
(identifier)
(parameter_list
(nullable_type
(array_type
(predefined_type)
(array_rank_specifier)))
(identifier))
(arrow_expression_clause
(integer_literal))))))
================================================================================
Method with scoped parameter and scoped local variable
================================================================================
ref struct S {
void M(scoped ref System.Span<int> p) {
scoped ref System.Span<int> i = ref p;
scoped System.Span<int> j = p;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
(identifier)
(declaration_list
(method_declaration
(predefined_type)
(identifier)
(parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
(qualified_name
(identifier)
(generic_name
(identifier)
(type_argument_list
(predefined_type))))
(identifier)))
(block
(local_declaration_statement
(variable_declaration
(scoped_type
(ref_type
(qualified_name
(identifier)
(generic_name
(identifier)
(type_argument_list
(predefined_type))))))
(variable_declarator
(identifier)
(equals_value_clause
(ref_expression
(identifier))))))
(local_declaration_statement
(variable_declaration
(scoped_type
(qualified_name
(identifier)
(generic_name
(identifier)
(type_argument_list
(predefined_type)))))
(variable_declarator
(identifier)
(equals_value_clause
(identifier))))))))))

@ -1,687 +0,0 @@
================================================================================
Operator declarations
================================================================================
class A
{
[SomeAttribute]
public static int operator +(A a) { return 0; }
public static int operator +(A a, A b) { return 0; }
int operator -(A a) { return 0; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(attribute_list
(attribute
(identifier)))
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(integer_literal))))
(operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(integer_literal))))
(operator_declaration
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(integer_literal)))))))
================================================================================
boolean operator declarations
================================================================================
class A
{
public static bool operator true(A a) { return true; }
bool operator false(A a) { return false; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(boolean_literal))))
(operator_declaration
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(boolean_literal)))))))
================================================================================
conversion operator declaration
================================================================================
class A
{
public static implicit operator int (A a) { return 0; }
explicit operator int (A a) { return 0; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(conversion_operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(integer_literal))))
(conversion_operator_declaration
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(integer_literal)))))))
================================================================================
conversion operator with expression body
================================================================================
class A
{
public static implicit operator int (A a) => 0;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(conversion_operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(arrow_expression_clause
(integer_literal))))))
================================================================================
extern operators
================================================================================
class A
{
public static extern int operator + (A a);
public static extern bool operator <(A a, A b);
public static explicit operator int (A a);
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(modifier)
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier))))
(operator_declaration
(modifier)
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier))))
(conversion_operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))))))
================================================================================
Class conversion operators with expression body
================================================================================
class A
{
public static extern int operator + (A a) => 0;
public static extern bool operator <(A a, A b) => true;
public static explicit operator int (A a) => 0;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(modifier)
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(arrow_expression_clause
(integer_literal)))
(operator_declaration
(modifier)
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(arrow_expression_clause
(boolean_literal)))
(conversion_operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(arrow_expression_clause
(integer_literal))))))
================================================================================
Unary operator overloads
================================================================================
class A
{
public static A operator +(A a) { return a; }
public static A operator -(A a) { return a; }
public static A operator !(A a) { return a; }
public static A operator ~(A a) { return a; }
public static A operator ++(A a) { return a; }
public static A operator --(A a) { return a; }
public static bool operator true (A a) { return true; }
public static bool operator false(A a) { return true; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(boolean_literal))))
(operator_declaration
(modifier)
(modifier)
(predefined_type)
(parameter_list
(parameter
(identifier)
(identifier)))
(block
(return_statement
(boolean_literal)))))))
================================================================================
Binary unpaired operator overloads
================================================================================
class A
{
public static A operator +(A a, A b) { return a == b; }
public static A operator -(A a, A b) { return a != b; }
public static A operator *(A a, A b) { return a < b; }
public static A operator /(A a, A b) { return a <= b; }
public static A operator %(A a, A b) { return a > b; }
public static A operator &(A a, A b) { return a >= b; }
public static A operator |(A a, A b) { return a >= b; }
public static A operator ^(A a, A b) { return a >= b; }
public static A operator <<(A a, A b) { return a >= b; }
public static A operator >>(A a, A b) { return a >= b; }
public static A operator >>>(A a, A b) { return a >= b; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier))))))))
================================================================================
Binary paired operator overloads
================================================================================
class A
{
public static A operator ==(A a, A b) { return a == b; }
public static A operator !=(A a, A b) { return a != b; }
public static A operator <(A a, A b) { return a < b; }
public static A operator <=(A a, A b) { return a <= b; }
public static A operator >(A a, A b) { return a > b; }
public static A operator >=(A a, A b) { return a >= b; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier)))))
(operator_declaration
(modifier)
(modifier)
(identifier)
(parameter_list
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(identifier)))
(block
(return_statement
(binary_expression
(identifier)
(identifier))))))))

@ -1,233 +0,0 @@
================================================================================
Class with bodyless properties
================================================================================
class Foo {
byte Get { get; }
char Set { set; }
uint GetSet { get; set; }
long SetGet { set; get; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration)))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Class with init properties
================================================================================
class Person
{
public string FirstName { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(modifier)
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Class with single-accessor property bodies
================================================================================
class Foo {
byte Get { get { return 0xFF; } }
char Set { set { x = value; } }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration
(block
(return_statement
(integer_literal))))))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration
(block
(expression_statement
(assignment_expression
(identifier)
(assignment_operator)
(identifier))))))))))
================================================================================
Class with double-accessor property bodies
================================================================================
class Foo {
uint GetSet {
get { return x; }
set { x = value; }
}
long SetGet {
set { x = value; }
get { return x; }
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration
(block
(return_statement
(identifier))))
(accessor_declaration
(block
(expression_statement
(assignment_expression
(identifier)
(assignment_operator)
(identifier)))))))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration
(block
(expression_statement
(assignment_expression
(identifier)
(assignment_operator)
(identifier)))))
(accessor_declaration
(block
(return_statement
(identifier)))))))))
================================================================================
Class with bodyless properties and initializers
================================================================================
class Foo {
byte Get { get; } = 0x00;
uint GetSet { get; set; } = 1;
long SetGet { set; get; } = 2;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration))
(integer_literal))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))
(integer_literal))
(property_declaration
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))
(integer_literal)))))
================================================================================
Class with explicit interface properties
================================================================================
class Foo: IFoo {
byte IFoo.Get { get; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(base_list
(identifier))
(declaration_list
(property_declaration
(predefined_type)
(explicit_interface_specifier
(identifier))
(identifier)
(accessor_list
(accessor_declaration))))))
================================================================================
Required properties
================================================================================
class A {
public required int B { get; set; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(identifier)
(declaration_list
(property_declaration
(modifier)
(modifier)
(predefined_type)
(identifier)
(accessor_list
(accessor_declaration)
(accessor_declaration))))))

File diff suppressed because it is too large Load Diff

@ -1,35 +0,0 @@
{
"name": "tree-sitter-c-sharp",
"version": "0.20.0",
"description": "C# grammar for tree-sitter",
"main": "bindings/node",
"keywords": [
"parser",
"tree-sitter",
"lexer"
],
"repository": {
"type": "git",
"url": "https://github.com/tree-sitter/tree-sitter-c-sharp.git"
},
"author": "The Tree-Sitter C# Team",
"license": "MIT",
"dependencies": {
"nan": "^2.14.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.0"
},
"scripts": {
"test": "tree-sitter test && script/update-file-sizes && script/parse-examples",
"test-windows": "tree-sitter test"
},
"tree-sitter": [
{
"scope": "source.cs",
"file-types": [
"cs"
]
}
]
}

@ -1,239 +0,0 @@
;; Methods
(method_declaration (identifier) @type (identifier) @function)
;; Types
(interface_declaration name: (identifier) @type)
(class_declaration name: (identifier) @type)
(enum_declaration name: (identifier) @type)
(struct_declaration (identifier) @type)
(record_declaration (identifier) @type)
(record_struct_declaration (identifier) @type)
(namespace_declaration name: (identifier) @type)
(constructor_declaration name: (identifier) @type)
(destructor_declaration name: (identifier) @type)
[
(implicit_type)
(nullable_type)
(pointer_type)
(function_pointer_type)
(predefined_type)
] @type.builtin
;; Enum
(enum_member_declaration (identifier) @property.definition)
;; Literals
[
(real_literal)
(integer_literal)
] @number
[
(character_literal)
(string_literal)
(verbatim_string_literal)
(interpolated_string_text)
(interpolated_verbatim_string_text)
"\""
"$\""
"@$\""
"$@\""
] @string
[
(boolean_literal)
(null_literal)
] @constant.builtin
;; Comments
(comment) @comment
;; Tokens
[
";"
"."
","
] @punctuation.delimiter
[
"--"
"-"
"-="
"&"
"&&"
"+"
"++"
"+="
"<"
"<<"
"="
"=="
"!"
"!="
"=>"
">"
">>"
"|"
"||"
"?"
"??"
"^"
"~"
"*"
"/"
"%"
":"
] @operator
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
;; Keywords
(modifier) @keyword
(this_expression) @keyword
(escape_sequence) @keyword
[
"as"
"base"
"break"
"case"
"catch"
"checked"
"class"
"continue"
"default"
"delegate"
"do"
"else"
"enum"
"event"
"explicit"
"finally"
"for"
"foreach"
"goto"
"if"
"implicit"
"interface"
"is"
"lock"
"namespace"
"operator"
"params"
"return"
"sizeof"
"stackalloc"
"struct"
"switch"
"throw"
"try"
"typeof"
"unchecked"
"using"
"while"
"new"
"await"
"in"
"yield"
"get"
"set"
"when"
"out"
"ref"
"from"
"where"
"select"
"record"
"init"
"with"
"let"
] @keyword
;; Linq
(from_clause (identifier) @variable)
(group_clause)
(order_by_clause)
(select_clause (identifier) @variable)
(query_continuation (identifier) @variable) @keyword
;; Record
(with_expression
(with_initializer_expression
(simple_assignment_expression
(identifier) @variable)))
;; Exprs
(binary_expression (identifier) @variable (identifier) @variable)
(binary_expression (identifier)* @variable)
(conditional_expression (identifier) @variable)
(prefix_unary_expression (identifier) @variable)
(postfix_unary_expression (identifier)* @variable)
(assignment_expression (identifier) @variable)
(cast_expression (identifier) @type (identifier) @variable)
;; Class
(base_list (identifier) @type)
(property_declaration (generic_name))
(property_declaration
type: (nullable_type) @type
name: (identifier) @variable)
(property_declaration
type: (predefined_type) @type
name: (identifier) @variable)
(property_declaration
type: (identifier) @type
name: (identifier) @variable)
;; Lambda
(lambda_expression) @variable
;; Attribute
(attribute) @type
;; Parameter
(parameter
type: (identifier) @type
name: (identifier) @variable.parameter)
(parameter (identifier) @variable.parameter)
(parameter_modifier) @keyword
;; Typeof
(type_of_expression (identifier) @type)
;; Variable
(variable_declaration (identifier) @type)
(variable_declarator (identifier) @variable)
;; Return
(return_statement (identifier) @variable)
(yield_statement (identifier) @variable)
;; Type
(generic_name (identifier) @type)
(type_parameter (identifier) @property.definition)
(type_argument_list (identifier) @type)
;; Type constraints
(type_parameter_constraints_clause (identifier) @property.definition)
(type_constraint (identifier) @type)
;; Exception
(catch_declaration (identifier) @type (identifier) @variable)
(catch_declaration (identifier) @type)
;; Switch
(switch_statement (identifier) @variable)
(switch_expression (identifier) @variable)
;; Lock statement
(lock_statement (identifier) @variable)

@ -1,23 +0,0 @@
(class_declaration name: (identifier) @name) @definition.class
(class_declaration bases: (base_list (_) @name)) @reference.class
(interface_declaration name: (identifier) @name) @definition.interface
(interface_declaration bases: (base_list (_) @name)) @reference.interface
(method_declaration name: (identifier) @name) @definition.method
(object_creation_expression type: (identifier) @name) @reference.class
(type_parameter_constraints_clause target: (identifier) @name) @reference.class
(type_constraint type: (identifier) @name) @reference.class
(variable_declaration type: (identifier) @name) @reference.class
(invocation_expression function: (member_access_expression name: (identifier) @name)) @reference.send
(namespace_declaration name: (identifier) @name) @definition.module
(namespace_declaration name: (identifier) @name) @module

@ -1,5 +0,0 @@
src/grammar.json 0.2MB 10975
src/node-types.json 0.1MB 7645
src/parser.c 49.4MB 1552175
src/scanner.c 0.0MB 29
total 49.7MB 1570824

@ -1,3 +0,0 @@
examples/Newtonsoft.Json/Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs
examples/Newtonsoft.Json/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs
examples/Newtonsoft.Json/Src/Newtonsoft.Json/JsonReader.cs

@ -1,45 +0,0 @@
#!/bin/bash
set -eu
cd "$(dirname "$0")/.."
function clone_repo {
owner=$1
name=$2
sha=$3
path=examples/$name
if [ ! -d "$path" ]; then
echo "Cloning $owner/$name"
git clone "https://github.com/$owner/$name" "$path"
fi
pushd "$path" > /dev/null
actual_sha=$(git rev-parse HEAD)
if [ "$actual_sha" != "$sha" ]; then
echo "Updating $owner/$name to $sha"
git fetch
git reset --hard $sha
fi
popd > /dev/null
}
clone_repo JamesNK Newtonsoft.Json 7c3d7f8da7e35dde8fa74188b0decff70f8f10e3
clone_repo nunit nunit ad49f27294bd0f2677d8699756c6ccb10df600f8
clone_repo OrchardCMS orchard 0a82721968232b07354edcaac63a9ccea02220c6
known_failures="$(cat script/known_failures.txt)"
tree-sitter parse -q \
'examples/**/*.cs' \
$(for failure in $known_failures; do echo "!${failure}"; done)
example_count=$(find examples -name '*.cs' | wc -l)
failure_count=$(wc -w <<< "$known_failures")
success_count=$(( $example_count - $failure_count ))
success_percent=$(bc -l <<< "100*${success_count}/${example_count}")
printf \
"Successfully parsed %d of %d example files (%.1f%%)\n" \
$success_count $example_count $success_percent

@ -1,3 +0,0 @@
#!/bin/bash
wc -l -m src/*.* | awk '{printf("%-20s\t%0.1fMB\t%10s\n", $3, $2/1048576, $1)}' > script/file_sizes.txt

@ -1,7 +0,0 @@
#!/bin/bash
set -eu
find examples -name '*.cs' -print0 | \
xargs -0 -n 1000 tree-sitter parse -q | \
tee >(cut -d' ' -f1 | sort > script/known-failures.txt)

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

@ -1,29 +0,0 @@
#include <tree_sitter/parser.h>
#include <wctype.h>
enum TokenType {
PREPROC_DIRECTIVE_END,
};
void *tree_sitter_c_sharp_external_scanner_create() { return NULL; }
void tree_sitter_c_sharp_external_scanner_destroy(void *p) {}
void tree_sitter_c_sharp_external_scanner_reset(void *p) {}
unsigned tree_sitter_c_sharp_external_scanner_serialize(void *p, char *buffer) { return 0; }
void tree_sitter_c_sharp_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
bool tree_sitter_c_sharp_external_scanner_scan(
void *payload,
TSLexer *lexer,
const bool *valid_symbols
) {
// Detect either a newline or EOF. Currently, external scanners
// are the only way to match against EOF.
if (!valid_symbols[PREPROC_DIRECTIVE_END]) return false;
lexer->result_symbol = PREPROC_DIRECTIVE_END;
for (;;) {
if (lexer->lookahead == 0) return true;
if (lexer->lookahead == '\n') return true;
if (!iswspace(lexer->lookahead)) return false;
lexer->advance(lexer, true);
}
}

@ -1,224 +0,0 @@
#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;
const TSStateId *primary_state_ids;
};
/*
* 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_

@ -1,3 +0,0 @@
console.log("Trying to require index.js in JavaScript");
require('.')
console.log("Require successfull");

@ -1,970 +0,0 @@
extern alias A;
// ^ punctuation.delimiter
using System;
// <- keyword
// ^ punctuation.delimiter
using global::System.Collections.Generic;
// <- keyword
// ^ punctuation.delimiter
// ^ punctuation.delimiter
// ^ punctuation.delimiter
using static System.Console;
// <- keyword
// ^ punctuation.delimiter
// ^ punctuation.delimiter
using X = System.Console;
// <- keyword
// ^ operator
// ^ punctuation.delimiter
// ^ punctuation.delimiter
global using A;
// ^ keyword
// ^ punctuation.delimiter
global using static A.B;
// ^ keyword
// ^ punctuation.delimiter
// ^ punctuation.delimiter
namespace Namespace
// <- keyword
// ^ type
{
// <- punctuation.bracket
using A;
// <- keyword
// ^ punctuation.delimiter
internal delegate void A(params int[] test);
// <- keyword
// ^ keyword
// ^ type.builtin
// ^ punctuation.bracket
// ^ keyword
// ^ type.builtin
// ^ punctuation.bracket
// ^ punctuation.bracket
public struct F<T> where T : struct { }
// <- keyword
// ^ keyword
// ^ type
// ^ operator
// ^ property.definition
// ^ operator
// ^ keyword
// ^ property.definition
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ punctuation.bracket
record struct F
// <- keyword
// ^ keyword
// ^ type
{
// <- punctuation.bracket
int Age { get; init; }
// <- type.builtin
// ^ variable
// ^ punctuation.bracket
// ^ keyword
// ^ punctuation.delimiter
// ^ keyword
// ^ punctuation.delimiter
// ^ punctuation.bracket
}
// <- punctuation.bracket
[Nice]
// <- punctuation.bracket
// <- type
// ^ punctuation.bracket
private record F<T1, T2> where T1 : I1, I2, new() where T2 : I2 { }
// <- keyword
// ^ keyword
// ^ type
// ^ operator
// ^ property.definition
// ^ punctuation.delimiter
// ^ property.definition
// ^ operator
// ^ keyword
// ^ property.definition
// ^ operator
// ^ type
// ^ punctuation.delimiter
// ^ type
// ^ punctuation.delimiter
// ^ keyword
// ^ punctuation.bracket
// ^ keyword
// ^ property.definition
// ^ operator
// ^ type
// ^ punctuation.bracket
// ^ punctuation.bracket
record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName);
// <- keyword
// ^ type
// ^ punctuation.bracket
// ^ type.builtin
// ^ variable.parameter
// ^ punctuation.delimiter
// ^ type.builtin
// ^ variable.parameter
// ^ punctuation.delimiter
// ^ type.builtin
// ^ variable.parameter
// ^ punctuation.bracket
// ^ operator
// ^ punctuation.bracket
// ^ punctuation.delimiter
// ^ punctuation.bracket
enum B { Ten = 10, Twenty = 20 }
// <- keyword
// ^ type
// ^ punctuation.bracket
// ^ property.definition
// ^ operator
// ^ number
// ^ punctuation.delimiter
// ^ property.definition
// ^ operator
// ^ number
// ^ punctuation.bracket
public class F : object, IAlpha, IOmega { }
// <- keyword
// ^ keyword
// ^ type
// ^ operator
// ^ type.builtin
// ^ punctuation.delimiter
// ^ type
// ^ punctuation.delimiter
// ^ type
// ^ punctuation.bracket
// ^ punctuation.bracket
public partial class Class<in TParam> where TParam : class?, notnull, F?
// <- keyword
// ^ keyword
// ^ keyword
// ^ type
// ^ operator
// ^ keyword
// ^ property.definition
// ^ operator
// ^ keyword
// ^ property.definition
// ^ operator
// ^ keyword
// ^ operator
// ^ punctuation.delimiter
// ^ type.builtin
// ^ operator
{
// <- punctuation.bracket
public event EventHandler<T> SomeEvent { add { } remove { } }
// <- keyword
// ^ keyword
// ^ type
// ^ operator
// ^ type
// ^ operator
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
public readonly int _B;
// <- keyword
// ^ keyword
// ^ type.builtin
// ^ variable
// ^ variable
// ^ punctuation.delimiter
Int64 D_e_f, g;
// <- type
// ^ variable
// ^ variable
// ^ variable
// ^ variable
// ^ variable
// ^ punctuation.delimiter
// ^ variable
// ^ punctuation.delimiter
Tuple<char, Nullable<int>> z;
// <- type
// ^ operator
// ^ type.builtin
// ^ punctuation.delimiter
// ^ type
// ^ operator
// ^ type.builtin
// ^ operator
// ^ variable
// ^ punctuation.delimiter
[SomeAttribute]
// <- punctuation.bracket
// <- type
// ^ punctuation.bracket
public static int operator +(A a) { return 0; }
// <- keyword
// ^ keyword
// ^ type.builtin
// ^ keyword
// ^ operator
// ^ type
// ^ variable.parameter
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ keyword
// ^ number
// ^ punctuation.delimiter
// ^ punctuation.bracket
uint GetSet { get; set; }
// <- type.builtin
// ^ variable
// ^ punctuation.bracket
// ^ keyword
// ^ punctuation.delimiter
// ^ keyword
// ^ punctuation.delimiter
// ^ punctuation.bracket
static extern Foo() { }
// <- keyword
// ^ keyword
// ^ type
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
extern ~Class() { }
// ^ operator
// ^ type
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
public void Method()
// <- keyword
// ^ type.builtin
// ^ punctuation.bracket
{
// <- punctuation.bracket
const int dec = 1_2;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const long hex = 0xf_1l;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const long hex2 = 0Xffff;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ punctuation.delimiter
const long hex3 = 0x_0_f;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const UInt64 dec = 1uL;
// <- keyword
// ^ type
// ^ variable
// ^ operator
// ^ number
// ^ punctuation.delimiter
const UInt16 bin = 0b0100_100;
// <- keyword
// ^ type
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const UInt16 bin2 = 0B01010__10;
// <- keyword
// ^ type
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const long bin3 = 0b_0_10;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const bool t = true, u = false;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ constant.builtin
// ^ punctuation.delimiter
// ^ variable
// ^ operator
// ^ constant.builtin
// ^ punctuation.delimiter
const char c = 'a';
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ string
// ^ string
const char esc = '\n';
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ keyword
// ^ string
const char hex = '\xf09a';
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ keyword
// ^ string
const char uni16 = '\ua0bf';
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ keyword
// ^ string
const char uni32 = '\UA0BFf9ca';
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ keyword
// ^ string
const float s = 012.23F;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const float e = 1e6f;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ punctuation.delimiter
const Single en = 0e-1f;
// <- keyword
// ^ type
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const Single ep = 1_1e+12f;
// <- keyword
// ^ type
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const double d = 0.9_9d;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const double e = .4_9d;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const decimal m = 0_1_2.9m;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const Decimal m2 = 102.349M;
// <- keyword
// ^ type
// ^ variable
// ^ operator
// ^ number
// ^ number
// ^ number
// ^ punctuation.delimiter
const string x = null;
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ constant.builtin
// ^ punctuation.delimiter
String e = "";
// <- type
// ^ variable
// ^ operator
// ^ string
string s = "a";
// <- type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ string
// ^ string
string m = "abc";
// <- type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ string
// ^ string
string esc = "ab\"\t";
// <- type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ string
// ^ keyword
// ^ keyword
// ^ string
string hex = "ab\x22r";
// <- type.builtin
// ^ variable
// ^ operator
// ^ string
// ^ string
// ^ keyword
// ^ keyword
// ^ string
int @var = @const;
// <- type.builtin
// ^ variable
// ^ variable
// ^ operator
// ^ punctuation.delimiter
var x = $"""The point {X}, {Y} is {Math.Sqrt(X * X + Y * Y)} from the origin""";
// <- type.builtin
// ^ variable
// ^ operator
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ punctuation.delimiter
// ^ punctuation.bracket
// ^ variable
// ^ operator
// ^ variable
// ^ operator
// ^ variable
// ^ operator
// ^ variable
// ^ punctuation.bracket
List<int> numbers = new() { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
// <- type
// ^ operator
// ^ type.builtin
// ^ operator
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.bracket
var query =
// <- type.builtin
// ^ variable
// ^ operator
from num in numbers
// <- keyword
// ^ variable
// ^ keyword
// ^ variable
where num < 3 || num > 7
// <- keyword
// ^ variable
// ^ operator
// ^ number
// ^ operator
// ^ variable
// ^ operator
// ^ number
orderby num ascending
select num;
// <- keyword
// ^ variable
// ^ punctuation.delimiter
var u = x is int?
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ type.builtin
// ^ operator
? a
// <- operator
//^ variable
: b;
// <- operator
//^ variable
// ^ punctuation.delimiter
a = (B)c + (C)d;
// <- variable
//^ operator
// ^ punctuation.bracket
// ^ type
// ^ punctuation.bracket
// ^ variable
// ^ operator
// ^ punctuation.bracket
// ^ type
// ^ punctuation.bracket
// ^ variable
// ^ punctuation.delimiter
b = (float)a[0];
// <- variable
//^ operator
// ^ punctuation.bracket
// ^ type.builtin
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ number
// ^ punctuation.bracket
var x = new
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
{
// <- punctuation.bracket
};
// <- punctuation.bracket
var three = checked(1 + 2);
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ number
// ^ operator
// ^ number
// ^ punctuation.bracket
var d = delegate (int a)
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ type.builtin
// ^ variable.parameter
// ^ punctuation.bracket
{
// <- punctuation.bracket
return a;
// <- keyword
// ^ variable
// ^ punctuation.delimiter
};
// <- punctuation.bracket
var l = (A a, B b) => { return a.c(b); };
// <- type.builtin
// ^ variable
// ^ operator
// ^ punctuation.bracket
// ^ type
// ^ variable.parameter
// ^ punctuation.delimiter
// ^ type
// ^ variable.parameter
// ^ punctuation.bracket
// ^ operator
// ^ punctuation.bracket
// ^ keyword
// ^ variable
// ^ punctuation.delimiter
// ^ variable
// ^ punctuation.bracket
// ^ variable
// ^ punctuation.bracket
// ^ punctuation.bracket
Do(async () => { });
//^ punctuation.bracket
// ^ keyword
// ^ punctuation.bracket
// ^ operator
// ^ punctuation.bracket
// ^ punctuation.bracket
var gp = __makeref(g);
// <- type.builtin
// ^ variable
// ^ operator
// ^ punctuation.bracket
// ^ punctuation.bracket
var z = typeof(List<string>.Enumerator);
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ type
// ^ operator
// ^ type.builtin
// ^ operator
// ^ punctuation.bracket
ref VeryLargeStruct reflocal = ref veryLargeStruct;
// <- keyword
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.delimiter
ref var elementRef = ref arr[0];
// <- keyword
// ^ type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ number
// ^ punctuation.bracket
var x = name is (var a);
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ punctuation.bracket
var x = c is < '0' or >= 'A' and <= 'Z';
// <- type.builtin
// ^ variable
// ^ operator
// ^ keyword
// ^ operator
// ^ string
// ^ string
// ^ string
// ^ string
// ^ string
// ^ string
// ^ string
// ^ string
// ^ string
var x = !this.Call();
// <- type.builtin
// ^ variable
// ^ operator
// ^ operator
// ^ keyword
// ^ punctuation.delimiter
// ^ punctuation.bracket
}
// <- punctuation.bracket
void Sample()
// <- type.builtin
// ^ punctuation.bracket
{
// <- punctuation.bracket
while (true) break;
// <- keyword
// ^ punctuation.bracket
// ^ constant.builtin
// ^ punctuation.bracket
// ^ keyword
// ^ punctuation.delimiter
throw ex;
// <- keyword
// ^ punctuation.delimiter
do { } while (a);
// <- keyword
// ^ punctuation.bracket
// ^ punctuation.bracket
// ^ keyword
// ^ punctuation.bracket
// ^ punctuation.bracket
goto end;
// <- keyword
// ^ punctuation.delimiter
end:
// ^ operator
return;
// <- keyword
// ^ punctuation.delimiter
if (true) return 1;
// <- keyword
// ^ punctuation.bracket
// ^ constant.builtin
// ^ punctuation.bracket
// ^ keyword
// ^ number
// ^ punctuation.delimiter
else return 0;
// <- keyword
// ^ keyword
// ^ number
// ^ punctuation.delimiter
(string a, bool b) c = default;
// <- punctuation.bracket
// <- type.builtin
// ^ punctuation.delimiter
// ^ type.builtin
// ^ punctuation.bracket
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.delimiter
switch (a, a)
// <- keyword
// ^ punctuation.bracket
// ^ punctuation.delimiter
// ^ punctuation.bracket
{
// <- punctuation.bracket
case (1, 1):
// <- keyword
// ^ punctuation.bracket
// ^ number
// ^ punctuation.delimiter
// ^ number
// ^ punctuation.bracket
return 1;
// <- keyword
// ^ number
// ^ punctuation.delimiter
default:
// <- keyword
// ^ operator
return 0;
// <- keyword
// ^ number
// ^ punctuation.delimiter
}
// <- punctuation.bracket
lock (this)
// <- keyword
// ^ punctuation.bracket
// ^ keyword
// ^ punctuation.bracket
{
// <- punctuation.bracket
return;
// <- keyword
// ^ punctuation.delimiter
}
// <- punctuation.bracket
yield return 1;
// <- keyword
// ^ keyword
// ^ number
// ^ punctuation.delimiter
using (Stream a = File.OpenRead("a"), b = new BinaryReader(a))
// <- keyword
// ^ punctuation.bracket
// ^ type
// ^ variable
// ^ operator
// ^ punctuation.delimiter
// ^ punctuation.bracket
// ^ string
// ^ string
// ^ variable
// ^ operator
// ^ keyword
// ^ punctuation.bracket
// ^ punctuation.bracket
{
// <- punctuation.bracket
return;
// <- keyword
// ^ punctuation.delimiter
}
// <- punctuation.bracket
foreach (var (x, y) in z)
// <- keyword
// ^ punctuation.bracket
// ^ type.builtin
// ^ punctuation.bracket
// ^ punctuation.delimiter
// ^ punctuation.bracket
// ^ keyword
// ^ punctuation.bracket
q += x;
// <- variable
//^ operator
// ^ variable
// ^ punctuation.delimiter
for (int x = 0; x < 100; x++)
// <- keyword
// ^ punctuation.bracket
// ^ type.builtin
// ^ variable
// ^ operator
// ^ number
// ^ punctuation.delimiter
// ^ variable
// ^ operator
// ^ number
// ^ punctuation.delimiter
// ^ variable
// ^ operator
{
// <- punctuation.bracket
z += x;
// <- variable
//^ operator
// ^ variable
// ^ punctuation.delimiter
}
// <- punctuation.bracket
dynamic dyn = "";
// <- type
// ^ variable
// ^ operator
// ^ string
}
// <- punctuation.bracket
string b(Object operation) =>
// <- type.builtin
// ^ punctuation.bracket
// ^ type
// ^ variable.parameter
// ^ punctuation.bracket
// ^ operator
operation switch
// <- variable
// ^ keyword
{
// <- punctuation.bracket
1 => "one",
// <- number
//^ operator
// ^ string
// ^ string
// ^ string
_ => "more",
//^ operator
// ^ string
// ^ string
// ^ string
};
// <- punctuation.bracket
}
// <- punctuation.bracket
}
// <- punctuation.bracket

@ -1,10 +0,0 @@
class var
// ^ type
{
void M()
{
var var = new var();
// <- type.builtin
// ^ variable
}
}

@ -1,14 +0,0 @@
namespace World
{
class Hello {
static void Main(string []args)
{
Hello x = new Hello();
System.Console.WriteLine("Hello, world.");
}
}
interface Blah {
}
}

@ -1,26 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/Generator.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

@ -1,41 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Generator.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Generator.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Generator.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

@ -1,177 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
if (args.Length != 1)
{
Console.WriteLine("Add the path to the file as an argument. The path needs to be fully qualified and point to an existing file in [REPO ROOT]/test/highlight.");
return;
}
var filePath = args[0];
// Some basic tests on the path, so that we have a chance:
if (!filePath.Contains("/test/highlight/") ||
!filePath.EndsWith(".cs") ||
!File.Exists(filePath) ||
!Path.IsPathFullyQualified(filePath))
{
Console.WriteLine("The file needs to exist in [REPO ROOT]/test/highlight, and the path needs to be fully qualified.");
return;
}
// Random variable name prefix, so that we don't accidentally replace something in the file:
var idPrefix = "a" + new Random(filePath.GetHashCode()).NextInt64(10000000) + "_";
var originalLines = File.ReadAllLines(filePath);
/// <summary>
/// Adds tree-sitter highlighting comments to the input file.
/// Comments start with either `// <-` or `// ^`, depending on the position of the hiughlighted token.
/// For highlight category, a unique random identifier is used.
/// </summary>
void AddCommentsToFile()
{
var newLines = new List<string>();
var index = 0;
foreach (var line in originalLines)
{
newLines.Add(line);
var leadingWhitespaces = line[..^line.TrimStart().Length];
var first = true;
var position = leadingWhitespaces.Length;
while (position < line.Length)
{
var ch = line[position];
bool HandleToken(Func<char, bool> isOfType)
{
if (!isOfType(ch))
{
return false;
}
var variable = $"{idPrefix}{index++}";
if (first)
{
newLines.Add($"{leadingWhitespaces}// <- {variable}");
first = false;
}
else
{
var spacesLength = position - leadingWhitespaces.Length - 2;
if (spacesLength < 0)
{
// Handle case when the first two characters need different highlight categories:
// Shift // by one space to the right.
newLines.Add($"{leadingWhitespaces} // <- {variable}");
}
else
{
var spaces = new string(' ', position - leadingWhitespaces.Length - 2);
newLines.Add($"{leadingWhitespaces}//{spaces}^ {variable}");
}
}
while (position < line.Length && isOfType(line[position]))
{
position++;
}
return true;
}
// The below char methods are not exactly what we need for token parsing, but good enough.
// For example
// - `_abc` is an identifier, but has both letter and punctuation characters.
// - string literals are parsed pretty badly, considering they can have all sorts of characters, even spaces, on which we split.
if (!HandleToken(char.IsLetterOrDigit) &&
!HandleToken(c => char.IsPunctuation(c) || char.IsSymbol(c)))
{
position++;
}
}
}
File.WriteAllLines(filePath, newLines.ToArray());
}
string GetHighlighterOutput()
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "tree-sitter",
Arguments = $"test --filter skip-all-corpus-tests",
UseShellExecute = false,
RedirectStandardOutput = true,
WorkingDirectory = Path.GetFullPath(Path.Combine(filePath, "..", "..", "..")),
}
};
process.Start();
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
var regexWithHighlight = new Regex($@"Failure - row: \d+, column: \d+, expected highlight '{idPrefix}(\d+)', actual highlights: '(.*)'", RegexOptions.Compiled);
var regexWithNone = new Regex($@"Failure - row: \d+, column: \d+, expected highlight '{idPrefix}(\d+)', actual highlights: none.", RegexOptions.Compiled);
/// <summary>
/// Runs the tree-sitter test command, and tries to find a single highlighting failure.
/// If a failure is found, the category is extracted from the output, and the corresponding variable is replaced with the category.
/// </summary>
bool FindAndFixHighlightFailure()
{
Console.Write(".");
var output = GetHighlighterOutput();
if (output.IndexOf("✗") != output.LastIndexOf("✗"))
{
Console.WriteLine("\nThe tree-sitter test execution identified multiple files with failed highlighting. Aborting.");
File.WriteAllLines(filePath, originalLines);
Environment.Exit(1);
}
var match = regexWithHighlight.Match(output);
if (match.Success && match.Groups.Count == 3)
{
// Highlight found for position, so replace with expected category.
var variableCat = $"{idPrefix}{match.Groups[1].Captures[0].Value}";
var category = match.Groups[2].Captures[0].Value;
File.WriteAllText(filePath, File.ReadAllText(filePath).Replace(variableCat + "\n", category + "\n"));
return true;
}
match = regexWithNone.Match(output);
if (!match.Success || match.Groups.Count != 2)
{
// Couldn't match any of the expected patterns.
return false;
}
// No highlight found for position, so remove entire line.
var variableNone = $"{idPrefix}{match.Groups[1].Captures[0].Value}";
var lines = File.ReadAllLines(filePath).Where(line => !line.EndsWith(variableNone)).ToArray();
File.WriteAllLines(filePath, lines);
return true;
}
AddCommentsToFile();
Console.WriteLine("Calling tree-sitter highlighter several times. This might take a while.");
while (FindAndFixHighlightFailure())
{ }
Console.WriteLine("");
Console.WriteLine("Done modifying the input file. It may require some manual cleanup.");

@ -1,6 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

@ -1,5 +0,0 @@
#!/bin/bash
ROOT="$(git rev-parse --show-toplevel)"
echo $ROOT/tools/highlight-test-generator/Generator.csproj
dotnet run --project $ROOT/tools/highlight-test-generator/Generator.csproj $1