"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParsedNode = void 0;
const DefaultParsedNode_js_1 = require("./core/DefaultParsedNode.js");
const ParsingState_js_1 = require("./core/ParsingState.js");
const EBNFProduction_js_1 = require("./ebnf/EBNFProduction.js");
class ParsedNode extends DefaultParsedNode_js_1.DefaultParsedNode {
    constructor(matcher, symbol, production) {
        super(matcher, symbol, production);
        this.nthEntryInParent = 0;
    }
    setNthEntryInParent(nthEntry) {
        this.nthEntryInParent = nthEntry;
    }
    getNthEntryInParent() {
        return this.nthEntryInParent;
    }
    getRule() {
        let production = this.getProduction();
        if (production !== undefined && production instanceof EBNFProduction_js_1.EBNFProduction)
            return production.getRule();
        return undefined;
    }
    parentHasSameRule() {
        let thisRule = this.getRule();
        if (thisRule === undefined)
            return false;
        let parent = this.getParent();
        if (parent === undefined)
            return false;
        let parentRule = parent.getRule();
        if (parentRule === undefined)
            return false;
        return thisRule === parentRule;
    }
    getAutocompletion(justCheck) {
        var _a;
        let rule = this.getRule();
        if (rule !== undefined && rule.getAutocompleter() !== undefined && !this.parentHasSameRule()) {
            return (_a = rule.getAutocompleter()) === null || _a === void 0 ? void 0 : _a.getAutocompletion(this, justCheck);
        }
        return super.getAutocompletion(justCheck);
    }
    notifyListeners() {
        for (let i = 0; i < this.numChildren(); i++)
            this.getChild(i).notifyListeners();
        const state = this.getMatcher().state;
        if (!state.equals(ParsingState_js_1.ParsingState.SUCCESSFUL) && !state.equals(ParsingState_js_1.ParsingState.END_OF_INPUT))
            return;
        let rule = this.getRule();
        if (rule !== undefined && !this.parentHasSameRule()) {
            let parseListener = rule.getOnSuccessfulParsed();
            if (parseListener !== undefined)
                parseListener(this);
        }
    }
    evaluate(...n) {
        if (n.length > 0)
            return super.evaluate(...n);
        let rule = this.getRule();
        if (rule !== undefined && rule.getEvaluator() !== undefined)
            return rule.getEvaluator().evaluate(this);
        return super.evaluate();
    }
}
exports.ParsedNode = ParsedNode;
//# sourceMappingURL=ParsedNode.js.map