use of dyvilx.tools.compiler.parser.annotation.AnnotationParser in project Dyvil by Dyvil.
the class TypeParameterParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case ANNOTATIONS:
switch(type) {
case DyvilSymbols.AT:
final Annotation annotation = new CodeAnnotation(token.raw());
this.attributes.add(annotation);
pm.pushParser(new AnnotationParser(annotation));
return;
case DyvilKeywords.TYPE:
// type IDENTIFIER
// type +IDENTIFIER
// type -IDENTIFIER
this.mode = VARIANCE;
return;
case BaseSymbols.SEMICOLON:
if (token.isInferred()) {
return;
}
}
if (TypeParser.isGenericEnd(token, type)) {
pm.popParser(true);
return;
}
// Fallthrough
case VARIANCE:
{
if (!Tokens.isIdentifier(type)) {
pm.report(token, "type_parameter.identifier");
return;
}
final Name name = token.nameValue();
if (Tokens.isIdentifier(token.next().type())) {
if (name == Names.plus) {
this.mode = NAME;
this.variance = Variance.COVARIANT;
return;
}
if (name == Names.minus) {
this.mode = NAME;
this.variance = Variance.CONTRAVARIANT;
return;
}
}
this.createTypeParameter(token, this.variance);
return;
}
case NAME:
if (Tokens.isIdentifier(type)) {
this.createTypeParameter(token, this.variance);
return;
}
pm.report(token, "type_parameter.identifier");
return;
case TYPE_BOUNDS:
switch(type) {
case DyvilKeywords.EXTENDS:
case BaseSymbols.COLON:
// type T: Super
// type T extends Super
pm.pushParser(this.newTypeParser());
this.setBoundMode(UPPER_BOUND);
return;
case DyvilKeywords.SUPER:
pm.pushParser(this.newTypeParser());
this.setBoundMode(LOWER_BOUND);
return;
}
if (BaseSymbols.isTerminator(type) || TypeParser.isGenericEnd(token, type)) {
if (this.typeParameter != null) {
this.typeParameterized.getTypeParameters().add(this.typeParameter);
}
pm.popParser(true);
return;
}
if (this.typeParameter != null) {
this.typeParameterized.getTypeParameters().add(this.typeParameter);
}
pm.popParser(true);
pm.report(token, "type_parameter.bound.invalid");
}
}
Aggregations