diff options
author | Liam Miller-Cushon <cushon@google.com> | 2021-09-30 18:24:08 -0700 |
---|---|---|
committer | Javac Team <javac-team+copybara@google.com> | 2021-09-30 18:24:40 -0700 |
commit | 3452789854d581fbad3068d22d64b7319d19e8b4 (patch) | |
tree | b0b65105d989a8ac5de126dc8474e53538930156 | |
parent | e5a1173a63ef32d670bc6a3ba8969bb954f9b7f6 (diff) | |
download | turbine-3452789854d581fbad3068d22d64b7319d19e8b4.tar.gz |
Extra a method for parsing a class member starting at the identifier
This is a pre-factoring for supporting pseudo-keywords like 'non-sealed'.
PiperOrigin-RevId: 400076080
-rw-r--r-- | java/com/google/turbine/parse/Parser.java | 168 |
1 files changed, 88 insertions, 80 deletions
diff --git a/java/com/google/turbine/parse/Parser.java b/java/com/google/turbine/parse/Parser.java index ea41bba..06b3db6 100644 --- a/java/com/google/turbine/parse/Parser.java +++ b/java/com/google/turbine/parse/Parser.java @@ -756,90 +756,98 @@ public class Parser { return memberRest(pos, access, annos, typaram, result, name); } case IDENT: + int pos = position; + Ident ident = eatIdent(); + return classMemberIdent(access, annos, typaram, pos, ident); + default: + throw error(token); + } + } + + private ImmutableList<Tree> classMemberIdent( + EnumSet<TurbineModifier> access, + ImmutableList<Anno> annos, + ImmutableList<TyParam> typaram, + int pos, + Ident ident) { + Type result; + Ident name; + switch (token) { + case LPAREN: { - int pos = position; - Ident ident = eatIdent(); - switch (token) { - case LPAREN: - { - name = ident; - return ImmutableList.of(methodRest(pos, access, annos, typaram, null, name)); - } - case IDENT: - { - result = - new ClassTy( - position, - Optional.<ClassTy>empty(), - ident, - ImmutableList.<Type>of(), - ImmutableList.of()); - pos = position; - name = eatIdent(); - return memberRest(pos, access, annos, typaram, result, name); - } - case AT: - case LBRACK: - { - result = - new ClassTy( - position, - Optional.<ClassTy>empty(), - ident, - ImmutableList.<Type>of(), - ImmutableList.of()); - result = maybeDims(maybeAnnos(), result); - break; - } - case LT: - { - result = - new ClassTy( - position, Optional.<ClassTy>empty(), ident, tyargs(), ImmutableList.of()); - result = maybeDims(maybeAnnos(), result); - break; - } - case DOT: - result = - new ClassTy( - position, - Optional.<ClassTy>empty(), - ident, - ImmutableList.<Type>of(), - ImmutableList.of()); - break; - default: - throw error(token); - } - if (result == null) { - throw error(token); - } - if (token == Token.DOT) { - next(); - if (!result.kind().equals(Kind.CLASS_TY)) { - throw error(token); - } - result = classty((ClassTy) result); - } - result = maybeDims(maybeAnnos(), result); + name = ident; + return ImmutableList.of(methodRest(pos, access, annos, typaram, null, name)); + } + case IDENT: + { + result = + new ClassTy( + position, + Optional.<ClassTy>empty(), + ident, + ImmutableList.<Type>of(), + ImmutableList.of()); pos = position; name = eatIdent(); - switch (token) { - case LPAREN: - return ImmutableList.of(methodRest(pos, access, annos, typaram, result, name)); - case LBRACK: - case SEMI: - case ASSIGN: - case COMMA: - { - if (!typaram.isEmpty()) { - throw error(ErrorKind.UNEXPECTED_TYPE_PARAMETER, typaram); - } - return fieldRest(pos, access, annos, result, name); - } - default: - throw error(token); + return memberRest(pos, access, annos, typaram, result, name); + } + case AT: + case LBRACK: + { + result = + new ClassTy( + position, + Optional.<ClassTy>empty(), + ident, + ImmutableList.<Type>of(), + ImmutableList.of()); + result = maybeDims(maybeAnnos(), result); + break; + } + case LT: + { + result = + new ClassTy(position, Optional.<ClassTy>empty(), ident, tyargs(), ImmutableList.of()); + result = maybeDims(maybeAnnos(), result); + break; + } + case DOT: + result = + new ClassTy( + position, + Optional.<ClassTy>empty(), + ident, + ImmutableList.<Type>of(), + ImmutableList.of()); + break; + default: + throw error(token); + } + if (result == null) { + throw error(token); + } + if (token == Token.DOT) { + next(); + if (!result.kind().equals(Kind.CLASS_TY)) { + throw error(token); + } + result = classty((ClassTy) result); + } + result = maybeDims(maybeAnnos(), result); + pos = position; + name = eatIdent(); + switch (token) { + case LPAREN: + return ImmutableList.of(methodRest(pos, access, annos, typaram, result, name)); + case LBRACK: + case SEMI: + case ASSIGN: + case COMMA: + { + if (!typaram.isEmpty()) { + throw error(ErrorKind.UNEXPECTED_TYPE_PARAMETER, typaram); } + return fieldRest(pos, access, annos, result, name); } default: throw error(token); |