UNPKG

cm-tarnation

Version:

An alternative parser for CodeMirror 6

30 lines 1.23 kB
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { LookupMatcher } from "../matchers/lookup"; import { Rule } from "./rule"; /** * A {@link Rule} subclass that uses a {@link LookupMatcher} for the * underlying pattern. This is a list of string options converted into a * very quick to match list internally. */ export class LookupRule extends Rule { /** * @param repo - The {@link Repository} to add this rule to. * @param rule - The rule definition. */ constructor(repo, rule) { super(repo, rule); let strings = rule.lookup; if (typeof strings === "string") { const [, ident] = strings.split(":"); const value = repo.variables[ident]; if (!Array.isArray(value)) throw new Error(`Variable ${ident} is not an array`); strings = value; } this.lookup = new LookupMatcher(strings, repo.ignoreCase, repo.variables); this.exec = this.lookup.match.bind(this.lookup); } } //# sourceMappingURL=lookup.js.map