initial commit

This commit is contained in:
2024-03-25 23:16:07 +01:00
commit 8f31c35bc9
62 changed files with 1348332 additions and 0 deletions

481
corpus/attributes.txt Normal file
View File

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

663
corpus/classes.txt Normal file
View File

@@ -0,0 +1,663 @@
================================================================================
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)
name: (identifier)
body: (declaration_list)))
================================================================================
Class with a single type parameter
================================================================================
class F<T> {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
body: (declaration_list)))
================================================================================
Class with multiple type parameters
================================================================================
internal class F<T1, T2> {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
body: (declaration_list)))
================================================================================
Class with co-variant and contra-variant type parameters
================================================================================
internal class F<in T1, out T2> {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
body: (declaration_list)))
================================================================================
Class with a type parameter struct constraint
================================================================================
public class F<T> where T:struct {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Class with a type parameter unmanaged constraint
================================================================================
public class F<T> where T:unmanaged {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Class with a type parameter class constraint
================================================================================
public class F<T> where T:class {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Class with a type parameter and nullable constraints
================================================================================
public class F<T> where T:class?, notnull, Mine? {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint)
constraints: (type_parameter_constraint)
constraints: (type_parameter_constraint
(type_constraint
type: (nullable_type
type: (identifier)))))
body: (declaration_list)))
================================================================================
Class with type parameter new constraint
================================================================================
public class F<T> where T: new() {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (declaration_list)))
================================================================================
Class with type parameter identifier constraint
================================================================================
public class F<T> where T: I {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier))))
body: (declaration_list)))
================================================================================
Class with type parameter identifier and new constraints
================================================================================
public class F<T> where T: I, new() {}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (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)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier))))
body: (declaration_list)))
================================================================================
Class with public constructor
================================================================================
class Foo {
public Foo() {}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(constructor_declaration
(modifier)
name: (identifier)
parameters: (parameter_list)
body: (block)))))
================================================================================
Class with expression bodied constructor
================================================================================
class Foo {
public Foo(string name) => Name = name;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(constructor_declaration
(modifier)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (arrow_expression_clause
(assignment_expression
left: (identifier)
(assignment_operator)
right: (identifier)))))))
================================================================================
Class with static constructor
================================================================================
class Foo {
static Foo() {}
static extern Foo() {}
extern static Foo() {}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(constructor_declaration
(modifier)
name: (identifier)
parameters: (parameter_list)
body: (block))
(constructor_declaration
(modifier)
(modifier)
name: (identifier)
parameters: (parameter_list)
body: (block))
(constructor_declaration
(modifier)
(modifier)
name: (identifier)
parameters: (parameter_list)
body: (block)))))
================================================================================
Class with extern destructor
================================================================================
class Foo {
extern ~Foo() {}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(destructor_declaration
name: (identifier)
parameters: (parameter_list)
body: (block)))))
================================================================================
Class with expression bodied destructor
================================================================================
class Foo {
~Foo() => DoSomething();
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(destructor_declaration
name: (identifier)
parameters: (parameter_list)
body: (arrow_expression_clause
(invocation_expression
function: (identifier)
arguments: (argument_list)))))))
================================================================================
Class with constants
================================================================================
class Foo {
private const int a = 1;
const string b = $"hello";
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal)))))
(field_declaration
(modifier)
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (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
name: (identifier)
body: (declaration_list
(indexer_declaration
(modifier)
type: (predefined_type)
parameters: (bracketed_parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
accessors: (accessor_list
(accessor_declaration
body: (block
(return_statement
(identifier))))
(accessor_declaration
body: (block
(expression_statement
(assignment_expression
left: (identifier)
(assignment_operator)
right: (identifier))))))))))
================================================================================
Class with expression bodied indexer
================================================================================
class Foo {
public bool this[int index] => a[index];
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(indexer_declaration
(modifier)
type: (predefined_type)
parameters: (bracketed_parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
value: (arrow_expression_clause
(element_access_expression
expression: (identifier)
subscript: (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
name: (identifier)
body: (declaration_list
(indexer_declaration
(modifier)
type: (predefined_type)
parameters: (bracketed_parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
accessors: (accessor_list
(accessor_declaration
body: (arrow_expression_clause
(element_access_expression
expression: (identifier)
subscript: (bracketed_argument_list
(argument
(identifier))))))
(accessor_declaration
body: (arrow_expression_clause
(assignment_expression
left: (element_access_expression
expression: (identifier)
subscript: (bracketed_argument_list
(argument
(identifier))))
(assignment_operator)
right: (identifier)))))))))
================================================================================
Class with varargs indexer
================================================================================
class A {
public int this[params string[] arguments] {
get { return 1; }
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(indexer_declaration
(modifier)
type: (predefined_type)
parameters: (bracketed_parameter_list
type: (array_type
type: (predefined_type)
rank: (array_rank_specifier))
name: (identifier))
accessors: (accessor_list
(accessor_declaration
body: (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
qualifier: (identifier)
name: (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
qualifier: (identifier)
name: (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)))

View File

@@ -0,0 +1,614 @@
================================================================================
From keyword can be a variable
================================================================================
var a = Assert.Range(from, to);
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(invocation_expression
function: (member_access_expression
expression: (identifier)
name: (identifier))
arguments: (argument_list
(argument
(identifier))
(argument
(identifier))))))))))
================================================================================
File keyword in invocation
================================================================================
file.Method(1, 2);
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(expression_statement
(invocation_expression
function: (member_access_expression
expression: (identifier)
name: (identifier))
arguments: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (identifier)
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(identifier)))))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list)))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(binary_expression
left: (identifier)
right: (integer_literal)))))))))
(class_declaration
(modifier)
name: (identifier)
body: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
type: (predefined_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
type: (identifier)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (identifier)
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (scoped_type
type: (ref_type
type: (predefined_type)))
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (scoped_type
type: (ref_type
type: (identifier)))
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list)))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(binary_expression
left: (identifier)
right: (integer_literal))))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(lambda_expression
parameters: (implicit_parameter_list
(parameter
name: (identifier)))
body: (null_literal))))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(lambda_expression
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (null_literal))))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(lambda_expression
parameters: (parameter_list
(parameter
name: (identifier))
(parameter
name: (identifier)))
body: (null_literal))))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(lambda_expression
type: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier)))
body: (null_literal)))))))))
(class_declaration
name: (identifier)
body: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (identifier)
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(identifier)))))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list)))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(binary_expression
left: (identifier)
right: (integer_literal)))))))))
(class_declaration
name: (identifier)
body: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (implicit_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(identifier)))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal)))))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list)))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(binary_expression
left: (identifier)
right: (integer_literal)))))))))
(class_declaration
name: (identifier)
body: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block)))
(global_statement
(local_function_statement
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (identifier)
(variable_declarator
name: (identifier)
(equals_value_clause
(null_literal)))))
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(identifier)))))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list)))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list
(argument
(identifier))
(argument
(identifier)))))
(expression_statement
(invocation_expression
function: (identifier)
arguments: (argument_list
(argument
(identifier)))))
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(binary_expression
left: (identifier)
right: (integer_literal)))))))))
(class_declaration
name: (identifier)
body: (declaration_list)))

