UNPKG

intlayer-editor

Version:

Integrate the Intlayer visual editor into your Intlayer projects, enabling CMS-like content management with multilingual support.

1,558 lines 269 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/angular-html-ChYFFmg7.js","assets/html-BOjX3v2Q.js","assets/javascript-DLs729Nk.js","assets/css-BtVcDqlU.js","assets/angular-ts-CpuGw9DZ.js","assets/scss-Dq-LbI_c.js","assets/astro-B0lt4qz0.js","assets/json-D07AUpjp.js","assets/typescript-Cju7JbYj.js","assets/postcss-kj1IbjVd.js","assets/tsx-B9RA6cgQ.js","assets/blade-DtOFwYfC.js","assets/html-derivative-Cswrtqyq.js","assets/xml-BMzZeaqs.js","assets/java-BfXh-0uJ.js","assets/sql-DzUuSofg.js","assets/coffee-DJkIX6_2.js","assets/cpp-zh2ePAE_.js","assets/regexp-BxWeO75u.js","assets/glsl-CGsiYPcu.js","assets/c-C4VtT7JA.js","assets/graphql-oNSp8dGZ.js","assets/jsx-BPmvoin2.js","assets/haml-BJ44RGT2.js","assets/handlebars-DTnHNTeU.js","assets/yaml-B_vW5iTY.js","assets/http-B1QlEqj7.js","assets/bash-Bz2gZrDc.js","assets/hurl-Br_hZn4E.js","assets/csv-Ba84L8e5.js","assets/jinja-BAZ4h1JD.js","assets/jison-Bwp1bXaL.js","assets/julia-D0f5tMoo.js","assets/python-CrdIx4PZ.js","assets/r-oprfD2-9.js","assets/marko-rwefYVra.js","assets/less-BAzLMJNR.js","assets/mdc-ucHOH9Vl.js","assets/markdown-F_EULe_G.js","assets/php-CI-6KGJr.js","assets/pug-C-LeC0-n.js","assets/svelte-CYSO_rLN.js","assets/ts-tags-DCkNjov3.js","assets/vue-BQglRdBF.js","assets/vue-html-BS551n9F.js","assets/vue-vine-B43RKH9N.js","assets/stylus-DXFa_2Jl.js"])))=>i.map(i=>d[i]); import { _ as __vitePreload } from "./index-DqbmCrrm.js"; let ShikiError$2 = class ShikiError extends Error { constructor(message) { super(message); this.name = "ShikiError"; } }; function clone(something) { return doClone(something); } function doClone(something) { if (Array.isArray(something)) { return cloneArray(something); } if (something instanceof RegExp) { return something; } if (typeof something === "object") { return cloneObj(something); } return something; } function cloneArray(arr) { let r = []; for (let i = 0, len = arr.length; i < len; i++) { r[i] = doClone(arr[i]); } return r; } function cloneObj(obj) { let r = {}; for (let key2 in obj) { r[key2] = doClone(obj[key2]); } return r; } function mergeObjects(target, ...sources) { sources.forEach((source) => { for (let key2 in source) { target[key2] = source[key2]; } }); return target; } function basename(path) { const idx = ~path.lastIndexOf("/") || ~path.lastIndexOf("\\"); if (idx === 0) { return path; } else if (~idx === path.length - 1) { return basename(path.substring(0, path.length - 1)); } else { return path.substr(~idx + 1); } } var CAPTURING_REGEX_SOURCE = /\$(\d+)|\${(\d+):\/(downcase|upcase)}/g; var RegexSource = class { static hasCaptures(regexSource) { if (regexSource === null) { return false; } CAPTURING_REGEX_SOURCE.lastIndex = 0; return CAPTURING_REGEX_SOURCE.test(regexSource); } static replaceCaptures(regexSource, captureSource, captureIndices) { return regexSource.replace(CAPTURING_REGEX_SOURCE, (match, index, commandIndex, command) => { let capture = captureIndices[parseInt(index || commandIndex, 10)]; if (capture) { let result = captureSource.substring(capture.start, capture.end); while (result[0] === ".") { result = result.substring(1); } switch (command) { case "downcase": return result.toLowerCase(); case "upcase": return result.toUpperCase(); default: return result; } } else { return match; } }); } }; function strcmp(a, b) { if (a < b) { return -1; } if (a > b) { return 1; } return 0; } function strArrCmp(a, b) { if (a === null && b === null) { return 0; } if (!a) { return -1; } if (!b) { return 1; } let len1 = a.length; let len2 = b.length; if (len1 === len2) { for (let i = 0; i < len1; i++) { let res = strcmp(a[i], b[i]); if (res !== 0) { return res; } } return 0; } return len1 - len2; } function isValidHexColor(hex) { if (/^#[0-9a-f]{6}$/i.test(hex)) { return true; } if (/^#[0-9a-f]{8}$/i.test(hex)) { return true; } if (/^#[0-9a-f]{3}$/i.test(hex)) { return true; } if (/^#[0-9a-f]{4}$/i.test(hex)) { return true; } return false; } function escapeRegExpCharacters(value) { return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, "\\$&"); } var CachedFn = class { constructor(fn) { this.fn = fn; } cache = /* @__PURE__ */ new Map(); get(key2) { if (this.cache.has(key2)) { return this.cache.get(key2); } const value = this.fn(key2); this.cache.set(key2, value); return value; } }; var Theme = class { constructor(_colorMap, _defaults, _root) { this._colorMap = _colorMap; this._defaults = _defaults; this._root = _root; } static createFromRawTheme(source, colorMap) { return this.createFromParsedTheme(parseTheme(source), colorMap); } static createFromParsedTheme(source, colorMap) { return resolveParsedThemeRules(source, colorMap); } _cachedMatchRoot = new CachedFn( (scopeName) => this._root.match(scopeName) ); getColorMap() { return this._colorMap.getColorMap(); } getDefaults() { return this._defaults; } match(scopePath) { if (scopePath === null) { return this._defaults; } const scopeName = scopePath.scopeName; const matchingTrieElements = this._cachedMatchRoot.get(scopeName); const effectiveRule = matchingTrieElements.find( (v) => _scopePathMatchesParentScopes(scopePath.parent, v.parentScopes) ); if (!effectiveRule) { return null; } return new StyleAttributes( effectiveRule.fontStyle, effectiveRule.foreground, effectiveRule.background ); } }; var ScopeStack = class _ScopeStack { constructor(parent, scopeName) { this.parent = parent; this.scopeName = scopeName; } static push(path, scopeNames) { for (const name of scopeNames) { path = new _ScopeStack(path, name); } return path; } static from(...segments) { let result = null; for (let i = 0; i < segments.length; i++) { result = new _ScopeStack(result, segments[i]); } return result; } push(scopeName) { return new _ScopeStack(this, scopeName); } getSegments() { let item = this; const result = []; while (item) { result.push(item.scopeName); item = item.parent; } result.reverse(); return result; } toString() { return this.getSegments().join(" "); } extends(other) { if (this === other) { return true; } if (this.parent === null) { return false; } return this.parent.extends(other); } getExtensionIfDefined(base) { const result = []; let item = this; while (item && item !== base) { result.push(item.scopeName); item = item.parent; } return item === base ? result.reverse() : void 0; } }; function _scopePathMatchesParentScopes(scopePath, parentScopes) { if (parentScopes.length === 0) { return true; } for (let index = 0; index < parentScopes.length; index++) { let scopePattern = parentScopes[index]; let scopeMustMatch = false; if (scopePattern === ">") { if (index === parentScopes.length - 1) { return false; } scopePattern = parentScopes[++index]; scopeMustMatch = true; } while (scopePath) { if (_matchesScope(scopePath.scopeName, scopePattern)) { break; } if (scopeMustMatch) { return false; } scopePath = scopePath.parent; } if (!scopePath) { return false; } scopePath = scopePath.parent; } return true; } function _matchesScope(scopeName, scopePattern) { return scopePattern === scopeName || scopeName.startsWith(scopePattern) && scopeName[scopePattern.length] === "."; } var StyleAttributes = class { constructor(fontStyle, foregroundId, backgroundId) { this.fontStyle = fontStyle; this.foregroundId = foregroundId; this.backgroundId = backgroundId; } }; function parseTheme(source) { if (!source) { return []; } if (!source.settings || !Array.isArray(source.settings)) { return []; } let settings = source.settings; let result = [], resultLen = 0; for (let i = 0, len = settings.length; i < len; i++) { let entry = settings[i]; if (!entry.settings) { continue; } let scopes; if (typeof entry.scope === "string") { let _scope = entry.scope; _scope = _scope.replace(/^[,]+/, ""); _scope = _scope.replace(/[,]+$/, ""); scopes = _scope.split(","); } else if (Array.isArray(entry.scope)) { scopes = entry.scope; } else { scopes = [""]; } let fontStyle = -1; if (typeof entry.settings.fontStyle === "string") { fontStyle = 0; let segments = entry.settings.fontStyle.split(" "); for (let j = 0, lenJ = segments.length; j < lenJ; j++) { let segment = segments[j]; switch (segment) { case "italic": fontStyle = fontStyle | 1; break; case "bold": fontStyle = fontStyle | 2; break; case "underline": fontStyle = fontStyle | 4; break; case "strikethrough": fontStyle = fontStyle | 8; break; } } } let foreground = null; if (typeof entry.settings.foreground === "string" && isValidHexColor(entry.settings.foreground)) { foreground = entry.settings.foreground; } let background = null; if (typeof entry.settings.background === "string" && isValidHexColor(entry.settings.background)) { background = entry.settings.background; } for (let j = 0, lenJ = scopes.length; j < lenJ; j++) { let _scope = scopes[j].trim(); let segments = _scope.split(" "); let scope = segments[segments.length - 1]; let parentScopes = null; if (segments.length > 1) { parentScopes = segments.slice(0, segments.length - 1); parentScopes.reverse(); } result[resultLen++] = new ParsedThemeRule( scope, parentScopes, i, fontStyle, foreground, background ); } } return result; } var ParsedThemeRule = class { constructor(scope, parentScopes, index, fontStyle, foreground, background) { this.scope = scope; this.parentScopes = parentScopes; this.index = index; this.fontStyle = fontStyle; this.foreground = foreground; this.background = background; } }; var FontStyle = /* @__PURE__ */ ((FontStyle2) => { FontStyle2[FontStyle2["NotSet"] = -1] = "NotSet"; FontStyle2[FontStyle2["None"] = 0] = "None"; FontStyle2[FontStyle2["Italic"] = 1] = "Italic"; FontStyle2[FontStyle2["Bold"] = 2] = "Bold"; FontStyle2[FontStyle2["Underline"] = 4] = "Underline"; FontStyle2[FontStyle2["Strikethrough"] = 8] = "Strikethrough"; return FontStyle2; })(FontStyle || {}); function resolveParsedThemeRules(parsedThemeRules, _colorMap) { parsedThemeRules.sort((a, b) => { let r = strcmp(a.scope, b.scope); if (r !== 0) { return r; } r = strArrCmp(a.parentScopes, b.parentScopes); if (r !== 0) { return r; } return a.index - b.index; }); let defaultFontStyle = 0; let defaultForeground = "#000000"; let defaultBackground = "#ffffff"; while (parsedThemeRules.length >= 1 && parsedThemeRules[0].scope === "") { let incomingDefaults = parsedThemeRules.shift(); if (incomingDefaults.fontStyle !== -1) { defaultFontStyle = incomingDefaults.fontStyle; } if (incomingDefaults.foreground !== null) { defaultForeground = incomingDefaults.foreground; } if (incomingDefaults.background !== null) { defaultBackground = incomingDefaults.background; } } let colorMap = new ColorMap(_colorMap); let defaults = new StyleAttributes(defaultFontStyle, colorMap.getId(defaultForeground), colorMap.getId(defaultBackground)); let root2 = new ThemeTrieElement(new ThemeTrieElementRule(0, null, -1, 0, 0), []); for (let i = 0, len = parsedThemeRules.length; i < len; i++) { let rule = parsedThemeRules[i]; root2.insert(0, rule.scope, rule.parentScopes, rule.fontStyle, colorMap.getId(rule.foreground), colorMap.getId(rule.background)); } return new Theme(colorMap, defaults, root2); } var ColorMap = class { _isFrozen; _lastColorId; _id2color; _color2id; constructor(_colorMap) { this._lastColorId = 0; this._id2color = []; this._color2id = /* @__PURE__ */ Object.create(null); if (Array.isArray(_colorMap)) { this._isFrozen = true; for (let i = 0, len = _colorMap.length; i < len; i++) { this._color2id[_colorMap[i]] = i; this._id2color[i] = _colorMap[i]; } } else { this._isFrozen = false; } } getId(color) { if (color === null) { return 0; } color = color.toUpperCase(); let value = this._color2id[color]; if (value) { return value; } if (this._isFrozen) { throw new Error(`Missing color in color map - ${color}`); } value = ++this._lastColorId; this._color2id[color] = value; this._id2color[value] = color; return value; } getColorMap() { return this._id2color.slice(0); } }; var emptyParentScopes = Object.freeze([]); var ThemeTrieElementRule = class _ThemeTrieElementRule { scopeDepth; parentScopes; fontStyle; foreground; background; constructor(scopeDepth, parentScopes, fontStyle, foreground, background) { this.scopeDepth = scopeDepth; this.parentScopes = parentScopes || emptyParentScopes; this.fontStyle = fontStyle; this.foreground = foreground; this.background = background; } clone() { return new _ThemeTrieElementRule(this.scopeDepth, this.parentScopes, this.fontStyle, this.foreground, this.background); } static cloneArr(arr) { let r = []; for (let i = 0, len = arr.length; i < len; i++) { r[i] = arr[i].clone(); } return r; } acceptOverwrite(scopeDepth, fontStyle, foreground, background) { if (this.scopeDepth > scopeDepth) { console.log("how did this happen?"); } else { this.scopeDepth = scopeDepth; } if (fontStyle !== -1) { this.fontStyle = fontStyle; } if (foreground !== 0) { this.foreground = foreground; } if (background !== 0) { this.background = background; } } }; var ThemeTrieElement = class _ThemeTrieElement { constructor(_mainRule, rulesWithParentScopes = [], _children = {}) { this._mainRule = _mainRule; this._children = _children; this._rulesWithParentScopes = rulesWithParentScopes; } _rulesWithParentScopes; static _cmpBySpecificity(a, b) { if (a.scopeDepth !== b.scopeDepth) { return b.scopeDepth - a.scopeDepth; } let aParentIndex = 0; let bParentIndex = 0; while (true) { if (a.parentScopes[aParentIndex] === ">") { aParentIndex++; } if (b.parentScopes[bParentIndex] === ">") { bParentIndex++; } if (aParentIndex >= a.parentScopes.length || bParentIndex >= b.parentScopes.length) { break; } const parentScopeLengthDiff = b.parentScopes[bParentIndex].length - a.parentScopes[aParentIndex].length; if (parentScopeLengthDiff !== 0) { return parentScopeLengthDiff; } aParentIndex++; bParentIndex++; } return b.parentScopes.length - a.parentScopes.length; } match(scope) { if (scope !== "") { let dotIndex = scope.indexOf("."); let head2; let tail; if (dotIndex === -1) { head2 = scope; tail = ""; } else { head2 = scope.substring(0, dotIndex); tail = scope.substring(dotIndex + 1); } if (this._children.hasOwnProperty(head2)) { return this._children[head2].match(tail); } } const rules = this._rulesWithParentScopes.concat(this._mainRule); rules.sort(_ThemeTrieElement._cmpBySpecificity); return rules; } insert(scopeDepth, scope, parentScopes, fontStyle, foreground, background) { if (scope === "") { this._doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background); return; } let dotIndex = scope.indexOf("."); let head2; let tail; if (dotIndex === -1) { head2 = scope; tail = ""; } else { head2 = scope.substring(0, dotIndex); tail = scope.substring(dotIndex + 1); } let child; if (this._children.hasOwnProperty(head2)) { child = this._children[head2]; } else { child = new _ThemeTrieElement(this._mainRule.clone(), ThemeTrieElementRule.cloneArr(this._rulesWithParentScopes)); this._children[head2] = child; } child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background); } _doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background) { if (parentScopes === null) { this._mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background); return; } for (let i = 0, len = this._rulesWithParentScopes.length; i < len; i++) { let rule = this._rulesWithParentScopes[i]; if (strArrCmp(rule.parentScopes, parentScopes) === 0) { rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background); return; } } if (fontStyle === -1) { fontStyle = this._mainRule.fontStyle; } if (foreground === 0) { foreground = this._mainRule.foreground; } if (background === 0) { background = this._mainRule.background; } this._rulesWithParentScopes.push(new ThemeTrieElementRule(scopeDepth, parentScopes, fontStyle, foreground, background)); } }; var EncodedTokenMetadata = class _EncodedTokenMetadata { static toBinaryStr(encodedTokenAttributes) { return encodedTokenAttributes.toString(2).padStart(32, "0"); } static print(encodedTokenAttributes) { const languageId = _EncodedTokenMetadata.getLanguageId(encodedTokenAttributes); const tokenType = _EncodedTokenMetadata.getTokenType(encodedTokenAttributes); const fontStyle = _EncodedTokenMetadata.getFontStyle(encodedTokenAttributes); const foreground = _EncodedTokenMetadata.getForeground(encodedTokenAttributes); const background = _EncodedTokenMetadata.getBackground(encodedTokenAttributes); console.log({ languageId, tokenType, fontStyle, foreground, background }); } static getLanguageId(encodedTokenAttributes) { return (encodedTokenAttributes & 255) >>> 0; } static getTokenType(encodedTokenAttributes) { return (encodedTokenAttributes & 768) >>> 8; } static containsBalancedBrackets(encodedTokenAttributes) { return (encodedTokenAttributes & 1024) !== 0; } static getFontStyle(encodedTokenAttributes) { return (encodedTokenAttributes & 30720) >>> 11; } static getForeground(encodedTokenAttributes) { return (encodedTokenAttributes & 16744448) >>> 15; } static getBackground(encodedTokenAttributes) { return (encodedTokenAttributes & 4278190080) >>> 24; } /** * Updates the fields in `metadata`. * A value of `0`, `NotSet` or `null` indicates that the corresponding field should be left as is. */ static set(encodedTokenAttributes, languageId, tokenType, containsBalancedBrackets, fontStyle, foreground, background) { let _languageId = _EncodedTokenMetadata.getLanguageId(encodedTokenAttributes); let _tokenType = _EncodedTokenMetadata.getTokenType(encodedTokenAttributes); let _containsBalancedBracketsBit = _EncodedTokenMetadata.containsBalancedBrackets(encodedTokenAttributes) ? 1 : 0; let _fontStyle = _EncodedTokenMetadata.getFontStyle(encodedTokenAttributes); let _foreground = _EncodedTokenMetadata.getForeground(encodedTokenAttributes); let _background = _EncodedTokenMetadata.getBackground(encodedTokenAttributes); if (languageId !== 0) { _languageId = languageId; } if (tokenType !== 8) { _tokenType = fromOptionalTokenType(tokenType); } if (containsBalancedBrackets !== null) { _containsBalancedBracketsBit = containsBalancedBrackets ? 1 : 0; } if (fontStyle !== -1) { _fontStyle = fontStyle; } if (foreground !== 0) { _foreground = foreground; } if (background !== 0) { _background = background; } return (_languageId << 0 | _tokenType << 8 | _containsBalancedBracketsBit << 10 | _fontStyle << 11 | _foreground << 15 | _background << 24) >>> 0; } }; function toOptionalTokenType(standardType) { return standardType; } function fromOptionalTokenType(standardType) { return standardType; } function createMatchers(selector, matchesName) { const results = []; const tokenizer = newTokenizer(selector); let token = tokenizer.next(); while (token !== null) { let priority = 0; if (token.length === 2 && token.charAt(1) === ":") { switch (token.charAt(0)) { case "R": priority = 1; break; case "L": priority = -1; break; default: console.log(`Unknown priority ${token} in scope selector`); } token = tokenizer.next(); } let matcher = parseConjunction(); results.push({ matcher, priority }); if (token !== ",") { break; } token = tokenizer.next(); } return results; function parseOperand() { if (token === "-") { token = tokenizer.next(); const expressionToNegate = parseOperand(); return (matcherInput) => !!expressionToNegate && !expressionToNegate(matcherInput); } if (token === "(") { token = tokenizer.next(); const expressionInParents = parseInnerExpression(); if (token === ")") { token = tokenizer.next(); } return expressionInParents; } if (isIdentifier(token)) { const identifiers = []; do { identifiers.push(token); token = tokenizer.next(); } while (isIdentifier(token)); return (matcherInput) => matchesName(identifiers, matcherInput); } return null; } function parseConjunction() { const matchers = []; let matcher = parseOperand(); while (matcher) { matchers.push(matcher); matcher = parseOperand(); } return (matcherInput) => matchers.every((matcher2) => matcher2(matcherInput)); } function parseInnerExpression() { const matchers = []; let matcher = parseConjunction(); while (matcher) { matchers.push(matcher); if (token === "|" || token === ",") { do { token = tokenizer.next(); } while (token === "|" || token === ","); } else { break; } matcher = parseConjunction(); } return (matcherInput) => matchers.some((matcher2) => matcher2(matcherInput)); } } function isIdentifier(token) { return !!token && !!token.match(/[\w\.:]+/); } function newTokenizer(input) { let regex = /([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g; let match = regex.exec(input); return { next: () => { if (!match) { return null; } const res = match[0]; match = regex.exec(input); return res; } }; } function disposeOnigString(str) { if (typeof str.dispose === "function") { str.dispose(); } } var TopLevelRuleReference = class { constructor(scopeName) { this.scopeName = scopeName; } toKey() { return this.scopeName; } }; var TopLevelRepositoryRuleReference = class { constructor(scopeName, ruleName) { this.scopeName = scopeName; this.ruleName = ruleName; } toKey() { return `${this.scopeName}#${this.ruleName}`; } }; var ExternalReferenceCollector = class { _references = []; _seenReferenceKeys = /* @__PURE__ */ new Set(); get references() { return this._references; } visitedRule = /* @__PURE__ */ new Set(); add(reference) { const key2 = reference.toKey(); if (this._seenReferenceKeys.has(key2)) { return; } this._seenReferenceKeys.add(key2); this._references.push(reference); } }; var ScopeDependencyProcessor = class { constructor(repo, initialScopeName) { this.repo = repo; this.initialScopeName = initialScopeName; this.seenFullScopeRequests.add(this.initialScopeName); this.Q = [new TopLevelRuleReference(this.initialScopeName)]; } seenFullScopeRequests = /* @__PURE__ */ new Set(); seenPartialScopeRequests = /* @__PURE__ */ new Set(); Q; processQueue() { const q = this.Q; this.Q = []; const deps = new ExternalReferenceCollector(); for (const dep of q) { collectReferencesOfReference(dep, this.initialScopeName, this.repo, deps); } for (const dep of deps.references) { if (dep instanceof TopLevelRuleReference) { if (this.seenFullScopeRequests.has(dep.scopeName)) { continue; } this.seenFullScopeRequests.add(dep.scopeName); this.Q.push(dep); } else { if (this.seenFullScopeRequests.has(dep.scopeName)) { continue; } if (this.seenPartialScopeRequests.has(dep.toKey())) { continue; } this.seenPartialScopeRequests.add(dep.toKey()); this.Q.push(dep); } } } }; function collectReferencesOfReference(reference, baseGrammarScopeName, repo, result) { const selfGrammar = repo.lookup(reference.scopeName); if (!selfGrammar) { if (reference.scopeName === baseGrammarScopeName) { throw new Error(`No grammar provided for <${baseGrammarScopeName}>`); } return; } const baseGrammar = repo.lookup(baseGrammarScopeName); if (reference instanceof TopLevelRuleReference) { collectExternalReferencesInTopLevelRule({ baseGrammar, selfGrammar }, result); } else { collectExternalReferencesInTopLevelRepositoryRule( reference.ruleName, { baseGrammar, selfGrammar, repository: selfGrammar.repository }, result ); } const injections = repo.injections(reference.scopeName); if (injections) { for (const injection of injections) { result.add(new TopLevelRuleReference(injection)); } } } function collectExternalReferencesInTopLevelRepositoryRule(ruleName, context, result) { if (context.repository && context.repository[ruleName]) { const rule = context.repository[ruleName]; collectExternalReferencesInRules([rule], context, result); } } function collectExternalReferencesInTopLevelRule(context, result) { if (context.selfGrammar.patterns && Array.isArray(context.selfGrammar.patterns)) { collectExternalReferencesInRules( context.selfGrammar.patterns, { ...context, repository: context.selfGrammar.repository }, result ); } if (context.selfGrammar.injections) { collectExternalReferencesInRules( Object.values(context.selfGrammar.injections), { ...context, repository: context.selfGrammar.repository }, result ); } } function collectExternalReferencesInRules(rules, context, result) { for (const rule of rules) { if (result.visitedRule.has(rule)) { continue; } result.visitedRule.add(rule); const patternRepository = rule.repository ? mergeObjects({}, context.repository, rule.repository) : context.repository; if (Array.isArray(rule.patterns)) { collectExternalReferencesInRules(rule.patterns, { ...context, repository: patternRepository }, result); } const include = rule.include; if (!include) { continue; } const reference = parseInclude(include); switch (reference.kind) { case 0: collectExternalReferencesInTopLevelRule({ ...context, selfGrammar: context.baseGrammar }, result); break; case 1: collectExternalReferencesInTopLevelRule(context, result); break; case 2: collectExternalReferencesInTopLevelRepositoryRule(reference.ruleName, { ...context, repository: patternRepository }, result); break; case 3: case 4: const selfGrammar = reference.scopeName === context.selfGrammar.scopeName ? context.selfGrammar : reference.scopeName === context.baseGrammar.scopeName ? context.baseGrammar : void 0; if (selfGrammar) { const newContext = { baseGrammar: context.baseGrammar, selfGrammar, repository: patternRepository }; if (reference.kind === 4) { collectExternalReferencesInTopLevelRepositoryRule(reference.ruleName, newContext, result); } else { collectExternalReferencesInTopLevelRule(newContext, result); } } else { if (reference.kind === 4) { result.add(new TopLevelRepositoryRuleReference(reference.scopeName, reference.ruleName)); } else { result.add(new TopLevelRuleReference(reference.scopeName)); } } break; } } } var BaseReference = class { kind = 0; }; var SelfReference = class { kind = 1; }; var RelativeReference = class { constructor(ruleName) { this.ruleName = ruleName; } kind = 2; }; var TopLevelReference = class { constructor(scopeName) { this.scopeName = scopeName; } kind = 3; }; var TopLevelRepositoryReference = class { constructor(scopeName, ruleName) { this.scopeName = scopeName; this.ruleName = ruleName; } kind = 4; }; function parseInclude(include) { if (include === "$base") { return new BaseReference(); } else if (include === "$self") { return new SelfReference(); } const indexOfSharp = include.indexOf("#"); if (indexOfSharp === -1) { return new TopLevelReference(include); } else if (indexOfSharp === 0) { return new RelativeReference(include.substring(1)); } else { const scopeName = include.substring(0, indexOfSharp); const ruleName = include.substring(indexOfSharp + 1); return new TopLevelRepositoryReference(scopeName, ruleName); } } var HAS_BACK_REFERENCES = /\\(\d+)/; var BACK_REFERENCING_END = /\\(\d+)/g; var endRuleId = -1; var whileRuleId = -2; function ruleIdFromNumber(id) { return id; } function ruleIdToNumber(id) { return id; } var Rule = class { $location; id; _nameIsCapturing; _name; _contentNameIsCapturing; _contentName; constructor($location, id, name, contentName) { this.$location = $location; this.id = id; this._name = name || null; this._nameIsCapturing = RegexSource.hasCaptures(this._name); this._contentName = contentName || null; this._contentNameIsCapturing = RegexSource.hasCaptures(this._contentName); } get debugName() { const location = this.$location ? `${basename(this.$location.filename)}:${this.$location.line}` : "unknown"; return `${this.constructor.name}#${this.id} @ ${location}`; } getName(lineText, captureIndices) { if (!this._nameIsCapturing || this._name === null || lineText === null || captureIndices === null) { return this._name; } return RegexSource.replaceCaptures(this._name, lineText, captureIndices); } getContentName(lineText, captureIndices) { if (!this._contentNameIsCapturing || this._contentName === null) { return this._contentName; } return RegexSource.replaceCaptures(this._contentName, lineText, captureIndices); } }; var CaptureRule = class extends Rule { retokenizeCapturedWithRuleId; constructor($location, id, name, contentName, retokenizeCapturedWithRuleId) { super($location, id, name, contentName); this.retokenizeCapturedWithRuleId = retokenizeCapturedWithRuleId; } dispose() { } collectPatterns(grammar, out) { throw new Error("Not supported!"); } compile(grammar, endRegexSource) { throw new Error("Not supported!"); } compileAG(grammar, endRegexSource, allowA, allowG) { throw new Error("Not supported!"); } }; var MatchRule = class extends Rule { _match; captures; _cachedCompiledPatterns; constructor($location, id, name, match, captures) { super($location, id, name, null); this._match = new RegExpSource(match, this.id); this.captures = captures; this._cachedCompiledPatterns = null; } dispose() { if (this._cachedCompiledPatterns) { this._cachedCompiledPatterns.dispose(); this._cachedCompiledPatterns = null; } } get debugMatchRegExp() { return `${this._match.source}`; } collectPatterns(grammar, out) { out.push(this._match); } compile(grammar, endRegexSource) { return this._getCachedCompiledPatterns(grammar).compile(grammar); } compileAG(grammar, endRegexSource, allowA, allowG) { return this._getCachedCompiledPatterns(grammar).compileAG(grammar, allowA, allowG); } _getCachedCompiledPatterns(grammar) { if (!this._cachedCompiledPatterns) { this._cachedCompiledPatterns = new RegExpSourceList(); this.collectPatterns(grammar, this._cachedCompiledPatterns); } return this._cachedCompiledPatterns; } }; var IncludeOnlyRule = class extends Rule { hasMissingPatterns; patterns; _cachedCompiledPatterns; constructor($location, id, name, contentName, patterns) { super($location, id, name, contentName); this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; this._cachedCompiledPatterns = null; } dispose() { if (this._cachedCompiledPatterns) { this._cachedCompiledPatterns.dispose(); this._cachedCompiledPatterns = null; } } collectPatterns(grammar, out) { for (const pattern of this.patterns) { const rule = grammar.getRule(pattern); rule.collectPatterns(grammar, out); } } compile(grammar, endRegexSource) { return this._getCachedCompiledPatterns(grammar).compile(grammar); } compileAG(grammar, endRegexSource, allowA, allowG) { return this._getCachedCompiledPatterns(grammar).compileAG(grammar, allowA, allowG); } _getCachedCompiledPatterns(grammar) { if (!this._cachedCompiledPatterns) { this._cachedCompiledPatterns = new RegExpSourceList(); this.collectPatterns(grammar, this._cachedCompiledPatterns); } return this._cachedCompiledPatterns; } }; var BeginEndRule = class extends Rule { _begin; beginCaptures; _end; endHasBackReferences; endCaptures; applyEndPatternLast; hasMissingPatterns; patterns; _cachedCompiledPatterns; constructor($location, id, name, contentName, begin, beginCaptures, end, endCaptures, applyEndPatternLast, patterns) { super($location, id, name, contentName); this._begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; this._end = new RegExpSource(end ? end : "￿", -1); this.endHasBackReferences = this._end.hasBackReferences; this.endCaptures = endCaptures; this.applyEndPatternLast = applyEndPatternLast || false; this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; this._cachedCompiledPatterns = null; } dispose() { if (this._cachedCompiledPatterns) { this._cachedCompiledPatterns.dispose(); this._cachedCompiledPatterns = null; } } get debugBeginRegExp() { return `${this._begin.source}`; } get debugEndRegExp() { return `${this._end.source}`; } getEndWithResolvedBackReferences(lineText, captureIndices) { return this._end.resolveBackReferences(lineText, captureIndices); } collectPatterns(grammar, out) { out.push(this._begin); } compile(grammar, endRegexSource) { return this._getCachedCompiledPatterns(grammar, endRegexSource).compile(grammar); } compileAG(grammar, endRegexSource, allowA, allowG) { return this._getCachedCompiledPatterns(grammar, endRegexSource).compileAG(grammar, allowA, allowG); } _getCachedCompiledPatterns(grammar, endRegexSource) { if (!this._cachedCompiledPatterns) { this._cachedCompiledPatterns = new RegExpSourceList(); for (const pattern of this.patterns) { const rule = grammar.getRule(pattern); rule.collectPatterns(grammar, this._cachedCompiledPatterns); } if (this.applyEndPatternLast) { this._cachedCompiledPatterns.push(this._end.hasBackReferences ? this._end.clone() : this._end); } else { this._cachedCompiledPatterns.unshift(this._end.hasBackReferences ? this._end.clone() : this._end); } } if (this._end.hasBackReferences) { if (this.applyEndPatternLast) { this._cachedCompiledPatterns.setSource(this._cachedCompiledPatterns.length() - 1, endRegexSource); } else { this._cachedCompiledPatterns.setSource(0, endRegexSource); } } return this._cachedCompiledPatterns; } }; var BeginWhileRule = class extends Rule { _begin; beginCaptures; whileCaptures; _while; whileHasBackReferences; hasMissingPatterns; patterns; _cachedCompiledPatterns; _cachedCompiledWhilePatterns; constructor($location, id, name, contentName, begin, beginCaptures, _while, whileCaptures, patterns) { super($location, id, name, contentName); this._begin = new RegExpSource(begin, this.id); this.beginCaptures = beginCaptures; this.whileCaptures = whileCaptures; this._while = new RegExpSource(_while, whileRuleId); this.whileHasBackReferences = this._while.hasBackReferences; this.patterns = patterns.patterns; this.hasMissingPatterns = patterns.hasMissingPatterns; this._cachedCompiledPatterns = null; this._cachedCompiledWhilePatterns = null; } dispose() { if (this._cachedCompiledPatterns) { this._cachedCompiledPatterns.dispose(); this._cachedCompiledPatterns = null; } if (this._cachedCompiledWhilePatterns) { this._cachedCompiledWhilePatterns.dispose(); this._cachedCompiledWhilePatterns = null; } } get debugBeginRegExp() { return `${this._begin.source}`; } get debugWhileRegExp() { return `${this._while.source}`; } getWhileWithResolvedBackReferences(lineText, captureIndices) { return this._while.resolveBackReferences(lineText, captureIndices); } collectPatterns(grammar, out) { out.push(this._begin); } compile(grammar, endRegexSource) { return this._getCachedCompiledPatterns(grammar).compile(grammar); } compileAG(grammar, endRegexSource, allowA, allowG) { return this._getCachedCompiledPatterns(grammar).compileAG(grammar, allowA, allowG); } _getCachedCompiledPatterns(grammar) { if (!this._cachedCompiledPatterns) { this._cachedCompiledPatterns = new RegExpSourceList(); for (const pattern of this.patterns) { const rule = grammar.getRule(pattern); rule.collectPatterns(grammar, this._cachedCompiledPatterns); } } return this._cachedCompiledPatterns; } compileWhile(grammar, endRegexSource) { return this._getCachedCompiledWhilePatterns(grammar, endRegexSource).compile(grammar); } compileWhileAG(grammar, endRegexSource, allowA, allowG) { return this._getCachedCompiledWhilePatterns(grammar, endRegexSource).compileAG(grammar, allowA, allowG); } _getCachedCompiledWhilePatterns(grammar, endRegexSource) { if (!this._cachedCompiledWhilePatterns) { this._cachedCompiledWhilePatterns = new RegExpSourceList(); this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences ? this._while.clone() : this._while); } if (this._while.hasBackReferences) { this._cachedCompiledWhilePatterns.setSource(0, endRegexSource ? endRegexSource : "￿"); } return this._cachedCompiledWhilePatterns; } }; var RuleFactory = class _RuleFactory { static createCaptureRule(helper, $location, name, contentName, retokenizeCapturedWithRuleId) { return helper.registerRule((id) => { return new CaptureRule($location, id, name, contentName, retokenizeCapturedWithRuleId); }); } static getCompiledRuleId(desc, helper, repository) { if (!desc.id) { helper.registerRule((id) => { desc.id = id; if (desc.match) { return new MatchRule( desc.$vscodeTextmateLocation, desc.id, desc.name, desc.match, _RuleFactory._compileCaptures(desc.captures, helper, repository) ); } if (typeof desc.begin === "undefined") { if (desc.repository) { repository = mergeObjects({}, repository, desc.repository); } let patterns = desc.patterns; if (typeof patterns === "undefined" && desc.include) { patterns = [{ include: desc.include }]; } return new IncludeOnlyRule( desc.$vscodeTextmateLocation, desc.id, desc.name, desc.contentName, _RuleFactory._compilePatterns(patterns, helper, repository) ); } if (desc.while) { return new BeginWhileRule( desc.$vscodeTextmateLocation, desc.id, desc.name, desc.contentName, desc.begin, _RuleFactory._compileCaptures(desc.beginCaptures || desc.captures, helper, repository), desc.while, _RuleFactory._compileCaptures(desc.whileCaptures || desc.captures, helper, repository), _RuleFactory._compilePatterns(desc.patterns, helper, repository) ); } return new BeginEndRule( desc.$vscodeTextmateLocation, desc.id, desc.name, desc.contentName, desc.begin, _RuleFactory._compileCaptures(desc.beginCaptures || desc.captures, helper, repository), desc.end, _RuleFactory._compileCaptures(desc.endCaptures || desc.captures, helper, repository), desc.applyEndPatternLast, _RuleFactory._compilePatterns(desc.patterns, helper, repository) ); }); } return desc.id; } static _compileCaptures(captures, helper, repository) { let r = []; if (captures) { let maximumCaptureId = 0; for (const captureId in captures) { if (captureId === "$vscodeTextmateLocation") { continue; } const numericCaptureId = parseInt(captureId, 10); if (numericCaptureId > maximumCaptureId) { maximumCaptureId = numericCaptureId; } } for (let i = 0; i <= maximumCaptureId; i++) { r[i] = null; } for (const captureId in captures) { if (captureId === "$vscodeTextmateLocation") { continue; } const numericCaptureId = parseInt(captureId, 10); let retokenizeCapturedWithRuleId = 0; if (captures[captureId].patterns) { retokenizeCapturedWithRuleId = _RuleFactory.getCompiledRuleId(captures[captureId], helper, repository); } r[numericCaptureId] = _RuleFactory.createCaptureRule(helper, captures[captureId].$vscodeTextmateLocation, captures[captureId].name, captures[captureId].contentName, retokenizeCapturedWithRuleId); } } return r; } static _compilePatterns(patterns, helper, repository) { let r = []; if (patterns) { for (let i = 0, len = patterns.length; i < len; i++) { const pattern = patterns[i]; let ruleId = -1; if (pattern.include) { const reference = parseInclude(pattern.include); switch (reference.kind) { case 0: case 1: ruleId = _RuleFactory.getCompiledRuleId(repository[pattern.include], helper, repository); break; case 2: let localIncludedRule = repository[reference.ruleName]; if (localIncludedRule) { ruleId = _RuleFactory.getCompiledRuleId(localIncludedRule, helper, repository); } break; case 3: case 4: const externalGrammarName = reference.scopeName; const externalGrammarInclude = reference.kind === 4 ? reference.ruleName : null; const externalGrammar = helper.getExternalGrammar(externalGrammarName, repository); if (externalGrammar) { if (externalGrammarInclude) { let externalIncludedRule = externalGrammar.repository[externalGrammarInclude]; if (externalIncludedRule) { ruleId = _RuleFactory.getCompiledRuleId(externalIncludedRule, helper, externalGrammar.repository); } } else { ruleId = _RuleFactory.getCompiledRuleId(externalGrammar.repository.$self, helper, externalGrammar.repository); } } break; } } else { ruleId = _RuleFactory.getCompiledRuleId(pattern, helper, repository); } if (ruleId !== -1) { const rule = helper.getRule(ruleId); let skipRule = false; if (rule instanceof IncludeOnlyRule || rule instanceof BeginEndRule || rule instanceof BeginWhileRule) { if (rule.hasMissingPatterns && rule.patterns.length === 0) { skipRule = true; } } if (skipRule) { continue; } r.push(ruleId); } } } return { patterns: r, hasMissingPatterns: (patterns ? patterns.length : 0) !== r.length }; } }; var RegExpSource = class _RegExpSource { source; ruleId; hasAnchor; hasBackReferences; _anchorCache; constructor(regExpSource, ruleId) { if (regExpSource && typeof regExpSource === "string") { const len = regExpSource.length; let lastPushedPos = 0; let output = []; let hasAnchor = false; for (let pos = 0; pos < len; pos++) { const ch = regExpSource.charAt(pos); if (ch === "\\") { if (pos + 1 < len) { const nextCh = regExpSource.charAt(pos + 1); if (nextCh === "z") { output.push(regExpSource.substring(lastPushedPos, pos)); output.push("$(?!\\n)(?<!\\n)"); lastPushedPos = pos + 2; } else if (nextCh === "A" || nextCh === "G") { hasAnchor = true; } pos++; } } } this.hasAnchor = hasAnchor; if (lastPushedPos === 0) { this.source = regExpSource; } else { output.push(regExpSource.substring(lastPushedPos, len)); this.source = output.join(""); } } else { this.hasAnchor = false; this.source = regExpSource; } if (this.hasAnchor) { this._anchorCache = this._buildAnchorCache(); } else { this._anchorCache = null; } this.ruleId = ruleId; if (typeof this.source === "string") { this.hasBackReferences = HAS_BACK_REFERENCES.test(this.source); } else { this.hasBackReferences = false; } } clone() { return new _RegExpSource(this.source, this.ruleId); } setSource(newSource) { if (this.source === newSource) { return; } this.source = newSource; if (this.hasAnchor) { this._anchorCache = this._buildAnchorCache(); } } resolveBackReferences(lineText, captureIndices) { if (typeof this.source !== "string") { throw new Error("This method should only be called if the source is a string"); } let capturedValues = captureIndices.map((capture) => { return lineText.substring(capture.start, capture.end); }); BACK_REFERENCING_END.lastIndex = 0; return this.source.replace(BACK_REFERENCING_END, (match, g1) => { return escapeRegExpCharacters(capturedValues[parseInt(g1, 10)] || ""); }); } _buildAnchorCache() { if (typeof this.source !== "string") { throw new Error("This method should only be called if the source is a string"); } let A0_G0_result = []; let A0_G1_result = []; let A1_G0_result = []; let A1_G1_result = []; let pos, len, ch, nextCh; for (pos = 0, len = this.source.length; pos < len; pos++) { ch = this.source.charAt(pos); A0_G0_result[pos] = ch; A0_G1_result[pos] = ch; A1_G0_result[pos] = ch; A1_G1_result[pos] = ch; if (ch === "\\") { if (pos + 1 < len) { nextCh = this.source.charAt(pos + 1); if (nextCh === "A") { A0_G0_result[pos + 1] = "￿"; A0_G1_result[pos + 1] = "￿"; A1_G0_result[pos + 1] = "A"; A1_G1_result[pos + 1] = "A"; } else if (nextCh === "G") { A0_G0_result[pos + 1] = "￿"; A0_G1_result[pos + 1] = "G"; A1_G0_result[pos + 1] = "￿"; A1_G1_result[pos + 1] = "G"; } else { A0_G0_result[pos + 1] = nextCh; A0_G1_result[pos + 1] = nextCh; A1_G0_result[pos + 1] = nextCh; A1_G1_result[pos + 1] = nextCh; } pos++; } } } return { A0_G0: A0_G0_result.join(""), A0_G1: A0_G1_result.join(""), A1_G0: A1_G0_result.join(""), A1_G1: A1_G1_result.join("") }; } resolveAnchors(allowA, allowG) { if (!this.hasAnchor || !this._anchorCache || typeof this.source !== "string") { return this.source; } if (allowA) { if (allowG) { return this._anchorCache.A1_G1; } else { return this._anchorCache.A1_G0; } } else { if (allowG) { return this._anchorCache.A0_G1; } else { return this._anchorCache.A0_G0; } } } }; var RegExpSourceList = class { _items; _hasAnchors; _cached; _anchorCache; constructor() { this._items = []; this._hasAnchors = false; this._cached = null; this._anchorCache = { A0_G0: null, A0_G1: null, A1_G0: null, A1_G1