import { Named } from "./Named.js";
import { Sym } from "./Symbol.js";
class NonTerminal extends Sym {
    constructor(symbol) {
        super(symbol);
    }
    isTerminal() {
        return false;
    }
    isNonTerminal() {
        return true;
    }
    isEpsilon() {
        return false;
    }
    withName(name = undefined) {
        return new Named(this, name);
    }
    uses(symbol, bnf, progressing) {
        if (progressing === undefined)
            progressing = new Set();
        const productions = bnf.getProductions(this);
        for (const p of productions) {
            if (progressing.has(p.toString()))
                continue;
            progressing.add(p.toString());
            const rhs = p.getRight();
            for (const rSym of rhs) {
                if (rSym.equals(symbol))
                    return true;
                else if (rSym instanceof NonTerminal) {
                    if (rSym.uses(symbol, bnf, progressing))
                        return true;
                }
            }
        }
        return false;
    }
    toString() {
        return "<" + this.getSymbol() + ">";
    }
    static makeRandomSymbol() {
        let length = 8;
        const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        const charactersLength = characters.length;
        let result = '';
        for (let i = 0; i < length; i++)
            result += characters.charAt(Math.floor(Math.random() * charactersLength));
        return result;
    }
}
export { NonTerminal };
//# sourceMappingURL=NonTerminal.js.map