59
corpus/enums.txt Normal file
View File

@@ -0,0 +1,59 @@
================================================================================
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)))))))

3457
corpus/expressions.txt Normal file

File diff suppressed because it is too large Load Diff

134
corpus/identifiers.txt Normal file
View File

@@ -0,0 +1,134 @@
================================================================================
basic indentifiers
================================================================================
int x = y;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(identifier)))))))
================================================================================
indentifiers with keyword names
================================================================================
int @var = @const;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (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
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal))))))
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal)))))))

335
corpus/interfaces.txt Normal file
View File

@@ -0,0 +1,335 @@
================================================================================
Global empty interface
================================================================================
public interface IOne {};
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
body: (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
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration)))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (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
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list))
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list))
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier))))
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))))))
================================================================================
Interface base single
================================================================================
private interface IOne : ITwo { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
bases: (base_list
(identifier))
body: (declaration_list)))
================================================================================
Interface base multiple
================================================================================
private interface IOne : ITwo, IThree { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
bases: (base_list
(identifier)
(identifier))
body: (declaration_list)))
================================================================================
Interface generic
================================================================================
private interface IOne<T1> : ITwo { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
bases: (base_list
(identifier))
body: (declaration_list)))
================================================================================
Interface generic single constraint
================================================================================
private interface IOne<T1> : ITwo where T1:T2 { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
bases: (base_list
(identifier))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier))))
body: (declaration_list)))
================================================================================
Interface generic multiple constraints
================================================================================
private interface IOne<T1, T3> : ITwo where T1:T2 where T3:new() { }
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
bases: (base_list
(identifier))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier))))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (declaration_list)))
================================================================================
Interface in namespace
================================================================================
namespace A {
interface IOne : ITwo { }
}
--------------------------------------------------------------------------------
(compilation_unit
(namespace_declaration
name: (identifier)
body: (declaration_list
(interface_declaration
name: (identifier)
bases: (base_list
(identifier))
body: (declaration_list)))))
================================================================================
Interface event declarations
================================================================================
interface A {
event EventHandler<T> SomeEvent;
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
name: (identifier)
body: (declaration_list
(event_field_declaration
(variable_declaration
type: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier)))
(variable_declarator
name: (identifier)))))))
================================================================================
Interface with indexer
================================================================================
interface A {
bool this[int index] { get; set; }
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
name: (identifier)
body: (declaration_list
(indexer_declaration
type: (predefined_type)
parameters: (bracketed_parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Interface with default method
================================================================================
interface MyDefault {
void Log(string message) {
Console.WriteLine(message);
}
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block
(expression_statement
(invocation_expression
function: (member_access_expression
expression: (identifier)
name: (identifier))
arguments: (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)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier))))))
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))))))

