Update grammar to Kotlin 1.1

Also drop obsolete comments and inline some trivial rules
This commit is contained in:
Alexander Udalov
2017-02-28 16:25:04 +03:00
parent 875fdef917
commit 3ad4f18e1a
10 changed files with 57 additions and 89 deletions
@@ -15,15 +15,17 @@ annotationList
;
annotationUseSiteTarget
: "file"
: "field"
: "file"
: "property"
: "get"
: "set"
: "receiver"
: "param"
: "setparam"
: "delegate"
;
unescapedAnnotation
: SimpleName{"."} typeArguments? valueArguments?
;
;
+8 -10
View File
@@ -42,28 +42,25 @@ anonymousInitializer
;
companionObject
: modifiers "companion" "object" SimpleName (":" delegationSpecifier{","})? classBody?
: modifiers "companion" "object" SimpleName? (":" delegationSpecifier{","})? classBody?
;
valueParameters
: "(" functionParameter{","}? ")" // default values
: "(" functionParameter{","}? ")"
;
functionParameter
: modifiers ("val" | "var")? parameter ("=" expression)?
;
initializer
: annotations constructorInvocation // type parameters may (must?) be omitted
;
block
: "{" statements "}"
;
function
: modifiers "fun" typeParameters?
(type "." | annotations/*for receiver type*/)?
: modifiers "fun"
typeParameters?
(type ".")?
SimpleName
typeParameters? valueParameters (":" type)?
typeConstraints
@@ -85,7 +82,8 @@ multipleVariableDeclarations
property
: modifiers ("val" | "var")
typeParameters? (type "." | annotations)?
typeParameters?
(type ".")?
(multipleVariableDeclarations | variableDeclarationEntry)
typeConstraints
("by" | "=" expression SEMI?)?
@@ -110,7 +108,7 @@ parameter
;
object
: "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody? // Class body can be optional: this is a declaration
: "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody?
secondaryConstructor
: modifiers "constructor" valueParameters (":" constructorDelegationCall)? block
+3 -3
View File
@@ -8,10 +8,10 @@ enumClassBody
: "{" enumEntries (";" members)? "}"
;
enumEntries (used by enumClassBody)
: (enumEntry{","} ","?)?
enumEntries
: (enumEntry{","} ","? ";"?)?
;
enumEntry
: modifiers SimpleName ((":" initializer) | ("(" arguments ")"))? classBody?
: modifiers SimpleName ("(" arguments ")")? classBody?
;
+6 -28
View File
@@ -66,7 +66,7 @@ comparison
namedInfix
: elvisExpression (inOperation elvisExpression)*
: elvisExpression (isOperation isRHS)?
: elvisExpression (isOperation type)?
;
elvisExpression
@@ -102,7 +102,7 @@ postfixUnaryExpression
: 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
: (userType "?"*)? "::" SimpleName typeArguments?
;
@@ -121,7 +121,6 @@ atomicExpression
: jump
: loop
: SimpleName
: FieldName
;
labelReference
@@ -158,15 +157,11 @@ longTemplate
: "${" expression "}"
;
isRHS
: type
;
declaration
: function
: property
: class
// : typeAlias
: typeAlias
: object
;
@@ -215,8 +210,8 @@ assignmentOperator
prefixUnaryOperation
: "-" : "+"
: "++" : "--"
: "!" // No ~
: annotations // mandatory
: "!"
: annotations
: labelDefinition
;
@@ -255,7 +250,6 @@ jump
// yield ?
;
// one can use "it" as a parameter name
functionLiteral
: "{" statements "}"
: "{" lambdaParameter{","} "->" statements "}"
@@ -279,21 +273,5 @@ arrayAccess
;
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
;
*/
+2 -9
View File
@@ -7,7 +7,7 @@ Digit
: ["0".."9"];
IntegerLiteral
: Digit+?
: Digit (Digit | "_")*
FloatLiteral
: <Java double literal>;
@@ -17,7 +17,7 @@ HexDigit
: Digit | ["A".."F", "a".."f"];
HexadecimalLiteral
: "0x" HexDigit+;
: "0x" HexDigit (HexDigit | "_")*;
CharacterLiteral
: <character as in Java>;
@@ -61,13 +61,6 @@ SimpleName
See [Java interoperability](java-interop.html)
*/
FieldName
: "$" SimpleName;
/*
See [Properties And Fields](properties.html)
*/
LabelName
: "@" SimpleName;
+11 -7
View File
@@ -3,14 +3,14 @@
*/
modifiers
: modifier*
: (modifier | annotations)*
;
typeModifiers
: (suspendModifier | annotations)*
;
modifier
: modifierKeyword
;
modifierKeyword
: classModifier
: accessModifier
: varianceAnnotation
@@ -19,7 +19,6 @@ modifierKeyword
: typeParameterModifier
: functionModifier
: propertyModifier
: annotations
;
classModifier
@@ -68,8 +67,13 @@ functionModifier
: "infix"
: "inline"
: "external"
: suspendModifier
;
propertyModifier
: "const"
;
;
suspendModifier
: "suspend"
;
+4 -6
View File
@@ -7,7 +7,7 @@ Relevant pages: [Packages](packages.html)
[start]
kotlinFile
: preamble toplevelObject*
: preamble topLevelObject*
;
[start]
@@ -43,16 +43,14 @@ import
See [Imports](packages.html#imports)
*/
toplevelObject
topLevelObject
: class
: object
: function
: property
// : typeAlias
: typeAlias
;
/*
typeAlias
: modifiers "typealias" SimpleName (typeParameters typeConstraints)? "=" type
: modifiers "typealias" SimpleName typeParameters? "=" type
;
*/
+6 -12
View File
@@ -13,13 +13,12 @@ Foo<Bar<X>, T, Object> // user type
*/
type
: annotations typeDescriptor
: typeModifiers typeReference
;
// IF YOU CHANGE THIS, please, update TYPE_FIRST in JetParsing
typeDescriptor
: "(" typeDescriptor ")"
// : selfType
// If you change this, consider updating TYPE_REF_FIRST in KotlinParsing
typeReference
: "(" typeReference ")"
: functionType
: userType
: nullableType
@@ -27,13 +26,8 @@ typeDescriptor
;
nullableType
: typeDescriptor "?"
/*
selfType
: "This"
: typeReference "?"
;
*/
userType
: simpleUserType{"."}
@@ -48,5 +42,5 @@ optionalProjection
;
functionType
: (type ".")? "(" (parameter | modifiers /*lazy out ref*/ type){","} ")" "->" type?
: (type ".")? "(" parameter{","}? ")" "->" type?
;
+2 -3
View File
@@ -1,5 +1,5 @@
/**
#### Pattern matching
#### When-expression
See [When-expression](control-flow.html#when-expression)
*/
@@ -10,7 +10,6 @@ when
"}"
;
// TODO : consider empty after ->
whenEntry
: whenCondition{","} "->" controlStructureBody SEMI
: "else" "->" controlStructureBody SEMI
@@ -19,5 +18,5 @@ whenEntry
whenCondition
: expression
: ("in" | "!in") expression
: ("is" | "!is") isRHS
: ("is" | "!is") type
;