UNPKG

pegisland

Version:

General PEG-based parser supporting island grammars with lake symbols

69 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FirstCalculator = void 0; const set_operations_1 = require("../set-operations"); const SetCalculator_1 = require("./SetCalculator"); class FirstCalculator extends SetCalculator_1.SetCalculator { constructor(rules) { super(rules, false); } visitNonterminal(pe) { this.set(pe, (0, set_operations_1.union)(this.get(pe.rule.rhs), new Set([pe]))); } visitTerminal(pe) { this.set(pe, new Set([pe])); } visitZeroOrMore(pe) { this.propagateOperandWithEpsilon(pe); } visitOneOrMore(pe) { this.propagateOperand(pe); } visitOptional(pe) { this.propagateOperandWithEpsilon(pe); } visitAnd(pe) { this.propagateOperand(pe); } visitNot(pe) { this.set(pe, new Set([SetCalculator_1.EPSILON])); } visitSequence(pe) { let newS = new Set([SetCalculator_1.EPSILON]); for (const operand of pe.operands) { const t = this.get(operand); newS = (0, set_operations_1.union)(newS, t); if (!t.has(SetCalculator_1.EPSILON)) { newS.delete(SetCalculator_1.EPSILON); break; } } this.set(pe, newS); } visitOrderedChoice(pe) { this.set(pe, (0, set_operations_1.union)(...pe.operands.map((operand) => this.get(operand)))); } visitGrouping(pe) { this.propagateOperand(pe); } visitRewriting(pe) { this.propagateOperand(pe); } visitColon(pe) { this.propagate(pe.rhs, pe); } visitColonNot(pe) { this.propagate(pe.lhs, pe); } visitLake(pe) { this.propagateOperandWithEpsilon(pe); } propagateOperandWithEpsilon(pe) { this.set(pe, (0, set_operations_1.union)(this.get(pe.operand), new Set([SetCalculator_1.EPSILON]))); } propagateOperand(pe) { this.propagate(pe.operand, pe); } } exports.FirstCalculator = FirstCalculator; //# sourceMappingURL=FirstCalculator.js.map