package net.ranides.assira.grammar.impl;

import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.grammar.G4Node;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.NoSuchElementException;

class NodeForTerm extends NodeAbstract implements G4Node {

    private final TerminalNode node;

    public NodeForTerm(RootAbstract root, G4Node parent, TerminalNode node) {
        super(root, parent);
        this.node = node;
    }

    @Override
    public CQuery<G4Node> children() {
        return CQuery.empty(() -> new NoSuchElementException("Terminal node has no children: " + this));
    }

    @Override
    public ParseTree unwrap() {
        return node;
    }

    @Override
    public String shortname() {
        return root.parser().tokenName(node.getSymbol().getType());
    }

    @Override
    public String qualifier() {
        return "";
    }

    @Override
    public String text() {
        return node.getText();
    }

}
