diff --git a/grammar/ReadMe.md b/grammar/ReadMe.md deleted file mode 100644 index 6180cc56fd1..00000000000 --- a/grammar/ReadMe.md +++ /dev/null @@ -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). diff --git a/grammar/src/annotations.grm b/grammar/src/annotations.grm deleted file mode 100644 index 14547bc4561..00000000000 --- a/grammar/src/annotations.grm +++ /dev/null @@ -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? - ; diff --git a/grammar/src/class.grm b/grammar/src/class.grm deleted file mode 100644 index 02353c87085..00000000000 --- a/grammar/src/class.grm +++ /dev/null @@ -1,69 +0,0 @@ -/** -## Classes - -See [Classes and Inheritance](classes.html) -*/ - -/* -internal class Example>(protected val x : Foo, y : Some) - : Bar(x), Foo by x, IAbstractSome by y.asAbstract() - where - T : Function -{ - // 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) -*/ \ No newline at end of file diff --git a/grammar/src/class_members.grm b/grammar/src/class_members.grm deleted file mode 100644 index 3d9d4b0c1af..00000000000 --- a/grammar/src/class_members.grm +++ /dev/null @@ -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) -*/ diff --git a/grammar/src/control.grm b/grammar/src/control.grm deleted file mode 100644 index 878365c97dd..00000000000 --- a/grammar/src/control.grm +++ /dev/null @@ -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 ")" - ; diff --git a/grammar/src/enum.grm b/grammar/src/enum.grm deleted file mode 100644 index 383a5a6e673..00000000000 --- a/grammar/src/enum.grm +++ /dev/null @@ -1,17 +0,0 @@ -/** -### Enum classes - -See [Enum classes](enum-classes.html) -*/ - -enumClassBody - : "{" enumEntries (";" members)? "}" - ; - -enumEntries - : (enumEntry{","} ","? ";"?)? - ; - -enumEntry - : modifiers SimpleName valueArguments? classBody? - ; diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm deleted file mode 100644 index 3c1f9d2fd1c..00000000000 --- a/grammar/src/expressions.grm +++ /dev/null @@ -1,282 +0,0 @@ -/** -## Expressions - - - -### 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{","}? "]" - ; diff --git a/grammar/src/lexical.grm b/grammar/src/lexical.grm deleted file mode 100644 index b0fe25823cd..00000000000 --- a/grammar/src/lexical.grm +++ /dev/null @@ -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 - : - ; - -[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 - : - ; - -/** -See [Basic types](basic-types.html) -*/ - -NoEscapeString - : <"""-quoted string> - ; - -RegularStringPart - : - ; - -ShortTemplateEntryStart - : "$" - ; - -EscapeSequence - : UnicodeEscapeSequence | RegularEscapeSequence - ; - -UnicodeEscapeSequence - : "\u" HexDigit{4} - ; - -RegularEscapeSequence - : "\" - ; - -/** -See [String templates](basic-types.html#string-templates) -*/ - -SEMI - : - ; - -SimpleName - : - : "`" "`" - ; - -/** -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 -*/ diff --git a/grammar/src/modifiers.grm b/grammar/src/modifiers.grm deleted file mode 100644 index 97d9e8c827b..00000000000 --- a/grammar/src/modifiers.grm +++ /dev/null @@ -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" - ; diff --git a/grammar/src/notation.grm b/grammar/src/notation.grm deleted file mode 100644 index 4fdf87f4680..00000000000 --- a/grammar/src/notation.grm +++ /dev/null @@ -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**.
-_Nonterminal symbol_ names start with a lowercase letter, e.g. **kotlinFile**.
-Each _production_ starts with a colon (**:**).
-_Symbol definitions_ may have many productions and are terminated by a semicolon (**;**).
-Symbol definitions may be prepended with _attributes_, e.g. `start` attribute denotes a start symbol. - -## EBNF expressions - -Operator `|` denotes _alternative_.
-Operator `*` denotes _iteration_ (zero or more).
-Operator `+` denotes _iteration_ (one or more).
-Operator `?` denotes _option_ (zero or one).
-alpha`{`beta`}` denotes a nonempty _beta_-separated list of _alpha_'s.
-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. - -*/ diff --git a/grammar/src/toplevel.grm b/grammar/src/toplevel.grm deleted file mode 100644 index 57b8cb37bd2..00000000000 --- a/grammar/src/toplevel.grm +++ /dev/null @@ -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 - ; diff --git a/grammar/src/types.grm b/grammar/src/types.grm deleted file mode 100644 index aeb5e0f9884..00000000000 --- a/grammar/src/types.grm +++ /dev/null @@ -1,46 +0,0 @@ -/** -## Types - -See [Types](basic-types.html) -*/ - -/* - -Foo, 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 - ; diff --git a/grammar/src/when.grm b/grammar/src/when.grm deleted file mode 100644 index 8b6ac5d0395..00000000000 --- a/grammar/src/when.grm +++ /dev/null @@ -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 - ;