1263
corpus/literals.txt Normal file

File diff suppressed because it is too large Load Diff

307
corpus/preprocessor.txt Normal file
View File

@@ -0,0 +1,307 @@
================================================================================
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
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(string_literal
(string_literal_fragment)))))))
(elif_directive
(identifier))
(global_statement
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(string_literal
(string_literal_fragment)))))))
(else_directive)
(global_statement
(local_declaration_statement
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (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
argument: (identifier)))
(if_directive
(binary_expression
left: (identifier)
right: (boolean_literal)))
(if_directive
(binary_expression
left: (prefix_unary_expression
argument: (identifier))
right: (boolean_literal)))
(if_directive
(binary_expression
left: (binary_expression
left: (identifier)
right: (identifier))
right: (identifier)))
(if_directive
(parenthesized_expression
(identifier)))
(if_directive
(parenthesized_expression
(binary_expression
left: (identifier)
right: (identifier))))
(if_directive
(binary_expression
left: (parenthesized_expression
(binary_expression
left: (identifier)
right: (identifier)))
right: (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
name: (identifier)
body: (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
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (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
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (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
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (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))

438
corpus/query-syntax.txt Normal file
View File

@@ -0,0 +1,438 @@
================================================================================
Query from select
================================================================================
var x = from a in source select a.B;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(select_clause
(member_access_expression
expression: (identifier)
name: (identifier))))))))))
================================================================================
Query from select with operator
================================================================================
var x = from a in source select a * 2;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(select_clause
(binary_expression
left: (identifier)
right: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(select_clause
(invocation_expression
function: (member_access_expression
expression: (identifier)
name: (identifier))
arguments: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(select_clause
(conditional_expression
condition: (identifier)
consequence: (integer_literal)
alternative: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(select_clause
(assignment_expression
left: (identifier)
(assignment_operator)
right: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(select_clause
(anonymous_object_creation_expression
(name_equals
(identifier))
(member_access_expression
expression: (identifier)
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(where_clause
(binary_expression
left: (member_access_expression
expression: (identifier)
name: (identifier))
right: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(where_clause
(binary_expression
left: (binary_expression
left: (member_access_expression
expression: (identifier)
name: (identifier))
right: (string_literal
(string_literal_fragment)))
right: (binary_expression
left: (member_access_expression
expression: (identifier)
name: (identifier))
right: (string_literal
(string_literal_fragment)))))
(select_clause
(anonymous_object_creation_expression
(name_equals
(identifier))
(member_access_expression
expression: (identifier)
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(order_by_clause
(member_access_expression
expression: (identifier)
name: (identifier)))
(order_by_clause
(member_access_expression
expression: (identifier)
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(let_clause
(identifier)
(anonymous_object_creation_expression
(member_access_expression
expression: (identifier)
name: (identifier))
(member_access_expression
expression: (identifier)
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(join_clause
name: (identifier)
(identifier)
(member_access_expression
expression: (identifier)
name: (identifier))
(member_access_expression
expression: (identifier)
name: (identifier)))
(select_clause
(anonymous_object_creation_expression
(member_access_expression
expression: (identifier)
name: (identifier))
(member_access_expression
expression: (identifier)
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(from_clause
name: (identifier)
(identifier))
(where_clause
(binary_expression
left: (member_access_expression
expression: (identifier)
name: (identifier))
right: (member_access_expression
expression: (identifier)
name: (identifier))))
(select_clause
(anonymous_object_creation_expression
(member_access_expression
expression: (identifier)
name: (identifier))
(member_access_expression
expression: (identifier)
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(query_expression
(from_clause
name: (identifier)
(identifier))
(group_clause
(identifier)
(member_access_expression
expression: (identifier)
name: (identifier)))
(query_continuation
name: (identifier)
(select_clause
(anonymous_object_creation_expression
(name_equals
(identifier))
(member_access_expression
expression: (identifier)
name: (identifier))
(name_equals
(identifier))
(invocation_expression
function: (member_access_expression
expression: (identifier)
name: (identifier))
arguments: (argument_list
(argument
(lambda_expression
parameters: (implicit_parameter_list
(parameter
name: (identifier)))
body: (member_access_expression
expression: (identifier)
name: (identifier))))))))))))))))

527
corpus/records.txt Normal file
View File

@@ -0,0 +1,527 @@
================================================================================
Basic record declaration
================================================================================
record F {
int Age { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Basic record struct declaration
================================================================================
record struct F {
int Age { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(record_struct_declaration
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Record class with optional `class` specification
================================================================================
record class F {
int Age { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (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)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Record with a type parameter class constraint
================================================================================
public record F<T> where T:class {}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Record with type parameter new constraint
================================================================================
public record F<T> where T: new() {}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (declaration_list)))
================================================================================
Record with interface
================================================================================
public record A : ISomething { }
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
name: (identifier)
bases: (base_list
(identifier))
body: (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
name: (identifier)))
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier))))
body: (declaration_list)))
================================================================================
Record with constructor
================================================================================
record Person(string FirstName, string LastName);
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier)))))
================================================================================
Record inheritance with constructor overload
================================================================================
record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName);
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier)))
bases: (base_list
(primary_constructor_base_type
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), Ns.I1, I2;
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier)))
bases: (base_list
(primary_constructor_base_type
type: (identifier)
(argument_list
(argument
(identifier))
(argument
(identifier))))
(qualified_name
qualifier: (identifier)
name: (identifier))
(identifier))))
================================================================================
Record inheritance with generic base
================================================================================
record Teacher() : Entity<Person>(), I1;
record A : System.IEquatable<A>;
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
parameters: (parameter_list)
bases: (base_list
(primary_constructor_base_type
type: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier)))
(argument_list))
(identifier)))
(record_declaration
name: (identifier)
bases: (base_list
(qualified_name
qualifier: (identifier)
name: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier)))))))
================================================================================
Record types can end with a semicolon
================================================================================
public record Person { };
public record struct Person2 { };
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
(modifier)
name: (identifier)
body: (declaration_list))
(record_struct_declaration
(modifier)
name: (identifier)
body: (declaration_list)))
================================================================================
Record types can seal ToString()
================================================================================
record A {
public sealed override string ToString(){
return "";
}
}
--------------------------------------------------------------------------------
(compilation_unit
(record_declaration
name: (identifier)
body: (declaration_list
(method_declaration
(modifier)
(modifier)
(modifier)
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (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
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)
body: (block
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(with_expression
(invocation_expression
function: (identifier)
arguments: (argument_list))
(with_initializer_expression
(simple_assignment_expression
(identifier)
(invocation_expression
function: (identifier)
arguments: (argument_list)))
(simple_assignment_expression
(identifier)
(invocation_expression
function: (identifier)
arguments: (argument_list)))))))))))))
================================================================================
Precedence between with and cast
================================================================================
var x = (Point) p1 with {X = 3};
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(with_expression
(cast_expression
type: (identifier)
value: (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
type: (implicit_type)
(variable_declarator
name: (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
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(binary_expression
left: (with_expression
(identifier)
(with_initializer_expression
(simple_assignment_expression
(identifier)
(integer_literal))))
right: (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
type: (implicit_type)
(variable_declarator
name: (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))))))))))

