From 407a8e168428a5e0458d2f889294cc7e0250bb5b Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 22 Dec 2010 19:46:09 +0300 Subject: [PATCH] Tests fixed --- grammar/src/class_members.grm | 4 +- .../jet/lang/parsing/JetParsing.java | 39 ++-------- idea/testData/psi/BabySteps_ERR.jet | 5 ++ idea/testData/psi/BabySteps_ERR.txt | 75 +++++++++++++++++++ idea/testData/psi/SimpleClassMembers_ERR.jet | 4 + idea/testData/psi/SimpleClassMembers_ERR.txt | 17 +++++ idea/testData/psi/SoftKeywords.jet | 58 +++++++++++++- .../jetbrains/jet/parsing/JetParsingTest.java | 1 + 8 files changed, 166 insertions(+), 37 deletions(-) create mode 100644 idea/testData/psi/BabySteps_ERR.jet create mode 100644 idea/testData/psi/BabySteps_ERR.txt diff --git a/grammar/src/class_members.grm b/grammar/src/class_members.grm index c7f66828998..e57a7be3c5a 100644 --- a/grammar/src/class_members.grm +++ b/grammar/src/class_members.grm @@ -89,11 +89,11 @@ property ; getter - : modifiers "get" "(" ")" functionBody + : modifiers "get" "(" ")" (":" type)? functionBody ; setter - : modifiers "set" "(" modifiers parameter ")" functionBody // TODO: Can the parameter be lazy? + : modifiers "set" "(" modifiers (SimpleName | parameter) ")" functionBody // TODO: Can the parameter be lazy? ; parameter diff --git a/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java index d87e744c089..6dbbc6318b7 100644 --- a/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -265,32 +265,6 @@ public class JetParsing extends AbstractJetParsing { return DECOMPOSER; } - /* - * modifier - * : "virtual" - * : "enum" - * : "open" - * : "attribute" - * : "override" - * : "abstract" - * : "private" - * : "protected" - * : "public" - * : "internal" - * : "lazy" - */ - private boolean parseModifierSoftKeyword() { - if (!at(IDENTIFIER)) return false; - String tokenText = myBuilder.getTokenText(); - IElementType tokenType = MODIFIER_KEYWORD_MAP.get(tokenText); - if (tokenType != null) { - myBuilder.remapCurrentToken(tokenType); - advance(); - return true; - } - return false; - } - /* * (modifier | attribute)* */ @@ -304,7 +278,7 @@ public class JetParsing extends AbstractJetParsing { advance(); // MODIFIER } else { - if (!parseModifierSoftKeyword()) break; + break; } empty = false; } @@ -921,12 +895,7 @@ public class JetParsing extends AbstractJetParsing { parseAttributeList(); PsiBuilder.Marker delegator = mark(); - if (at(LPAR)) { - error("Expecting type name"); - } - else { - parseTypeRef(); - } + parseTypeRef(); if (at(BY_KEYWORD)) { advance(); // BY_KEYWORD @@ -980,7 +949,9 @@ public class JetParsing extends AbstractJetParsing { */ private void parsePrimaryConstructorParameter() { PsiBuilder.Marker param = mark(); - parseModifierList(); + + int lastId = findLastBefore(TokenSet.create(IDENTIFIER), TokenSet.create(COMMA, RPAR, COLON), false); + createTruncatedBuilder(lastId).parseModifierList(); if (at(VAR_KEYWORD) || at(VAL_KEYWORD)) { advance(); // VAR_KEYWORD | VAL_KEYWORD diff --git a/idea/testData/psi/BabySteps_ERR.jet b/idea/testData/psi/BabySteps_ERR.jet new file mode 100644 index 00000000000..97653321e3c --- /dev/null +++ b/idea/testData/psi/BabySteps_ERR.jet @@ -0,0 +1,5 @@ +namespace foo + +class Runnable(a : doo = 0) : foo(d=0), ,bar by x, bar { + +} diff --git a/idea/testData/psi/BabySteps_ERR.txt b/idea/testData/psi/BabySteps_ERR.txt new file mode 100644 index 00000000000..e12f89e6b59 --- /dev/null +++ b/idea/testData/psi/BabySteps_ERR.txt @@ -0,0 +1,75 @@ +JetFile: BabySteps_ERR.jet + NAMESPACE + PsiElement(namespace)('namespace') + PsiWhiteSpace(' ') + NAMESPACE_NAME + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Runnable') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(GT)('>') + PRIMARY_CONSTRUCTOR_PARAMETERS_LIST + PsiElement(LPAR)('(') + PRIMARY_CONSTRUCTOR_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + PsiElement(IDENTIFIER)('doo') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + PsiElement(INTEGER_LITERAL)('0') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATION_SPECIFIER + DELEGATOR_SUPER_CALL + TYPE_REFERENCE + USER_TYPE + PsiElement(IDENTIFIER)('foo') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + NAMED_ARGUMENT + PsiElement(IDENTIFIER)('d') + PsiElement(EQ)('=') + PsiElement(INTEGER_LITERAL)('0') + PsiElement(RPAR)(')') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a delegation specifier + PsiElement(COMMA)(',') + DELEGATION_SPECIFIER + DELEGATOR_BY + TYPE_REFERENCE + USER_TYPE + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace(' ') + PsiElement(by)('by') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/idea/testData/psi/SimpleClassMembers_ERR.jet b/idea/testData/psi/SimpleClassMembers_ERR.jet index c925ecd858c..c6688422601 100644 --- a/idea/testData/psi/SimpleClassMembers_ERR.jet +++ b/idea/testData/psi/SimpleClassMembers_ERR.jet @@ -22,4 +22,8 @@ class foo { } + this() : - { + + } + } diff --git a/idea/testData/psi/SimpleClassMembers_ERR.txt b/idea/testData/psi/SimpleClassMembers_ERR.txt index e78b567a6cd..8d50b38e521 100644 --- a/idea/testData/psi/SimpleClassMembers_ERR.txt +++ b/idea/testData/psi/SimpleClassMembers_ERR.txt @@ -182,5 +182,22 @@ JetFile: SimpleClassMembers_ERR.jet PsiElement(LBRACE)('{') PsiWhiteSpace('\n\n ') PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + CONSTRUCTOR + PsiElement(this)('this') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + INITIALIZER_LIST + PsiErrorElement:Expecting constructor call (this(...)) or supertype initializer + PsiElement(MINUS)('-') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n') PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/idea/testData/psi/SoftKeywords.jet b/idea/testData/psi/SoftKeywords.jet index 19c2490ccd0..0099e3b40e4 100644 --- a/idea/testData/psi/SoftKeywords.jet +++ b/idea/testData/psi/SoftKeywords.jet @@ -109,7 +109,63 @@ ref public : t, private : t, protected : t, - internal : t + internal : t, + public protected private internal abstract + virtual + enum + open + attribute + override + virtual + abstract + private + protected + public + internal + lazy open : t + ) } + + +class F(val foo : bar, + abstract : t, + virtual : t, + enum : t, + open : t, + attribute : t, + override : t, + virtual : t, + abstract : t, + private : t, + protected : t, + public : t, + internal : t, + lazy : t, + wraps : t, + import : t, + where : t, + by : t, + get : t, + set : t, + public : t, + private : t, + protected : t, + internal : t, + public protected private internal abstract + virtual + enum + open + attribute + override + virtual + abstract + private + protected + public + internal + lazy open : b +) { + +} diff --git a/idea/tests/org/jetbrains/jet/parsing/JetParsingTest.java b/idea/tests/org/jetbrains/jet/parsing/JetParsingTest.java index e857026dd90..4fe1bfd87b8 100644 --- a/idea/tests/org/jetbrains/jet/parsing/JetParsingTest.java +++ b/idea/tests/org/jetbrains/jet/parsing/JetParsingTest.java @@ -29,6 +29,7 @@ public class JetParsingTest extends ParsingTestCase { public void testEmptyFile() throws Exception {doTest(true);} public void testBabySteps() throws Exception {doTest(true);} + public void testBabySteps_ERR() throws Exception {doTest(true);} public void testImports() throws Exception {doTest(true);} public void testImports_ERR() throws Exception {doTest(true);} public void testImportSoftKW() throws Exception {doTest(true);}