UNPKG

pegisland

Version:

General PEG-based parser supporting island grammars with lake symbols

39 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetCalculator = exports.EPSILON = void 0; // Copyright (C) 2021- Katsumi Okuda. All rights reserved. const ExpressionCollector_1 = require("../ExpressionCollector"); const ParsingExpression_1 = require("../ParsingExpression"); const utils_1 = require("../utils"); exports.EPSILON = new ParsingExpression_1.Sequence([]); class SetCalculator { constructor(rules, isPostorder) { this.expressions = new ExpressionCollector_1.ExpressionCollector().collect(rules); if (!isPostorder) { this.expressions.reverse(); } this.peSet = new Map(this.expressions.map((pe) => [pe, new Set()])); } calculate() { for (;;) { const sizeMap = new Map(this.expressions.map((pe) => [pe, this.get(pe).size])); this.expressions.forEach((pe) => pe.accept(this)); const wasChanged = this.expressions.some((pe) => sizeMap.get(pe) !== this.get(pe).size); if (!wasChanged) { break; } } return this.peSet; } get(pe) { return (0, utils_1.getValue)(this.peSet, pe); } set(pe, set) { this.peSet.set(pe, set); } propagate(src, dst) { this.set(dst, new Set(this.get(src))); } } exports.SetCalculator = SetCalculator; //# sourceMappingURL=SetCalculator.js.map