View File

@@ -0,0 +1,273 @@
================================================================================
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
name: (identifier)
body: (declaration_list
(using_directive
name: (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
name: (identifier)
body: (declaration_list
(namespace_declaration
name: (qualified_name
qualifier: (qualified_name
qualifier: (identifier)
name: (identifier))
name: (identifier))
body: (declaration_list))
(namespace_declaration
name: (qualified_name
qualifier: (identifier)
name: (identifier))
body: (declaration_list)))))
================================================================================
File scoped namespaces
================================================================================
namespace A;
class B {
}
--------------------------------------------------------------------------------
(compilation_unit
(file_scoped_namespace_declaration
name: (identifier)
(class_declaration
name: (identifier)
body: (declaration_list))))
================================================================================
Interfaces
================================================================================
public interface IFoo {
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
body: (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)
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
type: (predefined_type)
name: (identifier)
(equals_value_clause
(character_literal
(escape_sequence))))))
(delegate_declaration
(modifier)
type: (ref_type
type: (predefined_type))
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
type: (predefined_type)
name: (identifier)
(equals_value_clause
(character_literal
(escape_sequence))))))
(delegate_declaration
(modifier)
type: (ref_type
type: (predefined_type))
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
type: (predefined_type)
name: (identifier)
(equals_value_clause
(character_literal
(escape_sequence))))))
(delegate_declaration
type: (predefined_type)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
parameters: (parameter_list)
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint)))
(delegate_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
type: (array_type
type: (predefined_type)
rank: (array_rank_specifier))
name: (identifier)))
(class_declaration
name: (identifier)
body: (declaration_list
(delegate_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list)))))
================================================================================
Var declared equal to integer literal
================================================================================
var a = 1;
--------------------------------------------------------------------------------
(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
type: (implicit_type)
(variable_declarator
name: (identifier)
(equals_value_clause
(integer_literal)))))))

