From 3e3535f8cf60ee612eecbfaa55a85df6ac8231f3 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 28 Apr 2015 10:26:26 +0300 Subject: [PATCH] Temporary parse label definitions with both syntax versions Should be reverted after bootstrap --- .../kotlin/parsing/JetExpressionParsing.java | 23 +++- .../psi/newLabels/oldSyntaxExpressions.txt | 116 +++++++++--------- compiler/testData/psi/newLabels/recovery.txt | 14 +-- .../newLabels/spaceBeforeLabelReference.txt | 84 ++++++------- 4 files changed, 128 insertions(+), 109 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java index 52b3dfdeb72..0f034e0ac38 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java @@ -554,10 +554,15 @@ public class JetExpressionParsing extends AbstractJetParsing { return lookahead(2) == LBRACE; } + if (at(AT) && myBuilder.rawLookup(1) == IDENTIFIER) { + return lookahead(2) == LBRACE; + } + return at(AT) && lookahead(1) == LBRACE; } private boolean isAtLabelDefinitionOrMissingIdentifier() { + if (at(AT) && myBuilder.rawLookup(1) == IDENTIFIER) return true; return (at(IDENTIFIER) && myBuilder.rawLookup(1) == AT) || at(AT); } @@ -1659,8 +1664,22 @@ public class JetExpressionParsing extends AbstractJetParsing { */ private void parseLabelDefinition() { if (at(AT)) { - // recovery for empty label identifier - errorAndAdvance("Label must be named"); // AT + // recovery for old label syntax or empty label identifier + if (myBuilder.rawLookup(1) == IDENTIFIER) { + PsiBuilder.Marker labelWrap = mark(); + PsiBuilder.Marker mark = mark(); + + advance(); // AT + advance(); // IDENTIFIER + + mark.done(LABEL); + + labelWrap.done(LABEL_QUALIFIER); + return; + } + else { + errorAndAdvance("Label must be named"); // AT + } return; } diff --git a/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt b/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt index 9a5c9510208..2f7375e0431 100644 --- a/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt +++ b/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt @@ -13,61 +13,63 @@ JetFile: oldSyntaxExpressions.kt PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('loop1') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - - PsiWhiteSpace(' ') - FOR - PsiElement(for)('for') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('loop1') PsiWhiteSpace(' ') - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('i') - PsiWhiteSpace(' ') - PsiElement(in)('in') - PsiWhiteSpace(' ') - LOOP_RANGE - BINARY_EXPRESSION - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('1') - OPERATION_REFERENCE - PsiElement(RANGE)('..') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('100') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - BODY - BLOCK - PsiElement(LBRACE)('{') - PsiWhiteSpace(' ') - PsiElement(RBRACE)('}') + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('i') + PsiWhiteSpace(' ') + PsiElement(in)('in') + PsiWhiteSpace(' ') + LOOP_RANGE + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + OPERATION_REFERENCE + PsiElement(RANGE)('..') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('100') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BODY + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('x2') PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('filter') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(AT)('@') - PsiElement(IDENTIFIER)('f') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - PsiWhiteSpace('\n ') - BLOCK - RETURN - PsiElement(return)('return') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('filter') + PsiWhiteSpace(' ') + FUNCTION_LITERAL_ARGUMENT + LABELED_EXPRESSION + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('f') PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('2') - PsiWhiteSpace('\n ') - PsiElement(RBRACE)('}') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + BLOCK + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('2') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') RETURN PsiElement(return)('return') @@ -75,16 +77,14 @@ JetFile: oldSyntaxExpressions.kt PARENTHESIZED PsiElement(LPAR)('(') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('f') - PsiErrorElement:Expecting ')' - - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('3') - PsiElement(RPAR)(')') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('f') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('3') + PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') PROPERTY PsiElement(val)('val') diff --git a/compiler/testData/psi/newLabels/recovery.txt b/compiler/testData/psi/newLabels/recovery.txt index 7c69e391da7..149e83f8693 100644 --- a/compiler/testData/psi/newLabels/recovery.txt +++ b/compiler/testData/psi/newLabels/recovery.txt @@ -123,13 +123,13 @@ JetFile: recovery.kt PsiElement(return)('return') PsiWhiteSpace('\n ') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('loop2') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('4') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('loop2') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') diff --git a/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt b/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt index dba7c3cc185..70af9783bed 100644 --- a/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt +++ b/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt @@ -33,13 +33,13 @@ JetFile: spaceBeforeLabelReference.kt PsiElement(return)('return') PsiWhiteSpace(' ') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('l2') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('1') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('l2') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace('\n\n ') PROPERTY PsiElement(val)('val') @@ -55,20 +55,20 @@ JetFile: spaceBeforeLabelReference.kt PsiElement(return)('return') PsiWhiteSpace(' ') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('l3') - PsiWhiteSpace('\n\n ') - PROPERTY - PsiElement(val)('val') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('x') - PsiWhiteSpace(' ') - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('3') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('l3') + PsiWhiteSpace('\n\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('3') PsiWhiteSpace('\n\n ') CONTINUE PsiElement(continue)('continue') @@ -111,33 +111,33 @@ JetFile: spaceBeforeLabelReference.kt PsiWhiteSpace(' ') PsiComment(BLOCK_COMMENT)('/**/') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('l6') - PsiWhiteSpace('\n\n ') - PROPERTY - PsiElement(val)('val') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('x') - PsiWhiteSpace(' ') - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('8') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('l6') + PsiWhiteSpace('\n\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('8') PsiWhiteSpace('\n\n ') RETURN PsiElement(return)('return') PsiComment(EOL_COMMENT)('//') PsiWhiteSpace('\n') LABELED_EXPRESSION - PsiErrorElement:Label must be named - PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('l7') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('4') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('l7') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') PsiWhiteSpace('\n\n ') PROPERTY PsiElement(val)('val')