package net.ranides.assira.grammar.impl;

import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.grammar.G4Node;
import org.antlr.v4.runtime.CommonToken;

import java.util.NoSuchElementException;

class NodeForToken extends NodeAbstract implements G4Node {

    private final CommonToken token;

    public NodeForToken(RootAbstract root, G4Node parent, CommonToken token) {
        super(root, parent);
        this.token = token;
    }

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

    @Override
    public Object unwrap() {
        return token;
    }

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

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

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

}
