pegisland
Version:
General PEG-based parser supporting island grammars with lake symbols
60 lines • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SucceedCalculator = void 0;
// Copyright (C) 2021- Katsumi Okuda. All rights reserved.
const assert_1 = require("assert");
const set_operations_1 = require("../set-operations");
const SetCalculator_1 = require("./SetCalculator");
const TopDownSetCalculator_1 = require("./TopDownSetCalculator");
class SucceedCalculator extends TopDownSetCalculator_1.TopDownSetCalculator {
visitZeroOrMore(pe) {
this.propagateWithBeginning(pe);
}
visitOneOrMore(pe) {
this.propagateWithBeginning(pe);
}
visitOptional(pe) {
this.propagateToOperand(pe);
}
visitAnd(_pe) {
(0, assert_1.strict)(true);
}
visitNot(_pe) {
(0, assert_1.strict)(true);
}
visitSequence(pe) {
let succ = new Set(this.get(pe));
for (const ei of [...pe.operands].reverse()) {
this.set(ei, succ);
if (this.getBeginning(ei).has(SetCalculator_1.EPSILON)) {
succ = (0, set_operations_1.union)(succ, (0, set_operations_1.difference)(this.getBeginning(ei), new Set([SetCalculator_1.EPSILON])));
}
else {
succ = new Set(this.getBeginning(ei));
}
}
}
visitOrderedChoice(pe) {
pe.operands.forEach((operand) => this.propagate(pe, operand));
}
visitGrouping(pe) {
this.propagateToOperand(pe);
}
visitRewriting(pe) {
this.propagateToOperand(pe);
}
visitColon(pe) {
this.propagate(pe, pe.rhs);
}
visitColonNot(pe) {
this.propagate(pe, pe.lhs);
}
visitLake(pe) {
this.propagateToOperand(pe);
}
propagateWithBeginning(pe) {
this.set(pe.operand, (0, set_operations_1.union)(this.get(pe), (0, set_operations_1.difference)(this.getBeginning(pe), new Set([SetCalculator_1.EPSILON]))));
}
}
exports.SucceedCalculator = SucceedCalculator;
//# sourceMappingURL=SucceedCalculator.js.map