2039
corpus/statements.txt Normal file

File diff suppressed because it is too large Load Diff

140
corpus/structs.txt Normal file
View File

@@ -0,0 +1,140 @@
================================================================================
Struct with a type parameter struct constraint
================================================================================
public struct F<T> where T:struct {}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Struct with a type parameter class constraint
================================================================================
public struct F<T> where T:class {}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint))
body: (declaration_list)))
================================================================================
Struct with type parameter new constraint
================================================================================
public struct F<T> where T: new() {}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (declaration_list)))
================================================================================
Struct with interface
================================================================================
public struct A : ISomething { }
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
name: (identifier)
bases: (base_list
(identifier))
body: (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)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier))))
body: (declaration_list)))
================================================================================
Struct with readonly modifier
================================================================================
readonly struct Test {
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
name: (identifier)
body: (declaration_list)))
================================================================================
Struct with ref modifier
================================================================================
ref struct Test {
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
(modifier)
name: (identifier)
body: (declaration_list)))

83
corpus/type-events.txt Normal file
View File

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

382
corpus/type-fields.txt Normal file
View File

@@ -0,0 +1,382 @@
================================================================================
Class field declarations
================================================================================
class A {
public readonly int _B;
Int64 D_e_f, g;
Tuple<char, Nullable<int>> z;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (identifier)
(variable_declarator
name: (identifier))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(predefined_type)
(generic_name
name: (identifier)
type_arguments: (type_argument_list
(predefined_type)))))
(variable_declarator
name: (identifier)))))))
================================================================================
Struct field declarations
================================================================================
struct A {
private readonly int c_;
}
--------------------------------------------------------------------------------
(compilation_unit
(struct_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)))))))
================================================================================
Class field nullable type
================================================================================
class A {
public readonly int? i;
private Byte? b;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
type: (nullable_type
type: (predefined_type))
(variable_declarator
name: (identifier))))
(field_declaration
(modifier)
(variable_declaration
type: (nullable_type
type: (identifier))
(variable_declarator
name: (identifier)))))))
================================================================================
Class field pointer type
================================================================================
class A {
public readonly int* i;
private Byte* b;
private void* c;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
type: (pointer_type
type: (predefined_type))
(variable_declarator
name: (identifier))))
(field_declaration
(modifier)
(variable_declaration
type: (pointer_type
type: (identifier))
(variable_declarator
name: (identifier))))
(field_declaration
(modifier)
(variable_declaration
type: (pointer_type
type: (predefined_type))
(variable_declarator
name: (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
name: (identifier)
body: (declaration_list
(comment)
(field_declaration
(variable_declaration
type: (function_pointer_type
(function_pointer_parameter
type: (predefined_type))
(function_pointer_parameter
type: (predefined_type)))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (function_pointer_type
(function_pointer_parameter
type: (function_pointer_type
(function_pointer_parameter
(parameter_modifier)
type: (predefined_type))
(function_pointer_parameter
type: (predefined_type))))
(function_pointer_parameter
type: (function_pointer_type
(function_pointer_parameter
(parameter_modifier)
type: (predefined_type))
(function_pointer_parameter
type: (ref_type
type: (predefined_type))))))
(variable_declarator
name: (identifier))))
(comment)
(field_declaration
(variable_declaration
type: (function_pointer_type
(function_pointer_calling_convention)
(function_pointer_parameter
type: (predefined_type))
(function_pointer_parameter
type: (predefined_type)))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (function_pointer_type
(function_pointer_parameter
type: (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
type: (predefined_type))
(function_pointer_parameter
type: (predefined_type))))
(function_pointer_parameter
type: (function_pointer_type
(function_pointer_parameter
type: (predefined_type))
(function_pointer_parameter
type: (predefined_type)))))
(variable_declarator
name: (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
name: (identifier)
body: (declaration_list
(property_declaration
type: (ref_type
type: (identifier))
name: (identifier)
value: (arrow_expression_clause
(ref_expression
(identifier))))
(field_declaration
(variable_declaration
type: (ref_type
type: (pointer_type
type: (identifier)))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (ref_type
type: (array_type
type: (identifier)
rank: (array_rank_specifier)))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (ref_type
type: (nullable_type
type: (identifier)))
(variable_declarator
name: (identifier)))))))
================================================================================
Nullable reference types
================================================================================
class A {
string? a;
A? a;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(variable_declaration
type: (nullable_type
type: (predefined_type))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (nullable_type
type: (identifier))
(variable_declarator
name: (identifier)))))))
================================================================================
Tuple types
================================================================================
class A {
(int, string str) a;
(B b, C c, D d) a;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(variable_declaration
type: (tuple_type
(tuple_element
type: (predefined_type))
(tuple_element
type: (predefined_type)
name: (identifier)))
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (tuple_type
(tuple_element
type: (identifier)
name: (identifier))
(tuple_element
type: (identifier)
name: (identifier))
(tuple_element
type: (identifier)
name: (identifier)))
(variable_declarator
name: (identifier)))))))
================================================================================
Native integer types
================================================================================
class A {
nint a;
nuint b;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier))))
(field_declaration
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)))))))
================================================================================
Required fields
================================================================================
class A {
public required int B;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(field_declaration
(modifier)
(modifier)
(variable_declaration
type: (predefined_type)
(variable_declarator
name: (identifier)))))))

