Attributes
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
attributes
|
||||
: attributeAnnotation*
|
||||
;
|
||||
|
||||
attributeAnnotation
|
||||
: "[" attribute{","} "]"
|
||||
;
|
||||
|
||||
attribute
|
||||
: SimpleName{"."} valueArguments?
|
||||
;
|
||||
+10
-29
@@ -11,31 +11,19 @@ internal class Example<X, T : Comparable<X>>(protected val x : Foo<X, T>, y : So
|
||||
*/
|
||||
|
||||
class
|
||||
: classModifier* "class" SimpleName
|
||||
("<" typeParameter{","} ">")?
|
||||
: modifiers "class" SimpleName
|
||||
typeParameters?
|
||||
"wraps"?
|
||||
("(" primaryConstructorParameter{","} ")")?
|
||||
(":" delegationSpecifier{","})?
|
||||
("where" typeConstraint{","})? // TODO: Syntax is questionable
|
||||
(":" attributes delegationSpecifier{","})?
|
||||
classBody?
|
||||
;
|
||||
|
||||
classModifier
|
||||
: accessModifier
|
||||
: "abstract"
|
||||
: "virtual"
|
||||
: "enum"
|
||||
: "extendable" // TODO: open?
|
||||
// sealed by default
|
||||
typeParameters
|
||||
: "<" typeParameter{","} ">"
|
||||
("where" typeConstraint{","})? // TODO: Syntax is questionable
|
||||
;
|
||||
|
||||
accessModifier
|
||||
: "private"
|
||||
: "protected"
|
||||
: "public"
|
||||
: "internal"
|
||||
;
|
||||
|
||||
classBody
|
||||
: ("{" memberDeclaration{","} "}")?
|
||||
;
|
||||
@@ -50,21 +38,14 @@ explicitDelegation
|
||||
;
|
||||
|
||||
typeParameter
|
||||
: varianceAnnotation? SimpleName (":" userType)?
|
||||
;
|
||||
|
||||
varianceAnnotation
|
||||
: "in"
|
||||
: "out"
|
||||
: modifiers SimpleName (":" userType)?
|
||||
;
|
||||
|
||||
typeConstraint
|
||||
: userType ":" (userType | "this") // "this" for self-type
|
||||
: attributes userType ":" (userType | "this") // "this" for self-type
|
||||
// TODO: other constraints, maybe
|
||||
;
|
||||
|
||||
primaryConstructorParameter
|
||||
: accessModifier? ("val" | "var")? parameter
|
||||
;
|
||||
|
||||
|
||||
: modifiers ("val" | "var")? parameter // TODO: ref/out?
|
||||
;
|
||||
@@ -40,11 +40,11 @@ memberDeclaration
|
||||
;
|
||||
|
||||
classObject
|
||||
: "class" objectLiteral
|
||||
: modifiers "class" objectLiteral
|
||||
;
|
||||
|
||||
constructor
|
||||
: accessModifier? "this" functionParameters (":" initializers) block
|
||||
: modifiers "this" functionParameters (":" initializers) block
|
||||
;
|
||||
|
||||
functionParameters
|
||||
@@ -52,18 +52,12 @@ functionParameters
|
||||
;
|
||||
|
||||
functionParameter
|
||||
: parameterKind parameter ("=" expression)?
|
||||
;
|
||||
|
||||
parameterKind
|
||||
: "lazy"
|
||||
: "out"
|
||||
: "ref"
|
||||
: modifiers parameter ("=" expression)?
|
||||
;
|
||||
|
||||
initializers
|
||||
: "this" valueArguments
|
||||
: constructorInvocation // type parameters may (must?) be omitted
|
||||
: attributes "this" valueArguments
|
||||
: attributes constructorInvocation // type parameters may (must?) be omitted
|
||||
;
|
||||
|
||||
block
|
||||
@@ -71,19 +65,11 @@ block
|
||||
;
|
||||
|
||||
decomposer // TODO: consider other names
|
||||
: "decomposer" SimpleName "(" SimpleName{","} ")" // Public properties only
|
||||
: attributes "decomposer" SimpleName "(" (attributes SimpleName){","} ")" // Public properties only
|
||||
;
|
||||
|
||||
method
|
||||
: memberModifier* "fun" functionRest
|
||||
;
|
||||
|
||||
memberModifier
|
||||
: accessModifier
|
||||
: "override"
|
||||
: "virtual"
|
||||
: "abstract"
|
||||
: // TODO: inline
|
||||
: modifiers "fun" functionRest
|
||||
;
|
||||
|
||||
functionRest
|
||||
@@ -96,7 +82,7 @@ functionBody
|
||||
;
|
||||
|
||||
property
|
||||
: memberModifier* "lazy"? ("val" | "var") propertyRest
|
||||
: modifiers "lazy"? ("val" | "var") propertyRest
|
||||
;
|
||||
|
||||
propertyRest
|
||||
@@ -105,11 +91,11 @@ propertyRest
|
||||
;
|
||||
|
||||
getter
|
||||
: memberModifier* "get" "(" ")" functionBody
|
||||
: modifiers "get" "(" ")" functionBody
|
||||
;
|
||||
|
||||
setter
|
||||
: memberModifier* "set" "(" parameter ")" functionBody
|
||||
: modifiers "set" "(" modifiers parameter ")" functionBody // TODO: Can the parameter be lazy?
|
||||
;
|
||||
|
||||
parameter
|
||||
|
||||
@@ -6,17 +6,17 @@ extension
|
||||
;
|
||||
|
||||
completeExtension
|
||||
: accessModifier? "extension" SimpleName? typeParameters? "for" type classBody? // properties cannot be lazy, cannot have backing fields
|
||||
: modifiers "extension" SimpleName? typeParameters? "for" type classBody? // properties cannot be lazy, cannot have backing fields
|
||||
;
|
||||
|
||||
extensionMethod
|
||||
: accessModifier? "fun" type "." functionRest
|
||||
: modifiers "fun" type "." functionRest
|
||||
;
|
||||
|
||||
extensionProperty
|
||||
: accessModifier? propertyModifier? ("val" | "var") type "." propertyRest // Extension property cannot be lazy
|
||||
: modifiers ("val" | "var") type "." propertyRest // Extension property cannot be lazy
|
||||
;
|
||||
|
||||
extensionDecomposer
|
||||
: "decomposer" (type ".")? SimpleName "(" SimpleName{","} ")" // Public properties only
|
||||
: attributes "decomposer" (type ".")? SimpleName "(" attributes SimpleName{","} ")" // Public properties only
|
||||
;
|
||||
@@ -10,10 +10,3 @@ CharacterLiteral : /*character as in Java*/;
|
||||
StringWithTemplates : /*single-quoted string, $ can be escaped*/;
|
||||
NoEscapeString : /* """-quoted string */;
|
||||
|
||||
/*
|
||||
val foo = @"
|
||||
|Blah-blah-blah
|
||||
foobar
|
||||
barfoo
|
||||
"
|
||||
*/
|
||||
@@ -3,7 +3,7 @@ match
|
||||
;
|
||||
|
||||
matchEntry
|
||||
: "case" pattern ("if" "(" expression ")")? "=>" expression // TODO: Consider other options than "=>"
|
||||
: attributes "case" pattern ("if" "(" expression ")")? "=>" expression // TODO: Consider other options than "=>"
|
||||
;
|
||||
|
||||
pattern
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
modifiers
|
||||
: modifier*
|
||||
;
|
||||
|
||||
modifier
|
||||
: classModifier
|
||||
: accessModifier
|
||||
: varianceAnnotation
|
||||
: memberModifier
|
||||
: parameterKind
|
||||
: attributes
|
||||
// sealed by default
|
||||
;
|
||||
|
||||
classModifier
|
||||
: "abstract"
|
||||
: "virtual"
|
||||
: "enum"
|
||||
: "extendable" // TODO: open?
|
||||
: "attribute"
|
||||
;
|
||||
|
||||
memberModifier
|
||||
: "override"
|
||||
: "virtual"
|
||||
: "abstract"
|
||||
: // TODO: inline
|
||||
;
|
||||
|
||||
accessModifier
|
||||
: "private"
|
||||
: "protected"
|
||||
: "public"
|
||||
: "internal"
|
||||
;
|
||||
|
||||
varianceAnnotation
|
||||
: "in"
|
||||
: "out"
|
||||
;
|
||||
|
||||
parameterKind
|
||||
: "lazy"
|
||||
: "out"
|
||||
: "ref"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user