-
Notifications
You must be signed in to change notification settings - Fork 89
Type members (ref)
The following fields are allowed in class, module and variant body:
type_member =
field_definition
| property_definition
| event_definition
| method_definition
| type_declaration
field_definition =
Attributes_(ref):attributes Lexical_structure_(ref):IDENTIFIER ':'
Type_expressions_(ref):type [ '=' Expressions_(ref):expr ] ';'
Unless the optional mutable attribute is used, the field can be modified only inside the constructor.
property_definition =
attributes IDENTIFIER ':' type '{' property_body '}'
property_body =
{ field_definition } 'get' method_body [ 'set' method_body ]
| { field_definition } 'set' method_body [ 'get' method_body ]
The fields defined in a property are local for it, they cannot be referenced outside the property.
event_definition =
attributes 'event' IDENTIFIER : type '{' event_body '}'
event_body =
'add' Expressions_(ref):block 'remove' block
| 'remove' block 'add' block
interface_member =
[ 'new' ] method_header ';'
| [ 'new' ] 'event' IDENTIFIER ':' type ';'
| [ 'new' ] IDENTIFIER ':' type property_body
Keyword new
is necessary when the declared method hides the
inherited one from another interface.
method_definition =
attributes method_header method_body
This is a definition of method within class or module. Program entry
point is method static Main
.
operator_definition =
attributes method_header method_body
Operator definitions must have the static
attribute. The name
of method must be simply any valid OPERATOR
, which can be then
used (as a prefix or unary operator) on expressions of type specified
by parameters.
method_type_parameters =
'[' IDENTIFIER { ',' IDENTIFIER } ']'
The declaration of a polymorphic method needs its type variables listed after the identifier.
method_header =
IDENTIFIER [ method_type_parameters ] '(' method_parameters ')' ':'
type [ where_constraints ] method_implements
| 'this' [ method_type_parameters ] '(' method_parameters ')'
This is a declaration of method. Unlike in C#, the type is specified after the parameters list.
A special method named this specifies a constructor. This declaration cannot contain the method type and the method has to have type void.
method_implements =
[ 'implements' Expressions_(ref):qualified_identifier
{ ',' qualified_identifier } ]
method_parameter =
[ 'params' ] Expressions_(ref):identifier_or_dummy [ ':' type ]
A method parameter is a pair consisting of identifier or _
and its type specification. Type declaration can be omitted in local
functions definitions.
method_parameters =
[ method_parameter { ',' method_parameter } ]
Method parameters are comma-separated list of parameter specification.
method_body =
';' | block
Body of a method can be empty, or be a block.