"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Optional = void 0;
const Evaluator_js_1 = require("../Evaluator.js");
const Rule_js_1 = require("./Rule.js");
const Production_js_1 = require("../core/Production.js");
class Optional extends Rule_js_1.Rule {
    constructor(tgt, child) {
        super("optional", tgt, child);
        this.setEvaluator(Evaluator_js_1.Evaluator.ALL_CHILDREN_EVALUATOR);
    }
    getEntry() {
        return this.children[0];
    }
    createBNF(grammar) {
        const p1 = Rule_js_1.Rule.addProduction(grammar, this, this.tgt, this.children[0]);
        Rule_js_1.Rule.addProduction(grammar, this, this.tgt);
        const that = this;
        p1.onExtension((_parent, ...children) => {
            let c0 = children[0];
            c0.setNthEntryInParent(0);
            c0.setName(that.getNameForChild(0));
        });
        p1.setAstBuilder(Production_js_1.AstBuilder.DEFAULT);
    }
}
exports.Optional = Optional;
//# sourceMappingURL=Optional.js.map