UNPKG

@gdquest/codemirror-gdscript

Version:

Enables Codemirror to parse GDScript (ie. highlight and indent automatically).

1,130 lines (1,128 loc) 71.3 kB
// src/index.mts import { foldNodeProp, foldInside, indentNodeProp, LRLanguage, LanguageSupport } from "@codemirror/language"; // ../lezer-gdscript/dist/index.mjs import { LRParser } from "@lezer/lr"; import { ContextTracker, ExternalTokenizer } from "@lezer/lr"; import { styleTags, tags as t } from "@lezer/highlight"; var indent = 140; var dedent = 141; var newline = 142; var blankLineStart = 143; var newlineBracketed = 144; var eof = 145; var ParenL = 10; var CallParamsLiteralExpressionNode = 11; var CallParamsExpressionNode = 25; var ArrayExpressionNode = 27; var BracketL = 32; var CallExpressionNode = 59; var DictionaryExpressionNode = 63; var BraceL = 64; var GroupedExpressionNode = 66; var CallParamsParameterNode = 70; var bracketed = /* @__PURE__ */ new Set([ GroupedExpressionNode, ArrayExpressionNode, DictionaryExpressionNode, CallExpressionNode, CallParamsExpressionNode, CallParamsLiteralExpressionNode, CallParamsParameterNode ]); var newline2 = "\n".charCodeAt(0); var carriageReturn = "\r".charCodeAt(0); var space = " ".charCodeAt(0); var tab = " ".charCodeAt(0); var hash = "#".charCodeAt(0); var IndentLevel = class { constructor(parent, depth) { this.parent = parent; this.depth = depth; this.hash = (parent ? parent.hash + parent.hash << 8 : 0) + depth + (depth << 4); } }; var topIndent = new IndentLevel(null, 0); function isLineBreak(ch) { return ch === newline2 || ch === carriageReturn; } var newlines = new ExternalTokenizer( (input, stack) => { let prev; if (input.next < 0) { input.acceptToken(eof); } else if (stack.context.depth < 0) { if (isLineBreak(input.next)) { input.acceptToken(newlineBracketed, 1); } } else if (((prev = input.peek(-1)) < 0 || isLineBreak(prev)) && stack.canShift(blankLineStart)) { let spaces = 0; while (input.next === space || input.next === tab) { input.advance(); spaces++; } if (input.next === newline2 || input.next === carriageReturn || input.next === hash) { input.acceptToken(blankLineStart, -spaces); } } else if (isLineBreak(input.next)) { input.acceptToken(newline, 1); } }, { contextual: true } ); function countIndent(space2) { let depth = 0; for (let i = 0; i < space2.length; i++) depth += space2.charCodeAt(i) === tab ? 8 - depth % 8 : 1; return depth; } var trackIndent = new ContextTracker({ start: topIndent, reduce(context, term) { return context.depth < 0 && bracketed.has(term) ? context.parent : context; }, shift(context, term, stack, input) { switch (term) { case indent: return new IndentLevel( context, countIndent(input.read(input.pos, stack.pos)) ); case dedent: return context.parent; case ParenL: case BracketL: case BraceL: return new IndentLevel(context, -1); default: return context; } }, hash(context) { return context.hash; } }); var indentation = new ExternalTokenizer((input, stack) => { const contextDepth = stack.context.depth; if (contextDepth < 0) return; const prev = input.peek(-1); if (!(prev === newline2 || prev === carriageReturn)) { return; } let chars = 0; let depth = 0; while (true) { if (input.next === space) { depth++; } else if (input.next === tab) { depth += 8 - depth % 8; } else { break; } input.advance(); chars += 1; } if (depth !== contextDepth && input.next !== newline2 && input.next !== carriageReturn && input.next !== hash) { if (depth < contextDepth) { input.acceptToken(dedent, -chars); } else { input.acceptToken(indent); } } }); var gdscriptHighlighting = styleTags({ "for while if elif else return break continue pass assert await match case": t.controlKeyword, "in not and or is del": t.operatorKeyword, "func class class_name extends const var": t.definitionKeyword, "preload load": t.moduleKeyword, "as PI TAU INF NaN": t.keyword, True: t.bool, False: t.bool, Null: t.bool, Comment: t.lineComment, Number: t.number, String: t.string, UpdateOp: t.updateOperator, ArithOp: t.arithmeticOperator, BitOp: t.bitwiseOperator, CompareOp: t.compareOperator, AssignOp: t.definitionOperator, "ClassNode/Identifier ClassNode/ExtendsStatement/Identifier VariableNode/TypeCast/Type/Identifier": t.definition(t.className), "( )": t.paren, "[ ]": t.squareBracket, "{ }": t.brace, ".": t.derefOperator, ", ;": t.separator }); var spec_Identifier = { __proto__: null, PI: 34, TAU: 36, INF: 38, NaN: 40, assert: 48, var: 70, const: 80, await: 86, in: 116, as: 122, func: 138, preload: 162, is: 176, class_name: 186, extends: 190, signal: 194, pass: 198, return: 202, class: 214, if: 222, elif: 226, else: 230, for: 234, match: 238, while: 254 }; var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!r!s#O#x$a$f$q%W%i%{%|&X&f'd(P!_'m`z}!b#U$e$g$z%n&V&x&y&z&{&|&}'O'P'Q'R'S'T'U'V'c'i'x'{'|(QQ!y`R$O!bQ#|!`Q$u#[Q%h$SQ'e'pR'h'uR%^#z", nodeNames: "\u26A0 Comment Script SimpleStatement SmallStatement StandaloneAnnotationNode AnnotationNode @ Identifier ) ( CallParamsLiteralExpressionNode LiteralExpressionNode True False Null BuiltinConstants PI TAU INF NaN String , AssertNode assert CallParamsExpressionNode ] ArrayExpressionNode SubscriptExpressionNode VariableName GetNodeExpressionNode . [ AssignmentExpressionNode VariableNode var TypeCast : Type ConstantNode const ParameterNode AwaitExpressionNode await BinaryOperatorExpressionNode ArithOp ArithOp ArithOp BitOp CompareOp BitOp BitOp BitOp AndOp LogicOp OrOp LogicOp NotOp in CallExpressionNode CastExpressionNode as } DictionaryExpressionNode { DictionaryEntry GroupedExpressionNode IdentifierExpressionNode LambdaExpressionNode func CallParamsParameterNode AssignmentExpressionNode FunctionReturnType Body SuiteNodeBody Newline SuiteNode Indent Dedent ExpressionNodeBody PreloadExpressionNode preload SelfExpressionNode SelfToken TernaryOperatorExpressionNode TernaryOp TernaryOp TypeTestExpressionNode is ClassName UnaryOperatorNode ArithOp ClassNameStatement class_name ExtendsStatement extends SignalStatement signal PassStatement pass ReturnNode return Eof StatementGroup ; CompoundStatement ClassNode class FunctionNode IfNode IfClause if ElifClause elif ElseClause else ForNode for MatchNode match MatchBranchNode PatternNode VarPatternNode IdentifierPatternNode LiteralPatternNode WildcardPatternNode WhileNode while", maxTerm: 166, context: trackIndent, nodeProps: [ ["group", -2, 3, 105, "Statement", -18, 12, 27, 28, 30, 33, 42, 44, 59, 60, 63, 66, 67, 68, 80, 82, 84, 87, 90, "ExpressionNode", -3, 34, 39, 41, "AssignableNode"], ["openedBy", 9, "("], ["closedBy", 10, ")"] ], propSources: [gdscriptHighlighting], skippedNodes: [0, 1], repeatNodeCount: 11, tokenData: "Ae~R|XY#{p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9xUW~!Q![4X!c!}4X#R#S4X#T#h4X#h#i:[#i#o4X~:cS!Z~W~!Q![4X!c!}4X#R#S4X#T#o4X~:tUW~!Q![4X!c!}4X#R#S4X#T#`4X#`#a;W#a#o4X~;]UW~!Q![4X!c!}4X#R#S4X#T#`4X#`#a;o#a#o4X~;vS_~W~!Q![4X!c!}4X#R#S4X#T#o4X~<XUW~!Q![4X!c!}4X#R#S4X#T#f4X#f#g<k#g#o4X~<rS!X~W~!Q![4X!c!}4X#R#S4X#T#o4X~=TUW~!Q![4X!c!}4X#R#S4X#T#X4X#X#Y=g#Y#o4X~=lUW~!Q![4X!c!}4X#R#S4X#T#`4X#`#a>O#a#o4X~>TUW~!Q![4X!c!}4X#R#S4X#T#Y4X#Y#Z>g#Z#o4X~>nS!u~W~!Q![4X!c!}4X#R#S4X#T#o4X~?PUW~!Q![4X!c!}4X#R#S4X#T#f4X#f#g?c#g#o4X~?hUW~!Q![4X!c!}4X#R#S4X#T#i4X#i#j?z#j#o4X~@PUW~!Q![4X!c!}4X#R#S4X#T#X4X#X#Y@c#Y#o4X~@jS]~W~!Q![4X!c!}4X#R#S4X#T#o4X~@{O!b~~AQQ!S~!_!`)Q#p#qAW~A]P!Y~!_!`)Q~AeO!`~", tokenizers: [indentation, newlines, 0, 1, 2], topRules: { "Script": [0, 2] }, specialized: [{ term: 8, get: (value) => spec_Identifier[value] || -1 }], tokenPrec: 3645 }); // ../../node_modules/.pnpm/@lezer+common@1.0.3/node_modules/@lezer/common/dist/index.js var DefaultBufferLength = 1024; var nextPropID = 0; var NodeProp = class { /// Create a new node prop type. constructor(config = {}) { this.id = nextPropID++; this.perNode = !!config.perNode; this.deserialize = config.deserialize || (() => { throw new Error("This node type doesn't define a deserialize function"); }); } /// This is meant to be used with /// [`NodeSet.extend`](#common.NodeSet.extend) or /// [`LRParser.configure`](#lr.ParserConfig.props) to compute /// prop values for each node type in the set. Takes a [match /// object](#common.NodeType^match) or function that returns undefined /// if the node type doesn't get this prop, and the prop's value if /// it does. add(match) { if (this.perNode) throw new RangeError("Can't add per-node props to node types"); if (typeof match != "function") match = NodeType.match(match); return (type) => { let result = match(type); return result === void 0 ? null : [this, result]; }; } }; NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") }); NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") }); NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") }); NodeProp.contextHash = new NodeProp({ perNode: true }); NodeProp.lookAhead = new NodeProp({ perNode: true }); NodeProp.mounted = new NodeProp({ perNode: true }); var noProps = /* @__PURE__ */ Object.create(null); var NodeType = class _NodeType { /// @internal constructor(name, props, id, flags = 0) { this.name = name; this.props = props; this.id = id; this.flags = flags; } /// Define a node type. static define(spec) { let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps; let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0); let type = new _NodeType(spec.name || "", props, spec.id, flags); if (spec.props) for (let src of spec.props) { if (!Array.isArray(src)) src = src(type); if (src) { if (src[0].perNode) throw new RangeError("Can't store a per-node prop on a node type"); props[src[0].id] = src[1]; } } return type; } /// Retrieves a node prop for this type. Will return `undefined` if /// the prop isn't present on this node. prop(prop) { return this.props[prop.id]; } /// True when this is the top node of a grammar. get isTop() { return (this.flags & 1) > 0; } /// True when this node is produced by a skip rule. get isSkipped() { return (this.flags & 2) > 0; } /// Indicates whether this is an error node. get isError() { return (this.flags & 4) > 0; } /// When true, this node type doesn't correspond to a user-declared /// named node, for example because it is used to cache repetition. get isAnonymous() { return (this.flags & 8) > 0; } /// Returns true when this node's name or one of its /// [groups](#common.NodeProp^group) matches the given string. is(name) { if (typeof name == "string") { if (this.name == name) return true; let group = this.prop(NodeProp.group); return group ? group.indexOf(name) > -1 : false; } return this.id == name; } /// Create a function from node types to arbitrary values by /// specifying an object whose property names are node or /// [group](#common.NodeProp^group) names. Often useful with /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple /// names, separated by spaces, in a single property name to map /// multiple node names to a single value. static match(map) { let direct = /* @__PURE__ */ Object.create(null); for (let prop in map) for (let name of prop.split(" ")) direct[name] = map[prop]; return (node) => { for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) { let found = direct[i < 0 ? node.name : groups[i]]; if (found) return found; } }; } }; NodeType.none = new NodeType( "", /* @__PURE__ */ Object.create(null), 0, 8 /* NodeFlag.Anonymous */ ); var CachedNode = /* @__PURE__ */ new WeakMap(); var CachedInnerNode = /* @__PURE__ */ new WeakMap(); var IterMode; (function(IterMode2) { IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers"; IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous"; IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts"; IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays"; })(IterMode || (IterMode = {})); var Tree = class _Tree { /// Construct a new tree. See also [`Tree.build`](#common.Tree^build). constructor(type, children, positions, length, props) { this.type = type; this.children = children; this.positions = positions; this.length = length; this.props = null; if (props && props.length) { this.props = /* @__PURE__ */ Object.create(null); for (let [prop, value] of props) this.props[typeof prop == "number" ? prop : prop.id] = value; } } /// @internal toString() { let mounted = this.prop(NodeProp.mounted); if (mounted && !mounted.overlay) return mounted.tree.toString(); let children = ""; for (let ch of this.children) { let str = ch.toString(); if (str) { if (children) children += ","; children += str; } } return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : ""); } /// Get a [tree cursor](#common.TreeCursor) positioned at the top of /// the tree. Mode can be used to [control](#common.IterMode) which /// nodes the cursor visits. cursor(mode = 0) { return new TreeCursor(this.topNode, mode); } /// Get a [tree cursor](#common.TreeCursor) pointing into this tree /// at the given position and side (see /// [`moveTo`](#common.TreeCursor.moveTo). cursorAt(pos, side = 0, mode = 0) { let scope = CachedNode.get(this) || this.topNode; let cursor = new TreeCursor(scope); cursor.moveTo(pos, side); CachedNode.set(this, cursor._tree); return cursor; } /// Get a [syntax node](#common.SyntaxNode) object for the top of the /// tree. get topNode() { return new TreeNode(this, 0, 0, null); } /// Get the [syntax node](#common.SyntaxNode) at the given position. /// If `side` is -1, this will move into nodes that end at the /// position. If 1, it'll move into nodes that start at the /// position. With 0, it'll only enter nodes that cover the position /// from both sides. /// /// Note that this will not enter /// [overlays](#common.MountedTree.overlay), and you often want /// [`resolveInner`](#common.Tree.resolveInner) instead. resolve(pos, side = 0) { let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false); CachedNode.set(this, node); return node; } /// Like [`resolve`](#common.Tree.resolve), but will enter /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node /// pointing into the innermost overlaid tree at the given position /// (with parent links going through all parent structure, including /// the host trees). resolveInner(pos, side = 0) { let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true); CachedInnerNode.set(this, node); return node; } /// Iterate over the tree and its children, calling `enter` for any /// node that touches the `from`/`to` region (if given) before /// running over such a node's children, and `leave` (if given) when /// leaving the node. When `enter` returns `false`, that node will /// not have its children iterated over (or `leave` called). iterate(spec) { let { enter, leave, from = 0, to = this.length } = spec; let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0; for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) { let entered = false; if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) { if (c.firstChild()) continue; entered = true; } for (; ; ) { if (entered && leave && (anon || !c.type.isAnonymous)) leave(c); if (c.nextSibling()) break; if (!c.parent()) return; entered = true; } } } /// Get the value of the given [node prop](#common.NodeProp) for this /// node. Works with both per-node and per-type props. prop(prop) { return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0; } /// Returns the node's [per-node props](#common.NodeProp.perNode) in a /// format that can be passed to the [`Tree`](#common.Tree) /// constructor. get propValues() { let result = []; if (this.props) for (let id in this.props) result.push([+id, this.props[id]]); return result; } /// Balance the direct children of this tree, producing a copy of /// which may have children grouped into subtrees with type /// [`NodeType.none`](#common.NodeType^none). balance(config = {}) { return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new _Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new _Tree(NodeType.none, children, positions, length))); } /// Build a tree from a postfix-ordered buffer of node information, /// or a cursor over such a buffer. static build(data) { return buildTree(data); } }; Tree.empty = new Tree(NodeType.none, [], [], 0); var FlatBufferCursor = class _FlatBufferCursor { constructor(buffer, index) { this.buffer = buffer; this.index = index; } get id() { return this.buffer[this.index - 4]; } get start() { return this.buffer[this.index - 3]; } get end() { return this.buffer[this.index - 2]; } get size() { return this.buffer[this.index - 1]; } get pos() { return this.index; } next() { this.index -= 4; } fork() { return new _FlatBufferCursor(this.buffer, this.index); } }; var TreeBuffer = class _TreeBuffer { /// Create a tree buffer. constructor(buffer, length, set) { this.buffer = buffer; this.length = length; this.set = set; } /// @internal get type() { return NodeType.none; } /// @internal toString() { let result = []; for (let index = 0; index < this.buffer.length; ) { result.push(this.childString(index)); index = this.buffer[index + 3]; } return result.join(","); } /// @internal childString(index) { let id = this.buffer[index], endIndex = this.buffer[index + 3]; let type = this.set.types[id], result = type.name; if (/\W/.test(result) && !type.isError) result = JSON.stringify(result); index += 4; if (endIndex == index) return result; let children = []; while (index < endIndex) { children.push(this.childString(index)); index = this.buffer[index + 3]; } return result + "(" + children.join(",") + ")"; } /// @internal findChild(startIndex, endIndex, dir, pos, side) { let { buffer } = this, pick = -1; for (let i = startIndex; i != endIndex; i = buffer[i + 3]) { if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) { pick = i; if (dir > 0) break; } } return pick; } /// @internal slice(startI, endI, from) { let b = this.buffer; let copy = new Uint16Array(endI - startI), len = 0; for (let i = startI, j = 0; i < endI; ) { copy[j++] = b[i++]; copy[j++] = b[i++] - from; let to = copy[j++] = b[i++] - from; copy[j++] = b[i++] - startI; len = Math.max(len, to); } return new _TreeBuffer(copy, len, this.set); } }; function checkSide(side, pos, from, to) { switch (side) { case -2: return from < pos; case -1: return to >= pos && from < pos; case 0: return from < pos && to > pos; case 1: return from <= pos && to > pos; case 2: return to > pos; case 4: return true; } } function enterUnfinishedNodesBefore(node, pos) { let scan = node.childBefore(pos); while (scan) { let last = scan.lastChild; if (!last || last.to != scan.to) break; if (last.type.isError && last.from == last.to) { node = scan; scan = last.prevSibling; } else { scan = last; } } return node; } function resolveNode(node, pos, side, overlays) { var _a; while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) { let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent; if (!parent) return node; node = parent; } let mode = overlays ? 0 : IterMode.IgnoreOverlays; if (overlays) for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) { if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from) node = parent; } for (; ; ) { let inner = node.enter(pos, side, mode); if (!inner) return node; node = inner; } } var TreeNode = class _TreeNode { constructor(_tree, from, index, _parent) { this._tree = _tree; this.from = from; this.index = index; this._parent = _parent; } get type() { return this._tree.type; } get name() { return this._tree.type.name; } get to() { return this.from + this._tree.length; } nextChild(i, dir, pos, side, mode = 0) { for (let parent = this; ; ) { for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) { let next = children[i], start = positions[i] + parent.from; if (!checkSide(side, pos, start, start + next.length)) continue; if (next instanceof TreeBuffer) { if (mode & IterMode.ExcludeBuffers) continue; let index = next.findChild(0, next.buffer.length, dir, pos - start, side); if (index > -1) return new BufferNode(new BufferContext(parent, next, i, start), null, index); } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) { let mounted; if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay) return new _TreeNode(mounted.tree, start, i, parent); let inner = new _TreeNode(next, start, i, parent); return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side); } } if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous) return null; if (parent.index >= 0) i = parent.index + dir; else i = dir < 0 ? -1 : parent._parent._tree.children.length; parent = parent._parent; if (!parent) return null; } } get firstChild() { return this.nextChild( 0, 1, 0, 4 /* Side.DontCare */ ); } get lastChild() { return this.nextChild( this._tree.children.length - 1, -1, 0, 4 /* Side.DontCare */ ); } childAfter(pos) { return this.nextChild( 0, 1, pos, 2 /* Side.After */ ); } childBefore(pos) { return this.nextChild( this._tree.children.length - 1, -1, pos, -2 /* Side.Before */ ); } enter(pos, side, mode = 0) { let mounted; if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) { let rPos = pos - this.from; for (let { from, to } of mounted.overlay) { if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos)) return new _TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this); } } return this.nextChild(0, 1, pos, side, mode); } nextSignificantParent() { let val = this; while (val.type.isAnonymous && val._parent) val = val._parent; return val; } get parent() { return this._parent ? this._parent.nextSignificantParent() : null; } get nextSibling() { return this._parent && this.index >= 0 ? this._parent.nextChild( this.index + 1, 1, 0, 4 /* Side.DontCare */ ) : null; } get prevSibling() { return this._parent && this.index >= 0 ? this._parent.nextChild( this.index - 1, -1, 0, 4 /* Side.DontCare */ ) : null; } cursor(mode = 0) { return new TreeCursor(this, mode); } get tree() { return this._tree; } toTree() { return this._tree; } resolve(pos, side = 0) { return resolveNode(this, pos, side, false); } resolveInner(pos, side = 0) { return resolveNode(this, pos, side, true); } enterUnfinishedNodesBefore(pos) { return enterUnfinishedNodesBefore(this, pos); } getChild(type, before = null, after = null) { let r = getChildren(this, type, before, after); return r.length ? r[0] : null; } getChildren(type, before = null, after = null) { return getChildren(this, type, before, after); } /// @internal toString() { return this._tree.toString(); } get node() { return this; } matchContext(context) { return matchNodeContext(this, context); } }; function getChildren(node, type, before, after) { let cur = node.cursor(), result = []; if (!cur.firstChild()) return result; if (before != null) { while (!cur.type.is(before)) if (!cur.nextSibling()) return result; } for (; ; ) { if (after != null && cur.type.is(after)) return result; if (cur.type.is(type)) result.push(cur.node); if (!cur.nextSibling()) return after == null ? result : []; } } function matchNodeContext(node, context, i = context.length - 1) { for (let p = node.parent; i >= 0; p = p.parent) { if (!p) return false; if (!p.type.isAnonymous) { if (context[i] && context[i] != p.name) return false; i--; } } return true; } var BufferContext = class { constructor(parent, buffer, index, start) { this.parent = parent; this.buffer = buffer; this.index = index; this.start = start; } }; var BufferNode = class _BufferNode { get name() { return this.type.name; } get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; } get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; } constructor(context, _parent, index) { this.context = context; this._parent = _parent; this.index = index; this.type = context.buffer.set.types[context.buffer.buffer[index]]; } child(dir, pos, side) { let { buffer } = this.context; let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side); return index < 0 ? null : new _BufferNode(this.context, this, index); } get firstChild() { return this.child( 1, 0, 4 /* Side.DontCare */ ); } get lastChild() { return this.child( -1, 0, 4 /* Side.DontCare */ ); } childAfter(pos) { return this.child( 1, pos, 2 /* Side.After */ ); } childBefore(pos) { return this.child( -1, pos, -2 /* Side.Before */ ); } enter(pos, side, mode = 0) { if (mode & IterMode.ExcludeBuffers) return null; let { buffer } = this.context; let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side); return index < 0 ? null : new _BufferNode(this.context, this, index); } get parent() { return this._parent || this.context.parent.nextSignificantParent(); } externalSibling(dir) { return this._parent ? null : this.context.parent.nextChild( this.context.index + dir, dir, 0, 4 /* Side.DontCare */ ); } get nextSibling() { let { buffer } = this.context; let after = buffer.buffer[this.index + 3]; if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length)) return new _BufferNode(this.context, this._parent, after); return this.externalSibling(1); } get prevSibling() { let { buffer } = this.context; let parentStart = this._parent ? this._parent.index + 4 : 0; if (this.index == parentStart) return this.externalSibling(-1); return new _BufferNode(this.context, this._parent, buffer.findChild( parentStart, this.index, -1, 0, 4 /* Side.DontCare */ )); } cursor(mode = 0) { return new TreeCursor(this, mode); } get tree() { return null; } toTree() { let children = [], positions = []; let { buffer } = this.context; let startI = this.index + 4, endI = buffer.buffer[this.index + 3]; if (endI > startI) { let from = buffer.buffer[this.index + 1]; children.push(buffer.slice(startI, endI, from)); positions.push(0); } return new Tree(this.type, children, positions, this.to - this.from); } resolve(pos, side = 0) { return resolveNode(this, pos, side, false); } resolveInner(pos, side = 0) { return resolveNode(this, pos, side, true); } enterUnfinishedNodesBefore(pos) { return enterUnfinishedNodesBefore(this, pos); } /// @internal toString() { return this.context.buffer.childString(this.index); } getChild(type, before = null, after = null) { let r = getChildren(this, type, before, after); return r.length ? r[0] : null; } getChildren(type, before = null, after = null) { return getChildren(this, type, before, after); } get node() { return this; } matchContext(context) { return matchNodeContext(this, context); } }; var TreeCursor = class { /// Shorthand for `.type.name`. get name() { return this.type.name; } /// @internal constructor(node, mode = 0) { this.mode = mode; this.buffer = null; this.stack = []; this.index = 0; this.bufferNode = null; if (node instanceof TreeNode) { this.yieldNode(node); } else { this._tree = node.context.parent; this.buffer = node.context; for (let n = node._parent; n; n = n._parent) this.stack.unshift(n.index); this.bufferNode = node; this.yieldBuf(node.index); } } yieldNode(node) { if (!node) return false; this._tree = node; this.type = node.type; this.from = node.from; this.to = node.to; return true; } yieldBuf(index, type) { this.index = index; let { start, buffer } = this.buffer; this.type = type || buffer.set.types[buffer.buffer[index]]; this.from = start + buffer.buffer[index + 1]; this.to = start + buffer.buffer[index + 2]; return true; } yield(node) { if (!node) return false; if (node instanceof TreeNode) { this.buffer = null; return this.yieldNode(node); } this.buffer = node.context; return this.yieldBuf(node.index, node.type); } /// @internal toString() { return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString(); } /// @internal enterChild(dir, pos, side) { if (!this.buffer) return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode)); let { buffer } = this.buffer; let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side); if (index < 0) return false; this.stack.push(this.index); return this.yieldBuf(index); } /// Move the cursor to this node's first child. When this returns /// false, the node has no child, and the cursor has not been moved. firstChild() { return this.enterChild( 1, 0, 4 /* Side.DontCare */ ); } /// Move the cursor to this node's last child. lastChild() { return this.enterChild( -1, 0, 4 /* Side.DontCare */ ); } /// Move the cursor to the first child that ends after `pos`. childAfter(pos) { return this.enterChild( 1, pos, 2 /* Side.After */ ); } /// Move to the last child that starts before `pos`. childBefore(pos) { return this.enterChild( -1, pos, -2 /* Side.Before */ ); } /// Move the cursor to the child around `pos`. If side is -1 the /// child may end at that position, when 1 it may start there. This /// will also enter [overlaid](#common.MountedTree.overlay) /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is /// set to false. enter(pos, side, mode = this.mode) { if (!this.buffer) return this.yield(this._tree.enter(pos, side, mode)); return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side); } /// Move to the node's parent node, if this isn't the top node. parent() { if (!this.buffer) return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent); if (this.stack.length) return this.yieldBuf(this.stack.pop()); let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent(); this.buffer = null; return this.yieldNode(parent); } /// @internal sibling(dir) { if (!this.buffer) return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode)); let { buffer } = this.buffer, d = this.stack.length - 1; if (dir < 0) { let parentStart = d < 0 ? 0 : this.stack[d] + 4; if (this.index != parentStart) return this.yieldBuf(buffer.findChild( parentStart, this.index, -1, 0, 4 /* Side.DontCare */ )); } else { let after = buffer.buffer[this.index + 3]; if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3])) return this.yieldBuf(after); } return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false; } /// Move to this node's next sibling, if any. nextSibling() { return this.sibling(1); } /// Move to this node's previous sibling, if any. prevSibling() { return this.sibling(-1); } atLastNode(dir) { let index, parent, { buffer } = this; if (buffer) { if (dir > 0) { if (this.index < buffer.buffer.buffer.length) return false; } else { for (let i = 0; i < this.index; i++) if (buffer.buffer.buffer[i + 3] < this.index) return false; } ({ index, parent } = buffer); } else { ({ index, _parent: parent } = this._tree); } for (; parent; { index, _parent: parent } = parent) { if (index > -1) for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) { let child = parent._tree.children[i]; if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child)) return false; } } return true; } move(dir, enter) { if (enter && this.enterChild( dir, 0, 4 /* Side.DontCare */ )) return true; for (; ; ) { if (this.sibling(dir)) return true; if (this.atLastNode(dir) || !this.parent()) return false; } } /// Move to the next node in a /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR) /// traversal, going from a node to its first child or, if the /// current node is empty or `enter` is false, its next sibling or /// the next sibling of the first parent node that has one. next(enter = true) { return this.move(1, enter); } /// Move to the next node in a last-to-first pre-order traveral. A /// node is followed by its last child or, if it has none, its /// previous sibling or the previous sibling of the first parent /// node that has one. prev(enter = true) { return this.move(-1, enter); } /// Move the cursor to the innermost node that covers `pos`. If /// `side` is -1, it will enter