Search in sources :

Example 11 with ExpressionParser

use of dyvilx.tools.compiler.parser.expression.ExpressionParser in project Dyvil by Dyvil.

the class DataMemberParser 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.LET:
                    this.attributes.addFlag(Modifiers.FINAL);
                // Fallthrough
                case DyvilKeywords.VAR:
                    this.mode = NAME;
                    return;
            }
            if (this.parseModifier(pm, token)) {
                return;
            }
        // Fallthrough
        case NAME:
            if (!Tokens.isIdentifier(type)) {
                pm.report(token, "variable.identifier");
                return;
            }
            this.dataMember = this.consumer.createDataMember(token.raw(), token.nameValue(), Types.UNKNOWN, this.attributes);
            this.mode = TYPE;
            return;
        case TYPE:
            if (type == BaseSymbols.COLON) {
                // ... IDENTIFIER : TYPE ...
                pm.pushParser(new TypeParser(this.dataMember));
                this.mode = VALUE;
                return;
            }
        // Fallthrough
        case VALUE:
            if (type == BaseSymbols.EQUALS && (this.flags & PARSE_VALUE) != 0) {
                pm.pushParser(new ExpressionParser(this.dataMember));
                this.mode = END;
                return;
            }
        // Fallthrough
        case END:
            this.consumer.addDataMember(this.dataMember);
            pm.popParser(type != Tokens.EOF);
    }
}
Also used : TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Example 12 with ExpressionParser

use of dyvilx.tools.compiler.parser.expression.ExpressionParser in project Dyvil by Dyvil.

the class EnumConstantParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case DECLARATOR:
            if (type == DyvilKeywords.CASE) {
                this.mode = NAME;
            }
            return;
        case NAME:
            if (!Tokens.isIdentifier(type)) {
                pm.report(token, "field.identifier");
            }
            this.constant = new EnumConstant(token.raw(), token.nameValue(), this.attributes);
            this.mode = VALUE;
            return;
        case VALUE:
            if (type == BaseSymbols.EQUALS) {
                pm.pushParser(new ExpressionParser(this.constant));
                this.mode = END;
                return;
            }
        // Fallthrough
        case END:
            if (this.consumer.acceptEnums()) {
                // noinspection unchecked
                this.consumer.addDataMember(this.constant);
            } else {
                pm.report(this.constant.getPosition(), "field.enum.invalid");
            }
            pm.popParser(type != Tokens.EOF);
    }
}
Also used : EnumConstant(dyvilx.tools.compiler.ast.field.EnumConstant) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Example 13 with ExpressionParser

use of dyvilx.tools.compiler.parser.expression.ExpressionParser in project Dyvil by Dyvil.

the class FieldParser 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.CONST:
                    this.attributes.addFlag(Modifiers.CONST);
                    this.mode = NAME;
                    return;
                case DyvilKeywords.LET:
                    this.attributes.addFlag(Modifiers.FINAL);
                // Fallthrough
                case DyvilKeywords.VAR:
                    this.mode = NAME;
                    return;
            }
            if (this.parseModifier(pm, token)) {
                return;
            }
        // Fallthrough
        case NAME:
            if (!Tokens.isIdentifier(type)) {
                pm.report(token, "field.identifier");
                return;
            }
            this.position = token.raw();
            this.name = token.nameValue();
            this.mode = TYPE;
            return;
        case TYPE:
            if (type == BaseSymbols.COLON) {
                // ... IDENTIFIER : TYPE ...
                pm.pushParser(new TypeParser(this));
                this.mode = VALUE;
                return;
            }
        // Fallthrough
        case VALUE:
            if ((this.flags & NO_VALUES) == 0 && type == BaseSymbols.EQUALS) {
                // definitely a field
                final T field = this.initField();
                if ((this.flags & NO_PROPERTIES) != 0) {
                    this.mode = END;
                    pm.pushParser(new ExpressionParser(field));
                } else {
                    this.mode = PROPERTY;
                    pm.pushParser(new ExpressionParser(field).withFlags(ExpressionParser.IGNORE_CLOSURE));
                }
                return;
            }
        // Fallthrough
        case PROPERTY:
            if ((this.flags & NO_PROPERTIES) == 0 && type == BaseSymbols.OPEN_CURLY_BRACKET) {
                // either a standalone property or a field property
                pm.pushParser(new PropertyBodyParser(this.initProperty()), true);
                this.mode = END;
                return;
            }
        // Fallthrough
        case END:
            if (this.property != null) {
                this.consumer.addProperty(this.property);
            } else {
                // for fields without values or properties, the dataMember field has not beed initialized yet
                this.consumer.addDataMember(this.initField());
            }
            pm.popParser(type != Tokens.EOF);
    }
}
Also used : TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Example 14 with ExpressionParser

use of dyvilx.tools.compiler.parser.expression.ExpressionParser 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 15 with ExpressionParser

use of dyvilx.tools.compiler.parser.expression.ExpressionParser in project Dyvil by Dyvil.

the class SyncStatementParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case SYNCHRONIZED:
            this.mode = LOCK;
            if (type == DyvilKeywords.SYNCHRONIZED) {
                return;
            }
            pm.report(token, "sync.synchronized");
        // Fallthrough
        case LOCK:
            pm.pushParser(new ExpressionParser(this).withFlags(IGNORE_STATEMENT));
            this.mode = SEPARATOR;
            return;
        case SEPARATOR:
            switch(type) {
                case Tokens.EOF:
                    pm.popParser();
                    return;
                case BaseSymbols.SEMICOLON:
                    pm.popParser(true);
                    return;
            }
            this.mode = END;
            pm.pushParser(new ExpressionParser(this), true);
            // pm.report(token, "sync.separator");
            return;
        case ACTION:
            if (BaseSymbols.isTerminator(type) && !token.isInferred()) {
                pm.popParser(true);
                return;
            }
            pm.pushParser(new ExpressionParser(this), true);
            this.mode = END;
            return;
        case END:
            pm.popParser(true);
    }
}
Also used : ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Aggregations

ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)20 TypeParser (dyvilx.tools.compiler.parser.type.TypeParser)5 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)4 StatementListParser (dyvilx.tools.compiler.parser.statement.StatementListParser)4 ParameterListParser (dyvilx.tools.compiler.parser.method.ParameterListParser)3 Name (dyvil.lang.Name)2 TypeListParser (dyvilx.tools.compiler.parser.type.TypeListParser)2 IToken (dyvilx.tools.parsing.token.IToken)2 Modifiers (dyvil.reflect.Modifiers)1 LineSource (dyvil.source.LineSource)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)1 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)1 ITypeConsumer (dyvilx.tools.compiler.ast.consumer.ITypeConsumer)1 IContext (dyvilx.tools.compiler.ast.context.IContext)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)1 MatchCase (dyvilx.tools.compiler.ast.expression.MatchCase)1 InitializerCall (dyvilx.tools.compiler.ast.expression.access.InitializerCall)1