mermaid
Version:
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
4 lines • 1.53 MB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/ral.js", "../../../../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/is.js", "../../../../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/events.js", "../../../../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/cancellation.js", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/index.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/cst-utils.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/syntax-tree.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/stream.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/grammar-utils.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/errors.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/languages/generated/ast.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/ast-utils.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/regexp-utils.ts", "../../../../../node_modules/.pnpm/@chevrotain+regexp-to-ast@11.0.3/node_modules/@chevrotain/regexp-to-ast/src/utils.ts", "../../../../../node_modules/.pnpm/@chevrotain+regexp-to-ast@11.0.3/node_modules/@chevrotain/regexp-to-ast/src/character-classes.ts", "../../../../../node_modules/.pnpm/@chevrotain+regexp-to-ast@11.0.3/node_modules/@chevrotain/regexp-to-ast/src/regexp-parser.ts", "../../../../../node_modules/.pnpm/@chevrotain+regexp-to-ast@11.0.3/node_modules/@chevrotain/regexp-to-ast/src/base-regexp-visitor.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/languages/grammar-config.ts", "../../../../../node_modules/.pnpm/@chevrotain+utils@11.0.3/node_modules/@chevrotain/utils/src/print.ts", "../../../../../node_modules/.pnpm/@chevrotain+utils@11.0.3/node_modules/@chevrotain/utils/src/timer.ts", "../../../../../node_modules/.pnpm/@chevrotain+utils@11.0.3/node_modules/@chevrotain/utils/src/to-fast-properties.ts", "../../../../../node_modules/.pnpm/@chevrotain+gast@11.0.3/node_modules/@chevrotain/gast/src/model.ts", "../../../../../node_modules/.pnpm/@chevrotain+gast@11.0.3/node_modules/@chevrotain/gast/src/visitor.ts", "../../../../../node_modules/.pnpm/@chevrotain+gast@11.0.3/node_modules/@chevrotain/gast/src/helpers.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/rest.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/first.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/constants.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/follow.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/reg_exp_parser.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/reg_exp.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/lexer.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/tokens.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/lexer_errors_public.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/lexer_public.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/scan/tokens_public.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/errors_public.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/resolver.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/interpreter.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/lookahead.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/checks.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/gast/gast_resolver_public.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/exceptions_public.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/recoverable.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/keys.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/grammar/llk_lookahead.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/looksahead.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/cst/cst.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/lang/lang_extensions.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/cst/cst_visitor.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/tree_builder.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/lexer_adapter.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/recognizer_api.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/recognizer_engine.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/error_handler.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/context_assist.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/gast_recorder.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/traits/perf_tracer.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/utils/apply_mixins.ts", "../../../../../node_modules/.pnpm/chevrotain@11.0.3/node_modules/chevrotain/src/parse/parser/parser.ts", "../../../../../node_modules/.pnpm/chevrotain-allstar@0.3.1_chevrotain@11.0.3/node_modules/chevrotain-allstar/src/atn.ts", "../../../../../node_modules/.pnpm/chevrotain-allstar@0.3.1_chevrotain@11.0.3/node_modules/chevrotain-allstar/src/dfa.ts", "../../../../../node_modules/.pnpm/chevrotain-allstar@0.3.1_chevrotain@11.0.3/node_modules/chevrotain-allstar/src/all-star-lookahead.ts", "../../../../../node_modules/.pnpm/vscode-languageserver-types@3.17.5/node_modules/vscode-languageserver-types/lib/esm/main.js", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/cst-node-builder.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/langium-parser.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/parser-builder-base.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/completion-parser-builder.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/langium-parser-builder.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/token-builder.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/value-converter.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/cancellation.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/promise-utils.ts", "../../../../../node_modules/.pnpm/vscode-languageserver-textdocument@1.0.12/node_modules/vscode-languageserver-textdocument/lib/esm/main.js", "webpack://LIB/node_modules/path-browserify/index.js", "webpack://LIB/webpack/bootstrap", "webpack://LIB/webpack/runtime/define%20property%20getters", "webpack://LIB/webpack/runtime/hasOwnProperty%20shorthand", "webpack://LIB/webpack/runtime/make%20namespace%20object", "webpack://LIB/src/platform.ts", "webpack://LIB/src/uri.ts", "webpack://LIB/src/utils.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/uri-utils.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/documents.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/references/linker.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/references/name-provider.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/references/references.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/collections.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/references/scope-computation.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/references/scope.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/caching.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/references/scope-provider.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/serializer/json-serializer.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/service-registry.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/validation/validation-registry.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/validation/document-validator.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/ast-descriptions.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/ast-node-locator.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/event.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/configuration.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/disposable.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/document-builder.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/index-manager.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/workspace-manager.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/lexer.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/documentation/jsdoc.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/documentation/documentation-provider.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/documentation/comment-provider.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/async-parser.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/workspace-lock.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/serializer/hydrator.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/default-module.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/dependency-injection.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/parser/indentation-aware.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/index.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/workspace/file-system-provider.ts", "../../../../../node_modules/.pnpm/langium@3.3.1/node_modules/langium/src/utils/grammar-loader.ts", "../../../../parser/dist/chunks/mermaid-parser.core/chunk-YAJQ3QCK.mjs"],
"sourcesContent": ["\"use strict\";\n/* --------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n * ------------------------------------------------------------------------------------------ */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nlet _ral;\nfunction RAL() {\n if (_ral === undefined) {\n throw new Error(`No runtime abstraction layer installed`);\n }\n return _ral;\n}\n(function (RAL) {\n function install(ral) {\n if (ral === undefined) {\n throw new Error(`No runtime abstraction layer provided`);\n }\n _ral = ral;\n }\n RAL.install = install;\n})(RAL || (RAL = {}));\nexports.default = RAL;\n", "\"use strict\";\n/* --------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n * ------------------------------------------------------------------------------------------ */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.stringArray = exports.array = exports.func = exports.error = exports.number = exports.string = exports.boolean = void 0;\nfunction boolean(value) {\n return value === true || value === false;\n}\nexports.boolean = boolean;\nfunction string(value) {\n return typeof value === 'string' || value instanceof String;\n}\nexports.string = string;\nfunction number(value) {\n return typeof value === 'number' || value instanceof Number;\n}\nexports.number = number;\nfunction error(value) {\n return value instanceof Error;\n}\nexports.error = error;\nfunction func(value) {\n return typeof value === 'function';\n}\nexports.func = func;\nfunction array(value) {\n return Array.isArray(value);\n}\nexports.array = array;\nfunction stringArray(value) {\n return array(value) && value.every(elem => string(elem));\n}\nexports.stringArray = stringArray;\n", "\"use strict\";\n/* --------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n * ------------------------------------------------------------------------------------------ */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Emitter = exports.Event = void 0;\nconst ral_1 = require(\"./ral\");\nvar Event;\n(function (Event) {\n const _disposable = { dispose() { } };\n Event.None = function () { return _disposable; };\n})(Event || (exports.Event = Event = {}));\nclass CallbackList {\n add(callback, context = null, bucket) {\n if (!this._callbacks) {\n this._callbacks = [];\n this._contexts = [];\n }\n this._callbacks.push(callback);\n this._contexts.push(context);\n if (Array.isArray(bucket)) {\n bucket.push({ dispose: () => this.remove(callback, context) });\n }\n }\n remove(callback, context = null) {\n if (!this._callbacks) {\n return;\n }\n let foundCallbackWithDifferentContext = false;\n for (let i = 0, len = this._callbacks.length; i < len; i++) {\n if (this._callbacks[i] === callback) {\n if (this._contexts[i] === context) {\n // callback & context match => remove it\n this._callbacks.splice(i, 1);\n this._contexts.splice(i, 1);\n return;\n }\n else {\n foundCallbackWithDifferentContext = true;\n }\n }\n }\n if (foundCallbackWithDifferentContext) {\n throw new Error('When adding a listener with a context, you should remove it with the same context');\n }\n }\n invoke(...args) {\n if (!this._callbacks) {\n return [];\n }\n const ret = [], callbacks = this._callbacks.slice(0), contexts = this._contexts.slice(0);\n for (let i = 0, len = callbacks.length; i < len; i++) {\n try {\n ret.push(callbacks[i].apply(contexts[i], args));\n }\n catch (e) {\n // eslint-disable-next-line no-console\n (0, ral_1.default)().console.error(e);\n }\n }\n return ret;\n }\n isEmpty() {\n return !this._callbacks || this._callbacks.length === 0;\n }\n dispose() {\n this._callbacks = undefined;\n this._contexts = undefined;\n }\n}\nclass Emitter {\n constructor(_options) {\n this._options = _options;\n }\n /**\n * For the public to allow to subscribe\n * to events from this Emitter\n */\n get event() {\n if (!this._event) {\n this._event = (listener, thisArgs, disposables) => {\n if (!this._callbacks) {\n this._callbacks = new CallbackList();\n }\n if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {\n this._options.onFirstListenerAdd(this);\n }\n this._callbacks.add(listener, thisArgs);\n const result = {\n dispose: () => {\n if (!this._callbacks) {\n // disposable is disposed after emitter is disposed.\n return;\n }\n this._callbacks.remove(listener, thisArgs);\n result.dispose = Emitter._noop;\n if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {\n this._options.onLastListenerRemove(this);\n }\n }\n };\n if (Array.isArray(disposables)) {\n disposables.push(result);\n }\n return result;\n };\n }\n return this._event;\n }\n /**\n * To be kept private to fire an event to\n * subscribers\n */\n fire(event) {\n if (this._callbacks) {\n this._callbacks.invoke.call(this._callbacks, event);\n }\n }\n dispose() {\n if (this._callbacks) {\n this._callbacks.dispose();\n this._callbacks = undefined;\n }\n }\n}\nexports.Emitter = Emitter;\nEmitter._noop = function () { };\n", "\"use strict\";\n/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CancellationTokenSource = exports.CancellationToken = void 0;\nconst ral_1 = require(\"./ral\");\nconst Is = require(\"./is\");\nconst events_1 = require(\"./events\");\nvar CancellationToken;\n(function (CancellationToken) {\n CancellationToken.None = Object.freeze({\n isCancellationRequested: false,\n onCancellationRequested: events_1.Event.None\n });\n CancellationToken.Cancelled = Object.freeze({\n isCancellationRequested: true,\n onCancellationRequested: events_1.Event.None\n });\n function is(value) {\n const candidate = value;\n return candidate && (candidate === CancellationToken.None\n || candidate === CancellationToken.Cancelled\n || (Is.boolean(candidate.isCancellationRequested) && !!candidate.onCancellationRequested));\n }\n CancellationToken.is = is;\n})(CancellationToken || (exports.CancellationToken = CancellationToken = {}));\nconst shortcutEvent = Object.freeze(function (callback, context) {\n const handle = (0, ral_1.default)().timer.setTimeout(callback.bind(context), 0);\n return { dispose() { handle.dispose(); } };\n});\nclass MutableToken {\n constructor() {\n this._isCancelled = false;\n }\n cancel() {\n if (!this._isCancelled) {\n this._isCancelled = true;\n if (this._emitter) {\n this._emitter.fire(undefined);\n this.dispose();\n }\n }\n }\n get isCancellationRequested() {\n return this._isCancelled;\n }\n get onCancellationRequested() {\n if (this._isCancelled) {\n return shortcutEvent;\n }\n if (!this._emitter) {\n this._emitter = new events_1.Emitter();\n }\n return this._emitter.event;\n }\n dispose() {\n if (this._emitter) {\n this._emitter.dispose();\n this._emitter = undefined;\n }\n }\n}\nclass CancellationTokenSource {\n get token() {\n if (!this._token) {\n // be lazy and create the token only when\n // actually needed\n this._token = new MutableToken();\n }\n return this._token;\n }\n cancel() {\n if (!this._token) {\n // save an object by returning the default\n // cancelled token when cancellation happens\n // before someone asks for the token\n this._token = CancellationToken.Cancelled;\n }\n else {\n this._token.cancel();\n }\n }\n dispose() {\n if (!this._token) {\n // ensure to initialize with an empty token if we had none\n this._token = CancellationToken.None;\n }\n else if (this._token instanceof MutableToken) {\n // actually dispose\n this._token.dispose();\n }\n }\n}\nexports.CancellationTokenSource = CancellationTokenSource;\n", "/******************************************************************************\r\n * Copyright 2021 TypeFox GmbH\r\n * This program and the accompanying materials are made available under the\r\n * terms of the MIT License, which is available in the project root.\r\n *\r\n * @module langium\r\n */\r\n\r\nexport * from './default-module.js';\r\nexport * from './dependency-injection.js';\r\nexport * from './service-registry.js';\r\nexport * from './services.js';\r\nexport * from './syntax-tree.js';\r\nexport * from './documentation/index.js';\r\nexport * from './languages/index.js';\r\nexport * from './parser/index.js';\r\nexport * from './references/index.js';\r\nexport * from './serializer/index.js';\r\nexport * from './utils/index.js';\r\nexport * from './validation/index.js';\r\nexport * from './workspace/index.js';\r\n\r\n// Export the Langium Grammar AST definitions in the `GrammarAST` namespace\r\nimport * as GrammarAST from './languages/generated/ast.js';\r\nimport type { Grammar } from './languages/generated/ast.js';\r\nexport { Grammar, GrammarAST };\r\n", "/******************************************************************************\r\n * Copyright 2021 TypeFox GmbH\r\n * This program and the accompanying materials are made available under the\r\n * terms of the MIT License, which is available in the project root.\r\n ******************************************************************************/\r\n\r\nimport type { IToken } from '@chevrotain/types';\r\nimport type { Range } from 'vscode-languageserver-types';\r\nimport type { CstNode, CompositeCstNode, LeafCstNode } from '../syntax-tree.js';\r\nimport type { DocumentSegment } from '../workspace/documents.js';\r\nimport type { Stream, TreeStream } from './stream.js';\r\nimport { isCompositeCstNode, isLeafCstNode, isRootCstNode } from '../syntax-tree.js';\r\nimport { TreeStreamImpl } from './stream.js';\r\n\r\n/**\r\n * Create a stream of all CST nodes that are directly and indirectly contained in the given root node,\r\n * including the root node itself.\r\n */\r\nexport function streamCst(node: CstNode): TreeStream<CstNode> {\r\n return new TreeStreamImpl(node, element => {\r\n if (isCompositeCstNode(element)) {\r\n return element.content;\r\n } else {\r\n return [];\r\n }\r\n }, { includeRoot: true });\r\n}\r\n\r\n/**\r\n * Create a stream of all leaf nodes that are directly and indirectly contained in the given root node.\r\n */\r\nexport function flattenCst(node: CstNode): Stream<LeafCstNode> {\r\n return streamCst(node).filter(isLeafCstNode);\r\n}\r\n\r\n/**\r\n * Determines whether the specified cst node is a child of the specified parent node.\r\n */\r\nexport function isChildNode(child: CstNode, parent: CstNode): boolean {\r\n while (child.container) {\r\n child = child.container;\r\n if (child === parent) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nexport function tokenToRange(token: IToken): Range {\r\n // Chevrotain uses 1-based indices everywhere\r\n // So we subtract 1 from every value to align with the LSP\r\n return {\r\n start: {\r\n character: token.startColumn! - 1,\r\n line: token.startLine! - 1\r\n },\r\n end: {\r\n character: token.endColumn!, // endColumn uses the correct index\r\n line: token.endLine! - 1\r\n }\r\n };\r\n}\r\n\r\nexport function toDocumentSegment(node: CstNode): DocumentSegment;\r\nexport function toDocumentSegment(node?: CstNode): DocumentSegment | undefined;\r\nexport function toDocumentSegment(node?: CstNode): DocumentSegment | undefined {\r\n if (!node) {\r\n return undefined;\r\n }\r\n const { offset, end, range } = node;\r\n return {\r\n range,\r\n offset,\r\n end,\r\n length: end - offset\r\n };\r\n}\r\n\r\nexport enum RangeComparison {\r\n Before = 0,\r\n After = 1,\r\n OverlapFront = 2,\r\n OverlapBack = 3,\r\n Inside = 4,\r\n Outside = 5,\r\n}\r\n\r\nexport function compareRange(range: Range, to: Range): RangeComparison {\r\n if (range.end.line < to.start.line || (range.end.line === to.start.line && range.end.character <= to.start.character)) {\r\n return RangeComparison.Before;\r\n } else if (range.start.line > to.end.line || (range.start.line === to.end.line && range.start.character >= to.end.character)) {\r\n return RangeComparison.After;\r\n }\r\n const startInside = range.start.line > to.start.line || (range.start.line === to.start.line && range.start.character >= to.start.character);\r\n const endInside = range.end.line < to.end.line || (range.end.line === to.end.line && range.end.character <= to.end.character);\r\n if (startInside && endInside) {\r\n return RangeComparison.Inside;\r\n } else if (startInside) {\r\n return RangeComparison.OverlapBack;\r\n } else if (endInside) {\r\n return RangeComparison.OverlapFront;\r\n } else {\r\n return RangeComparison.Outside;\r\n }\r\n}\r\n\r\nexport function inRange(range: Range, to: Range): boolean {\r\n const comparison = compareRange(range, to);\r\n return comparison > RangeComparison.After;\r\n}\r\n\r\n// The \\p{L} regex matches any unicode letter character, i.e. characters from non-english alphabets\r\n// Together with \\w it matches any kind of character which can commonly appear in IDs\r\nexport const DefaultNameRegexp = /^[\\w\\p{L}]$/u;\r\n\r\n/**\r\n * Performs `findLeafNodeAtOffset` with a minor difference: When encountering a character that matches the `nameRegexp` argument,\r\n * it will instead return the leaf node at the `offset - 1` position.\r\n *\r\n * For LSP services, users expect that the declaration of an element is available if the cursor is directly after the element.\r\n */\r\nexport function findDeclarationNodeAtOffset(cstNode: CstNode | undefined, offset: number, nameRegexp = DefaultNameRegexp): LeafCstNode | undefined {\r\n if (cstNode) {\r\n if (offset > 0) {\r\n const localOffset = offset - cstNode.offset;\r\n const textAtOffset = cstNode.text.charAt(localOffset);\r\n if (!nameRegexp.test(textAtOffset)) {\r\n offset--;\r\n }\r\n }\r\n return findLeafNodeAtOffset(cstNode, offset);\r\n }\r\n return undefined;\r\n}\r\n\r\nexport function findCommentNode(cstNode: CstNode | undefined, commentNames: string[]): CstNode | undefined {\r\n if (cstNode) {\r\n const previous = getPreviousNode(cstNode, true);\r\n if (previous && isCommentNode(previous, commentNames)) {\r\n return previous;\r\n }\r\n if (isRootCstNode(cstNode)) {\r\n // Go from the first non-hidden node through all nodes in reverse order\r\n // We do this to find the comment node which directly precedes the root node\r\n const endIndex = cstNode.content.findIndex(e => !e.hidden);\r\n for (let i = endIndex - 1; i >= 0; i--) {\r\n const child = cstNode.content[i];\r\n if (isCommentNode(child, commentNames)) {\r\n return child;\r\n }\r\n }\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\nexport function isCommentNode(cstNode: CstNode, commentNames: string[]): boolean {\r\n return isLeafCstNode(cstNode) && commentNames.includes(cstNode.tokenType.name);\r\n}\r\n\r\n/**\r\n * Finds the leaf CST node at the specified 0-based string offset.\r\n * Note that the given offset will be within the range of the returned leaf node.\r\n *\r\n * If the offset does not point to a CST node (but just white space), this method will return `undefined`.\r\n *\r\n * @param node The CST node to search through.\r\n * @param offset The specified offset.\r\n * @returns The CST node at the specified offset.\r\n */\r\nexport function findLeafNodeAtOffset(node: CstNode, offset: number): LeafCstNode | undefined {\r\n if (isLeafCstNode(node)) {\r\n return node;\r\n } else if (isCompositeCstNode(node)) {\r\n const searchResult = binarySearch(node, offset, false);\r\n if (searchResult) {\r\n return findLeafNodeAtOffset(searchResult, offset);\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Finds the leaf CST node at the specified 0-based string offset.\r\n * If no CST node exists at the specified position, it will return the leaf node before it.\r\n *\r\n * If there is no leaf node before the specified offset, this method will return `undefined`.\r\n *\r\n * @param node The CST node to search through.\r\n * @param offset The specified offset.\r\n * @returns The CST node closest to the specified offset.\r\n */\r\nexport function findLeafNodeBeforeOffset(node: CstNode, offset: number): LeafCstNode | undefined {\r\n if (isLeafCstNode(node)) {\r\n return node;\r\n } else if (isCompositeCstNode(node)) {\r\n const searchResult = binarySearch(node, offset, true);\r\n if (searchResult) {\r\n return findLeafNodeBeforeOffset(searchResult, offset);\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\nfunction binarySearch(node: CompositeCstNode, offset: number, closest: boolean): CstNode | undefined {\r\n let left = 0;\r\n let right = node.content.length - 1;\r\n let closestNode: CstNode | undefined = undefined;\r\n\r\n while (left <= right) {\r\n const middle = Math.floor((left + right) / 2);\r\n const middleNode = node.content[middle];\r\n\r\n if (middleNode.offset <= offset && middleNode.end > offset) {\r\n // Found an exact match\r\n return middleNode;\r\n }\r\n\r\n if (middleNode.end <= offset) {\r\n // Update the closest node (less than offset) and move to the right half\r\n closestNode = closest ? middleNode : undefined;\r\n left = middle + 1;\r\n } else {\r\n // Move to the left half\r\n right = middle - 1;\r\n }\r\n }\r\n\r\n return closestNode;\r\n}\r\n\r\nexport function getPreviousNode(node: CstNode, hidden = true): CstNode | undefined {\r\n while (node.container) {\r\n const parent = node.container;\r\n let index = parent.content.indexOf(node);\r\n while (index > 0) {\r\n index--;\r\n const previous = parent.content[index];\r\n if (hidden || !previous.hidden) {\r\n return previous;\r\n }\r\n }\r\n node = parent;\r\n }\r\n return undefined;\r\n}\r\n\r\nexport function getNextNode(node: CstNode, hidden = true): CstNode | undefined {\r\n while (node.container) {\r\n const parent = node.container;\r\n let index = parent.content.indexOf(node);\r\n const last = parent.content.length - 1;\r\n while (index < last) {\r\n index++;\r\n const next = parent.content[index];\r\n if (hidden || !next.hidden) {\r\n return next;\r\n }\r\n }\r\n node = parent;\r\n }\r\n return undefined;\r\n}\r\n\r\nexport function getStartlineNode(node: CstNode): CstNode {\r\n if (node.range.start.character === 0) {\r\n return node;\r\n }\r\n const line = node.range.start.line;\r\n let last = node;\r\n let index: number | undefined;\r\n while (node.container) {\r\n const parent = node.container;\r\n const selfIndex = index ?? parent.content.indexOf(node);\r\n if (selfIndex === 0) {\r\n node = parent;\r\n index = undefined;\r\n } else {\r\n index = selfIndex - 1;\r\n node = parent.content[index];\r\n }\r\n if (node.range.start.line !== line) {\r\n break;\r\n }\r\n last = node;\r\n }\r\n return last;\r\n}\r\n\r\nexport function getInteriorNodes(start: CstNode, end: CstNode): CstNode[] {\r\n const commonParent = getCommonParent(start, end);\r\n if (!commonParent) {\r\n return [];\r\n }\r\n return commonParent.parent.content.slice(commonParent.a + 1, commonParent.b);\r\n}\r\n\r\nfunction getCommonParent(a: CstNode, b: CstNode): CommonParent | undefined {\r\n const aParents = getParentChain(a);\r\n const bParents = getParentChain(b);\r\n let current: CommonParent | undefined;\r\n for (let i = 0; i < aParents.length && i < bParents.length; i++) {\r\n const aParent = aParents[i];\r\n const bParent = bParents[i];\r\n if (aParent.parent === bParent.parent) {\r\n current = {\r\n parent: aParent.parent,\r\n a: aParent.index,\r\n b: bParent.index\r\n };\r\n } else {\r\n break;\r\n }\r\n }\r\n return current;\r\n}\r\n\r\ninterface CommonParent {\r\n parent: CompositeCstNode\r\n a: number\r\n b: number\r\n}\r\n\r\nfunction getParentChain(node: CstNode): ParentLink[] {\r\n const chain: ParentLink[] = [];\r\n while (node.container) {\r\n const parent = node.container;\r\n const index = parent.content.indexOf(node);\r\n chain.push({\r\n parent,\r\n index\r\n });\r\n node = parent;\r\n }\r\n return chain.reverse();\r\n}\r\n\r\ninterface ParentLink {\r\n parent: CompositeCstNode\r\n index: number\r\n}\r\n", "/******************************************************************************\r\n * Copyright 2021 TypeFox GmbH\r\n * This program and the accompanying materials are made available under the\r\n * terms of the MIT License, which is available in the project root.\r\n ******************************************************************************/\r\n\r\nimport type { TokenType } from 'chevrotain';\r\nimport type { URI } from './utils/uri-utils.js';\r\nimport type { AbstractElement } from './languages/generated/ast.js';\r\nimport type { DocumentSegment, LangiumDocument } from './workspace/documents.js';\r\n\r\n/**\r\n * A node in the Abstract Syntax Tree (AST).\r\n */\r\nexport interface AstNode {\r\n /** Every AST node has a type corresponding to what was specified in the grammar declaration. */\r\n readonly $type: string;\r\n /** The container node in the AST; every node except the root node has a container. */\r\n readonly $container?: AstNode;\r\n /** The property of the `$container` node that contains this node. This is either a direct reference or an array. */\r\n readonly $containerProperty?: string;\r\n /** In case `$containerProperty` is an array, the array index is stored here. */\r\n readonly $containerIndex?: number;\r\n /** The Concrete Syntax Tree (CST) node of the text range from which this node was parsed. */\r\n readonly $cstNode?: CstNode;\r\n /** The document containing the AST; only the root node has a direct reference to the document. */\r\n readonly $document?: LangiumDocument;\r\n}\r\n\r\nexport function isAstNode(obj: unknown): obj is AstNode {\r\n return typeof obj === 'object' && obj !== null && typeof (obj as AstNode).$type === 'string';\r\n}\r\n\r\nexport interface GenericAstNode extends AstNode {\r\n [key: string]: unknown\r\n}\r\n\r\ntype SpecificNodeProperties<N extends AstNode> = keyof Omit<N, keyof AstNode | number | symbol>;\r\n\r\n/**\r\n * The property names of a given AST node type.\r\n */\r\nexport type Properties<N extends AstNode> = SpecificNodeProperties<N> extends never ? string : SpecificNodeProperties<N>\r\n\r\n/**\r\n * A cross-reference in the AST. Cross-references may or may not be successfully resolved.\r\n */\r\nexport interface Reference<T extends AstNode = AstNode> {\r\n /**\r\n * The target AST node of this reference. Accessing this property may trigger cross-reference\r\n * resolution by the `Linker` in case it has not been done yet. If the reference cannot be resolved,\r\n * the value is `undefined`.\r\n */\r\n readonly ref?: T;\r\n\r\n /** If any problem occurred while resolving the reference, it is described by this property. */\r\n readonly error?: LinkingError;\r\n /** The CST node from which the reference was parsed */\r\n readonly $refNode?: CstNode;\r\n /** The actual text used to look up in the surrounding scope */\r\n readonly $refText: string;\r\n /** The node description for the AstNode returned by `ref` */\r\n readonly $nodeDescription?: AstNodeDescription;\r\n}\r\n\r\nexport function isReference(obj: unknown): obj is Reference {\r\n return typeof obj === 'object' && obj !== null && typeof (obj as Reference).$refText === 'string';\r\n}\r\n\r\nexport type ResolvedReference<T extends AstNode = AstNode> = Reference<T> & {\r\n readonly ref: T;\r\n}\r\n\r\n/**\r\n * A description of an AST node is used when constructing scopes and looking up cross-reference targets.\r\n */\r\nexport interface AstNodeDescription {\r\n /** The target node; should be present only for local references (linking to the same document). */\r\n node?: AstNode;\r\n /**\r\n * The document segment that represents the range of the name of the AST node.\r\n */\r\n nameSegment?: DocumentSegment;\r\n /**\r\n * The document segment that represents the full range of the AST node.\r\n */\r\n selectionSegment?: DocumentSegment;\r\n /** `$type` property value of the AST node */\r\n type: string;\r\n /** Name of the AST node; this is usually determined by the `NameProvider` service. */\r\n name: string;\r\n /** URI to the document containing the AST node */\r\n documentUri: URI;\r\n /** Navigation path inside the document */\r\n path: string;\r\n}\r\n\r\nexport function isAstNodeDescription(obj: unknown): obj is AstNodeDescription {\r\n return typeof obj === 'object' && obj !== null\r\n && typeof (obj as AstNodeDescription).name === 'string'\r\n && typeof (obj as AstNodeDescription).type === 'string'\r\n && typeof (obj as AstNodeDescription).path === 'string';\r\n}\r\n\r\n/**\r\n * Information about a cross-reference. This is used when traversing references in an AST or to describe\r\n * unresolved references.\r\n */\r\nexport interface ReferenceInfo {\r\n reference: Reference\r\n container: AstNode\r\n property: string\r\n index?: number\r\n}\r\n\r\n/**\r\n * Used to collect information when the `Linker` service fails to resolve a cross-reference.\r\n */\r\nexport interface LinkingError extends ReferenceInfo {\r\n message: string;\r\n targetDescription?: AstNodeDescription;\r\n}\r\n\r\nexport function isLinkingError(obj: unknown): obj is LinkingError {\r\n return typeof obj === 'object' && obj !== null\r\n && isAstNode((obj as LinkingError).container)\r\n && isReference((obj as LinkingError).reference)\r\n && typeof (obj as LinkingError).message === 'string';\r\n}\r\n\r\n/**\r\n * Service used for generic access to the structure of the AST. This service is shared between\r\n * all involved languages, so it operates on the superset of types of these languages.\r\n */\r\nexport interface AstReflection {\r\n getAllTypes(): string[]\r\n getAllSubTypes(type: string): string[]\r\n getReferenceType(refInfo: ReferenceInfo): string\r\n getTypeMetaData(type: string): TypeMetaData\r\n isInstance(node: unknown, type: string): boolean\r\n isSubtype(subtype: string, supertype: string): boolean\r\n}\r\n\r\n/**\r\n * An abstract implementation of the {@link AstReflection} interface.\r\n * Serves to cache subtype computation results to improve performance throughout different parts of Langium.\r\n */\r\nexport abstract class AbstractAstReflection implements AstReflection {\r\n\r\n protected subtypes: Record<string, Record<string, boolean | undefined>> = {};\r\n protected allSubtypes: Record<string, string[] | undefined> = {};\r\n\r\n abstract getAllTypes(): string[];\r\n abstract getReferenceType(refInfo: ReferenceInfo): string;\r\n abstract getTypeMetaData(type: string): TypeMetaData;\r\n protected abstract computeIsSubtype(subtype: string, supertype: string): boolean;\r\n\r\n isInstance(node: unknown, type: string): boolean {\r\n return isAstNode(node) && this.isSubtype(node.$type, type);\r\n }\r\n\r\n isSubtype(subtype: string, supertype: string): boolean {\r\n if (subtype === supertype) {\r\n return true;\r\n }\r\n let nested = this.subtypes[subtype];\r\n if (!nested) {\r\n nested = this.subtypes[subtype] = {};\r\n }\r\n const existing = nested[supertype];\r\n if (existing !== undefined) {\r\n return existing;\r\n } else {\r\n const result = this.computeIsSubtype(subtype, supertype);\r\n nested[supertype] = result;\r\n return result;\r\n }\r\n }\r\n\r\n getAllSubTypes(type: string): string[] {\r\n const existing = this.allSubtypes[type];\r\n if (existing) {\r\n return existing;\r\n } else {\r\n const allTypes = this.getAllTypes();\r\n const types: string[] = [];\r\n for (const possibleSubType of allTypes) {\r\n if (this.isSubtype(possibleSubType, type)) {\r\n types.push(possibleSubType);\r\n }\r\n }\r\n this.allSubtypes[type] = types;\r\n return types;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Represents runtime meta data about a meta model type.\r\n */\r\nexport interface TypeMetaData {\r\n /** The name of this meta model type. Corresponds to the `AstNode.$type` value. */\r\n name: string\r\n /** A list of properties. They can contain default values for their respective property in the AST. */\r\n properties: TypeProperty[]\r\n}\r\n\r\n/**\r\n * Describes the meta data of a property of an AST node.\r\n *\r\n * The optional `defaultValue` indicates that the property is mandatory in the AST node.\r\n * For example, if an AST node contains an array, but no elements of this array have been parsed, we still expect an empty array instead of `undefined`.\r\n */\r\nexport interface TypeProperty {\r\n name: string\r\n defaultValue?: PropertyType\r\n}\r\n\r\n/**\r\n * Represents a default value for an AST property.\r\n */\r\nexport type PropertyType = number | string | boolean | PropertyType[];\r\n\r\n/**\r\n * A node in the Concrete Syntax Tree (CST).\r\n */\r\nexport interface CstNode extends DocumentSegment {\r\n /** The container node in the CST */\r\n readonly container?: CompositeCstNode;\r\n /** @deprecated use `container` instead. */\r\n readonly parent?: CompositeCstNode;\r\n /** The actual text */\r\n readonly text: string;\r\n /** The root CST node */\r\n readonly root: RootCstNode;\r\n /** The grammar element from which this node was parsed */\r\n readonly grammarSource?: AbstractElement;\r\n /** @deprecated use `grammarSource` instead. */\r\n readonly feature?: AbstractElement;\r\n /** The AST node created from this CST node */\r\n readonly astNode: AstNode;\r\n /** @deprecated use `astNode` instead. */\r\n readonly element: AstNode;\r\n /** Whether the token is hidden, i.e. not explicitly part of the containing grammar rule */\r\n readonly hidden: boolean;\r\n}\r\n\r\n/**\r\n * A composite CST node contains other nodes, but no directly associated token.\r\n */\r\nexport interface CompositeCstNode extends CstNode {\r\n readonly content: CstNode[];\r\n /** @deprecated use `content` instead. */\r\n readonly children: CstNode[];\r\n}\r\n\r\nexport function isCompositeCstNode(node: unknown): node is CompositeCstNode {\r\n return typeof node === 'object' && node !== null && Array.isArray((node as CompositeCstNode).content);\r\n}\r\n\r\n/**\r\n * A leaf CST node corresponds to a token in the input token stream.\r\n */\r\nexport interface LeafCstNode extends CstNode {\r\n readonly tokenType: TokenType;\r\n}\r\n\r\nexport function isLeafCstNode(node: unknown): node is LeafCstNode {\r\n return typeof node === 'object' && node !== null && typeof (node as LeafCstNode).tokenType === 'object';\r\n}\r\n\r\nexport interface RootCstNode extends CompositeCstNode {\r\n readonly fullText: string\r\n}\r\n\r\nexport function isRootCstNode(node: unknown): node is RootCstNode {\r\n return isCompositeCstNode(node) && typeof (node as RootCstNode).fullText === 'string';\r\n}\r\n\r\n/**\r\n * Returns a type to have only properties names (!) of a type T whose property value is of a certain type K.\r\n */\r\ntype ExtractKeysOfValueType<T, K> = { [I in keyof T]: T[I] extends K ? I : never }[keyof T];\r\n\r\n/**\r\n * Returns the property names (!) of an AstNode that are cross-references.\r\n * Meant to be used during cross-reference resolution in combination with `assertUnreachable(context.property)`.\r\n */\r\nexport type CrossReferencesOfAstNodeType<N extends AstNode> = (\r\n ExtractKeysOfValueType<N, Reference|undefined>\r\n | ExtractKeysOfValueType<N, Array<Reference|undefined>|undefined>\r\n// eslint-disable-next-line @typescript-eslint/ban-types\r\n) & {};\r\n\r\n/**\r\n * Represents the enumeration-like type, that lists all AstNode types of your grammar.\r\n */\r\nexport type AstTypeList<T> = Record<keyof T, AstNode>;\r\n\r\n/**\r\n * Returns all types that contain cross-references, A is meant to be the interface `XXXAstType` fromm your generated `ast.ts` file.\r\n * Meant to be used during cross-reference resolution in combination with `assertUnreachable(context.container)`.\r\n */\r\nexport type AstNodeTypesWithCrossReferences<A extends AstTypeList<A>> = {\r\n [T in keyof A]: CrossReferencesOfAstNodeType<A[T]> extends never ? never : A[T]\r\n}[keyof A];\r\n\r\nexport type Mutable<T> = {\r\n -readonly [P in keyof T]: T[P]\r\n};\r\n", "/******************************************************************************\r\n * Copyright 2021 TypeFox GmbH\r\n * This program and the accompanying materials are made available under the\r\n * terms of the MIT License, which is available in the project root.\r\n ******************************************************************************/\r\n\r\n/**\r\n * A stream is a read-only sequence of values. While the contents of an array can be accessed\r\n * both sequentially and randomly (via index), a stream allows only sequential access.\r\n *\r\n * The advantage of this is that a stream can be evaluated lazily, so it does not require\r\n * to store intermediate values. This can boost performance when a large sequence is\r\n * processed via filtering, mapping etc. and accessed at most once. However, lazy\r\n * evaluation means that all processing is repeated when you access the sequence multiple\r\n * times; in such a case, it may be better to store the resulting sequence into an array.\r\n */\r\nexport interface Stream<T> extends Iterable<T> {\r\n\r\n /**\r\n * Returns an iterator for this stream. This is the same as calling the `Symbol.iterator` function property.\r\n */\r\n iterator(): IterableIterator<T>;\r\n\r\n /**\r\n * Determines whether this stream contains no elements.\r\n */\r\n isEmpty(): boolean;\r\n\r\n /**\r\n * Determines the number of elements in this stream.\r\n */\r\n count(): number;\r\n\r\n /**\r\n * Collects all elements of this stream into an array.\r\n */\r\n toArray(): T[];\r\n\r\n /**\r\n * Collects all elements of this stream into a Set.\r\n */\r\n