use of dyvilx.tools.compiler.parser.expression.ArgumentListParser in project Dyvil by Dyvil.
the class CallDirectiveParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case NAME:
if (Tokens.isIdentifier(type)) {
this.mode = OPEN_PAREN;
this.directive = new CallDirective(token.raw(), token.nameValue());
return;
}
pm.report(token, "directive.identifier");
return;
case OPEN_PAREN:
if (type == BaseSymbols.OPEN_PARENTHESIS) {
pm.pushParser(new ArgumentListParser(this.directive));
this.mode = CLOSE_PAREN;
return;
}
// Fallthrough
case BODY:
if (type == BaseSymbols.OPEN_CURLY_BRACKET) {
final StatementList closure = new StatementList();
pm.pushParser(new BlockParser(closure));
this.directive.setBlock(closure);
this.mode = BODY_END;
return;
}
this.list.add(this.directive);
pm.popParser(true);
return;
case CLOSE_PAREN:
if (type == BaseSymbols.CLOSE_PARENTHESIS) {
this.mode = BODY;
return;
}
pm.report(token, "directive.close_paren");
return;
case BODY_END:
assert type == BaseSymbols.CLOSE_CURLY_BRACKET;
this.list.add(this.directive);
pm.popParser();
}
}
use of dyvilx.tools.compiler.parser.expression.ArgumentListParser in project Dyvil by Dyvil.
the class ConstructorParser 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.INIT:
this.member = this.consumer.createConstructor(token.raw(), this.attributes);
this.mode = PARAMETERS;
return;
}
if (this.parseModifier(pm, token)) {
return;
}
// Fallthrough
case PARAMETERS:
this.mode = PARAMETERS_END;
if (type == BaseSymbols.OPEN_PARENTHESIS) {
pm.pushParser(new ParameterListParser(this.member));
return;
}
pm.reparse();
pm.report(token, "constructor.parameters.open_paren");
return;
case PARAMETERS_END:
this.mode = INITIALIZER;
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.reparse();
pm.report(token, "constructor.parameters.close_paren");
}
return;
case INITIALIZER:
if (type == BaseSymbols.COLON) {
this.mode = INIT_TYPE;
return;
}
// Fallthrough
case EXCEPTIONS:
if (type == DyvilKeywords.THROWS) {
pm.pushParser(new TypeListParser(this.member.getExceptions()));
this.mode = BODY;
return;
}
// Fallthrough
case BODY:
switch(type) {
case BaseSymbols.OPEN_CURLY_BRACKET:
pm.pushParser(new StatementListParser(this.member), true);
this.mode = END;
return;
case BaseSymbols.EQUALS:
pm.pushParser(new ExpressionParser(this.member));
this.mode = END;
return;
}
// Fallthrough
case END:
this.consumer.addConstructor(this.member);
pm.popParser(type != Tokens.EOF);
return;
case INIT_TYPE:
boolean isSuper = false;
switch(type) {
case DyvilKeywords.SUPER:
isSuper = true;
// Fallthrough
case DyvilKeywords.THIS:
final InitializerCall init = new InitializerCall(token.raw(), isSuper);
this.member.setInitializer(init);
this.mode = INIT_ARGUMENTS;
return;
}
pm.report(token, "initializer.call.type");
return;
case INIT_ARGUMENTS:
if (type == BaseSymbols.OPEN_PARENTHESIS) {
pm.pushParser(new ArgumentListParser(this.member.getInitializer()));
this.mode = INIT_END;
return;
}
pm.report(token, "initializer.call.open_paren");
this.mode = EXCEPTIONS;
return;
case INIT_END:
if (type != BaseSymbols.CLOSE_PARENTHESIS) {
pm.report(token, "initializer.call.close_paren");
return;
}
this.mode = EXCEPTIONS;
return;
}
}
Aggregations