import { AstBuilder } from "../core/Production.js";
import { Evaluator } from "../Evaluator.js";
import { Rule } from "./Rule.js";
export class Repeat extends Rule {
    constructor(tgt, child, from, to) {
        super("repeat", tgt, child);
        this.from = from;
        this.to = to;
        this.setEvaluator(Evaluator.ALL_CHILDREN_EVALUATOR);
    }
    getFrom() {
        return this.from;
    }
    getTo() {
        return this.to;
    }
    getEntry() {
        return this.children[0];
    }
    createBNF(grammar) {
        for (let seqLen = this.to; seqLen >= this.from; seqLen--) {
            const rhs = [];
            for (let i = 0; i < seqLen; i++)
                rhs[i] = this.children[0];
            const p = Rule.addProduction(grammar, this, this.tgt, ...rhs);
            const that = this;
            p.onExtension((_parent, ...children) => {
                for (let c = 0; c < children.length; c++) {
                    let ch = children[c];
                    ch.setNthEntryInParent(c);
                    ch.setName(that.getNameForChild(c));
                }
            });
            p.setAstBuilder(AstBuilder.DEFAULT);
        }
    }
}
//# sourceMappingURL=Repeat.js.map