"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Repeat = void 0;
const Production_js_1 = require("../core/Production.js");
const Evaluator_js_1 = require("../Evaluator.js");
const Rule_js_1 = require("./Rule.js");
class Repeat extends Rule_js_1.Rule {
    constructor(tgt, child, from, to) {
        super("repeat", tgt, child);
        this.from = from;
        this.to = to;
        this.setEvaluator(Evaluator_js_1.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_js_1.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(Production_js_1.AstBuilder.DEFAULT);
        }
    }
}
exports.Repeat = Repeat;
//# sourceMappingURL=Repeat.js.map