use of dyvilx.tools.compiler.parser.type.TypeParameterListParser in project Dyvil by Dyvil.
the class TypeAliasParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
int type = token.type();
switch(this.mode) {
case END:
this.map.addTypeAlias(this.typeAlias);
pm.popParser(true);
return;
case TYPE:
this.mode = NAME;
if (type != DyvilKeywords.TYPE) {
pm.reparse();
pm.report(token, "typealias.type");
}
return;
case NAME:
if (Tokens.isIdentifier(type)) {
Name name = token.nameValue();
this.typeAlias = new TypeAlias(name, token.raw());
this.mode = TYPE_PARAMETERS;
return;
}
pm.popParser();
pm.report(token, "typealias.identifier");
return;
case TYPE_PARAMETERS:
if (TypeParser.isGenericStart(token, type)) {
this.mode = TYPE_PARAMETERS_END;
pm.splitJump(token, 1);
pm.pushParser(new TypeParameterListParser(this.typeAlias));
return;
}
// Fallthrough
case EQUAL:
this.mode = END;
pm.pushParser(new TypeParser(this.typeAlias));
if (type != BaseSymbols.EQUALS) {
pm.reparse();
pm.report(token, "typealias.equals");
}
return;
case TYPE_PARAMETERS_END:
this.mode = EQUAL;
if (TypeParser.isGenericEnd(token, type)) {
pm.splitJump(token, 1);
return;
}
pm.reparse();
pm.report(token, "generic.close_angle");
}
}
use of dyvilx.tools.compiler.parser.type.TypeParameterListParser in project Dyvil by Dyvil.
the class ClassDeclarationParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
int type = token.type();
switch(this.mode) {
case NAME:
if (!Tokens.isIdentifier(type)) {
pm.report(token, "class.identifier");
return;
}
final Name name = token.nameValue();
if (name.qualified.indexOf('$') >= 0) {
pm.report(Markers.syntaxError(token, "class.identifier.invalid", name, name.qualified));
}
this.theClass = this.consumer.createClass(token.raw(), name, this.classAttributes);
this.mode = GENERICS;
return;
case GENERICS:
if (type == BaseSymbols.SEMICOLON && token.isInferred() && TypeParser.isGenericStart(token.next())) {
// allow an implicit semicolon / line break between name and generic argument list
return;
}
if (TypeParser.isGenericStart(token, type)) {
pm.splitJump(token, 1);
pm.pushParser(new TypeParameterListParser(this.theClass));
this.mode = GENERICS_END;
return;
}
// Fallthrough
case PARAMETERS:
final Modifier modifier = ModifierParser.parseModifier(token, pm);
if (modifier != null) {
this.theClass.getConstructorAttributes().add(modifier);
return;
}
if (type == DyvilSymbols.AT) {
final Annotation annotation = new CodeAnnotation(token.raw());
this.theClass.getConstructorAttributes().add(annotation);
pm.pushParser(new AnnotationParser(annotation));
return;
}
if (type == BaseSymbols.OPEN_PARENTHESIS) {
pm.pushParser(new ParameterListParser(this.theClass).withFlags(ParameterListParser.ALLOW_PROPERTIES));
this.mode = PARAMETERS_END;
return;
}
// Fallthrough
case EXTENDS:
if (type == DyvilKeywords.EXTENDS) {
if (this.theClass.isInterface()) {
pm.pushParser(new TypeListParser(this));
this.mode = BODY;
return;
}
pm.pushParser(new TypeParser(this));
this.mode = EXTENDS_PARAMETERS;
return;
}
// Fallthrough
case IMPLEMENTS:
if (type == DyvilKeywords.IMPLEMENTS) {
pm.pushParser(new TypeListParser(this));
this.mode = BODY;
if (this.theClass.isInterface()) {
pm.report(token, "class.interface.implements");
return;
}
return;
}
// Fallthrough
case BODY:
if (type == BaseSymbols.OPEN_CURLY_BRACKET) {
ClassBody body = new ClassBody(this.theClass);
this.theClass.setBody(body);
pm.pushParser(new ClassBodyParser(body), true);
this.mode = BODY_END;
return;
}
if (BaseSymbols.isTerminator(type)) {
if (token.isInferred()) {
switch(token.next().type()) {
case DyvilKeywords.EXTENDS:
this.mode = EXTENDS;
return;
case DyvilKeywords.IMPLEMENTS:
this.mode = IMPLEMENTS;
return;
case BaseSymbols.OPEN_SQUARE_BRACKET:
this.mode = GENERICS;
return;
case BaseSymbols.OPEN_PARENTHESIS:
this.mode = PARAMETERS;
return;
}
}
pm.popParser(true);
this.consumer.addClass(this.theClass);
return;
}
this.mode = BODY_END;
pm.report(token, "class.body.separator");
return;
case GENERICS_END:
this.mode = PARAMETERS;
if (TypeParser.isGenericEnd(token, type)) {
pm.splitJump(token, 1);
return;
}
pm.reparse();
pm.report(token, "generic.close_angle");
return;
case PARAMETERS_END:
this.mode = EXTENDS;
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.reparse();
pm.report(token, "class.parameters.close_paren");
}
return;
case BODY_END:
pm.popParser();
this.consumer.addClass(this.theClass);
if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
pm.reparse();
pm.report(token, "class.body.close_brace");
}
return;
case EXTENDS_PARAMETERS_END:
this.mode = IMPLEMENTS;
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.reparse();
pm.report(token, "class.extends.close_paren");
}
return;
case EXTENDS_PARAMETERS:
if (type == BaseSymbols.OPEN_PARENTHESIS) {
ArgumentListParser.parseArguments(pm, token.next(), this.theClass::setSuperConstructorArguments);
this.mode = EXTENDS_PARAMETERS_END;
return;
}
this.mode = IMPLEMENTS;
pm.reparse();
}
}
use of dyvilx.tools.compiler.parser.type.TypeParameterListParser in project Dyvil by Dyvil.
the class MethodParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case DECLARATOR:
switch(type) {
case DyvilSymbols.AT:
this.parseAnnotation(pm, token);
return;
case DyvilKeywords.FUNC:
case DyvilKeywords.OPERATOR:
this.mode = METHOD_NAME;
return;
}
if (this.parseModifier(pm, token)) {
return;
}
// Fallthrough
case METHOD_NAME:
if (!Tokens.isIdentifier(type)) {
pm.report(token, "method.identifier");
return;
}
this.method = this.consumer.createMethod(token.raw(), token.nameValue(), Types.UNKNOWN, this.attributes);
this.mode = GENERICS;
return;
// Fallthrough
case GENERICS:
if (TypeParser.isGenericStart(token, type)) {
pm.splitJump(token, 1);
this.mode = GENERICS_END;
pm.pushParser(new TypeParameterListParser(this.method));
return;
}
// Fallthrough
case PARAMETERS:
if (type == BaseSymbols.OPEN_PARENTHESIS) {
this.mode = PARAMETERS_END;
pm.pushParser(new ParameterListParser(this.method));
return;
}
// Fallthrough
case TYPE:
switch(type) {
case BaseSymbols.COLON:
pm.report(Markers.syntaxWarning(token, "method.type.colon.deprecated"));
// Fallthrough
case DyvilSymbols.ARROW_RIGHT:
pm.pushParser(new TypeParser(this.method));
this.mode = EXCEPTIONS;
return;
}
// Fallthrough
case EXCEPTIONS:
if (type == DyvilKeywords.THROWS) {
pm.pushParser(new TypeListParser(this.method.getExceptions()));
this.mode = BODY;
return;
}
// Fallthrough
case BODY:
switch(type) {
case BaseSymbols.OPEN_CURLY_BRACKET:
pm.pushParser(new StatementListParser(this.method), true);
this.mode = END;
return;
case BaseSymbols.EQUALS:
pm.pushParser(new ExpressionParser(this.method));
this.mode = END;
return;
}
// Fallthrough
case END:
this.consumer.addMethod(this.method);
pm.popParser(type != Tokens.EOF);
return;
case GENERICS_END:
this.mode = PARAMETERS;
if (TypeParser.isGenericEnd(token, type)) {
pm.splitJump(token, 1);
return;
}
pm.reparse();
pm.report(token, "generic.close_angle");
return;
case PARAMETERS_END:
this.mode = TYPE;
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.reparse();
pm.report(token, "method.parameters.close_paren");
}
return;
}
}
Aggregations