Search in sources :

Example 1 with StatementListParser

use of dyvilx.tools.compiler.parser.statement.StatementListParser in project Dyvil by Dyvil.

the class PropertyBodyParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case OPEN_BRACE:
            if (type == BaseSymbols.OPEN_CURLY_BRACKET) {
                this.mode = TAG;
            }
            return;
        case TAG:
            switch(type) {
                case BaseSymbols.CLOSE_CURLY_BRACKET:
                    pm.popParser();
                    return;
                case BaseSymbols.SEMICOLON:
                    if (token.isInferred()) {
                        return;
                    }
                    break;
                case Tokens.LETTER_IDENTIFIER:
                    final Name name = token.nameValue();
                    if (name == Names.get) {
                        this.configureMethod(this.property.initGetter(), token);
                        this.mode = SEPARATOR;
                        this.target = GETTER;
                        return;
                    }
                    if (name == Names.set) {
                        this.configureMethod(this.property.initSetter(), token);
                        this.mode = SETTER_PARAMETER;
                        this.target = SETTER;
                        return;
                    }
                    pm.report(token, "property.tag.unknown");
                    return;
                case DyvilKeywords.INIT:
                    this.property.setInitializerPosition(token.raw());
                    this.mode = SEPARATOR;
                    this.target = INITIALIZER;
                    return;
                case DyvilSymbols.AT:
                    this.parseAnnotation(pm, token);
                    return;
            }
            if (this.parseModifier(pm, token)) {
                return;
            }
            pm.report(token, "property.tag");
            return;
        case SETTER_PARAMETER:
            if (type == BaseSymbols.OPEN_PARENTHESIS) {
                this.mode = SETTER_PARAMETER_NAME;
                return;
            }
        // Fallthrough
        case SEPARATOR:
            switch(type) {
                case BaseSymbols.COLON:
                    pm.pushParser(new ExpressionParser(this));
                    return;
                case BaseSymbols.OPEN_CURLY_BRACKET:
                    pm.pushParser(new StatementListParser(this), true);
                    return;
                case BaseSymbols.CLOSE_CURLY_BRACKET:
                    pm.popParser();
                    return;
                case BaseSymbols.SEMICOLON:
                    this.mode = TAG;
                    return;
            }
            pm.report(token, "property.separator");
            return;
        case SETTER_PARAMETER_NAME:
            this.mode = SETTER_PARAMETER_END;
            if (Tokens.isIdentifier(type)) {
                this.property.setSetterParameterName(token.nameValue());
            } else {
                pm.report(token, "property.setter.identifier");
            }
            return;
        case SETTER_PARAMETER_END:
            this.mode = SEPARATOR;
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.report(token, "property.setter.close_paren");
            }
    }
}
Also used : StatementListParser(dyvilx.tools.compiler.parser.statement.StatementListParser) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser) Name(dyvil.lang.Name)

Example 2 with StatementListParser

use of dyvilx.tools.compiler.parser.statement.StatementListParser 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)

Example 3 with StatementListParser

use of dyvilx.tools.compiler.parser.statement.StatementListParser 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);
    }
}
Also used : StatementListParser(dyvilx.tools.compiler.parser.statement.StatementListParser) MatchCase(dyvilx.tools.compiler.ast.expression.MatchCase) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Example 4 with StatementListParser

use of dyvilx.tools.compiler.parser.statement.StatementListParser in project Dyvil by Dyvil.

the class MemberParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case DECLARATOR:
            switch(type) {
                case BaseSymbols.SEMICOLON:
                    if (token.isInferred()) {
                        return;
                    }
                // Fallthrough
                case BaseSymbols.CLOSE_CURLY_BRACKET:
                    pm.reparse();
                // Fallthrough
                case Tokens.EOF:
                    if (!this.attributes.isEmpty()) {
                        pm.report(token, "member.declarator");
                    }
                    pm.popParser();
                    return;
                case // constructor declaration or initializer
                DyvilKeywords.INIT:
                    if (// initializer
                    token.next().type() == BaseSymbols.OPEN_CURLY_BRACKET) {
                        final IInitializer initializer = this.consumer.createInitializer(token.raw(), this.attributes);
                        this.consumer.addInitializer(initializer);
                        this.mode = END;
                        pm.pushParser(new StatementListParser(initializer));
                        return;
                    }
                    this.mode = END;
                    pm.pushParser(new ConstructorParser(this.consumer, this.attributes), true);
                    return;
                case DyvilKeywords.CONST:
                case DyvilKeywords.LET:
                case DyvilKeywords.VAR:
                    final FieldParser<T> parser = new FieldParser<>(this.consumer, this.attributes);
                    if ((this.flags & NO_FIELD_PROPERTIES) != 0) {
                        parser.withFlags(FieldParser.NO_PROPERTIES);
                    }
                    pm.pushParser(parser, true);
                    this.mode = END;
                    return;
                case DyvilKeywords.CASE:
                    if (!Tokens.isIdentifier(token.next().type())) {
                        break;
                    }
                    pm.pushParser(new EnumConstantParser(this.consumer), true);
                    this.mode = END;
                    return;
                case DyvilKeywords.FUNC:
                case DyvilKeywords.OPERATOR:
                    this.mode = END;
                    pm.pushParser(new MethodParser(this.consumer, this.attributes), true);
                    return;
            }
            final Modifier modifier;
            if ((modifier = ModifierParser.parseModifier(token, pm)) != null) {
                this.attributes.add(modifier);
                return;
            }
            int classType;
            if ((classType = ModifierParser.parseClassTypeModifier(token, pm)) >= 0) {
                this.attributes.addFlag(classType);
                ClassDeclarationParser parser = new ClassDeclarationParser(this.consumer, this.attributes);
                pm.pushParser(parser);
                this.mode = END;
                return;
            }
            // This is not in the above switch because 'readClassTypeModifier' above has to check for '@ interface' first
            if (type == DyvilSymbols.AT) {
                this.parseAnnotation(pm, token);
                return;
            }
            pm.report(token, "member.declarator");
            return;
        case END:
            pm.popParser(type != Tokens.EOF);
    }
}
Also used : StatementListParser(dyvilx.tools.compiler.parser.statement.StatementListParser) IInitializer(dyvilx.tools.compiler.ast.constructor.IInitializer) Modifier(dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)

Example 5 with StatementListParser

use of dyvilx.tools.compiler.parser.statement.StatementListParser 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)

Aggregations

StatementListParser (dyvilx.tools.compiler.parser.statement.StatementListParser)5 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)4 ParameterListParser (dyvilx.tools.compiler.parser.method.ParameterListParser)2 TypeListParser (dyvilx.tools.compiler.parser.type.TypeListParser)2 Name (dyvil.lang.Name)1 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)1 IInitializer (dyvilx.tools.compiler.ast.constructor.IInitializer)1 MatchCase (dyvilx.tools.compiler.ast.expression.MatchCase)1 InitializerCall (dyvilx.tools.compiler.ast.expression.access.InitializerCall)1 ArgumentListParser (dyvilx.tools.compiler.parser.expression.ArgumentListParser)1 TypeParameterListParser (dyvilx.tools.compiler.parser.type.TypeParameterListParser)1 TypeParser (dyvilx.tools.compiler.parser.type.TypeParser)1