Update grammar to Kotlin 1.1
Also drop obsolete comments and inline some trivial rules
This commit is contained in:
@@ -570,7 +570,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
* : "@" (annotationUseSiteTarget ":")? "[" unescapedAnnotation+ "]"
|
* : "@" (annotationUseSiteTarget ":")? "[" unescapedAnnotation+ "]"
|
||||||
* ;
|
* ;
|
||||||
*
|
*
|
||||||
* annotationUseSiteTarget
|
* annotationUseSiteTarget
|
||||||
* : "file"
|
* : "file"
|
||||||
* : "field"
|
* : "field"
|
||||||
* : "property"
|
* : "property"
|
||||||
@@ -1234,7 +1234,8 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
*
|
*
|
||||||
* property
|
* property
|
||||||
* : modifiers ("val" | "var")
|
* : modifiers ("val" | "var")
|
||||||
* typeParameters? (type "." | annotations)?
|
* typeParameters?
|
||||||
|
* (type ".")?
|
||||||
* ("(" variableDeclarationEntry{","} ")" | variableDeclarationEntry)
|
* ("(" variableDeclarationEntry{","} ")" | variableDeclarationEntry)
|
||||||
* typeConstraints
|
* typeConstraints
|
||||||
* ("by" | "=" expression SEMI?)?
|
* ("by" | "=" expression SEMI?)?
|
||||||
@@ -1505,7 +1506,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
/*
|
/*
|
||||||
* function
|
* function
|
||||||
* : modifiers "fun" typeParameters?
|
* : modifiers "fun" typeParameters?
|
||||||
* (type "." | annotations)?
|
* (type ".")?
|
||||||
* SimpleName
|
* SimpleName
|
||||||
* typeParameters? functionParameters (":" type)?
|
* typeParameters? functionParameters (":" type)?
|
||||||
* typeConstraints
|
* typeConstraints
|
||||||
@@ -1887,10 +1888,10 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* type
|
* type
|
||||||
* : annotations typeDescriptor
|
* : typeModifiers typeReference
|
||||||
|
* ;
|
||||||
*
|
*
|
||||||
* typeDescriptor
|
* typeReference
|
||||||
* : selfType
|
|
||||||
* : functionType
|
* : functionType
|
||||||
* : userType
|
* : userType
|
||||||
* : nullableType
|
* : nullableType
|
||||||
@@ -1898,7 +1899,8 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
* ;
|
* ;
|
||||||
*
|
*
|
||||||
* nullableType
|
* nullableType
|
||||||
* : typeDescriptor "?"
|
* : typeReference "?"
|
||||||
|
* ;
|
||||||
*/
|
*/
|
||||||
void parseTypeRef() {
|
void parseTypeRef() {
|
||||||
parseTypeRef(TokenSet.EMPTY);
|
parseTypeRef(TokenSet.EMPTY);
|
||||||
@@ -2165,7 +2167,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* functionType
|
* functionType
|
||||||
* : "(" (parameter | modifiers type){","}? ")" "->" type?
|
* : (type ".")? "(" parameter{","}? ")" "->" type?
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
private void parseFunctionType() {
|
private void parseFunctionType() {
|
||||||
@@ -2188,7 +2190,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* functionParameters
|
* functionParameters
|
||||||
* : "(" functionParameter{","}? ")" // default values
|
* : "(" functionParameter{","}? ")"
|
||||||
* ;
|
* ;
|
||||||
*
|
*
|
||||||
* functionParameter
|
* functionParameter
|
||||||
|
|||||||
@@ -15,15 +15,17 @@ annotationList
|
|||||||
;
|
;
|
||||||
|
|
||||||
annotationUseSiteTarget
|
annotationUseSiteTarget
|
||||||
: "file"
|
|
||||||
: "field"
|
: "field"
|
||||||
|
: "file"
|
||||||
: "property"
|
: "property"
|
||||||
: "get"
|
: "get"
|
||||||
: "set"
|
: "set"
|
||||||
|
: "receiver"
|
||||||
: "param"
|
: "param"
|
||||||
: "setparam"
|
: "setparam"
|
||||||
|
: "delegate"
|
||||||
;
|
;
|
||||||
|
|
||||||
unescapedAnnotation
|
unescapedAnnotation
|
||||||
: SimpleName{"."} typeArguments? valueArguments?
|
: SimpleName{"."} typeArguments? valueArguments?
|
||||||
;
|
;
|
||||||
@@ -42,28 +42,25 @@ anonymousInitializer
|
|||||||
;
|
;
|
||||||
|
|
||||||
companionObject
|
companionObject
|
||||||
: modifiers "companion" "object" SimpleName (":" delegationSpecifier{","})? classBody?
|
: modifiers "companion" "object" SimpleName? (":" delegationSpecifier{","})? classBody?
|
||||||
;
|
;
|
||||||
|
|
||||||
valueParameters
|
valueParameters
|
||||||
: "(" functionParameter{","}? ")" // default values
|
: "(" functionParameter{","}? ")"
|
||||||
;
|
;
|
||||||
|
|
||||||
functionParameter
|
functionParameter
|
||||||
: modifiers ("val" | "var")? parameter ("=" expression)?
|
: modifiers ("val" | "var")? parameter ("=" expression)?
|
||||||
;
|
;
|
||||||
|
|
||||||
initializer
|
|
||||||
: annotations constructorInvocation // type parameters may (must?) be omitted
|
|
||||||
;
|
|
||||||
|
|
||||||
block
|
block
|
||||||
: "{" statements "}"
|
: "{" statements "}"
|
||||||
;
|
;
|
||||||
|
|
||||||
function
|
function
|
||||||
: modifiers "fun" typeParameters?
|
: modifiers "fun"
|
||||||
(type "." | annotations/*for receiver type*/)?
|
typeParameters?
|
||||||
|
(type ".")?
|
||||||
SimpleName
|
SimpleName
|
||||||
typeParameters? valueParameters (":" type)?
|
typeParameters? valueParameters (":" type)?
|
||||||
typeConstraints
|
typeConstraints
|
||||||
@@ -85,7 +82,8 @@ multipleVariableDeclarations
|
|||||||
|
|
||||||
property
|
property
|
||||||
: modifiers ("val" | "var")
|
: modifiers ("val" | "var")
|
||||||
typeParameters? (type "." | annotations)?
|
typeParameters?
|
||||||
|
(type ".")?
|
||||||
(multipleVariableDeclarations | variableDeclarationEntry)
|
(multipleVariableDeclarations | variableDeclarationEntry)
|
||||||
typeConstraints
|
typeConstraints
|
||||||
("by" | "=" expression SEMI?)?
|
("by" | "=" expression SEMI?)?
|
||||||
@@ -110,7 +108,7 @@ parameter
|
|||||||
;
|
;
|
||||||
|
|
||||||
object
|
object
|
||||||
: "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody? // Class body can be optional: this is a declaration
|
: "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody?
|
||||||
|
|
||||||
secondaryConstructor
|
secondaryConstructor
|
||||||
: modifiers "constructor" valueParameters (":" constructorDelegationCall)? block
|
: modifiers "constructor" valueParameters (":" constructorDelegationCall)? block
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ enumClassBody
|
|||||||
: "{" enumEntries (";" members)? "}"
|
: "{" enumEntries (";" members)? "}"
|
||||||
;
|
;
|
||||||
|
|
||||||
enumEntries (used by enumClassBody)
|
enumEntries
|
||||||
: (enumEntry{","} ","?)?
|
: (enumEntry{","} ","? ";"?)?
|
||||||
;
|
;
|
||||||
|
|
||||||
enumEntry
|
enumEntry
|
||||||
: modifiers SimpleName ((":" initializer) | ("(" arguments ")"))? classBody?
|
: modifiers SimpleName ("(" arguments ")")? classBody?
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ comparison
|
|||||||
|
|
||||||
namedInfix
|
namedInfix
|
||||||
: elvisExpression (inOperation elvisExpression)*
|
: elvisExpression (inOperation elvisExpression)*
|
||||||
: elvisExpression (isOperation isRHS)?
|
: elvisExpression (isOperation type)?
|
||||||
;
|
;
|
||||||
|
|
||||||
elvisExpression
|
elvisExpression
|
||||||
@@ -102,7 +102,7 @@ postfixUnaryExpression
|
|||||||
: callableReference postfixUnaryOperation*
|
: callableReference postfixUnaryOperation*
|
||||||
;
|
;
|
||||||
|
|
||||||
// TODO: callSuffix is forbidden after callableReference, since parentheses will be used to provide parameter types
|
// TODO: update this rule to include class literals and bound callable references
|
||||||
callableReference
|
callableReference
|
||||||
: (userType "?"*)? "::" SimpleName typeArguments?
|
: (userType "?"*)? "::" SimpleName typeArguments?
|
||||||
;
|
;
|
||||||
@@ -121,7 +121,6 @@ atomicExpression
|
|||||||
: jump
|
: jump
|
||||||
: loop
|
: loop
|
||||||
: SimpleName
|
: SimpleName
|
||||||
: FieldName
|
|
||||||
;
|
;
|
||||||
|
|
||||||
labelReference
|
labelReference
|
||||||
@@ -158,15 +157,11 @@ longTemplate
|
|||||||
: "${" expression "}"
|
: "${" expression "}"
|
||||||
;
|
;
|
||||||
|
|
||||||
isRHS
|
|
||||||
: type
|
|
||||||
;
|
|
||||||
|
|
||||||
declaration
|
declaration
|
||||||
: function
|
: function
|
||||||
: property
|
: property
|
||||||
: class
|
: class
|
||||||
// : typeAlias
|
: typeAlias
|
||||||
: object
|
: object
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -215,8 +210,8 @@ assignmentOperator
|
|||||||
prefixUnaryOperation
|
prefixUnaryOperation
|
||||||
: "-" : "+"
|
: "-" : "+"
|
||||||
: "++" : "--"
|
: "++" : "--"
|
||||||
: "!" // No ~
|
: "!"
|
||||||
: annotations // mandatory
|
: annotations
|
||||||
: labelDefinition
|
: labelDefinition
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -255,7 +250,6 @@ jump
|
|||||||
// yield ?
|
// yield ?
|
||||||
;
|
;
|
||||||
|
|
||||||
// one can use "it" as a parameter name
|
|
||||||
functionLiteral
|
functionLiteral
|
||||||
: "{" statements "}"
|
: "{" statements "}"
|
||||||
: "{" lambdaParameter{","} "->" statements "}"
|
: "{" lambdaParameter{","} "->" statements "}"
|
||||||
@@ -279,21 +273,5 @@ arrayAccess
|
|||||||
;
|
;
|
||||||
|
|
||||||
objectLiteral
|
objectLiteral
|
||||||
: "object" (":" delegationSpecifier{","})? classBody // Cannot make class body optional: foo(object : F, A)
|
: "object" (":" delegationSpecifier{","})? classBody
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Factory methods:
|
|
||||||
|
|
||||||
objectLiteral
|
|
||||||
: "object" delegationSpecifier{","} ("{" objectLiteralMember{","} "}")?
|
|
||||||
;
|
|
||||||
|
|
||||||
objectLiteralMember
|
|
||||||
: memberDeclaration
|
|
||||||
: factoryMethod
|
|
||||||
;
|
|
||||||
|
|
||||||
factoryMethod
|
|
||||||
: accessModifier? SimpleName typeParameters? functionParameters functionBody
|
|
||||||
;
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Digit
|
|||||||
: ["0".."9"];
|
: ["0".."9"];
|
||||||
|
|
||||||
IntegerLiteral
|
IntegerLiteral
|
||||||
: Digit+?
|
: Digit (Digit | "_")*
|
||||||
|
|
||||||
FloatLiteral
|
FloatLiteral
|
||||||
: <Java double literal>;
|
: <Java double literal>;
|
||||||
@@ -17,7 +17,7 @@ HexDigit
|
|||||||
: Digit | ["A".."F", "a".."f"];
|
: Digit | ["A".."F", "a".."f"];
|
||||||
|
|
||||||
HexadecimalLiteral
|
HexadecimalLiteral
|
||||||
: "0x" HexDigit+;
|
: "0x" HexDigit (HexDigit | "_")*;
|
||||||
|
|
||||||
CharacterLiteral
|
CharacterLiteral
|
||||||
: <character as in Java>;
|
: <character as in Java>;
|
||||||
@@ -61,13 +61,6 @@ SimpleName
|
|||||||
See [Java interoperability](java-interop.html)
|
See [Java interoperability](java-interop.html)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FieldName
|
|
||||||
: "$" SimpleName;
|
|
||||||
|
|
||||||
/*
|
|
||||||
See [Properties And Fields](properties.html)
|
|
||||||
*/
|
|
||||||
|
|
||||||
LabelName
|
LabelName
|
||||||
: "@" SimpleName;
|
: "@" SimpleName;
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
modifiers
|
modifiers
|
||||||
: modifier*
|
: (modifier | annotations)*
|
||||||
|
;
|
||||||
|
|
||||||
|
typeModifiers
|
||||||
|
: (suspendModifier | annotations)*
|
||||||
;
|
;
|
||||||
|
|
||||||
modifier
|
modifier
|
||||||
: modifierKeyword
|
|
||||||
;
|
|
||||||
|
|
||||||
modifierKeyword
|
|
||||||
: classModifier
|
: classModifier
|
||||||
: accessModifier
|
: accessModifier
|
||||||
: varianceAnnotation
|
: varianceAnnotation
|
||||||
@@ -19,7 +19,6 @@ modifierKeyword
|
|||||||
: typeParameterModifier
|
: typeParameterModifier
|
||||||
: functionModifier
|
: functionModifier
|
||||||
: propertyModifier
|
: propertyModifier
|
||||||
: annotations
|
|
||||||
;
|
;
|
||||||
|
|
||||||
classModifier
|
classModifier
|
||||||
@@ -68,8 +67,13 @@ functionModifier
|
|||||||
: "infix"
|
: "infix"
|
||||||
: "inline"
|
: "inline"
|
||||||
: "external"
|
: "external"
|
||||||
|
: suspendModifier
|
||||||
;
|
;
|
||||||
|
|
||||||
propertyModifier
|
propertyModifier
|
||||||
: "const"
|
: "const"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
suspendModifier
|
||||||
|
: "suspend"
|
||||||
|
;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Relevant pages: [Packages](packages.html)
|
|||||||
|
|
||||||
[start]
|
[start]
|
||||||
kotlinFile
|
kotlinFile
|
||||||
: preamble toplevelObject*
|
: preamble topLevelObject*
|
||||||
;
|
;
|
||||||
|
|
||||||
[start]
|
[start]
|
||||||
@@ -43,16 +43,14 @@ import
|
|||||||
See [Imports](packages.html#imports)
|
See [Imports](packages.html#imports)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
toplevelObject
|
topLevelObject
|
||||||
: class
|
: class
|
||||||
: object
|
: object
|
||||||
: function
|
: function
|
||||||
: property
|
: property
|
||||||
// : typeAlias
|
: typeAlias
|
||||||
;
|
;
|
||||||
|
|
||||||
/*
|
|
||||||
typeAlias
|
typeAlias
|
||||||
: modifiers "typealias" SimpleName (typeParameters typeConstraints)? "=" type
|
: modifiers "typealias" SimpleName typeParameters? "=" type
|
||||||
;
|
;
|
||||||
*/
|
|
||||||
|
|||||||
+6
-12
@@ -13,13 +13,12 @@ Foo<Bar<X>, T, Object> // user type
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
type
|
type
|
||||||
: annotations typeDescriptor
|
: typeModifiers typeReference
|
||||||
;
|
;
|
||||||
|
|
||||||
// IF YOU CHANGE THIS, please, update TYPE_FIRST in JetParsing
|
// If you change this, consider updating TYPE_REF_FIRST in KotlinParsing
|
||||||
typeDescriptor
|
typeReference
|
||||||
: "(" typeDescriptor ")"
|
: "(" typeReference ")"
|
||||||
// : selfType
|
|
||||||
: functionType
|
: functionType
|
||||||
: userType
|
: userType
|
||||||
: nullableType
|
: nullableType
|
||||||
@@ -27,13 +26,8 @@ typeDescriptor
|
|||||||
;
|
;
|
||||||
|
|
||||||
nullableType
|
nullableType
|
||||||
: typeDescriptor "?"
|
: typeReference "?"
|
||||||
|
|
||||||
/*
|
|
||||||
selfType
|
|
||||||
: "This"
|
|
||||||
;
|
;
|
||||||
*/
|
|
||||||
|
|
||||||
userType
|
userType
|
||||||
: simpleUserType{"."}
|
: simpleUserType{"."}
|
||||||
@@ -48,5 +42,5 @@ optionalProjection
|
|||||||
;
|
;
|
||||||
|
|
||||||
functionType
|
functionType
|
||||||
: (type ".")? "(" (parameter | modifiers /*lazy out ref*/ type){","} ")" "->" type?
|
: (type ".")? "(" parameter{","}? ")" "->" type?
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
#### Pattern matching
|
#### When-expression
|
||||||
|
|
||||||
See [When-expression](control-flow.html#when-expression)
|
See [When-expression](control-flow.html#when-expression)
|
||||||
*/
|
*/
|
||||||
@@ -10,7 +10,6 @@ when
|
|||||||
"}"
|
"}"
|
||||||
;
|
;
|
||||||
|
|
||||||
// TODO : consider empty after ->
|
|
||||||
whenEntry
|
whenEntry
|
||||||
: whenCondition{","} "->" controlStructureBody SEMI
|
: whenCondition{","} "->" controlStructureBody SEMI
|
||||||
: "else" "->" controlStructureBody SEMI
|
: "else" "->" controlStructureBody SEMI
|
||||||
@@ -19,5 +18,5 @@ whenEntry
|
|||||||
whenCondition
|
whenCondition
|
||||||
: expression
|
: expression
|
||||||
: ("in" | "!in") expression
|
: ("in" | "!in") expression
|
||||||
: ("is" | "!is") isRHS
|
: ("is" | "!is") type
|
||||||
;
|
;
|
||||||
|
|||||||
Reference in New Issue
Block a user