494
corpus/type-methods.txt Normal file
View File

@@ -0,0 +1,494 @@
================================================================================
Class method with single parameter
================================================================================
class A {
private int GetBack(int b) {
return b;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
(modifier)
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block
(return_statement
(identifier)))))))
================================================================================
Class method with multiple parameters
================================================================================
class A {
void DoSomething(A a, B b) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block)))))
================================================================================
Class generic method
================================================================================
class A {
void Accept<T>(T accept) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block)))))
================================================================================
Class generic method with new type constraint
================================================================================
class A {
void Accept<T>(T accept) where T: new() {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (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
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier))
(type_parameter
name: (identifier)))
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(constructor_constraint)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (identifier)))
constraints: (type_parameter_constraint
(constructor_constraint)))
body: (block)))))
================================================================================
Class method with out parameter
================================================================================
class A {
void HasAnOut(out int a) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
type: (predefined_type)
name: (identifier)))
body: (block)))))
================================================================================
Class method with in parameter
================================================================================
class A {
void HasAnOut(in int a) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
type: (predefined_type)
name: (identifier)))
body: (block)))))
================================================================================
Class method with ref parameter
================================================================================
class A {
void HasAnOut(ref int a) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
type: (predefined_type)
name: (identifier)))
body: (block)))))
================================================================================
Class method with extension ref parameter
================================================================================
class A {
void M(this ref int a) { }
void M(this scoped ref int a) { }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
type: (predefined_type)
name: (identifier)))
body: (block))
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
(parameter_modifier)
type: (predefined_type)
name: (identifier)))
body: (block)))))
================================================================================
Class method with contextually-reserved keyword named parameters
================================================================================
class A {
void HasAnOut(int from, string partial) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier))
(parameter
type: (predefined_type)
name: (identifier)))
body: (block)))))
================================================================================
Class method with default parameter
================================================================================
class A {
void HasAnOut(int a = 5) {
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)
(equals_value_clause
(integer_literal))))
body: (block)))))
================================================================================
Class static method with single parameter
================================================================================
class A {
static int GetBack(int b) {
return b;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
(modifier)
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block
(return_statement
(identifier)))))))
================================================================================
Class method with explicit interface specifier
================================================================================
class A : ISomething {
int ISomething.GetBack(int b) {
return b;
}
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
bases: (base_list
(identifier))
body: (declaration_list
(method_declaration
type: (predefined_type)
(explicit_interface_specifier
name: (identifier))
name: (identifier)
parameters: (parameter_list
(parameter
type: (predefined_type)
name: (identifier)))
body: (block
(return_statement
(identifier)))))))
================================================================================
Class method with readonly method
================================================================================
class A {
public readonly double Add => x + y;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(property_declaration
(modifier)
(modifier)
type: (predefined_type)
name: (identifier)
value: (arrow_expression_clause
(binary_expression
left: (identifier)
right: (identifier)))))))
================================================================================
Class method with nullable parameter list
================================================================================
class A {
public int Zero(params int[]? ints) => 0;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(method_declaration
(modifier)
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
type: (nullable_type
type: (array_type
type: (predefined_type)
rank: (array_rank_specifier)))
name: (identifier))
body: (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)
name: (identifier)
body: (declaration_list
(method_declaration
type: (predefined_type)
name: (identifier)
parameters: (parameter_list
(parameter
(parameter_modifier)
(parameter_modifier)
type: (qualified_name
qualifier: (identifier)
name: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(predefined_type))))
name: (identifier)))
body: (block
(local_declaration_statement
(variable_declaration
type: (scoped_type
type: (ref_type
type: (qualified_name
qualifier: (identifier)
name: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(predefined_type))))))
(variable_declarator
name: (identifier)
(equals_value_clause
(ref_expression
(identifier))))))
(local_declaration_statement
(variable_declaration
type: (scoped_type
type: (qualified_name
qualifier: (identifier)
name: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(predefined_type)))))
(variable_declarator
name: (identifier)
(equals_value_clause
(identifier))))))))))

