Object literals and class objects
This commit is contained in:
@@ -30,11 +30,15 @@ class Example(a : Foo, i : Int) : Bar(i), Some {
|
||||
// h5. Grammar
|
||||
|
||||
memberDeclaration
|
||||
: classObject
|
||||
: constructor
|
||||
: method
|
||||
: property
|
||||
: class //TODO : static
|
||||
// : constant ???
|
||||
: class
|
||||
;
|
||||
|
||||
classObject
|
||||
: "class" objectLiteral
|
||||
;
|
||||
|
||||
constructor
|
||||
@@ -51,7 +55,7 @@ super
|
||||
;
|
||||
|
||||
method
|
||||
: methodModifier* "fun" SimpleName functionParameters (":" type)? functionBody?
|
||||
: methodModifier* "fun" SimpleName typeParameters? functionParameters (":" type)? functionBody?
|
||||
;
|
||||
|
||||
functionParameters
|
||||
|
||||
@@ -11,9 +11,8 @@ expression
|
||||
: expressionWithPrecedences
|
||||
: match
|
||||
: if
|
||||
: "new" constructorInvocation
|
||||
: anonymousInnerClassInstantiation // TODO
|
||||
// TODO: list comprehension
|
||||
: "new" constructorInvocation // TODO: Do we need "new"?, see factory methods
|
||||
: objectLiteral
|
||||
: jump
|
||||
;
|
||||
|
||||
@@ -159,6 +158,23 @@ arrayAccess
|
||||
: "[" expression "]"
|
||||
;
|
||||
|
||||
anonymousInnerClassInstantiation
|
||||
: "object" delegationSpecifier{","} classBody
|
||||
;
|
||||
objectLiteral
|
||||
: "object" delegationSpecifier{","} classBody?
|
||||
;
|
||||
|
||||
/* Factory methods:
|
||||
|
||||
objectLiteral
|
||||
: "object" delegationSpecifier{","} ("{" objectLiteralMember{","} "}")?
|
||||
;
|
||||
|
||||
objectLiteralMember
|
||||
: memberDeclaration
|
||||
: factoryMethod
|
||||
;
|
||||
|
||||
factoryMethod
|
||||
: accessModifier? SimpleName typeParameters? functionParameters functionBody
|
||||
;
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user