use of dyvilx.tools.compiler.parser.type.TypeParser 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;
}
}
use of dyvilx.tools.compiler.parser.type.TypeParser in project Dyvil by Dyvil.
the class ConstructorCallParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case NEW:
if (type != DyvilKeywords.NEW) {
pm.report(token, "constructor.new");
pm.reparse();
}
final ArgumentList arguments = token.next().type() == BaseSymbols.OPEN_PARENTHESIS ? null : ArgumentList.empty();
this.call = new ConstructorCall(token.raw(), arguments);
this.mode = CONSTRUCTOR_PARAMETERS;
pm.pushParser(new TypeParser(this.call));
return;
case CONSTRUCTOR_PARAMETERS:
// ^
if (type == BaseSymbols.OPEN_PARENTHESIS) {
// new ... (
this.mode = CONSTRUCTOR_PARAMETERS_END;
ArgumentListParser.parseArguments(pm, token.next(), this.call);
return;
}
// Fallthrough
case ANONYMOUS_CLASS:
if (type == BaseSymbols.OPEN_CURLY_BRACKET && (this.flags & IGNORE_ANON_CLASS) == 0) {
// new ... ( ... ) { ...
this.parseBody(pm);
return;
}
pm.reparse();
this.end(pm, token.prev());
return;
case CONSTRUCTOR_PARAMETERS_END:
// new ... ( ... )
// ^
this.mode = ANONYMOUS_CLASS;
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.reparse();
pm.report(token, "constructor.call.close_paren");
}
return;
case ANONYMOUS_CLASS_END:
// new ... { ... } ...
// ^
this.end(pm, token);
if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
pm.reparse();
pm.report(token, "class.anonymous.body.end");
}
}
}
use of dyvilx.tools.compiler.parser.type.TypeParser in project Dyvil by Dyvil.
the class ForDirectiveParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
// #for (IDENTIFIER <- EXPRESSION) {BLOCK}
final int type = token.type();
switch(this.mode) {
case FOR:
assert type == GenSrcSymbols.FOR;
this.mode = OPEN_PAREN;
this.directive = new ForEachDirective(token.raw(), null);
return;
case OPEN_PAREN:
if (type != BaseSymbols.OPEN_PARENTHESIS) {
pm.report(token, "for.open_paren");
this.list.add(this.directive);
pm.popParser(true);
return;
}
this.mode = VAR_NAME;
return;
case VAR_NAME:
if (type == Tokens.LETTER_IDENTIFIER) {
this.directive.setVariable(new Variable(token.raw(), token.nameValue(), Types.UNKNOWN));
this.mode = TYPE_ASCRIPTION;
return;
}
pm.report(token, "for.identifier");
if (type == BaseSymbols.CLOSE_PARENTHESIS) {
this.mode = BODY;
}
return;
case TYPE_ASCRIPTION:
if (type == BaseSymbols.COLON) {
pm.pushParser(new TypeParser(this.directive.getVariable()));
this.mode = ARROW;
return;
}
// Fallthrough
case ARROW:
if (type != GenSrcSymbols.ARROW_LEFT) {
pm.reparse();
pm.report(token, "for.arrow_left");
}
pm.pushParser(new ExpressionParser(this.directive.getVariable()));
this.mode = CLOSE_PAREN;
return;
case CLOSE_PAREN:
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.report(token, "for.close_paren");
return;
}
this.mode = BODY;
return;
case BODY:
if (type != BaseSymbols.OPEN_CURLY_BRACKET) {
pm.report(token, "for.open_brace");
this.list.add(this.directive);
pm.popParser(true);
return;
}
final StatementList body = new StatementList();
pm.pushParser(new BlockParser(body));
this.directive.setAction(body);
this.mode = BODY_END;
return;
case BODY_END:
if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
pm.report(token, "for.close_brace");
}
this.list.add(this.directive);
pm.popParser();
}
}
Aggregations