Search in sources :

Example 1 with CallDirective

use of dyvilx.tools.gensrc.ast.directive.CallDirective 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();
    }
}
Also used : CallDirective(dyvilx.tools.gensrc.ast.directive.CallDirective) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) ArgumentListParser(dyvilx.tools.compiler.parser.expression.ArgumentListParser)

Aggregations

StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 ArgumentListParser (dyvilx.tools.compiler.parser.expression.ArgumentListParser)1 CallDirective (dyvilx.tools.gensrc.ast.directive.CallDirective)1