UNPKG

chevrotain

Version:

Chevrotain is a high performance fault tolerant javascript parsing DSL for building recursive decent parsers

68 lines 3.11 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.buildInProdFollowPrefix = exports.buildBetweenProdsFollowPrefix = exports.computeAllProdsFollows = exports.ResyncFollowsWalker = void 0; var rest_1 = require("./rest"); var first_1 = require("./first"); var utils_1 = require("../../utils/utils"); var constants_1 = require("../constants"); var gast_public_1 = require("./gast/gast_public"); // This ResyncFollowsWalker computes all of the follows required for RESYNC // (skipping reference production). var ResyncFollowsWalker = /** @class */ (function (_super) { __extends(ResyncFollowsWalker, _super); function ResyncFollowsWalker(topProd) { var _this = _super.call(this) || this; _this.topProd = topProd; _this.follows = {}; return _this; } ResyncFollowsWalker.prototype.startWalking = function () { this.walk(this.topProd); return this.follows; }; ResyncFollowsWalker.prototype.walkTerminal = function (terminal, currRest, prevRest) { // do nothing! just like in the public sector after 13:00 }; ResyncFollowsWalker.prototype.walkProdRef = function (refProd, currRest, prevRest) { var followName = buildBetweenProdsFollowPrefix(refProd.referencedRule, refProd.idx) + this.topProd.name; var fullRest = currRest.concat(prevRest); var restProd = new gast_public_1.Alternative({ definition: fullRest }); var t_in_topProd_follows = first_1.first(restProd); this.follows[followName] = t_in_topProd_follows; }; return ResyncFollowsWalker; }(rest_1.RestWalker)); exports.ResyncFollowsWalker = ResyncFollowsWalker; function computeAllProdsFollows(topProductions) { var reSyncFollows = {}; utils_1.forEach(topProductions, function (topProd) { var currRefsFollow = new ResyncFollowsWalker(topProd).startWalking(); utils_1.assign(reSyncFollows, currRefsFollow); }); return reSyncFollows; } exports.computeAllProdsFollows = computeAllProdsFollows; function buildBetweenProdsFollowPrefix(inner, occurenceInParent) { return inner.name + occurenceInParent + constants_1.IN; } exports.buildBetweenProdsFollowPrefix = buildBetweenProdsFollowPrefix; function buildInProdFollowPrefix(terminal) { var terminalName = terminal.terminalType.name; return terminalName + terminal.idx + constants_1.IN; } exports.buildInProdFollowPrefix = buildInProdFollowPrefix; //# sourceMappingURL=follow.js.map