UNPKG

pegisland

Version:

General PEG-based parser supporting island grammars with lake symbols

66 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AltCalculator = void 0; const set_operations_1 = require("../set-operations"); const SetCalculator_1 = require("./SetCalculator"); const TopDownSetCalculator_1 = require("./TopDownSetCalculator"); const utils_1 = require("../utils"); class AltCalculator extends TopDownSetCalculator_1.TopDownSetCalculator { constructor(rules, beginning, succeed) { super(rules, beginning); this.succeed = succeed; } visitZeroOrMore(pe) { this.propagateWithSucceed(pe); } visitOneOrMore(pe) { this.propagateWithSucceed(pe); } visitOptional(pe) { this.propagateWithSucceed(pe); } visitAnd(_pe) { // Do nothing } visitNot(_pe) { // Do nothing } visitSequence(pe) { for (const ei of pe.operands) { this.propagate(pe, ei); if (!this.getBeginning(ei).has(SetCalculator_1.EPSILON)) { break; } } } visitOrderedChoice(pe) { pe.operands.forEach((ei, i) => { this.set(ei, (0, set_operations_1.union)(this.get(pe), (0, set_operations_1.difference)((0, set_operations_1.union)(new Set([]), ...pe.operands .filter((_ej, j) => j > i) .map((ej) => this.getBeginning(ej))), new Set([SetCalculator_1.EPSILON])))); }); } 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.propagateWithSucceed(pe); } propagateWithSucceed(pe) { this.set(pe.operand, (0, set_operations_1.union)(this.get(pe), this.getSucceed(pe))); } getSucceed(pe) { return (0, utils_1.getValue)(this.succeed, pe); } } exports.AltCalculator = AltCalculator; //# sourceMappingURL=AltCalculator.js.map