Made parser aware of object literals in statement position (they were parsed as object declarations)
This commit is contained in:
@@ -1389,6 +1389,18 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
declType = myJetParsing.parseTypeDef();
|
||||
}
|
||||
else if (keywordToken == OBJECT_KEYWORD) {
|
||||
// Object expression may appear at the statement position: should parse it
|
||||
// as expression instead of object declaration
|
||||
// sample:
|
||||
// {
|
||||
// object : Thread() {
|
||||
// }
|
||||
// }
|
||||
IElementType lookahead = lookahead(1);
|
||||
if (lookahead == COLON || lookahead == LBRACE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
myJetParsing.parseObject(true, true);
|
||||
declType = OBJECT_DECLARATION;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fun main(args : Array<String>) {
|
||||
object : Thread() {
|
||||
}.run()
|
||||
|
||||
object {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
JetFile: ObjectLiteralAsStatement.jet
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
FUN
|
||||
PsiElement(fun)('fun')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('main')
|
||||
VALUE_PARAMETER_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
VALUE_PARAMETER
|
||||
PsiElement(IDENTIFIER)('args')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace(' ')
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('Array')
|
||||
TYPE_ARGUMENT_LIST
|
||||
PsiElement(LT)('<')
|
||||
TYPE_PROJECTION
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('String')
|
||||
PsiElement(GT)('>')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
OBJECT_LITERAL
|
||||
OBJECT_DECLARATION
|
||||
PsiElement(object)('object')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace(' ')
|
||||
DELEGATION_SPECIFIER_LIST
|
||||
DELEGATOR_SUPER_CALL
|
||||
CONSTRUCTOR_CALLEE
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('Thread')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
CLASS_BODY
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiElement(DOT)('.')
|
||||
CALL_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('run')
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
OBJECT_LITERAL
|
||||
OBJECT_DECLARATION
|
||||
PsiElement(object)('object')
|
||||
PsiWhiteSpace(' ')
|
||||
CLASS_BODY
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(RBRACE)('}')
|
||||
Reference in New Issue
Block a user