blob: 50d2f184201f98eac48ffcc4305e0ac3eb36f2f9 [file] [log] [blame]
/**
### Class members
*/
/*
class Example(a : Foo, i : Int) : Bar(i), Some {
// functions
abstract fun foo(a : Bar)
fun foo(a : Bar) = 0
fun foo(a : Bar) = {
return 0
}
fun foo(a : Bar) { // return type is Unit
// properties
val x : Int = 5
var y : Double = 7.0d
var z : String = "SDfsdf" {
get() = $z + "sdfsd"
private set(s : String) { $z = s }
}
}
*/
memberDeclaration
: companionObject
: object
: function
: property
: class
: typeAlias
: anonymousInitializer
: secondaryConstructor
;
anonymousInitializer
: "init" block
;
companionObject
: modifiers "companion" "object" SimpleName? (":" delegationSpecifier{","})? classBody?
;
valueParameters
: "(" functionParameter{","}? ")"
;
functionParameter
: modifiers ("val" | "var")? parameter ("=" expression)?
;
block
: "{" statements "}"
;
function
: modifiers "fun"
typeParameters?
(type ".")?
SimpleName
typeParameters? valueParameters (":" type)?
typeConstraints
functionBody?
;
functionBody
: block
: "=" expression
;
variableDeclarationEntry
: SimpleName (":" type)?
;
multipleVariableDeclarations
: "(" variableDeclarationEntry{","} ")"
;
property
: modifiers ("val" | "var")
typeParameters?
(type ".")?
(multipleVariableDeclarations | variableDeclarationEntry)
typeConstraints
("by" | "=" expression SEMI?)?
(getter? setter? | setter? getter?) SEMI?
;
/**
See [Properties and Fields](properties.html)
*/
getter
: modifiers "get"
: modifiers "get" "(" ")" (":" type)? functionBody
;
setter
: modifiers "set"
: modifiers "set" "(" modifiers (SimpleName | parameter) ")" functionBody
;
parameter
: SimpleName ":" type
;
object
: "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody?
secondaryConstructor
: modifiers "constructor" valueParameters (":" constructorDelegationCall)? block
;
constructorDelegationCall
: "this" valueArguments
: "super" valueArguments
;
/**
See [Object expressions and Declarations](object-declarations.html)
*/