Search in sources :

Example 1 with ArgumentListParser

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

Example 2 with ArgumentListParser

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;
    }
}
Also used : StatementListParser(dyvilx.tools.compiler.parser.statement.StatementListParser) ParameterListParser(dyvilx.tools.compiler.parser.method.ParameterListParser) TypeListParser(dyvilx.tools.compiler.parser.type.TypeListParser) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser) ArgumentListParser(dyvilx.tools.compiler.parser.expression.ArgumentListParser) InitializerCall(dyvilx.tools.compiler.ast.expression.access.InitializerCall)

Aggregations

ArgumentListParser (dyvilx.tools.compiler.parser.expression.ArgumentListParser)2 InitializerCall (dyvilx.tools.compiler.ast.expression.access.InitializerCall)1 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)1 ParameterListParser (dyvilx.tools.compiler.parser.method.ParameterListParser)1 StatementListParser (dyvilx.tools.compiler.parser.statement.StatementListParser)1 TypeListParser (dyvilx.tools.compiler.parser.type.TypeListParser)1 CallDirective (dyvilx.tools.gensrc.ast.directive.CallDirective)1