@uiw/react-codemirror 4.21.8 → 4.21.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codemirror.js +611 -357
- package/dist/codemirror.min.js +1 -1
- package/package.json +2 -2
package/dist/codemirror.js
CHANGED
|
@@ -99,31 +99,31 @@ function _arrayWithHoles(arr) {
|
|
|
99
99
|
if (Array.isArray(arr)) return arr;
|
|
100
100
|
}
|
|
101
101
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js
|
|
102
|
-
function _iterableToArrayLimit(
|
|
103
|
-
var
|
|
104
|
-
if (null !=
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
function _iterableToArrayLimit(r, l) {
|
|
103
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
104
|
+
if (null != t) {
|
|
105
|
+
var e,
|
|
106
|
+
n,
|
|
107
|
+
i,
|
|
108
|
+
u,
|
|
109
|
+
a = [],
|
|
110
|
+
f = !0,
|
|
111
|
+
o = !1;
|
|
112
112
|
try {
|
|
113
|
-
if (
|
|
114
|
-
if (Object(
|
|
115
|
-
|
|
116
|
-
} else for (; !(
|
|
117
|
-
} catch (
|
|
118
|
-
|
|
113
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
114
|
+
if (Object(t) !== t) return;
|
|
115
|
+
f = !1;
|
|
116
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
117
|
+
} catch (r) {
|
|
118
|
+
o = !0, n = r;
|
|
119
119
|
} finally {
|
|
120
120
|
try {
|
|
121
|
-
if (!
|
|
121
|
+
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
|
|
122
122
|
} finally {
|
|
123
|
-
if (
|
|
123
|
+
if (o) throw n;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
return
|
|
126
|
+
return a;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
|
|
@@ -297,12 +297,13 @@ class SearchCursor {
|
|
|
297
297
|
for (let i = 0, pos = start;; i++) {
|
|
298
298
|
let code = norm.charCodeAt(i);
|
|
299
299
|
let match = this.match(code, pos);
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
300
|
+
if (i == norm.length - 1) {
|
|
301
|
+
if (match) {
|
|
302
|
+
this.value = match;
|
|
303
|
+
return this;
|
|
304
|
+
}
|
|
305
305
|
break;
|
|
306
|
+
}
|
|
306
307
|
if (pos == start && i < str.length && str.charCodeAt(i) == code)
|
|
307
308
|
pos++;
|
|
308
309
|
}
|
|
@@ -557,10 +558,10 @@ function createLineDialog(view) {
|
|
|
557
558
|
line = line * (sign == "-" ? -1 : 1) + startLine.number;
|
|
558
559
|
}
|
|
559
560
|
let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line)));
|
|
561
|
+
let selection = state_.EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length)));
|
|
560
562
|
view.dispatch({
|
|
561
|
-
effects: dialogEffect.of(false),
|
|
562
|
-
selection
|
|
563
|
-
scrollIntoView: true
|
|
563
|
+
effects: [dialogEffect.of(false), view_.EditorView.scrollIntoView(selection.from, { y: 'center' })],
|
|
564
|
+
selection,
|
|
564
565
|
});
|
|
565
566
|
view.focus();
|
|
566
567
|
}
|
|
@@ -4381,14 +4382,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
4381
4382
|
});
|
|
4382
4383
|
|
|
4383
4384
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
4384
|
-
function _typeof(
|
|
4385
|
+
function _typeof(o) {
|
|
4385
4386
|
"@babel/helpers - typeof";
|
|
4386
4387
|
|
|
4387
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (
|
|
4388
|
-
return typeof
|
|
4389
|
-
} : function (
|
|
4390
|
-
return
|
|
4391
|
-
}, _typeof(
|
|
4388
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
4389
|
+
return typeof o;
|
|
4390
|
+
} : function (o) {
|
|
4391
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
4392
|
+
}, _typeof(o);
|
|
4392
4393
|
}
|
|
4393
4394
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
4394
4395
|
|
|
@@ -4427,26 +4428,26 @@ function _defineProperty(obj, key, value) {
|
|
|
4427
4428
|
}
|
|
4428
4429
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/objectSpread2.js
|
|
4429
4430
|
|
|
4430
|
-
function ownKeys(
|
|
4431
|
-
var
|
|
4431
|
+
function ownKeys(e, r) {
|
|
4432
|
+
var t = Object.keys(e);
|
|
4432
4433
|
if (Object.getOwnPropertySymbols) {
|
|
4433
|
-
var
|
|
4434
|
-
|
|
4435
|
-
return Object.getOwnPropertyDescriptor(
|
|
4436
|
-
})),
|
|
4434
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
4435
|
+
r && (o = o.filter(function (r) {
|
|
4436
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
4437
|
+
})), t.push.apply(t, o);
|
|
4437
4438
|
}
|
|
4438
|
-
return
|
|
4439
|
-
}
|
|
4440
|
-
function _objectSpread2(
|
|
4441
|
-
for (var
|
|
4442
|
-
var
|
|
4443
|
-
|
|
4444
|
-
_defineProperty(
|
|
4445
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(
|
|
4446
|
-
Object.defineProperty(
|
|
4439
|
+
return t;
|
|
4440
|
+
}
|
|
4441
|
+
function _objectSpread2(e) {
|
|
4442
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
4443
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
4444
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
4445
|
+
_defineProperty(e, r, t[r]);
|
|
4446
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
4447
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
4447
4448
|
});
|
|
4448
4449
|
}
|
|
4449
|
-
return
|
|
4450
|
+
return e;
|
|
4450
4451
|
}
|
|
4451
4452
|
|
|
4452
4453
|
/***/ }),
|
|
@@ -7059,7 +7060,7 @@ class StyleModule {
|
|
|
7059
7060
|
return C + id.toString(36)
|
|
7060
7061
|
}
|
|
7061
7062
|
|
|
7062
|
-
// :: (union<Document, ShadowRoot>, union<[StyleModule], StyleModule
|
|
7063
|
+
// :: (union<Document, ShadowRoot>, union<[StyleModule], StyleModule>, ?{nonce: ?string})
|
|
7063
7064
|
//
|
|
7064
7065
|
// Mount the given set of modules in the given DOM root, which ensures
|
|
7065
7066
|
// that the CSS rules defined by the module are available in that
|
|
@@ -7072,15 +7073,21 @@ class StyleModule {
|
|
|
7072
7073
|
// modules. If you call this function multiple times for the same root
|
|
7073
7074
|
// in a way that changes the order of already mounted modules, the old
|
|
7074
7075
|
// order will be changed.
|
|
7075
|
-
|
|
7076
|
-
|
|
7076
|
+
//
|
|
7077
|
+
// If a Content Security Policy nonce is provided, it is added to
|
|
7078
|
+
// the `<style>` tag generated by the library.
|
|
7079
|
+
static mount(root, modules, options) {
|
|
7080
|
+
let set = root[SET], nonce = options && options.nonce
|
|
7081
|
+
if (!set) set = new StyleSet(root, nonce)
|
|
7082
|
+
else if (nonce) set.setNonce(nonce)
|
|
7083
|
+
set.mount(Array.isArray(modules) ? modules : [modules])
|
|
7077
7084
|
}
|
|
7078
7085
|
}
|
|
7079
7086
|
|
|
7080
7087
|
let adoptedSet = new Map //<Document, StyleSet>
|
|
7081
7088
|
|
|
7082
7089
|
class StyleSet {
|
|
7083
|
-
constructor(root) {
|
|
7090
|
+
constructor(root, nonce) {
|
|
7084
7091
|
let doc = root.ownerDocument || root, win = doc.defaultView
|
|
7085
7092
|
if (!root.head && root.adoptedStyleSheets && win.CSSStyleSheet) {
|
|
7086
7093
|
let adopted = adoptedSet.get(doc)
|
|
@@ -7093,6 +7100,7 @@ class StyleSet {
|
|
|
7093
7100
|
adoptedSet.set(doc, this)
|
|
7094
7101
|
} else {
|
|
7095
7102
|
this.styleTag = doc.createElement("style")
|
|
7103
|
+
if (nonce) this.styleTag.setAttribute("nonce", nonce)
|
|
7096
7104
|
let target = root.head || root
|
|
7097
7105
|
target.insertBefore(this.styleTag, target.firstChild)
|
|
7098
7106
|
}
|
|
@@ -7128,6 +7136,11 @@ class StyleSet {
|
|
|
7128
7136
|
this.styleTag.textContent = text
|
|
7129
7137
|
}
|
|
7130
7138
|
}
|
|
7139
|
+
|
|
7140
|
+
setNonce(nonce) {
|
|
7141
|
+
if (this.styleTag && this.styleTag.getAttribute("nonce") != nonce)
|
|
7142
|
+
this.styleTag.setAttribute("nonce", nonce)
|
|
7143
|
+
}
|
|
7131
7144
|
}
|
|
7132
7145
|
|
|
7133
7146
|
// Style::Object<union<Style,string>>
|
|
@@ -8020,7 +8033,7 @@ function getIndentation(context, pos) {
|
|
|
8020
8033
|
return result;
|
|
8021
8034
|
}
|
|
8022
8035
|
let tree = syntaxTree(context.state);
|
|
8023
|
-
return tree ? syntaxIndentation(context, tree, pos) : null;
|
|
8036
|
+
return tree.length >= pos ? syntaxIndentation(context, tree, pos) : null;
|
|
8024
8037
|
}
|
|
8025
8038
|
/**
|
|
8026
8039
|
Create a change set that auto-indents all lines touched by the
|
|
@@ -8459,11 +8472,16 @@ const foldState = /*@__PURE__*/state_.StateField.define({
|
|
|
8459
8472
|
update(folded, tr) {
|
|
8460
8473
|
folded = folded.map(tr.changes);
|
|
8461
8474
|
for (let e of tr.effects) {
|
|
8462
|
-
if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to))
|
|
8463
|
-
|
|
8464
|
-
|
|
8475
|
+
if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
|
|
8476
|
+
let { preparePlaceholder } = tr.state.facet(foldConfig);
|
|
8477
|
+
let widget = !preparePlaceholder ? foldWidget :
|
|
8478
|
+
view_.Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, e.value)) });
|
|
8479
|
+
folded = folded.update({ add: [widget.range(e.value.from, e.value.to)] });
|
|
8480
|
+
}
|
|
8481
|
+
else if (e.is(unfoldEffect)) {
|
|
8465
8482
|
folded = folded.update({ filter: (from, to) => e.value.from != from || e.value.to != to,
|
|
8466
8483
|
filterFrom: e.value.from, filterTo: e.value.to });
|
|
8484
|
+
}
|
|
8467
8485
|
}
|
|
8468
8486
|
// Clear folded ranges that cover the selection head
|
|
8469
8487
|
if (tr.selection) {
|
|
@@ -8640,6 +8658,7 @@ const foldKeymap = [
|
|
|
8640
8658
|
];
|
|
8641
8659
|
const defaultConfig = {
|
|
8642
8660
|
placeholderDOM: null,
|
|
8661
|
+
preparePlaceholder: null,
|
|
8643
8662
|
placeholderText: "…"
|
|
8644
8663
|
};
|
|
8645
8664
|
const foldConfig = /*@__PURE__*/state_.Facet.define({
|
|
@@ -8654,27 +8673,36 @@ function codeFolding(config) {
|
|
|
8654
8673
|
result.push(foldConfig.of(config));
|
|
8655
8674
|
return result;
|
|
8656
8675
|
}
|
|
8676
|
+
function widgetToDOM(view, prepared) {
|
|
8677
|
+
let { state } = view, conf = state.facet(foldConfig);
|
|
8678
|
+
let onclick = (event) => {
|
|
8679
|
+
let line = view.lineBlockAt(view.posAtDOM(event.target));
|
|
8680
|
+
let folded = findFold(view.state, line.from, line.to);
|
|
8681
|
+
if (folded)
|
|
8682
|
+
view.dispatch({ effects: unfoldEffect.of(folded) });
|
|
8683
|
+
event.preventDefault();
|
|
8684
|
+
};
|
|
8685
|
+
if (conf.placeholderDOM)
|
|
8686
|
+
return conf.placeholderDOM(view, onclick, prepared);
|
|
8687
|
+
let element = document.createElement("span");
|
|
8688
|
+
element.textContent = conf.placeholderText;
|
|
8689
|
+
element.setAttribute("aria-label", state.phrase("folded code"));
|
|
8690
|
+
element.title = state.phrase("unfold");
|
|
8691
|
+
element.className = "cm-foldPlaceholder";
|
|
8692
|
+
element.onclick = onclick;
|
|
8693
|
+
return element;
|
|
8694
|
+
}
|
|
8657
8695
|
const foldWidget = /*@__PURE__*/view_.Decoration.replace({ widget: /*@__PURE__*/new class extends view_.WidgetType {
|
|
8658
|
-
toDOM(view) {
|
|
8659
|
-
let { state } = view, conf = state.facet(foldConfig);
|
|
8660
|
-
let onclick = (event) => {
|
|
8661
|
-
let line = view.lineBlockAt(view.posAtDOM(event.target));
|
|
8662
|
-
let folded = findFold(view.state, line.from, line.to);
|
|
8663
|
-
if (folded)
|
|
8664
|
-
view.dispatch({ effects: unfoldEffect.of(folded) });
|
|
8665
|
-
event.preventDefault();
|
|
8666
|
-
};
|
|
8667
|
-
if (conf.placeholderDOM)
|
|
8668
|
-
return conf.placeholderDOM(view, onclick);
|
|
8669
|
-
let element = document.createElement("span");
|
|
8670
|
-
element.textContent = conf.placeholderText;
|
|
8671
|
-
element.setAttribute("aria-label", state.phrase("folded code"));
|
|
8672
|
-
element.title = state.phrase("unfold");
|
|
8673
|
-
element.className = "cm-foldPlaceholder";
|
|
8674
|
-
element.onclick = onclick;
|
|
8675
|
-
return element;
|
|
8676
|
-
}
|
|
8696
|
+
toDOM(view) { return widgetToDOM(view, null); }
|
|
8677
8697
|
} });
|
|
8698
|
+
class PreparedFoldWidget extends view_.WidgetType {
|
|
8699
|
+
constructor(value) {
|
|
8700
|
+
super();
|
|
8701
|
+
this.value = value;
|
|
8702
|
+
}
|
|
8703
|
+
eq(other) { return this.value == other.value; }
|
|
8704
|
+
toDOM(view) { return widgetToDOM(view, this.value); }
|
|
8705
|
+
}
|
|
8678
8706
|
const foldGutterDefaults = {
|
|
8679
8707
|
openText: "⌄",
|
|
8680
8708
|
closedText: "›",
|
|
@@ -9644,7 +9672,7 @@ function createTokenType(extra, tagStr) {
|
|
|
9644
9672
|
return type.id;
|
|
9645
9673
|
}
|
|
9646
9674
|
function docID(data) {
|
|
9647
|
-
let type = NodeType.define({ id: typeArray.length, name: "Document", props: [languageDataProp.add(() => data)] });
|
|
9675
|
+
let type = NodeType.define({ id: typeArray.length, name: "Document", props: [languageDataProp.add(() => data)], top: true });
|
|
9648
9676
|
typeArray.push(type);
|
|
9649
9677
|
return type;
|
|
9650
9678
|
}
|
|
@@ -9669,7 +9697,9 @@ function docID(data) {
|
|
|
9669
9697
|
/* unused harmony exports DefaultBufferLength, MountedTree, NodeWeakMap, TreeBuffer, TreeCursor, parseMixed */
|
|
9670
9698
|
// FIXME profile adding a per-Tree TreeNode cache, validating it by
|
|
9671
9699
|
// parent pointer
|
|
9672
|
-
|
|
9700
|
+
/**
|
|
9701
|
+
The default maximum length of a `TreeBuffer` node.
|
|
9702
|
+
*/
|
|
9673
9703
|
const DefaultBufferLength = 1024;
|
|
9674
9704
|
let nextPropID = 0;
|
|
9675
9705
|
class Range {
|
|
@@ -9678,11 +9708,15 @@ class Range {
|
|
|
9678
9708
|
this.to = to;
|
|
9679
9709
|
}
|
|
9680
9710
|
}
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9711
|
+
/**
|
|
9712
|
+
Each [node type](#common.NodeType) or [individual tree](#common.Tree)
|
|
9713
|
+
can have metadata associated with it in props. Instances of this
|
|
9714
|
+
class represent prop names.
|
|
9715
|
+
*/
|
|
9684
9716
|
class NodeProp {
|
|
9685
|
-
|
|
9717
|
+
/**
|
|
9718
|
+
Create a new node prop type.
|
|
9719
|
+
*/
|
|
9686
9720
|
constructor(config = {}) {
|
|
9687
9721
|
this.id = nextPropID++;
|
|
9688
9722
|
this.perNode = !!config.perNode;
|
|
@@ -9690,13 +9724,15 @@ class NodeProp {
|
|
|
9690
9724
|
throw new Error("This node type doesn't define a deserialize function");
|
|
9691
9725
|
});
|
|
9692
9726
|
}
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9727
|
+
/**
|
|
9728
|
+
This is meant to be used with
|
|
9729
|
+
[`NodeSet.extend`](#common.NodeSet.extend) or
|
|
9730
|
+
[`LRParser.configure`](#lr.ParserConfig.props) to compute
|
|
9731
|
+
prop values for each node type in the set. Takes a [match
|
|
9732
|
+
object](#common.NodeType^match) or function that returns undefined
|
|
9733
|
+
if the node type doesn't get this prop, and the prop's value if
|
|
9734
|
+
it does.
|
|
9735
|
+
*/
|
|
9700
9736
|
add(match) {
|
|
9701
9737
|
if (this.perNode)
|
|
9702
9738
|
throw new RangeError("Can't add per-node props to node types");
|
|
@@ -9708,48 +9744,68 @@ class NodeProp {
|
|
|
9708
9744
|
};
|
|
9709
9745
|
}
|
|
9710
9746
|
}
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9747
|
+
/**
|
|
9748
|
+
Prop that is used to describe matching delimiters. For opening
|
|
9749
|
+
delimiters, this holds an array of node names (written as a
|
|
9750
|
+
space-separated string when declaring this prop in a grammar)
|
|
9751
|
+
for the node types of closing delimiters that match it.
|
|
9752
|
+
*/
|
|
9715
9753
|
NodeProp.closedBy = new NodeProp({ deserialize: str => str.split(" ") });
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9754
|
+
/**
|
|
9755
|
+
The inverse of [`closedBy`](#common.NodeProp^closedBy). This is
|
|
9756
|
+
attached to closing delimiters, holding an array of node names
|
|
9757
|
+
of types of matching opening delimiters.
|
|
9758
|
+
*/
|
|
9719
9759
|
NodeProp.openedBy = new NodeProp({ deserialize: str => str.split(" ") });
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9760
|
+
/**
|
|
9761
|
+
Used to assign node types to groups (for example, all node
|
|
9762
|
+
types that represent an expression could be tagged with an
|
|
9763
|
+
`"Expression"` group).
|
|
9764
|
+
*/
|
|
9723
9765
|
NodeProp.group = new NodeProp({ deserialize: str => str.split(" ") });
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9766
|
+
/**
|
|
9767
|
+
The hash of the [context](#lr.ContextTracker.constructor)
|
|
9768
|
+
that the node was parsed in, if any. Used to limit reuse of
|
|
9769
|
+
contextual nodes.
|
|
9770
|
+
*/
|
|
9727
9771
|
NodeProp.contextHash = new NodeProp({ perNode: true });
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9772
|
+
/**
|
|
9773
|
+
The distance beyond the end of the node that the tokenizer
|
|
9774
|
+
looked ahead for any of the tokens inside the node. (The LR
|
|
9775
|
+
parser only stores this when it is larger than 25, for
|
|
9776
|
+
efficiency reasons.)
|
|
9777
|
+
*/
|
|
9732
9778
|
NodeProp.lookAhead = new NodeProp({ perNode: true });
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9779
|
+
/**
|
|
9780
|
+
This per-node prop is used to replace a given node, or part of a
|
|
9781
|
+
node, with another tree. This is useful to include trees from
|
|
9782
|
+
different languages in mixed-language parsers.
|
|
9783
|
+
*/
|
|
9736
9784
|
NodeProp.mounted = new NodeProp({ perNode: true });
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9785
|
+
/**
|
|
9786
|
+
A mounted tree, which can be [stored](#common.NodeProp^mounted) on
|
|
9787
|
+
a tree node to indicate that parts of its content are
|
|
9788
|
+
represented by another tree.
|
|
9789
|
+
*/
|
|
9740
9790
|
class MountedTree {
|
|
9741
9791
|
constructor(
|
|
9742
|
-
|
|
9792
|
+
/**
|
|
9793
|
+
The inner tree.
|
|
9794
|
+
*/
|
|
9743
9795
|
tree,
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9796
|
+
/**
|
|
9797
|
+
If this is null, this tree replaces the entire node (it will
|
|
9798
|
+
be included in the regular iteration instead of its host
|
|
9799
|
+
node). If not, only the given ranges are considered to be
|
|
9800
|
+
covered by this tree. This is used for trees that are mixed in
|
|
9801
|
+
a way that isn't strictly hierarchical. Such mounted trees are
|
|
9802
|
+
only entered by [`resolveInner`](#common.Tree.resolveInner)
|
|
9803
|
+
and [`enter`](#common.SyntaxNode.enter).
|
|
9804
|
+
*/
|
|
9751
9805
|
overlay,
|
|
9752
|
-
|
|
9806
|
+
/**
|
|
9807
|
+
The parser used to create this subtree.
|
|
9808
|
+
*/
|
|
9753
9809
|
parser) {
|
|
9754
9810
|
this.tree = tree;
|
|
9755
9811
|
this.overlay = overlay;
|
|
@@ -9757,28 +9813,42 @@ class MountedTree {
|
|
|
9757
9813
|
}
|
|
9758
9814
|
}
|
|
9759
9815
|
const noProps = Object.create(null);
|
|
9760
|
-
|
|
9816
|
+
/**
|
|
9817
|
+
Each node in a syntax tree has a node type associated with it.
|
|
9818
|
+
*/
|
|
9761
9819
|
class NodeType {
|
|
9762
|
-
|
|
9820
|
+
/**
|
|
9821
|
+
@internal
|
|
9822
|
+
*/
|
|
9763
9823
|
constructor(
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
9824
|
+
/**
|
|
9825
|
+
The name of the node type. Not necessarily unique, but if the
|
|
9826
|
+
grammar was written properly, different node types with the
|
|
9827
|
+
same name within a node set should play the same semantic
|
|
9828
|
+
role.
|
|
9829
|
+
*/
|
|
9768
9830
|
name,
|
|
9769
|
-
|
|
9831
|
+
/**
|
|
9832
|
+
@internal
|
|
9833
|
+
*/
|
|
9770
9834
|
props,
|
|
9771
|
-
|
|
9772
|
-
|
|
9835
|
+
/**
|
|
9836
|
+
The id of this node in its set. Corresponds to the term ids
|
|
9837
|
+
used in the parser.
|
|
9838
|
+
*/
|
|
9773
9839
|
id,
|
|
9774
|
-
|
|
9840
|
+
/**
|
|
9841
|
+
@internal
|
|
9842
|
+
*/
|
|
9775
9843
|
flags = 0) {
|
|
9776
9844
|
this.name = name;
|
|
9777
9845
|
this.props = props;
|
|
9778
9846
|
this.id = id;
|
|
9779
9847
|
this.flags = flags;
|
|
9780
9848
|
}
|
|
9781
|
-
|
|
9849
|
+
/**
|
|
9850
|
+
Define a node type.
|
|
9851
|
+
*/
|
|
9782
9852
|
static define(spec) {
|
|
9783
9853
|
let props = spec.props && spec.props.length ? Object.create(null) : noProps;
|
|
9784
9854
|
let flags = (spec.top ? 1 /* NodeFlag.Top */ : 0) | (spec.skipped ? 2 /* NodeFlag.Skipped */ : 0) |
|
|
@@ -9796,20 +9866,32 @@ class NodeType {
|
|
|
9796
9866
|
}
|
|
9797
9867
|
return type;
|
|
9798
9868
|
}
|
|
9799
|
-
|
|
9800
|
-
|
|
9869
|
+
/**
|
|
9870
|
+
Retrieves a node prop for this type. Will return `undefined` if
|
|
9871
|
+
the prop isn't present on this node.
|
|
9872
|
+
*/
|
|
9801
9873
|
prop(prop) { return this.props[prop.id]; }
|
|
9802
|
-
|
|
9874
|
+
/**
|
|
9875
|
+
True when this is the top node of a grammar.
|
|
9876
|
+
*/
|
|
9803
9877
|
get isTop() { return (this.flags & 1 /* NodeFlag.Top */) > 0; }
|
|
9804
|
-
|
|
9878
|
+
/**
|
|
9879
|
+
True when this node is produced by a skip rule.
|
|
9880
|
+
*/
|
|
9805
9881
|
get isSkipped() { return (this.flags & 2 /* NodeFlag.Skipped */) > 0; }
|
|
9806
|
-
|
|
9882
|
+
/**
|
|
9883
|
+
Indicates whether this is an error node.
|
|
9884
|
+
*/
|
|
9807
9885
|
get isError() { return (this.flags & 4 /* NodeFlag.Error */) > 0; }
|
|
9808
|
-
|
|
9809
|
-
|
|
9886
|
+
/**
|
|
9887
|
+
When true, this node type doesn't correspond to a user-declared
|
|
9888
|
+
named node, for example because it is used to cache repetition.
|
|
9889
|
+
*/
|
|
9810
9890
|
get isAnonymous() { return (this.flags & 8 /* NodeFlag.Anonymous */) > 0; }
|
|
9811
|
-
|
|
9812
|
-
|
|
9891
|
+
/**
|
|
9892
|
+
Returns true when this node's name or one of its
|
|
9893
|
+
[groups](#common.NodeProp^group) matches the given string.
|
|
9894
|
+
*/
|
|
9813
9895
|
is(name) {
|
|
9814
9896
|
if (typeof name == 'string') {
|
|
9815
9897
|
if (this.name == name)
|
|
@@ -9819,12 +9901,14 @@ class NodeType {
|
|
|
9819
9901
|
}
|
|
9820
9902
|
return this.id == name;
|
|
9821
9903
|
}
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9826
|
-
|
|
9827
|
-
|
|
9904
|
+
/**
|
|
9905
|
+
Create a function from node types to arbitrary values by
|
|
9906
|
+
specifying an object whose property names are node or
|
|
9907
|
+
[group](#common.NodeProp^group) names. Often useful with
|
|
9908
|
+
[`NodeProp.add`](#common.NodeProp.add). You can put multiple
|
|
9909
|
+
names, separated by spaces, in a single property name to map
|
|
9910
|
+
multiple node names to a single value.
|
|
9911
|
+
*/
|
|
9828
9912
|
static match(map) {
|
|
9829
9913
|
let direct = Object.create(null);
|
|
9830
9914
|
for (let prop in map)
|
|
@@ -9839,29 +9923,39 @@ class NodeType {
|
|
|
9839
9923
|
};
|
|
9840
9924
|
}
|
|
9841
9925
|
}
|
|
9842
|
-
|
|
9926
|
+
/**
|
|
9927
|
+
An empty dummy node type to use when no actual type is available.
|
|
9928
|
+
*/
|
|
9843
9929
|
NodeType.none = new NodeType("", Object.create(null), 0, 8 /* NodeFlag.Anonymous */);
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9930
|
+
/**
|
|
9931
|
+
A node set holds a collection of node types. It is used to
|
|
9932
|
+
compactly represent trees by storing their type ids, rather than a
|
|
9933
|
+
full pointer to the type object, in a numeric array. Each parser
|
|
9934
|
+
[has](#lr.LRParser.nodeSet) a node set, and [tree
|
|
9935
|
+
buffers](#common.TreeBuffer) can only store collections of nodes
|
|
9936
|
+
from the same set. A set can have a maximum of 2**16 (65536) node
|
|
9937
|
+
types in it, so that the ids fit into 16-bit typed array slots.
|
|
9938
|
+
*/
|
|
9851
9939
|
class NodeSet {
|
|
9852
|
-
|
|
9853
|
-
|
|
9940
|
+
/**
|
|
9941
|
+
Create a set with the given types. The `id` property of each
|
|
9942
|
+
type should correspond to its position within the array.
|
|
9943
|
+
*/
|
|
9854
9944
|
constructor(
|
|
9855
|
-
|
|
9945
|
+
/**
|
|
9946
|
+
The node types in this set, by id.
|
|
9947
|
+
*/
|
|
9856
9948
|
types) {
|
|
9857
9949
|
this.types = types;
|
|
9858
9950
|
for (let i = 0; i < types.length; i++)
|
|
9859
9951
|
if (types[i].id != i)
|
|
9860
9952
|
throw new RangeError("Node type ids should correspond to array positions when creating a node set");
|
|
9861
9953
|
}
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9954
|
+
/**
|
|
9955
|
+
Create a copy of this set with some node properties added. The
|
|
9956
|
+
arguments to this method can be created with
|
|
9957
|
+
[`NodeProp.add`](#common.NodeProp.add).
|
|
9958
|
+
*/
|
|
9865
9959
|
extend(...props) {
|
|
9866
9960
|
let newTypes = [];
|
|
9867
9961
|
for (let type of this.types) {
|
|
@@ -9880,61 +9974,87 @@ class NodeSet {
|
|
|
9880
9974
|
}
|
|
9881
9975
|
}
|
|
9882
9976
|
const CachedNode = new WeakMap(), CachedInnerNode = new WeakMap();
|
|
9883
|
-
|
|
9884
|
-
|
|
9977
|
+
/**
|
|
9978
|
+
Options that control iteration. Can be combined with the `|`
|
|
9979
|
+
operator to enable multiple ones.
|
|
9980
|
+
*/
|
|
9885
9981
|
var IterMode;
|
|
9886
9982
|
(function (IterMode) {
|
|
9887
|
-
|
|
9888
|
-
|
|
9889
|
-
|
|
9983
|
+
/**
|
|
9984
|
+
When enabled, iteration will only visit [`Tree`](#common.Tree)
|
|
9985
|
+
objects, not nodes packed into
|
|
9986
|
+
[`TreeBuffer`](#common.TreeBuffer)s.
|
|
9987
|
+
*/
|
|
9890
9988
|
IterMode[IterMode["ExcludeBuffers"] = 1] = "ExcludeBuffers";
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9989
|
+
/**
|
|
9990
|
+
Enable this to make iteration include anonymous nodes (such as
|
|
9991
|
+
the nodes that wrap repeated grammar constructs into a balanced
|
|
9992
|
+
tree).
|
|
9993
|
+
*/
|
|
9894
9994
|
IterMode[IterMode["IncludeAnonymous"] = 2] = "IncludeAnonymous";
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9995
|
+
/**
|
|
9996
|
+
By default, regular [mounted](#common.NodeProp^mounted) nodes
|
|
9997
|
+
replace their base node in iteration. Enable this to ignore them
|
|
9998
|
+
instead.
|
|
9999
|
+
*/
|
|
9898
10000
|
IterMode[IterMode["IgnoreMounts"] = 4] = "IgnoreMounts";
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
10001
|
+
/**
|
|
10002
|
+
This option only applies in
|
|
10003
|
+
[`enter`](#common.SyntaxNode.enter)-style methods. It tells the
|
|
10004
|
+
library to not enter mounted overlays if one covers the given
|
|
10005
|
+
position.
|
|
10006
|
+
*/
|
|
9903
10007
|
IterMode[IterMode["IgnoreOverlays"] = 8] = "IgnoreOverlays";
|
|
9904
10008
|
})(IterMode || (IterMode = {}));
|
|
9905
|
-
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
10009
|
+
/**
|
|
10010
|
+
A piece of syntax tree. There are two ways to approach these
|
|
10011
|
+
trees: the way they are actually stored in memory, and the
|
|
10012
|
+
convenient way.
|
|
10013
|
+
|
|
10014
|
+
Syntax trees are stored as a tree of `Tree` and `TreeBuffer`
|
|
10015
|
+
objects. By packing detail information into `TreeBuffer` leaf
|
|
10016
|
+
nodes, the representation is made a lot more memory-efficient.
|
|
10017
|
+
|
|
10018
|
+
However, when you want to actually work with tree nodes, this
|
|
10019
|
+
representation is very awkward, so most client code will want to
|
|
10020
|
+
use the [`TreeCursor`](#common.TreeCursor) or
|
|
10021
|
+
[`SyntaxNode`](#common.SyntaxNode) interface instead, which provides
|
|
10022
|
+
a view on some part of this data structure, and can be used to
|
|
10023
|
+
move around to adjacent nodes.
|
|
10024
|
+
*/
|
|
9919
10025
|
class Tree {
|
|
9920
|
-
|
|
10026
|
+
/**
|
|
10027
|
+
Construct a new tree. See also [`Tree.build`](#common.Tree^build).
|
|
10028
|
+
*/
|
|
9921
10029
|
constructor(
|
|
9922
|
-
|
|
10030
|
+
/**
|
|
10031
|
+
The type of the top node.
|
|
10032
|
+
*/
|
|
9923
10033
|
type,
|
|
9924
|
-
|
|
10034
|
+
/**
|
|
10035
|
+
This node's child nodes.
|
|
10036
|
+
*/
|
|
9925
10037
|
children,
|
|
9926
|
-
|
|
9927
|
-
|
|
10038
|
+
/**
|
|
10039
|
+
The positions (offsets relative to the start of this tree) of
|
|
10040
|
+
the children.
|
|
10041
|
+
*/
|
|
9928
10042
|
positions,
|
|
9929
|
-
|
|
10043
|
+
/**
|
|
10044
|
+
The total length of this tree
|
|
10045
|
+
*/
|
|
9930
10046
|
length,
|
|
9931
|
-
|
|
10047
|
+
/**
|
|
10048
|
+
Per-node [node props](#common.NodeProp) to associate with this node.
|
|
10049
|
+
*/
|
|
9932
10050
|
props) {
|
|
9933
10051
|
this.type = type;
|
|
9934
10052
|
this.children = children;
|
|
9935
10053
|
this.positions = positions;
|
|
9936
10054
|
this.length = length;
|
|
9937
|
-
|
|
10055
|
+
/**
|
|
10056
|
+
@internal
|
|
10057
|
+
*/
|
|
9938
10058
|
this.props = null;
|
|
9939
10059
|
if (props && props.length) {
|
|
9940
10060
|
this.props = Object.create(null);
|
|
@@ -9942,7 +10062,9 @@ class Tree {
|
|
|
9942
10062
|
this.props[typeof prop == "number" ? prop : prop.id] = value;
|
|
9943
10063
|
}
|
|
9944
10064
|
}
|
|
9945
|
-
|
|
10065
|
+
/**
|
|
10066
|
+
@internal
|
|
10067
|
+
*/
|
|
9946
10068
|
toString() {
|
|
9947
10069
|
let mounted = this.prop(NodeProp.mounted);
|
|
9948
10070
|
if (mounted && !mounted.overlay)
|
|
@@ -9960,15 +10082,19 @@ class Tree {
|
|
|
9960
10082
|
(/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) +
|
|
9961
10083
|
(children.length ? "(" + children + ")" : "");
|
|
9962
10084
|
}
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
10085
|
+
/**
|
|
10086
|
+
Get a [tree cursor](#common.TreeCursor) positioned at the top of
|
|
10087
|
+
the tree. Mode can be used to [control](#common.IterMode) which
|
|
10088
|
+
nodes the cursor visits.
|
|
10089
|
+
*/
|
|
9966
10090
|
cursor(mode = 0) {
|
|
9967
10091
|
return new TreeCursor(this.topNode, mode);
|
|
9968
10092
|
}
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
10093
|
+
/**
|
|
10094
|
+
Get a [tree cursor](#common.TreeCursor) pointing into this tree
|
|
10095
|
+
at the given position and side (see
|
|
10096
|
+
[`moveTo`](#common.TreeCursor.moveTo).
|
|
10097
|
+
*/
|
|
9972
10098
|
cursorAt(pos, side = 0, mode = 0) {
|
|
9973
10099
|
let scope = CachedNode.get(this) || this.topNode;
|
|
9974
10100
|
let cursor = new TreeCursor(scope);
|
|
@@ -9976,40 +10102,48 @@ class Tree {
|
|
|
9976
10102
|
CachedNode.set(this, cursor._tree);
|
|
9977
10103
|
return cursor;
|
|
9978
10104
|
}
|
|
9979
|
-
|
|
9980
|
-
|
|
10105
|
+
/**
|
|
10106
|
+
Get a [syntax node](#common.SyntaxNode) object for the top of the
|
|
10107
|
+
tree.
|
|
10108
|
+
*/
|
|
9981
10109
|
get topNode() {
|
|
9982
10110
|
return new TreeNode(this, 0, 0, null);
|
|
9983
10111
|
}
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
|
|
9991
|
-
|
|
9992
|
-
|
|
10112
|
+
/**
|
|
10113
|
+
Get the [syntax node](#common.SyntaxNode) at the given position.
|
|
10114
|
+
If `side` is -1, this will move into nodes that end at the
|
|
10115
|
+
position. If 1, it'll move into nodes that start at the
|
|
10116
|
+
position. With 0, it'll only enter nodes that cover the position
|
|
10117
|
+
from both sides.
|
|
10118
|
+
|
|
10119
|
+
Note that this will not enter
|
|
10120
|
+
[overlays](#common.MountedTree.overlay), and you often want
|
|
10121
|
+
[`resolveInner`](#common.Tree.resolveInner) instead.
|
|
10122
|
+
*/
|
|
9993
10123
|
resolve(pos, side = 0) {
|
|
9994
10124
|
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
9995
10125
|
CachedNode.set(this, node);
|
|
9996
10126
|
return node;
|
|
9997
10127
|
}
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10128
|
+
/**
|
|
10129
|
+
Like [`resolve`](#common.Tree.resolve), but will enter
|
|
10130
|
+
[overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
|
|
10131
|
+
pointing into the innermost overlaid tree at the given position
|
|
10132
|
+
(with parent links going through all parent structure, including
|
|
10133
|
+
the host trees).
|
|
10134
|
+
*/
|
|
10003
10135
|
resolveInner(pos, side = 0) {
|
|
10004
10136
|
let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
|
|
10005
10137
|
CachedInnerNode.set(this, node);
|
|
10006
10138
|
return node;
|
|
10007
10139
|
}
|
|
10008
|
-
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10140
|
+
/**
|
|
10141
|
+
Iterate over the tree and its children, calling `enter` for any
|
|
10142
|
+
node that touches the `from`/`to` region (if given) before
|
|
10143
|
+
running over such a node's children, and `leave` (if given) when
|
|
10144
|
+
leaving the node. When `enter` returns `false`, that node will
|
|
10145
|
+
not have its children iterated over (or `leave` called).
|
|
10146
|
+
*/
|
|
10013
10147
|
iterate(spec) {
|
|
10014
10148
|
let { enter, leave, from = 0, to = this.length } = spec;
|
|
10015
10149
|
let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
|
|
@@ -10031,14 +10165,18 @@ class Tree {
|
|
|
10031
10165
|
}
|
|
10032
10166
|
}
|
|
10033
10167
|
}
|
|
10034
|
-
|
|
10035
|
-
|
|
10168
|
+
/**
|
|
10169
|
+
Get the value of the given [node prop](#common.NodeProp) for this
|
|
10170
|
+
node. Works with both per-node and per-type props.
|
|
10171
|
+
*/
|
|
10036
10172
|
prop(prop) {
|
|
10037
10173
|
return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : undefined;
|
|
10038
10174
|
}
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10175
|
+
/**
|
|
10176
|
+
Returns the node's [per-node props](#common.NodeProp.perNode) in a
|
|
10177
|
+
format that can be passed to the [`Tree`](#common.Tree)
|
|
10178
|
+
constructor.
|
|
10179
|
+
*/
|
|
10042
10180
|
get propValues() {
|
|
10043
10181
|
let result = [];
|
|
10044
10182
|
if (this.props)
|
|
@@ -10046,18 +10184,24 @@ class Tree {
|
|
|
10046
10184
|
result.push([+id, this.props[id]]);
|
|
10047
10185
|
return result;
|
|
10048
10186
|
}
|
|
10049
|
-
|
|
10050
|
-
|
|
10051
|
-
|
|
10187
|
+
/**
|
|
10188
|
+
Balance the direct children of this tree, producing a copy of
|
|
10189
|
+
which may have children grouped into subtrees with type
|
|
10190
|
+
[`NodeType.none`](#common.NodeType^none).
|
|
10191
|
+
*/
|
|
10052
10192
|
balance(config = {}) {
|
|
10053
10193
|
return this.children.length <= 8 /* Balance.BranchFactor */ ? this :
|
|
10054
10194
|
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)));
|
|
10055
10195
|
}
|
|
10056
|
-
|
|
10057
|
-
|
|
10196
|
+
/**
|
|
10197
|
+
Build a tree from a postfix-ordered buffer of node information,
|
|
10198
|
+
or a cursor over such a buffer.
|
|
10199
|
+
*/
|
|
10058
10200
|
static build(data) { return buildTree(data); }
|
|
10059
10201
|
}
|
|
10060
|
-
|
|
10202
|
+
/**
|
|
10203
|
+
The empty tree
|
|
10204
|
+
*/
|
|
10061
10205
|
Tree.empty = new Tree(NodeType.none, [], [], 0);
|
|
10062
10206
|
class FlatBufferCursor {
|
|
10063
10207
|
constructor(buffer, index) {
|
|
@@ -10072,26 +10216,40 @@ class FlatBufferCursor {
|
|
|
10072
10216
|
next() { this.index -= 4; }
|
|
10073
10217
|
fork() { return new FlatBufferCursor(this.buffer, this.index); }
|
|
10074
10218
|
}
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10219
|
+
/**
|
|
10220
|
+
Tree buffers contain (type, start, end, endIndex) quads for each
|
|
10221
|
+
node. In such a buffer, nodes are stored in prefix order (parents
|
|
10222
|
+
before children, with the endIndex of the parent indicating which
|
|
10223
|
+
children belong to it).
|
|
10224
|
+
*/
|
|
10079
10225
|
class TreeBuffer {
|
|
10080
|
-
|
|
10226
|
+
/**
|
|
10227
|
+
Create a tree buffer.
|
|
10228
|
+
*/
|
|
10081
10229
|
constructor(
|
|
10082
|
-
|
|
10230
|
+
/**
|
|
10231
|
+
The buffer's content.
|
|
10232
|
+
*/
|
|
10083
10233
|
buffer,
|
|
10084
|
-
|
|
10234
|
+
/**
|
|
10235
|
+
The total length of the group of nodes in the buffer.
|
|
10236
|
+
*/
|
|
10085
10237
|
length,
|
|
10086
|
-
|
|
10238
|
+
/**
|
|
10239
|
+
The node set used in this buffer.
|
|
10240
|
+
*/
|
|
10087
10241
|
set) {
|
|
10088
10242
|
this.buffer = buffer;
|
|
10089
10243
|
this.length = length;
|
|
10090
10244
|
this.set = set;
|
|
10091
10245
|
}
|
|
10092
|
-
|
|
10246
|
+
/**
|
|
10247
|
+
@internal
|
|
10248
|
+
*/
|
|
10093
10249
|
get type() { return NodeType.none; }
|
|
10094
|
-
|
|
10250
|
+
/**
|
|
10251
|
+
@internal
|
|
10252
|
+
*/
|
|
10095
10253
|
toString() {
|
|
10096
10254
|
let result = [];
|
|
10097
10255
|
for (let index = 0; index < this.buffer.length;) {
|
|
@@ -10100,7 +10258,9 @@ class TreeBuffer {
|
|
|
10100
10258
|
}
|
|
10101
10259
|
return result.join(",");
|
|
10102
10260
|
}
|
|
10103
|
-
|
|
10261
|
+
/**
|
|
10262
|
+
@internal
|
|
10263
|
+
*/
|
|
10104
10264
|
childString(index) {
|
|
10105
10265
|
let id = this.buffer[index], endIndex = this.buffer[index + 3];
|
|
10106
10266
|
let type = this.set.types[id], result = type.name;
|
|
@@ -10116,7 +10276,9 @@ class TreeBuffer {
|
|
|
10116
10276
|
}
|
|
10117
10277
|
return result + "(" + children.join(",") + ")";
|
|
10118
10278
|
}
|
|
10119
|
-
|
|
10279
|
+
/**
|
|
10280
|
+
@internal
|
|
10281
|
+
*/
|
|
10120
10282
|
findChild(startIndex, endIndex, dir, pos, side) {
|
|
10121
10283
|
let { buffer } = this, pick = -1;
|
|
10122
10284
|
for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
|
|
@@ -10128,7 +10290,9 @@ class TreeBuffer {
|
|
|
10128
10290
|
}
|
|
10129
10291
|
return pick;
|
|
10130
10292
|
}
|
|
10131
|
-
|
|
10293
|
+
/**
|
|
10294
|
+
@internal
|
|
10295
|
+
*/
|
|
10132
10296
|
slice(startI, endI, from) {
|
|
10133
10297
|
let b = this.buffer;
|
|
10134
10298
|
let copy = new Uint16Array(endI - startI), len = 0;
|
|
@@ -10287,7 +10451,9 @@ class TreeNode {
|
|
|
10287
10451
|
getChildren(type, before = null, after = null) {
|
|
10288
10452
|
return getChildren(this, type, before, after);
|
|
10289
10453
|
}
|
|
10290
|
-
|
|
10454
|
+
/**
|
|
10455
|
+
@internal
|
|
10456
|
+
*/
|
|
10291
10457
|
toString() { return this._tree.toString(); }
|
|
10292
10458
|
get node() { return this; }
|
|
10293
10459
|
matchContext(context) { return matchNodeContext(this, context); }
|
|
@@ -10395,7 +10561,9 @@ class BufferNode {
|
|
|
10395
10561
|
return resolveNode(this, pos, side, true);
|
|
10396
10562
|
}
|
|
10397
10563
|
enterUnfinishedNodesBefore(pos) { return enterUnfinishedNodesBefore(this, pos); }
|
|
10398
|
-
|
|
10564
|
+
/**
|
|
10565
|
+
@internal
|
|
10566
|
+
*/
|
|
10399
10567
|
toString() { return this.context.buffer.childString(this.index); }
|
|
10400
10568
|
getChild(type, before = null, after = null) {
|
|
10401
10569
|
let r = getChildren(this, type, before, after);
|
|
@@ -10407,20 +10575,32 @@ class BufferNode {
|
|
|
10407
10575
|
get node() { return this; }
|
|
10408
10576
|
matchContext(context) { return matchNodeContext(this, context); }
|
|
10409
10577
|
}
|
|
10410
|
-
|
|
10411
|
-
|
|
10578
|
+
/**
|
|
10579
|
+
A tree cursor object focuses on a given node in a syntax tree, and
|
|
10580
|
+
allows you to move to adjacent nodes.
|
|
10581
|
+
*/
|
|
10412
10582
|
class TreeCursor {
|
|
10413
|
-
|
|
10583
|
+
/**
|
|
10584
|
+
Shorthand for `.type.name`.
|
|
10585
|
+
*/
|
|
10414
10586
|
get name() { return this.type.name; }
|
|
10415
|
-
|
|
10587
|
+
/**
|
|
10588
|
+
@internal
|
|
10589
|
+
*/
|
|
10416
10590
|
constructor(node,
|
|
10417
|
-
|
|
10591
|
+
/**
|
|
10592
|
+
@internal
|
|
10593
|
+
*/
|
|
10418
10594
|
mode = 0) {
|
|
10419
10595
|
this.mode = mode;
|
|
10420
|
-
|
|
10596
|
+
/**
|
|
10597
|
+
@internal
|
|
10598
|
+
*/
|
|
10421
10599
|
this.buffer = null;
|
|
10422
10600
|
this.stack = [];
|
|
10423
|
-
|
|
10601
|
+
/**
|
|
10602
|
+
@internal
|
|
10603
|
+
*/
|
|
10424
10604
|
this.index = 0;
|
|
10425
10605
|
this.bufferNode = null;
|
|
10426
10606
|
if (node instanceof TreeNode) {
|
|
@@ -10462,11 +10642,15 @@ class TreeCursor {
|
|
|
10462
10642
|
this.buffer = node.context;
|
|
10463
10643
|
return this.yieldBuf(node.index, node.type);
|
|
10464
10644
|
}
|
|
10465
|
-
|
|
10645
|
+
/**
|
|
10646
|
+
@internal
|
|
10647
|
+
*/
|
|
10466
10648
|
toString() {
|
|
10467
10649
|
return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
|
|
10468
10650
|
}
|
|
10469
|
-
|
|
10651
|
+
/**
|
|
10652
|
+
@internal
|
|
10653
|
+
*/
|
|
10470
10654
|
enterChild(dir, pos, side) {
|
|
10471
10655
|
if (!this.buffer)
|
|
10472
10656
|
return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
|
|
@@ -10477,26 +10661,38 @@ class TreeCursor {
|
|
|
10477
10661
|
this.stack.push(this.index);
|
|
10478
10662
|
return this.yieldBuf(index);
|
|
10479
10663
|
}
|
|
10480
|
-
|
|
10481
|
-
|
|
10664
|
+
/**
|
|
10665
|
+
Move the cursor to this node's first child. When this returns
|
|
10666
|
+
false, the node has no child, and the cursor has not been moved.
|
|
10667
|
+
*/
|
|
10482
10668
|
firstChild() { return this.enterChild(1, 0, 4 /* Side.DontCare */); }
|
|
10483
|
-
|
|
10669
|
+
/**
|
|
10670
|
+
Move the cursor to this node's last child.
|
|
10671
|
+
*/
|
|
10484
10672
|
lastChild() { return this.enterChild(-1, 0, 4 /* Side.DontCare */); }
|
|
10485
|
-
|
|
10673
|
+
/**
|
|
10674
|
+
Move the cursor to the first child that ends after `pos`.
|
|
10675
|
+
*/
|
|
10486
10676
|
childAfter(pos) { return this.enterChild(1, pos, 2 /* Side.After */); }
|
|
10487
|
-
|
|
10677
|
+
/**
|
|
10678
|
+
Move to the last child that starts before `pos`.
|
|
10679
|
+
*/
|
|
10488
10680
|
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Side.Before */); }
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10681
|
+
/**
|
|
10682
|
+
Move the cursor to the child around `pos`. If side is -1 the
|
|
10683
|
+
child may end at that position, when 1 it may start there. This
|
|
10684
|
+
will also enter [overlaid](#common.MountedTree.overlay)
|
|
10685
|
+
[mounted](#common.NodeProp^mounted) trees unless `overlays` is
|
|
10686
|
+
set to false.
|
|
10687
|
+
*/
|
|
10494
10688
|
enter(pos, side, mode = this.mode) {
|
|
10495
10689
|
if (!this.buffer)
|
|
10496
10690
|
return this.yield(this._tree.enter(pos, side, mode));
|
|
10497
10691
|
return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
|
|
10498
10692
|
}
|
|
10499
|
-
|
|
10693
|
+
/**
|
|
10694
|
+
Move to the node's parent node, if this isn't the top node.
|
|
10695
|
+
*/
|
|
10500
10696
|
parent() {
|
|
10501
10697
|
if (!this.buffer)
|
|
10502
10698
|
return this.yieldNode((this.mode & IterMode.IncludeAnonymous) ? this._tree._parent : this._tree.parent);
|
|
@@ -10506,7 +10702,9 @@ class TreeCursor {
|
|
|
10506
10702
|
this.buffer = null;
|
|
10507
10703
|
return this.yieldNode(parent);
|
|
10508
10704
|
}
|
|
10509
|
-
|
|
10705
|
+
/**
|
|
10706
|
+
@internal
|
|
10707
|
+
*/
|
|
10510
10708
|
sibling(dir) {
|
|
10511
10709
|
if (!this.buffer)
|
|
10512
10710
|
return !this._tree._parent ? false
|
|
@@ -10525,9 +10723,13 @@ class TreeCursor {
|
|
|
10525
10723
|
}
|
|
10526
10724
|
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4 /* Side.DontCare */, this.mode)) : false;
|
|
10527
10725
|
}
|
|
10528
|
-
|
|
10726
|
+
/**
|
|
10727
|
+
Move to this node's next sibling, if any.
|
|
10728
|
+
*/
|
|
10529
10729
|
nextSibling() { return this.sibling(1); }
|
|
10530
|
-
|
|
10730
|
+
/**
|
|
10731
|
+
Move to this node's previous sibling, if any.
|
|
10732
|
+
*/
|
|
10531
10733
|
prevSibling() { return this.sibling(-1); }
|
|
10532
10734
|
atLastNode(dir) {
|
|
10533
10735
|
let index, parent, { buffer } = this;
|
|
@@ -10569,20 +10771,26 @@ class TreeCursor {
|
|
|
10569
10771
|
return false;
|
|
10570
10772
|
}
|
|
10571
10773
|
}
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10774
|
+
/**
|
|
10775
|
+
Move to the next node in a
|
|
10776
|
+
[pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
|
|
10777
|
+
traversal, going from a node to its first child or, if the
|
|
10778
|
+
current node is empty or `enter` is false, its next sibling or
|
|
10779
|
+
the next sibling of the first parent node that has one.
|
|
10780
|
+
*/
|
|
10577
10781
|
next(enter = true) { return this.move(1, enter); }
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10782
|
+
/**
|
|
10783
|
+
Move to the next node in a last-to-first pre-order traveral. A
|
|
10784
|
+
node is followed by its last child or, if it has none, its
|
|
10785
|
+
previous sibling or the previous sibling of the first parent
|
|
10786
|
+
node that has one.
|
|
10787
|
+
*/
|
|
10582
10788
|
prev(enter = true) { return this.move(-1, enter); }
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
|
|
10789
|
+
/**
|
|
10790
|
+
Move the cursor to the innermost node that covers `pos`. If
|
|
10791
|
+
`side` is -1, it will enter nodes that end at `pos`. If it is 1,
|
|
10792
|
+
it will enter nodes that start at `pos`.
|
|
10793
|
+
*/
|
|
10586
10794
|
moveTo(pos, side = 0) {
|
|
10587
10795
|
// Move up to a node that actually holds the position, if possible
|
|
10588
10796
|
while (this.from == this.to ||
|
|
@@ -10594,8 +10802,10 @@ class TreeCursor {
|
|
|
10594
10802
|
while (this.enterChild(1, pos, side)) { }
|
|
10595
10803
|
return this;
|
|
10596
10804
|
}
|
|
10597
|
-
|
|
10598
|
-
|
|
10805
|
+
/**
|
|
10806
|
+
Get a [syntax node](#common.SyntaxNode) at the cursor's current
|
|
10807
|
+
position.
|
|
10808
|
+
*/
|
|
10599
10809
|
get node() {
|
|
10600
10810
|
if (!this.buffer)
|
|
10601
10811
|
return this._tree;
|
|
@@ -10617,16 +10827,20 @@ class TreeCursor {
|
|
|
10617
10827
|
result = new BufferNode(this.buffer, result, this.stack[i]);
|
|
10618
10828
|
return this.bufferNode = new BufferNode(this.buffer, result, this.index);
|
|
10619
10829
|
}
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10830
|
+
/**
|
|
10831
|
+
Get the [tree](#common.Tree) that represents the current node, if
|
|
10832
|
+
any. Will return null when the node is in a [tree
|
|
10833
|
+
buffer](#common.TreeBuffer).
|
|
10834
|
+
*/
|
|
10623
10835
|
get tree() {
|
|
10624
10836
|
return this.buffer ? null : this._tree._tree;
|
|
10625
10837
|
}
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10838
|
+
/**
|
|
10839
|
+
Iterate over the current node and all its descendants, calling
|
|
10840
|
+
`enter` when entering a node and `leave`, if given, when leaving
|
|
10841
|
+
one. When `enter` returns `false`, any children of that node are
|
|
10842
|
+
skipped, and `leave` isn't called for it.
|
|
10843
|
+
*/
|
|
10630
10844
|
iterate(enter, leave) {
|
|
10631
10845
|
for (let depth = 0;;) {
|
|
10632
10846
|
let mustLeave = false;
|
|
@@ -10652,9 +10866,11 @@ class TreeCursor {
|
|
|
10652
10866
|
}
|
|
10653
10867
|
}
|
|
10654
10868
|
}
|
|
10655
|
-
|
|
10656
|
-
|
|
10657
|
-
|
|
10869
|
+
/**
|
|
10870
|
+
Test whether the current node matches a given context—a sequence
|
|
10871
|
+
of direct parent node names. Empty strings in the context array
|
|
10872
|
+
are treated as wildcards.
|
|
10873
|
+
*/
|
|
10658
10874
|
matchContext(context) {
|
|
10659
10875
|
if (!this.buffer)
|
|
10660
10876
|
return matchNodeContext(this.node, context);
|
|
@@ -10929,9 +11145,11 @@ mkTree) {
|
|
|
10929
11145
|
divide(children, positions, from, to, 0);
|
|
10930
11146
|
return (mkTop || mkTree)(localChildren, localPositions, length);
|
|
10931
11147
|
}
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
11148
|
+
/**
|
|
11149
|
+
Provides a way to associate values with pieces of trees. As long
|
|
11150
|
+
as that part of the tree is reused, the associated values can be
|
|
11151
|
+
retrieved from an updated tree.
|
|
11152
|
+
*/
|
|
10935
11153
|
class NodeWeakMap {
|
|
10936
11154
|
constructor() {
|
|
10937
11155
|
this.map = new WeakMap();
|
|
@@ -10946,57 +11164,77 @@ class NodeWeakMap {
|
|
|
10946
11164
|
let inner = this.map.get(buffer);
|
|
10947
11165
|
return inner && inner.get(index);
|
|
10948
11166
|
}
|
|
10949
|
-
|
|
11167
|
+
/**
|
|
11168
|
+
Set the value for this syntax node.
|
|
11169
|
+
*/
|
|
10950
11170
|
set(node, value) {
|
|
10951
11171
|
if (node instanceof BufferNode)
|
|
10952
11172
|
this.setBuffer(node.context.buffer, node.index, value);
|
|
10953
11173
|
else if (node instanceof TreeNode)
|
|
10954
11174
|
this.map.set(node.tree, value);
|
|
10955
11175
|
}
|
|
10956
|
-
|
|
11176
|
+
/**
|
|
11177
|
+
Retrieve value for this syntax node, if it exists in the map.
|
|
11178
|
+
*/
|
|
10957
11179
|
get(node) {
|
|
10958
11180
|
return node instanceof BufferNode ? this.getBuffer(node.context.buffer, node.index)
|
|
10959
11181
|
: node instanceof TreeNode ? this.map.get(node.tree) : undefined;
|
|
10960
11182
|
}
|
|
10961
|
-
|
|
11183
|
+
/**
|
|
11184
|
+
Set the value for the node that a cursor currently points to.
|
|
11185
|
+
*/
|
|
10962
11186
|
cursorSet(cursor, value) {
|
|
10963
11187
|
if (cursor.buffer)
|
|
10964
11188
|
this.setBuffer(cursor.buffer.buffer, cursor.index, value);
|
|
10965
11189
|
else
|
|
10966
11190
|
this.map.set(cursor.tree, value);
|
|
10967
11191
|
}
|
|
10968
|
-
|
|
10969
|
-
|
|
11192
|
+
/**
|
|
11193
|
+
Retrieve the value for the node that a cursor currently points
|
|
11194
|
+
to.
|
|
11195
|
+
*/
|
|
10970
11196
|
cursorGet(cursor) {
|
|
10971
11197
|
return cursor.buffer ? this.getBuffer(cursor.buffer.buffer, cursor.index) : this.map.get(cursor.tree);
|
|
10972
11198
|
}
|
|
10973
11199
|
}
|
|
10974
11200
|
|
|
10975
|
-
|
|
10976
|
-
|
|
10977
|
-
|
|
10978
|
-
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
|
|
11201
|
+
/**
|
|
11202
|
+
Tree fragments are used during [incremental
|
|
11203
|
+
parsing](#common.Parser.startParse) to track parts of old trees
|
|
11204
|
+
that can be reused in a new parse. An array of fragments is used
|
|
11205
|
+
to track regions of an old tree whose nodes might be reused in new
|
|
11206
|
+
parses. Use the static
|
|
11207
|
+
[`applyChanges`](#common.TreeFragment^applyChanges) method to
|
|
11208
|
+
update fragments for document changes.
|
|
11209
|
+
*/
|
|
10982
11210
|
class TreeFragment {
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
11211
|
+
/**
|
|
11212
|
+
Construct a tree fragment. You'll usually want to use
|
|
11213
|
+
[`addTree`](#common.TreeFragment^addTree) and
|
|
11214
|
+
[`applyChanges`](#common.TreeFragment^applyChanges) instead of
|
|
11215
|
+
calling this directly.
|
|
11216
|
+
*/
|
|
10987
11217
|
constructor(
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
11218
|
+
/**
|
|
11219
|
+
The start of the unchanged range pointed to by this fragment.
|
|
11220
|
+
This refers to an offset in the _updated_ document (as opposed
|
|
11221
|
+
to the original tree).
|
|
11222
|
+
*/
|
|
10991
11223
|
from,
|
|
10992
|
-
|
|
11224
|
+
/**
|
|
11225
|
+
The end of the unchanged range.
|
|
11226
|
+
*/
|
|
10993
11227
|
to,
|
|
10994
|
-
|
|
11228
|
+
/**
|
|
11229
|
+
The tree that this fragment is based on.
|
|
11230
|
+
*/
|
|
10995
11231
|
tree,
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11232
|
+
/**
|
|
11233
|
+
The offset between the fragment's tree and the document that
|
|
11234
|
+
this fragment can be used against. Add this when going from
|
|
11235
|
+
document to tree positions, subtract it to go from tree to
|
|
11236
|
+
document positions.
|
|
11237
|
+
*/
|
|
11000
11238
|
offset, openStart = false, openEnd = false) {
|
|
11001
11239
|
this.from = from;
|
|
11002
11240
|
this.to = to;
|
|
@@ -11004,20 +11242,26 @@ class TreeFragment {
|
|
|
11004
11242
|
this.offset = offset;
|
|
11005
11243
|
this.open = (openStart ? 1 /* Open.Start */ : 0) | (openEnd ? 2 /* Open.End */ : 0);
|
|
11006
11244
|
}
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11245
|
+
/**
|
|
11246
|
+
Whether the start of the fragment represents the start of a
|
|
11247
|
+
parse, or the end of a change. (In the second case, it may not
|
|
11248
|
+
be safe to reuse some nodes at the start, depending on the
|
|
11249
|
+
parsing algorithm.)
|
|
11250
|
+
*/
|
|
11011
11251
|
get openStart() { return (this.open & 1 /* Open.Start */) > 0; }
|
|
11012
|
-
|
|
11013
|
-
|
|
11252
|
+
/**
|
|
11253
|
+
Whether the end of the fragment represents the end of a
|
|
11254
|
+
full-document parse, or the start of a change.
|
|
11255
|
+
*/
|
|
11014
11256
|
get openEnd() { return (this.open & 2 /* Open.End */) > 0; }
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11257
|
+
/**
|
|
11258
|
+
Create a set of fragments from a freshly parsed tree, or update
|
|
11259
|
+
an existing set of fragments by replacing the ones that overlap
|
|
11260
|
+
with a tree with content from the new tree. When `partial` is
|
|
11261
|
+
true, the parse is treated as incomplete, and the resulting
|
|
11262
|
+
fragment has [`openEnd`](#common.TreeFragment.openEnd) set to
|
|
11263
|
+
true.
|
|
11264
|
+
*/
|
|
11021
11265
|
static addTree(tree, fragments = [], partial = false) {
|
|
11022
11266
|
let result = [new TreeFragment(0, tree.length, tree, 0, false, partial)];
|
|
11023
11267
|
for (let f of fragments)
|
|
@@ -11025,9 +11269,11 @@ class TreeFragment {
|
|
|
11025
11269
|
result.push(f);
|
|
11026
11270
|
return result;
|
|
11027
11271
|
}
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11272
|
+
/**
|
|
11273
|
+
Apply a set of edits to an array of fragments, removing or
|
|
11274
|
+
splitting fragments as necessary to remove edited ranges, and
|
|
11275
|
+
adjusting offsets for fragments that moved.
|
|
11276
|
+
*/
|
|
11031
11277
|
static applyChanges(fragments, changes, minGap = 128) {
|
|
11032
11278
|
if (!changes.length)
|
|
11033
11279
|
return fragments;
|
|
@@ -11057,23 +11303,29 @@ class TreeFragment {
|
|
|
11057
11303
|
return result;
|
|
11058
11304
|
}
|
|
11059
11305
|
}
|
|
11060
|
-
|
|
11306
|
+
/**
|
|
11307
|
+
A superclass that parsers should extend.
|
|
11308
|
+
*/
|
|
11061
11309
|
class Parser {
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11065
|
-
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
|
-
|
|
11069
|
-
|
|
11310
|
+
/**
|
|
11311
|
+
Start a parse, returning a [partial parse](#common.PartialParse)
|
|
11312
|
+
object. [`fragments`](#common.TreeFragment) can be passed in to
|
|
11313
|
+
make the parse incremental.
|
|
11314
|
+
|
|
11315
|
+
By default, the entire input is parsed. You can pass `ranges`,
|
|
11316
|
+
which should be a sorted array of non-empty, non-overlapping
|
|
11317
|
+
ranges, to parse only those ranges. The tree returned in that
|
|
11318
|
+
case will start at `ranges[0].from`.
|
|
11319
|
+
*/
|
|
11070
11320
|
startParse(input, fragments, ranges) {
|
|
11071
11321
|
if (typeof input == "string")
|
|
11072
11322
|
input = new StringInput(input);
|
|
11073
11323
|
ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map(r => new Range(r.from, r.to)) : [new Range(0, 0)];
|
|
11074
11324
|
return this.createParse(input, fragments || [], ranges);
|
|
11075
11325
|
}
|
|
11076
|
-
|
|
11326
|
+
/**
|
|
11327
|
+
Run a full parse, returning the resulting tree.
|
|
11328
|
+
*/
|
|
11077
11329
|
parse(input, fragments, ranges) {
|
|
11078
11330
|
let parse = this.startParse(input, fragments, ranges);
|
|
11079
11331
|
for (;;) {
|
|
@@ -11093,11 +11345,13 @@ class StringInput {
|
|
|
11093
11345
|
read(from, to) { return this.string.slice(from, to); }
|
|
11094
11346
|
}
|
|
11095
11347
|
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11348
|
+
/**
|
|
11349
|
+
Create a parse wrapper that, after the inner parse completes,
|
|
11350
|
+
scans its tree for mixed language regions with the `nest`
|
|
11351
|
+
function, runs the resulting [inner parses](#common.NestedParse),
|
|
11352
|
+
and then [mounts](#common.NodeProp^mounted) their results onto the
|
|
11353
|
+
tree.
|
|
11354
|
+
*/
|
|
11101
11355
|
function parseMixed(nest) {
|
|
11102
11356
|
return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
|
|
11103
11357
|
}
|