901
corpus/type-operators.txt Normal file
View File

@@ -0,0 +1,901 @@
================================================================================
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
name: (identifier)
body: (declaration_list
(operator_declaration
(attribute_list
(attribute
name: (identifier)))
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(integer_literal))))
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(integer_literal))))
(operator_declaration
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (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
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(boolean_literal))))
(operator_declaration
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (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
name: (identifier)
body: (declaration_list
(conversion_operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(integer_literal))))
(conversion_operator_declaration
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(integer_literal)))))))
================================================================================
conversion operator with expression body
================================================================================
class A
{
public static implicit operator int (A a) => 0;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(conversion_operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (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
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))))
(operator_declaration
(modifier)
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier))))
(conversion_operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (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
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(integer_literal)))
(operator_declaration
(modifier)
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(boolean_literal)))
(conversion_operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (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
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(identifier))))
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(boolean_literal))))
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (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
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (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
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier)))))
(operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(binary_expression
left: (identifier)
right: (identifier))))))))
================================================================================
Explicit operator overloads
================================================================================
interface I
{
static abstract int operator +(I i, I j);
}
public class C : I
{
static int I.operator +(I i, I j) { return 1; }
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier))))))
(class_declaration
(modifier)
name: (identifier)
bases: (base_list
(identifier))
body: (declaration_list
(operator_declaration
(modifier)
type: (predefined_type)
(explicit_interface_specifier
name: (identifier))
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (block
(return_statement
(integer_literal)))))))
================================================================================
Checked operators
================================================================================
public class C
{
public static int operator checked +(C i, C j) => throw null;
public static int operator +(C i, C j) => throw null;
public static explicit operator checked int(C c) => throw null;
public static explicit operator int(C c) => throw null;
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
(modifier)
name: (identifier)
body: (declaration_list
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(throw_expression
(null_literal))))
(operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(throw_expression
(null_literal))))
(conversion_operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(throw_expression
(null_literal))))
(conversion_operator_declaration
(modifier)
(modifier)
type: (predefined_type)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(throw_expression
(null_literal)))))))
================================================================================
Explicit conversion operator overloads
================================================================================
public interface I<T> where T : I<T>
{
static abstract explicit operator T(C c);
static abstract explicit operator checked T(C c);
}
public class C : I<C>
{
static explicit I<C>.operator C(C c) => throw null;
static explicit I<C>.operator checked C(C c) => throw null;
}
--------------------------------------------------------------------------------
(compilation_unit
(interface_declaration
(modifier)
name: (identifier)
type_parameters: (type_parameter_list
(type_parameter
name: (identifier)))
(type_parameter_constraints_clause
target: (identifier)
constraints: (type_parameter_constraint
(type_constraint
type: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier))))))
body: (declaration_list
(conversion_operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))))
(conversion_operator_declaration
(modifier)
(modifier)
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier))))))
(class_declaration
(modifier)
name: (identifier)
bases: (base_list
(generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier))))
body: (declaration_list
(conversion_operator_declaration
(modifier)
(explicit_interface_specifier
name: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier))))
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(throw_expression
(null_literal))))
(conversion_operator_declaration
(modifier)
(explicit_interface_specifier
name: (generic_name
name: (identifier)
type_arguments: (type_argument_list
(identifier))))
type: (identifier)
parameters: (parameter_list
(parameter
type: (identifier)
name: (identifier)))
body: (arrow_expression_clause
(throw_expression
(null_literal)))))))

