tree-sitter-c-sharp/corpus/attributes.txt
2024-03-25 23:16:07 +01:00

482 lines
13 KiB
Plaintext

================================================================================
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))))))))))))