package net.ranides.assira.grammar.impl;

import lombok.experimental.UtilityClass;
import net.ranides.assira.grammar.G4ErrorHandler;
import net.ranides.assira.grammar.G4Parser;
import net.ranides.assira.reflection.IClass;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Parser;

@UtilityClass
public class ParserFactory {

    public static G4Parser newInstance(IClass<? extends Lexer> lexer, IClass<? extends Parser> parser, G4ErrorHandler handler) {
        return new G4ParserGenerated(lexer, parser, handler);
    }

    public static G4Parser newInstance(String grammar, String imports, G4ErrorHandler handler) {
        return (G4Parser) Li.INTERPRETER.construct(grammar, imports, handler);
    }

    private static class Li {
        static final IClass<?> INTERPRETER = IClass.typeinfo("net.ranides.assira.grammar.impl.G4ParserInterpreter");
    }

}
