use of dyvilx.tools.compiler.ast.expression.MatchCase in project Dyvil by Dyvil.
the class CaseParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case CASE:
if (type == DyvilKeywords.CASE) {
this.matchCase = new MatchCase();
this.mode = CONDITION;
pm.pushParser(new PatternParser(this.matchCase));
return;
}
if (BaseSymbols.isTerminator(type)) {
pm.popParser(true);
return;
}
pm.report(token, "match.case");
return;
case CONDITION:
if (type == DyvilKeywords.IF) {
this.mode = ACTION;
pm.pushParser(new ExpressionParser(this).withFlags(IGNORE_COLON | IGNORE_CLOSURE | IGNORE_LAMBDA));
return;
}
// Fallthrough
case ACTION:
this.mode = END;
if (type == BaseSymbols.OPEN_CURLY_BRACKET) {
pm.pushParser(new StatementListParser(this), true);
return;
}
pm.pushParser(new ExpressionParser(this));
if (type != BaseSymbols.COLON && type != DyvilSymbols.DOUBLE_ARROW_RIGHT) {
pm.reparse();
pm.report(token, "match.case.action");
}
return;
case END:
pm.popParser(true);
this.caseConsumer.addCase(this.matchCase);
}
}
Aggregations