package net.ranides.assira.grammar.impl;

import net.ranides.assira.generic.Ref;
import net.ranides.assira.grammar.G4Exception;
import net.ranides.assira.grammar.G4Node;
import net.ranides.assira.grammar.G4Parser;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.tree.RuleNode;
import org.antlr.v4.runtime.tree.TerminalNode;

abstract class RootAbstract {

    public abstract G4Parser parser();

    public abstract G4Node tree();

    public abstract String branchName(G4Node g4node);

    public abstract Ref<G4Node> findLabel(G4Node g4node, String labelName);

    public final G4Node wrap(G4Node parent, Object tree) {
        if(tree instanceof RuleNode) {
            return new NodeForRule(this, parent, (RuleNode) tree);
        }
        if(tree instanceof TerminalNode) {
            return new NodeForTerm(this, parent, (TerminalNode) tree);
        }
        if(tree instanceof CommonToken) {
            return new NodeForToken(this, parent, (CommonToken) tree);
        }
        throw new G4Exception("Inside '"+parent+"' there is unknown node type: " + tree.getClass());
    }


}
