Allow type parameters right after fun, val, var
This commit is contained in:
@@ -71,7 +71,11 @@ block
|
|||||||
;
|
;
|
||||||
|
|
||||||
function
|
function
|
||||||
: modifiers "fun" (type ".")? attributes/*for receiver type*/ typeParameters? functionParameters (":" type)? functionBody?
|
: modifiers "fun" typeParameters?
|
||||||
|
(type "." | attributes/*for receiver type*/)?
|
||||||
|
SimpleName
|
||||||
|
typeParameters? functionParameters (":" type)?
|
||||||
|
functionBody?
|
||||||
;
|
;
|
||||||
|
|
||||||
functionBody
|
functionBody
|
||||||
@@ -80,7 +84,10 @@ functionBody
|
|||||||
;
|
;
|
||||||
|
|
||||||
property
|
property
|
||||||
: modifiers ("val" | "var") attributes (type ".")? SimpleName (":" type)? ("=" expression SEMI?)?
|
: modifiers ("val" | "var")
|
||||||
|
typeParameters? (type "." | attributes)?
|
||||||
|
SimpleName (":" type)?
|
||||||
|
("=" expression SEMI?)?
|
||||||
(getter? setter? | setter? getter?) SEMI?
|
(getter? setter? | setter? getter?) SEMI?
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -672,7 +672,10 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* property
|
* property
|
||||||
* : modifiers ("val" | "var") attributes (type ".")? SimpleName (":" type)? ("=" expression SEMI?)?
|
* : modifiers ("val" | "var")
|
||||||
|
* typeParameters? (type "." | attributes)?
|
||||||
|
* SimpleName (":" type)?
|
||||||
|
* ("=" expression SEMI?)?
|
||||||
* (getter? setter? | setter? getter?) SEMI?
|
* (getter? setter? | setter? getter?) SEMI?
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
@@ -681,14 +684,16 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JetNodeType parseProperty(boolean local) {
|
public JetNodeType parseProperty(boolean local) {
|
||||||
// TODO: how to write an extension ptoperty for a generic type? (val List<T>.i -- what is T?!)
|
|
||||||
|
|
||||||
if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) {
|
if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) {
|
||||||
advance(); // VAL_KEYWORD or VAR_KEYWORD
|
advance(); // VAL_KEYWORD or VAR_KEYWORD
|
||||||
} else {
|
} else {
|
||||||
errorAndAdvance("Expecting 'val' or 'var'");
|
errorAndAdvance("Expecting 'val' or 'var'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (at(LT)) {
|
||||||
|
parseTypeParameterList(TokenSet.create(IDENTIFIER, EQ, COLON, SEMICOLON));
|
||||||
|
}
|
||||||
|
|
||||||
TokenSet propertyNameFollow = TokenSet.create(COLON, EQ, LBRACE, SEMICOLON);
|
TokenSet propertyNameFollow = TokenSet.create(COLON, EQ, LBRACE, SEMICOLON);
|
||||||
|
|
||||||
// TODO: extract constant
|
// TODO: extract constant
|
||||||
@@ -805,11 +810,11 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* function
|
* function
|
||||||
* : modifiers "fun" (type ".")? functionRest
|
* : modifiers "fun" typeParameters?
|
||||||
* ;
|
* (type "." | attributes)?
|
||||||
*
|
* SimpleName
|
||||||
* functionRest
|
* typeParameters? functionParameters (":" type)?
|
||||||
* : attributes SimpleName typeParameters? functionParameters (":" type)? functionBody?
|
* functionBody?
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
public JetNodeType parseFunction() {
|
public JetNodeType parseFunction() {
|
||||||
@@ -817,6 +822,10 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
advance(); // FUN_KEYWORD
|
advance(); // FUN_KEYWORD
|
||||||
|
|
||||||
|
if (at(LT)) {
|
||||||
|
parseTypeParameterList(TokenSet.create(LBRACKET, LBRACE, LPAR));
|
||||||
|
}
|
||||||
|
|
||||||
int lastDot = findLastBefore(TokenSet.create(DOT), TokenSet.create(LPAR), true);
|
int lastDot = findLastBefore(TokenSet.create(DOT), TokenSet.create(LPAR), true);
|
||||||
|
|
||||||
if (lastDot == -1) { // There's no explicit receiver type specified
|
if (lastDot == -1) { // There's no explicit receiver type specified
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun <A, B> foo()
|
||||||
|
fun <A, B> [a] foo()
|
||||||
|
fun <A, B> [a] T.foo()
|
||||||
|
fun <A, B> [a] {() : Unit}.foo()
|
||||||
|
|
||||||
|
val <A> List<A>.foo
|
||||||
|
var <A> List<A>.foo
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
JetFile: TypeParametersBeforeName.jet
|
||||||
|
NAMESPACE
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('B')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
<empty list>
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('B')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
ATTRIBUTE_ANNOTATION
|
||||||
|
PsiElement(LBRACKET)('[')
|
||||||
|
ATTRIBUTE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(RBRACKET)(']')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
<empty list>
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('B')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
ATTRIBUTE_ANNOTATION
|
||||||
|
PsiElement(LBRACKET)('[')
|
||||||
|
ATTRIBUTE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(RBRACKET)(']')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('T')
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
<empty list>
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('B')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
ATTRIBUTE_ANNOTATION
|
||||||
|
PsiElement(LBRACKET)('[')
|
||||||
|
ATTRIBUTE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(RBRACKET)(']')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
FUNCTION_TYPE
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('Unit')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
<empty list>
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n\n')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('List')
|
||||||
|
TYPE_ARGUMENT_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(var)('var')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_PARAMETER_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('List')
|
||||||
|
TYPE_ARGUMENT_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
Reference in New Issue
Block a user