From 3452789854d581fbad3068d22d64b7319d19e8b4 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 30 Sep 2021 18:24:08 -0700 Subject: [PATCH] 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 --- java/com/google/turbine/parse/Parser.java | 168 +++++++++++----------- 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/java/com/google/turbine/parse/Parser.java b/java/com/google/turbine/parse/Parser.java index ea41bba0..06b3db65 100644 --- a/java/com/google/turbine/parse/Parser.java +++ b/java/com/google/turbine/parse/Parser.java @@ -756,90 +756,98 @@ private ImmutableList classMember( 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 classMemberIdent( + EnumSet access, + ImmutableList annos, + ImmutableList 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.empty(), - ident, - ImmutableList.of(), - ImmutableList.of()); - pos = position; - name = eatIdent(); - return memberRest(pos, access, annos, typaram, result, name); - } - case AT: - case LBRACK: - { - result = - new ClassTy( - position, - Optional.empty(), - ident, - ImmutableList.of(), - ImmutableList.of()); - result = maybeDims(maybeAnnos(), result); - break; - } - case LT: - { - result = - new ClassTy( - position, Optional.empty(), ident, tyargs(), ImmutableList.of()); - result = maybeDims(maybeAnnos(), result); - break; - } - case DOT: - result = - new ClassTy( - position, - Optional.empty(), - ident, - ImmutableList.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.empty(), + ident, + ImmutableList.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.empty(), + ident, + ImmutableList.of(), + ImmutableList.of()); + result = maybeDims(maybeAnnos(), result); + break; + } + case LT: + { + result = + new ClassTy(position, Optional.empty(), ident, tyargs(), ImmutableList.of()); + result = maybeDims(maybeAnnos(), result); + break; + } + case DOT: + result = + new ClassTy( + position, + Optional.empty(), + ident, + ImmutableList.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);