Skip to content

Commit

Permalink
Extra a method for parsing a class member starting at the identifier
Browse files Browse the repository at this point in the history
This is a pre-factoring for supporting pseudo-keywords like 'non-sealed'.

PiperOrigin-RevId: 400076080
  • Loading branch information
cushon authored and Javac Team committed Oct 1, 2021
1 parent e5a1173 commit 3452789
Showing 1 changed file with 88 additions and 80 deletions.
168 changes: 88 additions & 80 deletions java/com/google/turbine/parse/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,90 +756,98 @@ private ImmutableList<Tree> 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<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);
Expand Down

0 comments on commit 3452789

Please sign in to comment.