UNPKG

pegisland

Version:

General PEG-based parser supporting island grammars with lake symbols

66 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Indexer = void 0; // Copyright (C) 2022- Katsumi Okuda. All rights reserved. const BottomUpParser_1 = require("./BottomUpParser"); const DepthFirstTraverser_1 = require("./DepthFirstTraverser"); class Indexer { constructor() { this.indexMap = new Map(); this.index = 0; this.terminals = []; } build(peg) { const traverser = new DepthFirstTraverser_1.DepthFirstTraverser(this, (0, BottomUpParser_1.getTopLevelExpressions)(peg)); traverser.traverse(); return [this.indexMap, this.terminals]; } giveIndex(pe) { this.indexMap.set(pe, this.index++); } visitNonterminal(pe) { this.giveIndex(pe); } visitTerminal(pe) { this.terminals.push(pe); this.giveIndex(pe); } visitZeroOrMore(pe) { this.giveIndex(pe); } visitOneOrMore(pe) { this.giveIndex(pe); } visitOptional(pe) { this.giveIndex(pe); } visitAnd(pe) { this.giveIndex(pe); } visitNot(pe) { this.giveIndex(pe); } visitSequence(pe) { this.giveIndex(pe); } visitOrderedChoice(pe) { this.giveIndex(pe); } visitGrouping(pe) { this.giveIndex(pe); } visitRewriting(pe) { this.giveIndex(pe); } visitColon(pe) { this.giveIndex(pe); } visitColonNot(pe) { this.giveIndex(pe); } visitLake(pe) { this.giveIndex(pe); } } exports.Indexer = Indexer; //# sourceMappingURL=Indexer.js.map