From 9d87638a1183cd34ea7b7db93d865e21465150d0 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 9 Jun 2015 14:00:21 +0300 Subject: [PATCH] Clarify grammar rules for annotations --- .../jetbrains/kotlin/parsing/JetParsing.java | 38 ++++++++++++------- grammar/src/attributes.grm | 15 ++++++-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index ff58f17c449..4617685b448 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -447,14 +447,14 @@ public class JetParsing extends AbstractJetParsing { if (at(AT)) { if (!tryParseModifier(tokenConsumer)) { - parseAnnotation(annotationParsingMode); + parseAnnotationOrList(annotationParsingMode); } } else if (tryParseModifier(tokenConsumer)) { // modifier advanced } else if (annotationParsingMode.allowShortAnnotations && at(IDENTIFIER)) { - parseAnnotationEntry(annotationParsingMode); + parseAnnotation(annotationParsingMode); } else { break; @@ -513,13 +513,13 @@ public class JetParsing extends AbstractJetParsing { /* * annotations - * : annotation* + * : (annotation | annotationList)* * ; */ boolean parseAnnotations(AnnotationParsingMode mode) { - if (!parseAnnotation(mode)) return false; + if (!parseAnnotationOrList(mode)) return false; - while (parseAnnotation(mode)) { + while (parseAnnotationOrList(mode)) { // do nothing } @@ -528,14 +528,20 @@ public class JetParsing extends AbstractJetParsing { /* * annotation - * : "[" ("file" ":")? annotationEntry+ "]" - * : annotationEntry - * : "@" annotationEntry + * : annotationPrefix? unescapedAnnotation + * ; + * + * annotationList + * : annotationPrefix "[" unescapedAnnotation+ "]" + * ; + * + * annotationPrefix: + * : ("@" (":" "file")?) * ; */ - private boolean parseAnnotation(AnnotationParsingMode mode) { + private boolean parseAnnotationOrList(AnnotationParsingMode mode) { if (mode.allowShortAnnotations && at(IDENTIFIER)) { - return parseAnnotationEntry(mode); + return parseAnnotation(mode); } else if (at(AT)) { IElementType nextRawToken = myBuilder.rawLookup(1); @@ -553,7 +559,7 @@ public class JetParsing extends AbstractJetParsing { } if (tokenToMatch == IDENTIFIER) { - return parseAnnotationEntry(mode); + return parseAnnotation(mode); } else if (tokenToMatch == LBRACKET) { return parseAnnotationList(mode); @@ -604,7 +610,7 @@ public class JetParsing extends AbstractJetParsing { continue; } - parseAnnotationEntry(ALLOW_UNESCAPED_REGULAR_ANNOTATIONS); + parseAnnotation(ALLOW_UNESCAPED_REGULAR_ANNOTATIONS); while (at(COMMA)) { errorAndAdvance("No commas needed to separate annotations"); } @@ -650,11 +656,15 @@ public class JetParsing extends AbstractJetParsing { } /* - * annotationEntry + * annotation + * : annotationPrefix? unescapedAnnotation + * ; + * + * unescapedAnnotation * : SimpleName{"."} typeArguments? valueArguments? * ; */ - private boolean parseAnnotationEntry(AnnotationParsingMode mode) { + private boolean parseAnnotation(AnnotationParsingMode mode) { assert _at(IDENTIFIER) || (_at(AT) && !WHITE_SPACE_OR_COMMENT_BIT_SET.contains(myBuilder.rawLookup(1))); diff --git a/grammar/src/attributes.grm b/grammar/src/attributes.grm index 37e9570adc8..412c3debfaf 100644 --- a/grammar/src/attributes.grm +++ b/grammar/src/attributes.grm @@ -3,14 +3,21 @@ */ annotations - : annotation* + : (annotation | annotationList)* ; annotation - : "@"? "[" annotationEntry+ "]" - : "@"? annotationEntry + : annotationPrefix? unescapedAnnotation ; -annotationEntry +annotationList + : annotationPrefix "[" unescapedAnnotation+ "]" + ; + +annotationPrefix: + : ("@" (":" "file")?) + ; + +unescapedAnnotation : SimpleName{"."} typeArguments? valueArguments? ; \ No newline at end of file