import { Evaluator } from "../Evaluator.js";
import { Rule } from "./Rule.js";
import { AstBuilder } from "../core/Production.js";
export class Optional extends Rule {
    constructor(tgt, child) {
        super("optional", tgt, child);
        this.setEvaluator(Evaluator.ALL_CHILDREN_EVALUATOR);
    }
    getEntry() {
        return this.children[0];
    }
    createBNF(grammar) {
        const p1 = Rule.addProduction(grammar, this, this.tgt, this.children[0]);
        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(AstBuilder.DEFAULT);
    }
}
//# sourceMappingURL=Optional.js.map