Search in sources :

Example 1 with IInitializer

use of dyvilx.tools.compiler.ast.constructor.IInitializer 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)

Aggregations

Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)1 IInitializer (dyvilx.tools.compiler.ast.constructor.IInitializer)1 StatementListParser (dyvilx.tools.compiler.parser.statement.StatementListParser)1