Remove old grammar files

The new grammar is located in the Kotlin spec repo: https://github.com/JetBrains/kotlin-spec/tree/spec-rework/src/grammar
This commit is contained in:
victor.petukhov
2019-01-30 11:48:01 +03:00
parent cbf6aa4ac3
commit 6f04deff0e
13 changed files with 0 additions and 981 deletions
-3
View File
@@ -1,3 +0,0 @@
This module contains a semi-formal description of Kotlin grammar.
It is processed by a [tool](https://github.com/JetBrains/kotlin-grammar-generator) to generate the Kotlin
grammar specification on the [Kotlin Web site](http://kotlinlang.org/docs/reference/grammar.html).
-31
View File
@@ -1,31 +0,0 @@
/**
## Annotations
*/
annotations
: (annotation | annotationList)*
;
annotation
: "@" (annotationUseSiteTarget ":")? unescapedAnnotation
;
annotationList
: "@" (annotationUseSiteTarget ":")? "[" unescapedAnnotation+ "]"
;
annotationUseSiteTarget
: "field"
: "file"
: "property"
: "get"
: "set"
: "receiver"
: "param"
: "setparam"
: "delegate"
;
unescapedAnnotation
: SimpleName{"."} typeArguments? valueArguments?
;
-69
View File
@@ -1,69 +0,0 @@
/**
## Classes
See [Classes and Inheritance](classes.html)
*/
/*
internal class Example<X, T : Comparable<X>>(protected val x : Foo<X, T>, y : Some)
: Bar(x), Foo<X, T> by x, IAbstractSome by y.asAbstract()
where
T : Function<Object, Object>
{
// members
}
*/
class
: modifiers ("class" | "interface") SimpleName
typeParameters?
primaryConstructor?
(":" annotations delegationSpecifier{","})?
typeConstraints
(classBody? | enumClassBody)
;
primaryConstructor
: (modifiers "constructor")? ("(" functionParameter{","} ")")
;
classBody
: ("{" members "}")?
;
members
: memberDeclaration*
;
delegationSpecifier
: constructorInvocation // type and constructor arguments
: userType
: explicitDelegation
;
explicitDelegation
: userType "by" expression // internal this expression no foo {bar} is allowed
;
typeParameters
: "<" typeParameter{","} ">"
;
typeParameter
: modifiers SimpleName (":" userType)?
;
/**
See [Generic classes](generics.html)
*/
typeConstraints
: ("where" typeConstraint{","})?
;
typeConstraint
: annotations SimpleName ":" type
;
/**
See [Generic constraints](generics.html#generic-constraints)
*/
-124
View File
@@ -1,124 +0,0 @@
/**
### 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
: modifiers "object" SimpleName primaryConstructor? (":" delegationSpecifier{","})? classBody?
;
secondaryConstructor
: modifiers "constructor" valueParameters (":" constructorDelegationCall)? block
;
constructorDelegationCall
: "this" valueArguments
: "super" valueArguments
;
/**
See [Object expressions and Declarations](object-declarations.html)
*/
-44
View File
@@ -1,44 +0,0 @@
/**
## Control structures
See [Control structures](control-flow.html)
*/
controlStructureBody
: block
: blockLevelExpression
;
if
: "if" "(" expression ")" controlStructureBody SEMI? ("else" controlStructureBody)?
;
try
: "try" block catchBlock* finallyBlock?
;
catchBlock
: "catch" "(" annotations SimpleName ":" userType ")" block
;
finallyBlock
: "finally" block
;
loop
: for
: while
: doWhile
;
for
: "for" "(" annotations (multipleVariableDeclarations | variableDeclarationEntry) "in" expression ")" controlStructureBody
;
while
: "while" "(" expression ")" controlStructureBody
;
doWhile
: "do" controlStructureBody "while" "(" expression ")"
;
-17
View File
@@ -1,17 +0,0 @@
/**
### Enum classes
See [Enum classes](enum-classes.html)
*/
enumClassBody
: "{" enumEntries (";" members)? "}"
;
enumEntries
: (enumEntry{","} ","? ";"?)?
;
enumEntry
: modifiers SimpleName valueArguments? classBody?
;
-282
View File
@@ -1,282 +0,0 @@
/**
## Expressions
<!--See [Expressions](expressions.html)-->
### Precedence
| Precedence | Title | Symbols |
|------------|-------|---------|
| Highest | Postfix | `++`, `--`, `.`, `?.`, `?` |
| | Prefix | `-`, `+`, `++`, `--`, `!`, [`labelDefinition`](#labelDefinition) |
| | Type RHS | `:`, `as`, `as?` |
| | Multiplicative | `*`, `/`, `%` |
| | Additive | `+`, `-` |
| | Range | `..` |
| | Infix function | [`SimpleName`](#SimpleName) |
| | Elvis | `?:` |
| | Named checks | `in`, `!in`, `is`, `!is` |
| | Comparison | `<`, `>`, `<=`, `>=` |
| | Equality | `==`, `!==` |
| | Conjunction | `&&` |
| | Disjunction | `||` |
| Lowest | Assignment | `=`, `+=`, `-=`, `*=`, `/=`, `%=` |
### Rules
*/
/*
Decreasing precedence:
memberAccessOperation
postfixUnaryOperation
prefixUnaryOperation
multiplicativeOperation
additiveOperation
".."
SimpleName
"?:"
namedInfixOrTypeOperation
comparisonOperation
equalityOperation
"&&"
"||"
assignmentOperator
*/
expression
: disjunction (assignmentOperator disjunction)*
;
disjunction
: conjunction ("||" conjunction)*
;
conjunction
: equalityComparison ("&&" equalityComparison)*
;
equalityComparison
: comparison (equalityOperation comparison)*
;
comparison
: namedInfix (comparisonOperation namedInfix)*
;
namedInfix
: elvisExpression (inOperation elvisExpression)*
: elvisExpression (isOperation type)?
;
elvisExpression
: infixFunctionCall ("?:" infixFunctionCall)*
;
infixFunctionCall
: rangeExpression (SimpleName rangeExpression)*
;
rangeExpression
: additiveExpression (".." additiveExpression)*
;
additiveExpression
: multiplicativeExpression (additiveOperation multiplicativeExpression)*
;
multiplicativeExpression
: typeRHS (multiplicativeOperation typeRHS)*
;
typeRHS
: prefixUnaryExpression (typeOperation prefixUnaryExpression)*
;
prefixUnaryExpression
: prefixUnaryOperation* postfixUnaryExpression
;
postfixUnaryExpression
: atomicExpression postfixUnaryOperation*
: callableReference postfixUnaryOperation*
;
// TODO: update this rule to include class literals and bound callable references
callableReference
: (userType "?"*)? "::" SimpleName typeArguments?
;
// !!! When you add here, remember to update the FIRST set in the parser
atomicExpression
: "(" expression ")"
: literalConstant
: functionLiteral
: "this" labelReference?
: "super" ("<" type ">")? labelReference?
: if
: when
: try
: objectLiteral
: jump
: loop
: collectionLiteral
: SimpleName
;
labelReference
: "@" ++ LabelName
;
labelDefinition
: LabelName ++ "@"
;
literalConstant
: "true" | "false"
: stringTemplate
: NoEscapeString
: IntegerLiteral
: CharacterLiteral
: FloatLiteral
: "null"
;
stringTemplate
: "\"" stringTemplateElement* "\""
;
stringTemplateElement
: RegularStringPart
: ShortTemplateEntryStart (SimpleName | "this")
: EscapeSequence
: longTemplate
;
longTemplate
: "${" expression "}"
;
declaration
: function
: property
: class
: typeAlias
: object
;
statement
: declaration
: blockLevelExpression
;
blockLevelExpression
: annotations ("\n")+ expression
;
multiplicativeOperation
: "*" : "/" : "%"
;
additiveOperation
: "+" : "-"
;
inOperation
: "in" : "!in"
;
typeOperation
: "as" : "as?" : ":"
;
isOperation
: "is" : "!is"
;
comparisonOperation
: "<" : ">" : ">=" : "<="
;
equalityOperation
: "!=" : "=="
;
assignmentOperator
: "="
: "+=" : "-=" : "*=" : "/=" : "%="
;
prefixUnaryOperation
: "-" : "+"
: "++" : "--"
: "!"
: annotations
: labelDefinition
;
postfixUnaryOperation
: "++" : "--" : "!!"
: callSuffix
: arrayAccess
: memberAccessOperation postfixUnaryExpression // TODO: Review
;
callSuffix
: typeArguments? valueArguments annotatedLambda
: typeArguments annotatedLambda
;
annotatedLambda
: ("@" unescapedAnnotation)* labelDefinition? functionLiteral
;
memberAccessOperation
: "." : "?." : "?"
;
typeArguments
: "<" type{","} ">"
;
valueArguments
: "(" ((SimpleName "=")? "*"? expression){","} ")"
;
jump
: "throw" expression
: "return" ++ labelReference? expression?
: "continue" ++ labelReference?
: "break" ++ labelReference?
// yield ?
;
functionLiteral
: "{" statements "}"
: "{" lambdaParameter{","} "->" statements "}"
;
lambdaParameter
: variableDeclarationEntry
: multipleVariableDeclarations (":" type)?
;
statements
: SEMI* statement{SEMI+} SEMI*
;
constructorInvocation
: userType callSuffix
;
arrayAccess
: "[" expression{","} "]"
;
objectLiteral
: "object" (":" delegationSpecifier{","})? classBody
;
collectionLiteral
: "[" expression{","}? "]"
;
-174
View File
@@ -1,174 +0,0 @@
/**
# Lexical structure
*/
[helper]
LongSuffix
: "L"
;
IntegerLiteral
: DecimalLiteral LongSuffix?
: HexadecimalLiteral LongSuffix?
: BinaryLiteral LongSuffix?
;
[helper]
Digit
: ["0".."9"]
;
DecimalLiteral
: Digit
: Digit (Digit | "_")* Digit
;
FloatLiteral
: <Java double literal>
;
[helper]
HexDigit
: Digit | ["A".."F", "a".."f"]
;
HexadecimalLiteral
: "0" ("x" | "X") HexDigit
: "0" ("x" | "X") HexDigit (HexDigit | "_")* HexDigit
;
[helper]
BinaryDigit
: ("0" | "1")
;
BinaryLiteral
: "0" ("b" | "B") BinaryDigit
: "0" ("b" | "B") BinaryDigit (BinaryDigit | "_")* BinaryDigit
CharacterLiteral
: <character as in Java>
;
/**
See [Basic types](basic-types.html)
*/
NoEscapeString
: <"""-quoted string>
;
RegularStringPart
: <any character other than backslash, quote, $ or newline>
;
ShortTemplateEntryStart
: "$"
;
EscapeSequence
: UnicodeEscapeSequence | RegularEscapeSequence
;
UnicodeEscapeSequence
: "\u" HexDigit{4}
;
RegularEscapeSequence
: "\" <any character other than newline>
;
/**
See [String templates](basic-types.html#string-templates)
*/
SEMI
: <semicolon or newline>
;
SimpleName
: <java identifier>
: "`" <java identifier> "`"
;
/**
See [Java interoperability](java-interop.html)
*/
LabelName
: SimpleName
;
/**
See [Returns and jumps](returns.html)
*/
/* Symbols:
[](){}<>
,
.
:
<= >= == != === !==
+ - * / %
=
+= -= *= /= %=
++ -- !
&& || -- may be just & and |
=>
..
?
?:
?.
*/
/* Keywords:
package
as
type
class
this
val
var
fun
extension
for
null
typeof
new
true
false
is
in
throw
return
break
continue
object
if
else
while
do
when
out
ref
try
Soft:
where -- in class, function and type headers
by -- in a class header (Delegation specifier)
get, set -- in a property definition
import
final
abstract
enum
open
annotation
override
private
public
internal
protected
catch
finally
*/
-85
View File
@@ -1,85 +0,0 @@
/**
## Modifiers
*/
modifiers
: (modifier | annotations)*
;
typeModifiers
: (suspendModifier | annotations)*
;
modifier
: classModifier
: accessModifier
: varianceAnnotation
: memberModifier
: parameterModifier
: typeParameterModifier
: functionModifier
: propertyModifier
: multiPlatformModifier
;
classModifier
: "abstract"
: "final"
: "enum"
: "open"
: "annotation"
: "sealed"
: "data"
;
memberModifier
: "override"
: "open"
: "final"
: "abstract"
: "lateinit"
;
accessModifier
: "private"
: "protected"
: "public"
: "internal"
;
varianceAnnotation
: "in"
: "out"
;
parameterModifier
: "noinline"
: "crossinline"
: "vararg"
;
typeParameterModifier
: "reified"
;
functionModifier
: "tailrec"
: "operator"
: "infix"
: "inline"
: "external"
: suspendModifier
;
propertyModifier
: "const"
;
suspendModifier
: "suspend"
;
multiPlatformModifier
: "expect"
: "actual"
;
-29
View File
@@ -1,29 +0,0 @@
/**
# Notation
This section informally explains the grammar notation used below.
## Symbols and naming
_Terminal symbol_ names start with an uppercase letter, e.g. **SimpleName**.<br>
_Nonterminal symbol_ names start with a lowercase letter, e.g. **kotlinFile**.<br>
Each _production_ starts with a colon (**:**).<br>
_Symbol definitions_ may have many productions and are terminated by a semicolon (**;**).<br>
Symbol definitions may be prepended with _attributes_, e.g. `start` attribute denotes a start symbol.
## EBNF expressions
Operator `|` denotes _alternative_.<br>
Operator `*` denotes _iteration_ (zero or more).<br>
Operator `+` denotes _iteration_ (one or more).<br>
Operator `?` denotes _option_ (zero or one).<br>
alpha`{`beta`}` denotes a nonempty _beta_-separated list of _alpha_'s. <br>
Operator `++` means that no space or comment is allowed between operands.
# Semicolons
Kotlin provides "semicolon inference": syntactically, subsentences (e.g., statements, declarations etc) are separated by
the pseudo-token [SEMI](#SEMI), which stands for "semicolon or newline". In most cases, there's no need for semicolons in
Kotlin code.
*/
-55
View File
@@ -1,55 +0,0 @@
/**
# Syntax
Relevant pages: [Packages](packages.html)
*/
[start]
kotlinFile
: preamble topLevelObject*
;
[start]
script
: preamble expression*
;
preamble
: fileAnnotations? packageHeader? import*
;
fileAnnotations
: fileAnnotation*
;
fileAnnotation
: "@" "file" ":" ("[" unescapedAnnotation+ "]" | unescapedAnnotation)
;
packageHeader
: modifiers "package" SimpleName{"."} SEMI?
;
/**
See [Packages](packages.html)
*/
import
: "import" SimpleName{"."} ("." "*" | "as" SimpleName)? SEMI?
;
/**
See [Imports](packages.html#imports)
*/
topLevelObject
: class
: object
: function
: property
: typeAlias
;
typeAlias
: modifiers "typealias" SimpleName typeParameters? "=" type
;
-46
View File
@@ -1,46 +0,0 @@
/**
## Types
See [Types](basic-types.html)
*/
/*
Foo<Bar<X>, T, Object> // user type
(A, Object) -> Foo // function type
() -> Foo // function with no arguments
*/
type
: typeModifiers typeReference
;
// If you change this, consider updating TYPE_REF_FIRST in KotlinParsing
typeReference
: "(" typeReference ")"
: functionType
: userType
: nullableType
: "dynamic"
;
nullableType
: typeReference "?"
;
userType
: simpleUserType{"."}
;
simpleUserType
: SimpleName ("<" (projection? type | "*"){","} ">")?
;
projection
: varianceAnnotation
;
functionType
: (type ".")? "(" parameter{","}? ")" "->" type
;
-22
View File
@@ -1,22 +0,0 @@
/**
#### When-expression
See [When-expression](control-flow.html#when-expression)
*/
when
: "when" ("(" expression ")")? "{"
whenEntry*
"}"
;
whenEntry
: whenCondition{","} "->" controlStructureBody SEMI
: "else" "->" controlStructureBody SEMI
;
whenCondition
: expression
: ("in" | "!in") expression
: ("is" | "!is") type
;