Search in sources :

Example 1 with DataMemberParser

use of dyvilx.tools.compiler.parser.classes.DataMemberParser in project Dyvil by Dyvil.

the class VarDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case KEYWORD:
            AttributeList attributes = new AttributeList();
            switch(type) {
                case GenSrcSymbols.VAR:
                    break;
                case GenSrcSymbols.CONST:
                case GenSrcSymbols.LET:
                    attributes.addFlag(Modifiers.FINAL);
                    break;
                default:
                    pm.report(token, "var.declarator");
                    return;
            }
            this.mode = OPEN_PAREN;
            return;
        case OPEN_PAREN:
            if (type != BaseSymbols.OPEN_PARENTHESIS) {
                this.directives.add(this.varDirective);
                pm.popParser(true);
                return;
            }
            pm.pushParser(new DataMemberParser<>(this).withFlags(DataMemberParser.PARSE_VALUE));
            this.mode = CLOSE_PAREN;
            return;
        case CLOSE_PAREN:
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.report(token, "var.close_paren");
                return;
            }
            this.mode = BODY;
            return;
        case BODY:
            if (type != BaseSymbols.OPEN_CURLY_BRACKET) {
                this.directives.add(this.varDirective);
                pm.popParser(true);
                return;
            }
            final StatementList body = new StatementList();
            pm.pushParser(new BlockParser(body));
            this.varDirective.setBlock(body);
            this.mode = BODY_END;
            return;
        case BODY_END:
            assert type == BaseSymbols.CLOSE_CURLY_BRACKET;
            this.directives.add(this.varDirective);
            pm.popParser();
    }
}
Also used : AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) DataMemberParser(dyvilx.tools.compiler.parser.classes.DataMemberParser) StatementList(dyvilx.tools.compiler.ast.statement.StatementList)

Aggregations

AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 DataMemberParser (dyvilx.tools.compiler.parser.classes.DataMemberParser)1