233
corpus/type-properties.txt Normal file
View File

@@ -0,0 +1,233 @@
================================================================================
Class with bodyless properties
================================================================================
class Foo {
byte Get { get; }
char Set { set; }
uint GetSet { get; set; }
long SetGet { set; get; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration)))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))))))
================================================================================
Class with init properties
================================================================================
class Person
{
public string FirstName { get; init; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(property_declaration
(modifier)
type: (predefined_type)
name: (identifier)
accessors: (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
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration
body: (block
(return_statement
(integer_literal))))))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration
body: (block
(expression_statement
(assignment_expression
left: (identifier)
(assignment_operator)
right: (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
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration
body: (block
(return_statement
(identifier))))
(accessor_declaration
body: (block
(expression_statement
(assignment_expression
left: (identifier)
(assignment_operator)
right: (identifier)))))))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration
body: (block
(expression_statement
(assignment_expression
left: (identifier)
(assignment_operator)
right: (identifier)))))
(accessor_declaration
body: (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
name: (identifier)
body: (declaration_list
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration))
value: (integer_literal))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))
value: (integer_literal))
(property_declaration
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))
value: (integer_literal)))))
================================================================================
Class with explicit interface properties
================================================================================
class Foo: IFoo {
byte IFoo.Get { get; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
bases: (base_list
(identifier))
body: (declaration_list
(property_declaration
type: (predefined_type)
(explicit_interface_specifier
name: (identifier))
name: (identifier)
accessors: (accessor_list
(accessor_declaration))))))
================================================================================
Required properties
================================================================================
class A {
public required int B { get; set; }
}
--------------------------------------------------------------------------------
(compilation_unit
(class_declaration
name: (identifier)
body: (declaration_list
(property_declaration
(modifier)
(modifier)
type: (predefined_type)
name: (identifier)
accessors: (accessor_list
(accessor_declaration)
(accessor_declaration))))))