summaryrefslogtreecommitdiff
path: root/sources/scala/tools/scalac/ast/parser/Parser.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sources/scala/tools/scalac/ast/parser/Parser.scala')
-rw-r--r--sources/scala/tools/scalac/ast/parser/Parser.scala40
1 files changed, 36 insertions, 4 deletions
diff --git a/sources/scala/tools/scalac/ast/parser/Parser.scala b/sources/scala/tools/scalac/ast/parser/Parser.scala
index 60111dd803..4cf476ac82 100644
--- a/sources/scala/tools/scalac/ast/parser/Parser.scala
+++ b/sources/scala/tools/scalac/ast/parser/Parser.scala
@@ -157,7 +157,7 @@ class Parser(unit: CompilationUnit) {
false;
}
-/////// COMMENT COLLECTION ///////////////////////////////////////////////////
+/////// COMMENT AND ATTRIBUTE COLLECTION //////////////////////////////////////
/** Stack of comments
*/
@@ -2006,8 +2006,12 @@ class Parser(unit: CompilationUnit) {
s.token == TRAIT ||
s.token == OBJECT ||
s.token == CASEOBJECT ||
+ s.token == LBRACKET ||
isModifier()) {
- stats.append(joinComment(clsDef(modifiers())));
+ stats.append(
+ joinAttributes(
+ attributes(),
+ joinComment(clsDef(modifiers()))));
} else if (s.token != SEMI) {
syntaxError("illegal start of class or object definition", true);
}
@@ -2030,8 +2034,11 @@ class Parser(unit: CompilationUnit) {
stats.append(importClause());
} else if (isExprIntro()) {
stats.append(expr());
- } else if (isDefIntro() || isModifier()) {
- stats.append(joinComment(defOrDcl(modifiers())));
+ } else if (isDefIntro() || isModifier() || s.token == LBRACKET) {
+ stats.append(
+ joinAttributes(
+ attributes(),
+ joinComment(defOrDcl(modifiers()))))
} else if (s.token != SEMI) {
syntaxError("illegal start of definition", true);
}
@@ -2040,6 +2047,31 @@ class Parser(unit: CompilationUnit) {
stats.toArray()
}
+ def attributes(): List[Tree] = {
+ var attrs: List[Tree] = List();
+ while (s.token == LBRACKET) {
+ s.nextToken();
+ attrs = constr() :: attrs;
+ while (s.token == COMMA) {
+ s.nextToken();
+ attrs = constr() :: attrs;
+ }
+ accept(RBRACKET);
+ }
+ attrs
+ }
+
+ def joinAttributes(attrs: List[Tree], defs: Array[Tree]): Array[Tree] = attrs match {
+ case List() =>
+ defs
+ case attr :: attrs1 =>
+ var i = 0; while (i < defs.length) {
+ defs(i) = make.Attributed(attr.pos, attr, defs(i));
+ i = i + 1;
+ }
+ joinAttributes(attrs1, defs)
+ }
+
/** RefineStatSeq ::= RefineStat {`;' RefineStat}
* RefineStat ::= Dcl
* | type TypeDef