Search in sources :

Example 11 with TypeParser

use of dyvilx.tools.compiler.parser.type.TypeParser in project Dyvil by Dyvil.

the class MethodParser 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.FUNC:
                case DyvilKeywords.OPERATOR:
                    this.mode = METHOD_NAME;
                    return;
            }
            if (this.parseModifier(pm, token)) {
                return;
            }
        // Fallthrough
        case METHOD_NAME:
            if (!Tokens.isIdentifier(type)) {
                pm.report(token, "method.identifier");
                return;
            }
            this.method = this.consumer.createMethod(token.raw(), token.nameValue(), Types.UNKNOWN, this.attributes);
            this.mode = GENERICS;
            return;
        // Fallthrough
        case GENERICS:
            if (TypeParser.isGenericStart(token, type)) {
                pm.splitJump(token, 1);
                this.mode = GENERICS_END;
                pm.pushParser(new TypeParameterListParser(this.method));
                return;
            }
        // Fallthrough
        case PARAMETERS:
            if (type == BaseSymbols.OPEN_PARENTHESIS) {
                this.mode = PARAMETERS_END;
                pm.pushParser(new ParameterListParser(this.method));
                return;
            }
        // Fallthrough
        case TYPE:
            switch(type) {
                case BaseSymbols.COLON:
                    pm.report(Markers.syntaxWarning(token, "method.type.colon.deprecated"));
                // Fallthrough
                case DyvilSymbols.ARROW_RIGHT:
                    pm.pushParser(new TypeParser(this.method));
                    this.mode = EXCEPTIONS;
                    return;
            }
        // Fallthrough
        case EXCEPTIONS:
            if (type == DyvilKeywords.THROWS) {
                pm.pushParser(new TypeListParser(this.method.getExceptions()));
                this.mode = BODY;
                return;
            }
        // Fallthrough
        case BODY:
            switch(type) {
                case BaseSymbols.OPEN_CURLY_BRACKET:
                    pm.pushParser(new StatementListParser(this.method), true);
                    this.mode = END;
                    return;
                case BaseSymbols.EQUALS:
                    pm.pushParser(new ExpressionParser(this.method));
                    this.mode = END;
                    return;
            }
        // Fallthrough
        case END:
            this.consumer.addMethod(this.method);
            pm.popParser(type != Tokens.EOF);
            return;
        case GENERICS_END:
            this.mode = PARAMETERS;
            if (TypeParser.isGenericEnd(token, type)) {
                pm.splitJump(token, 1);
                return;
            }
            pm.reparse();
            pm.report(token, "generic.close_angle");
            return;
        case PARAMETERS_END:
            this.mode = TYPE;
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.reparse();
                pm.report(token, "method.parameters.close_paren");
            }
            return;
    }
}
Also used : StatementListParser(dyvilx.tools.compiler.parser.statement.StatementListParser) TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) TypeParameterListParser(dyvilx.tools.compiler.parser.type.TypeParameterListParser) ParameterListParser(dyvilx.tools.compiler.parser.method.ParameterListParser) TypeListParser(dyvilx.tools.compiler.parser.type.TypeListParser) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser) TypeParameterListParser(dyvilx.tools.compiler.parser.type.TypeParameterListParser)

Example 12 with TypeParser

use of dyvilx.tools.compiler.parser.type.TypeParser in project Dyvil by Dyvil.

the class ConstructorCallParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case NEW:
            if (type != DyvilKeywords.NEW) {
                pm.report(token, "constructor.new");
                pm.reparse();
            }
            final ArgumentList arguments = token.next().type() == BaseSymbols.OPEN_PARENTHESIS ? null : ArgumentList.empty();
            this.call = new ConstructorCall(token.raw(), arguments);
            this.mode = CONSTRUCTOR_PARAMETERS;
            pm.pushParser(new TypeParser(this.call));
            return;
        case CONSTRUCTOR_PARAMETERS:
            // ^
            if (type == BaseSymbols.OPEN_PARENTHESIS) {
                // new ... (
                this.mode = CONSTRUCTOR_PARAMETERS_END;
                ArgumentListParser.parseArguments(pm, token.next(), this.call);
                return;
            }
        // Fallthrough
        case ANONYMOUS_CLASS:
            if (type == BaseSymbols.OPEN_CURLY_BRACKET && (this.flags & IGNORE_ANON_CLASS) == 0) {
                // new ... ( ... ) { ...
                this.parseBody(pm);
                return;
            }
            pm.reparse();
            this.end(pm, token.prev());
            return;
        case CONSTRUCTOR_PARAMETERS_END:
            // new ... ( ... )
            // ^
            this.mode = ANONYMOUS_CLASS;
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.reparse();
                pm.report(token, "constructor.call.close_paren");
            }
            return;
        case ANONYMOUS_CLASS_END:
            // new ... { ... } ...
            // ^
            this.end(pm, token);
            if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
                pm.reparse();
                pm.report(token, "class.anonymous.body.end");
            }
    }
}
Also used : TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) ClassConstructorCall(dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall)

