Search in sources :

Example 1 with MethodParser

use of dyvilx.tools.compiler.parser.classes.MethodParser in project Dyvil by Dyvil.

the class FuncDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case KEYWORD:
            if (type != GenSrcSymbols.FUNC) {
                pm.report(token, "func.declarator");
                return;
            }
            this.mode = OPEN_PAREN;
            return;
        case OPEN_PAREN:
            if (type != BaseSymbols.OPEN_PARENTHESIS) {
                this.directives.add(this.funcDirective);
                pm.popParser(true);
                return;
            }
            pm.pushParser(new MethodParser(this));
            this.mode = CLOSE_PAREN;
            return;
        case CLOSE_PAREN:
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.report(token, "func.close_paren");
                return;
            }
            this.mode = BODY;
            return;
        case BODY:
            if (type != BaseSymbols.OPEN_CURLY_BRACKET) {
                this.directives.add(this.funcDirective);
                pm.popParser(true);
                return;
            }
            final StatementList body = new StatementList();
            pm.pushParser(new BlockParser(body));
            this.funcDirective.setBlock(body);
            this.mode = BODY_END;
            return;
        case BODY_END:
            assert type == BaseSymbols.CLOSE_CURLY_BRACKET;
            this.directives.add(this.funcDirective);
            pm.popParser();
    }
}
Also used : StatementList(dyvilx.tools.compiler.ast.statement.StatementList) MethodParser(dyvilx.tools.compiler.parser.classes.MethodParser)

Aggregations

StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 MethodParser (dyvilx.tools.compiler.parser.classes.MethodParser)1