Search in sources :

Example 1 with ImportParser

use of dyvilx.tools.compiler.parser.header.ImportParser in project Dyvil by Dyvil.

the class ImportDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case KEYWORD:
            switch(type) {
                case GenSrcSymbols.USING:
                    this.mask = KindedImport.USING_DECLARATION;
                // Fallthrough
                case GenSrcSymbols.IMPORT:
                    this.declaration = new ImportDeclaration(token.raw());
                    if (this.template == null) {
                        pm.report(token, "import.context");
                    }
                    this.mode = OPEN_PAREN;
                    return;
            }
            throw new Error();
        case OPEN_PAREN:
            if (type != BaseSymbols.OPEN_PARENTHESIS) {
                pm.report(token, "import.open_paren");
                pm.popParser(true);
                return;
            }
            pm.pushParser(new ImportParser(this.declaration, this.mask));
            this.mode = CLOSE_PAREN;
            return;
        case CLOSE_PAREN:
            switch(type) {
                case BaseSymbols.CLOSE_PARENTHESIS:
                    if (this.template != null && this.declaration.getImport() != null) {
                        this.template.addImport(this.declaration);
                    }
                    pm.popParser();
                    return;
                case Tokens.EOF:
                    pm.report(token, "import.close_paren");
                    pm.popParser();
                    return;
            }
            pm.report(token, "import.close_paren");
            return;
    }
}
Also used : ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) ImportParser(dyvilx.tools.compiler.parser.header.ImportParser)

Aggregations

ImportDeclaration (dyvilx.tools.compiler.ast.imports.ImportDeclaration)1 ImportParser (dyvilx.tools.compiler.parser.header.ImportParser)1