Example 13 with TypeParser

use of dyvilx.tools.compiler.parser.type.TypeParser in project Dyvil by Dyvil.

the class ForDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    // #for (IDENTIFIER <- EXPRESSION) {BLOCK}
    final int type = token.type();
    switch(this.mode) {
        case FOR:
            assert type == GenSrcSymbols.FOR;
            this.mode = OPEN_PAREN;
            this.directive = new ForEachDirective(token.raw(), null);
            return;
        case OPEN_PAREN:
            if (type != BaseSymbols.OPEN_PARENTHESIS) {
                pm.report(token, "for.open_paren");
                this.list.add(this.directive);
                pm.popParser(true);
                return;
            }
            this.mode = VAR_NAME;
            return;
        case VAR_NAME:
            if (type == Tokens.LETTER_IDENTIFIER) {
                this.directive.setVariable(new Variable(token.raw(), token.nameValue(), Types.UNKNOWN));
                this.mode = TYPE_ASCRIPTION;
                return;
            }
            pm.report(token, "for.identifier");
            if (type == BaseSymbols.CLOSE_PARENTHESIS) {
                this.mode = BODY;
            }
            return;
        case TYPE_ASCRIPTION:
            if (type == BaseSymbols.COLON) {
                pm.pushParser(new TypeParser(this.directive.getVariable()));
                this.mode = ARROW;
                return;
            }
        // Fallthrough
        case ARROW:
            if (type != GenSrcSymbols.ARROW_LEFT) {
                pm.reparse();
                pm.report(token, "for.arrow_left");
            }
            pm.pushParser(new ExpressionParser(this.directive.getVariable()));
            this.mode = CLOSE_PAREN;
            return;
        case CLOSE_PAREN:
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.report(token, "for.close_paren");
                return;
            }
            this.mode = BODY;
            return;
        case BODY:
            if (type != BaseSymbols.OPEN_CURLY_BRACKET) {
                pm.report(token, "for.open_brace");
                this.list.add(this.directive);
                pm.popParser(true);
                return;
            }
            final StatementList body = new StatementList();
            pm.pushParser(new BlockParser(body));
            this.directive.setAction(body);
            this.mode = BODY_END;
            return;
        case BODY_END:
            if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
                pm.report(token, "for.close_brace");
            }
            this.list.add(this.directive);
            pm.popParser();
    }
}
Also used : Variable(dyvilx.tools.compiler.ast.field.Variable) TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ForEachDirective(dyvilx.tools.gensrc.ast.directive.ForEachDirective) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Aggregations

TypeParser (dyvilx.tools.compiler.parser.type.TypeParser)13 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)5 Name (dyvil.lang.Name)4 TypeParameterListParser (dyvilx.tools.compiler.parser.type.TypeParameterListParser)3 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)2 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)2 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)2 AnnotationParser (dyvilx.tools.compiler.parser.annotation.AnnotationParser)2 ParameterListParser (dyvilx.tools.compiler.parser.method.ParameterListParser)2 TypeListParser (dyvilx.tools.compiler.parser.type.TypeListParser)2 IToken (dyvilx.tools.parsing.token.IToken)2 Modifiers (dyvil.reflect.Modifiers)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 ITypeConsumer (dyvilx.tools.compiler.ast.consumer.ITypeConsumer)1 ClassOperator (dyvilx.tools.compiler.ast.expression.ClassOperator)1 SuperExpr (dyvilx.tools.compiler.ast.expression.SuperExpr)1 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)1 TypeOperator (dyvilx.tools.compiler.ast.expression.TypeOperator)1 ClassConstructorCall (dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall)1