n8n-editor-ui 1.63.2 → 1.64.0
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/assets/{AnnotationTagsDropdown.ee-BrHzX0gM.js → AnnotationTagsDropdown.ee.vue_vue_type_script_setup_true_lang-D3L0Zqex.js} +2 -3
- package/dist/assets/{AuthView-DBTpAWBR.js → AuthView-Bc_d9TU4.js} +3 -6
- package/dist/assets/{AuthView-BnHKMYu_.css → AuthView-Cnr31xHM.css} +6 -5
- package/dist/assets/{CanvasControls-DJjSv7Wo.js → CanvasControls-BZZ5xUA4.js} +1 -31
- package/dist/assets/{ChangePasswordView-4HfufusV.js → ChangePasswordView-BmKDYqVl.js} +2 -32
- package/dist/assets/CollectionParameter-CZX6_SwN.js +4 -0
- package/dist/assets/{CredentialsView-ChVc0kqb.js → CredentialsView-BERKB9pX.js} +5 -35
- package/dist/assets/{ErrorView-C3MNpu-h.js → ErrorView-CGHYke1h.js} +1 -31
- package/dist/assets/{ExecutionsFilter-C71cMIbt.js → ExecutionsFilter-DgmpIaxp.js} +2 -5
- package/dist/assets/{ExecutionsView-CyfD2AaP.js → ExecutionsView-BVJE03N7.js} +18 -54
- package/dist/assets/{file-saver-Dbfm4l4I.js → FileSaver.min-vFM8HBH6.js} +5 -12
- package/dist/assets/{FixedCollectionParameter-DjS7zdm4.js → FixedCollectionParameter-Cu1pUHaU.js} +1 -32
- package/dist/assets/{ForgotMyPasswordView-BThu5AzW.js → ForgotMyPasswordView-CA1z31op.js} +2 -32
- package/dist/assets/{MainHeader-BonioYN5.js → MainHeader-lphq3_C7.js} +8 -47
- package/dist/assets/{MainSidebar-NOlas3VF.js → MainSidebar-CkmsLAKw.js} +5 -44
- package/dist/assets/{NodeCreation-ByUlHR8c.js → NodeCreation-CDKKeIJl.js} +4 -7
- package/dist/assets/{NodeCreator-DE9FRbnS.js → NodeCreator-vrcCon6T.js} +20 -64
- package/dist/assets/{NodeViewSwitcher-D7fdLnF1.js → NodeViewSwitcher-CebfwLIC.js} +17198 -4326
- package/dist/assets/{NodeViewSwitcher-BMWd0Gm9.css → NodeViewSwitcher-DFIa0RPL.css} +136 -135
- package/dist/assets/{ProjectCardBadge-f4baniz3.js → ProjectCardBadge.vue_vue_type_script_setup_true_lang-FPZVaoxg.js} +1 -12
- package/dist/assets/{ProjectSettings-CeJUMGSQ.js → ProjectSettings-CGPWNP7C.js} +6 -38
- package/dist/assets/{ProjectTabs-dq7a740r.js → ProjectTabs-D-UxAFWq.js} +1 -3
- package/dist/assets/{PushConnectionTracker-Bs_UzKPJ.js → PushConnectionTracker-dMPKSiLd.js} +1 -4
- package/dist/assets/{ResourcesListLayout-B1XBsMRy.js → ResourcesListLayout-BmEYzLen.js} +2 -7
- package/dist/assets/{RunDataAi-DdGO06st.js → RunDataAi-iy_LiKYx.js} +51 -13
- package/dist/assets/{RunDataJson-DTKvzLZz.js → RunDataJson-30CwTvxp.js} +11 -34
- package/dist/assets/{jsonpath--XXuA3UN.js → RunDataJsonActions-DM8Iegu4.js} +272 -73
- package/dist/assets/{RunDataSearch-CW0connN.js → RunDataSearch-BBZyQz1l.js} +1 -31
- package/dist/assets/{RunDataTable-C-mEq2dD.js → RunDataTable-DlYCaRmD.js} +43 -70
- package/dist/assets/{SamlOnboarding-BfsNvcA1.js → SamlOnboarding-YPyqQAED.js} +2 -32
- package/dist/assets/{SettingsApiView--aIfdlDF.js → SettingsApiView-DM8-r2vC.js} +11 -42
- package/dist/assets/{SettingsCommunityNodesView-DdyT-sgu.js → SettingsCommunityNodesView-CKUSvNJA.js} +3 -35
- package/dist/assets/{SettingsExternalSecrets-DTMX68vp.js → SettingsExternalSecrets-rn0Uon3J.js} +2 -32
- package/dist/assets/SettingsFakeDoorView-DRt2eUs1.js +44 -0
- package/dist/assets/{humanize-duration-DdvB4QXM.js → SettingsLdapView-BkNvZbuP.js} +827 -12
- package/dist/assets/{SettingsLogStreamingView-lQvw760T.js → SettingsLogStreamingView-DJgGrIQ1.js} +1 -31
- package/dist/assets/{SettingsPersonalView-2vlxeSgj.js → SettingsPersonalView-B2bLHSrL.js} +1 -31
- package/dist/assets/{SettingsSourceControl-1Z-AF1Yv.js → SettingsSourceControl-B_iPYBUX.js} +4 -35
- package/dist/assets/{SettingsSso-Bp82V4Mw.js → SettingsSso-Bo8ktz1t.js} +1 -31
- package/dist/assets/{SettingsUsageAndPlan-CDXY25ax.js → SettingsUsageAndPlan-C9jiEOqE.js} +1 -32
- package/dist/assets/{SettingsUsersView-3sIYeb4A.js → SettingsUsersView-Do-E2R-M.js} +1 -31
- package/dist/assets/{SettingsView-BNNArsIx.js → SettingsView-DK-_ao4_.js} +25 -34
- package/dist/assets/{SetupView-pspJi2at.js → SetupView-ZFKQKIJD.js} +2 -32
- package/dist/assets/{SetupWorkflowCredentialsButton-SC5-MI0D.js → SetupWorkflowCredentialsButton-BaMJBfk2.js} +1 -31
- package/dist/assets/{SetupWorkflowFromTemplateView-CU3grpvN.js → SetupWorkflowFromTemplateView-BvmNbGYh.js} +3 -33
- package/dist/assets/{SigninView-CZdE2LU3.js → SigninView-k_FnQgNC.js} +2 -32
- package/dist/assets/SignoutView-DTgJmCun.js +27 -0
- package/dist/assets/{SignupView-BPlt_Lbh.js → SignupView-GFIqKxQ1.js} +2 -32
- package/dist/assets/{TemplateDetails-CdRKYWL6.js → TemplateDetails-CrE5d8Z2.js} +1 -4
- package/dist/assets/{TemplateList-BYq50eQG.js → TemplateList-DugVXLa6.js} +1 -3
- package/dist/assets/{TemplatesCollectionView-D-N6pD00.js → TemplatesCollectionView-BulzRTVk.js} +5 -35
- package/dist/assets/{TemplatesSearchView-CaRL_LUd.js → TemplatesSearchView--aU9JJ_A.js} +738 -41
- package/dist/assets/{TemplatesSearchView-BYNWZYGm.css → TemplatesSearchView-BiokbeYf.css} +94 -1
- package/dist/assets/{TemplatesView-C5HnqMFU.js → TemplatesView-VxuSLtRB.js} +1 -3
- package/dist/assets/{TemplatesWorkflowView-XV_mNcau.js → TemplatesWorkflowView-DEOmoGFU.js} +5 -35
- package/dist/assets/{VariablesView-CDacoelY.js → VariablesView-D0qaiG35.js} +2 -33
- package/dist/assets/{WorkerView-DciBUDzM.js → WorkerView-BQWPVPCG.js} +159 -43
- package/dist/assets/{WorkflowActivator-GHyUbwAO.js → WorkflowActivator-CFE8HnEQ.js} +3 -7
- package/dist/assets/{WorkflowExecutionsInfoAccordion-Dez7kHwM.js → WorkflowExecutionsInfoAccordion-j1oBChRL.js} +1 -3
- package/dist/assets/{WorkflowExecutionsLandingPage-j7sS9stL.js → WorkflowExecutionsLandingPage-7PqoziUe.js} +2 -32
- package/dist/assets/{WorkflowExecutionsPreview-DLogApYK.js → WorkflowExecutionsPreview-BCKc44DY.js} +10 -42
- package/dist/assets/{WorkflowExecutionsView-CZ0E-5CZ.js → WorkflowExecutionsView-De-rqjwc.js} +6 -37
- package/dist/assets/{WorkflowHistory-D6BLJ_QX.js → WorkflowHistory-BQHDI-k-.js} +8 -45
- package/dist/assets/{WorkflowOnboardingView-7Z0s7yrd.js → WorkflowOnboardingView-B3aKS1PJ.js} +1 -31
- package/dist/assets/{WorkflowPreview-C2zFAYYi.js → WorkflowPreview-jblZXN9D.js} +1 -3
- package/dist/assets/{WorkflowsView-CLNYtnzv.js → WorkflowsView-DQqwovww.js} +19 -37
- package/dist/assets/cloud-ChkMgrsu.js +37 -0
- package/dist/assets/{dateFormatter-B-oph3V5.js → dateFormatter-BOFH7hQn.js} +1 -1
- package/dist/assets/index-B5Li9oNe.js +331713 -0
- package/dist/assets/{index-B5Pl_Rdy.css → index-BGyoJ6bM.css} +3941 -8
- package/dist/assets/{pushConnection.store-C38m0a4q.js → pushConnection.store-Cp0wdk-m.js} +3 -3
- package/dist/assets/{templateActions-BDzt5tYG.js → templateActions-DbRugCSY.js} +1 -1
- package/dist/assets/{useBeforeUnload-DAuWtScP.js → useBeforeUnload-HSb2Wsej.js} +1 -2
- package/dist/assets/{useExecutionDebugging-DjezN4ny.js → useExecutionDebugging-Czs7eCHy.js} +1 -2
- package/dist/assets/{usePushConnection-C-AngCFB.js → usePushConnection-CLr2QrgA.js} +12 -17
- package/dist/assets/{useWorkflowActivate-CgGEceEs.js → useWorkflowActivate-D9OoUkBo.js} +1 -2
- package/dist/index.html +2 -33
- package/package.json +1 -1
- package/vite.config.mts +0 -41
- package/dist/assets/@jsplumb/browser-ui-D3WTv2iL.js +0 -5431
- package/dist/assets/@jsplumb/common-Cn2WooAp.js +0 -142
- package/dist/assets/@jsplumb/connector-bezier-BsoOTqok.js +0 -1019
- package/dist/assets/@jsplumb/core-DLCSr9D4.js +0 -7317
- package/dist/assets/@jsplumb/util-DggqnqQo.js +0 -936
- package/dist/assets/@lezer/common-Bs5t-XhT.js +0 -1988
- package/dist/assets/@n8n/api-types-Clq_Leox.js +0 -1
- package/dist/assets/@n8n/codemirror-lang-Bizw8G99.js +0 -20928
- package/dist/assets/@n8n/codemirror-lang-sql-C9sfSTUi.js +0 -14443
- package/dist/assets/@n8n/permissions-BxSXRD9U.js +0 -52
- package/dist/assets/@sentry/vue-By9cUXYj.js +0 -23618
- package/dist/assets/@vue-flow/background-B1J8rodd.js +0 -123
- package/dist/assets/@vue-flow/controls-B4bXJQnK.js +0 -204
- package/dist/assets/@vue-flow/core-tETEFGtP.js +0 -9818
- package/dist/assets/@vue-flow/minimap-CGW7BbeH.js +0 -2951
- package/dist/assets/@vue-flow/node-resizer-C7hxX6Ea.js +0 -1398
- package/dist/assets/@vueuse/core-BTO0AmLR.js +0 -8894
- package/dist/assets/RunDataJsonActions-0J53luAF.js +0 -270
- package/dist/assets/SettingsFakeDoorView-CpouiCJM.js +0 -74
- package/dist/assets/SettingsLdapView-DtUi0T-K.js +0 -746
- package/dist/assets/SignoutView-DN2qdM5U.js +0 -57
- package/dist/assets/aws-secrets-manager-NwVFybsa.svg +0 -18
- package/dist/assets/axios-BW6T4tHC.js +0 -2403
- package/dist/assets/azure-key-vault-DTTl_IR7.svg +0 -23
- package/dist/assets/bowser-CDCHPFWD.js +0 -1931
- package/dist/assets/change-case-Dux1iW35.js +0 -137
- package/dist/assets/chart.js-BYpPl_l4.js +0 -14318
- package/dist/assets/cloud-DJUTi_f-.js +0 -95
- package/dist/assets/codemirror-lang-html-n8n-BElKE4vf.js +0 -2498
- package/dist/assets/dateformat-BevCJF2z.js +0 -208
- package/dist/assets/email-providers-Brdpqw-Z.js +0 -1
- package/dist/assets/esprima-next-DUEu30kB.js +0 -6712
- package/dist/assets/fast-json-stable-stringify-D9R5x91P.js +0 -55
- package/dist/assets/flatted-BLlNkUR-.js +0 -76
- package/dist/assets/gcp-secrets-manager-BcK0Zj6Y.svg +0 -9
- package/dist/assets/hashicorp-5zlHdJCj.webp +0 -0
- package/dist/assets/highlight.js-Brdpqw-Z.js +0 -1
- package/dist/assets/index-DOjaKjUd.js +0 -87778
- package/dist/assets/infisical-Db7VXgLp.webp +0 -0
- package/dist/assets/lodash-es-DCRmYdQ5.js +0 -6061
- package/dist/assets/luxon-N8mghSWH.js +0 -6159
- package/dist/assets/n8n-C6KBCWah.css +0 -4973
- package/dist/assets/n8n-o-6nV4eX.js +0 -163925
- package/dist/assets/pinia-BWzoPyXU.js +0 -1650
- package/dist/assets/prettier-eWLVZldr.js +0 -2294
- package/dist/assets/qrcode.vue-BavVPFUM.js +0 -1132
- package/dist/assets/timeago.js-CgQus8nl.js +0 -116
- package/dist/assets/useUserHelpers-nsswfS_i.js +0 -27
- package/dist/assets/uuid-DRDfXVM2.js +0 -542
- package/dist/assets/v3-infinite-loading-CHlSsXAy.js +0 -114
- package/dist/assets/vendor-D8YCjNHu.js +0 -14463
- package/dist/assets/vue-agile-B2NGbzqY.css +0 -93
- package/dist/assets/vue-agile-Busf3nxn.js +0 -727
- package/dist/assets/vue-chartjs-DBNEiLG-.js +0 -203
- package/dist/assets/vue-i18n-CeifA_Nk.js +0 -5329
- package/dist/assets/vue-json-pretty-DHS8nWi_.js +0 -340
- package/dist/assets/vue3-touch-events-DVOgU3fI.js +0 -301
- package/dist/assets/xss-Brdpqw-Z.js +0 -1
|
@@ -1,1988 +0,0 @@
|
|
|
1
|
-
const DefaultBufferLength = 1024;
|
|
2
|
-
let nextPropID = 0;
|
|
3
|
-
class Range {
|
|
4
|
-
constructor(from, to) {
|
|
5
|
-
this.from = from;
|
|
6
|
-
this.to = to;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
class NodeProp {
|
|
10
|
-
/**
|
|
11
|
-
Create a new node prop type.
|
|
12
|
-
*/
|
|
13
|
-
constructor(config = {}) {
|
|
14
|
-
this.id = nextPropID++;
|
|
15
|
-
this.perNode = !!config.perNode;
|
|
16
|
-
this.deserialize = config.deserialize || (() => {
|
|
17
|
-
throw new Error("This node type doesn't define a deserialize function");
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
This is meant to be used with
|
|
22
|
-
[`NodeSet.extend`](#common.NodeSet.extend) or
|
|
23
|
-
[`LRParser.configure`](#lr.ParserConfig.props) to compute
|
|
24
|
-
prop values for each node type in the set. Takes a [match
|
|
25
|
-
object](#common.NodeType^match) or function that returns undefined
|
|
26
|
-
if the node type doesn't get this prop, and the prop's value if
|
|
27
|
-
it does.
|
|
28
|
-
*/
|
|
29
|
-
add(match) {
|
|
30
|
-
if (this.perNode)
|
|
31
|
-
throw new RangeError("Can't add per-node props to node types");
|
|
32
|
-
if (typeof match != "function")
|
|
33
|
-
match = NodeType.match(match);
|
|
34
|
-
return (type) => {
|
|
35
|
-
let result = match(type);
|
|
36
|
-
return result === void 0 ? null : [this, result];
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
|
|
41
|
-
NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
|
|
42
|
-
NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
|
|
43
|
-
NodeProp.contextHash = new NodeProp({ perNode: true });
|
|
44
|
-
NodeProp.lookAhead = new NodeProp({ perNode: true });
|
|
45
|
-
NodeProp.mounted = new NodeProp({ perNode: true });
|
|
46
|
-
class MountedTree {
|
|
47
|
-
constructor(tree, overlay, parser) {
|
|
48
|
-
this.tree = tree;
|
|
49
|
-
this.overlay = overlay;
|
|
50
|
-
this.parser = parser;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
@internal
|
|
54
|
-
*/
|
|
55
|
-
static get(tree) {
|
|
56
|
-
return tree && tree.props && tree.props[NodeProp.mounted.id];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const noProps = /* @__PURE__ */ Object.create(null);
|
|
60
|
-
class NodeType {
|
|
61
|
-
/**
|
|
62
|
-
@internal
|
|
63
|
-
*/
|
|
64
|
-
constructor(name, props, id, flags = 0) {
|
|
65
|
-
this.name = name;
|
|
66
|
-
this.props = props;
|
|
67
|
-
this.id = id;
|
|
68
|
-
this.flags = flags;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
Define a node type.
|
|
72
|
-
*/
|
|
73
|
-
static define(spec) {
|
|
74
|
-
let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
|
|
75
|
-
let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
|
|
76
|
-
let type = new NodeType(spec.name || "", props, spec.id, flags);
|
|
77
|
-
if (spec.props)
|
|
78
|
-
for (let src of spec.props) {
|
|
79
|
-
if (!Array.isArray(src))
|
|
80
|
-
src = src(type);
|
|
81
|
-
if (src) {
|
|
82
|
-
if (src[0].perNode)
|
|
83
|
-
throw new RangeError("Can't store a per-node prop on a node type");
|
|
84
|
-
props[src[0].id] = src[1];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return type;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
Retrieves a node prop for this type. Will return `undefined` if
|
|
91
|
-
the prop isn't present on this node.
|
|
92
|
-
*/
|
|
93
|
-
prop(prop) {
|
|
94
|
-
return this.props[prop.id];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
True when this is the top node of a grammar.
|
|
98
|
-
*/
|
|
99
|
-
get isTop() {
|
|
100
|
-
return (this.flags & 1) > 0;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
True when this node is produced by a skip rule.
|
|
104
|
-
*/
|
|
105
|
-
get isSkipped() {
|
|
106
|
-
return (this.flags & 2) > 0;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
Indicates whether this is an error node.
|
|
110
|
-
*/
|
|
111
|
-
get isError() {
|
|
112
|
-
return (this.flags & 4) > 0;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
When true, this node type doesn't correspond to a user-declared
|
|
116
|
-
named node, for example because it is used to cache repetition.
|
|
117
|
-
*/
|
|
118
|
-
get isAnonymous() {
|
|
119
|
-
return (this.flags & 8) > 0;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
Returns true when this node's name or one of its
|
|
123
|
-
[groups](#common.NodeProp^group) matches the given string.
|
|
124
|
-
*/
|
|
125
|
-
is(name) {
|
|
126
|
-
if (typeof name == "string") {
|
|
127
|
-
if (this.name == name)
|
|
128
|
-
return true;
|
|
129
|
-
let group = this.prop(NodeProp.group);
|
|
130
|
-
return group ? group.indexOf(name) > -1 : false;
|
|
131
|
-
}
|
|
132
|
-
return this.id == name;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
Create a function from node types to arbitrary values by
|
|
136
|
-
specifying an object whose property names are node or
|
|
137
|
-
[group](#common.NodeProp^group) names. Often useful with
|
|
138
|
-
[`NodeProp.add`](#common.NodeProp.add). You can put multiple
|
|
139
|
-
names, separated by spaces, in a single property name to map
|
|
140
|
-
multiple node names to a single value.
|
|
141
|
-
*/
|
|
142
|
-
static match(map) {
|
|
143
|
-
let direct = /* @__PURE__ */ Object.create(null);
|
|
144
|
-
for (let prop in map)
|
|
145
|
-
for (let name of prop.split(" "))
|
|
146
|
-
direct[name] = map[prop];
|
|
147
|
-
return (node) => {
|
|
148
|
-
for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
|
|
149
|
-
let found = direct[i < 0 ? node.name : groups[i]];
|
|
150
|
-
if (found)
|
|
151
|
-
return found;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
NodeType.none = new NodeType(
|
|
157
|
-
"",
|
|
158
|
-
/* @__PURE__ */ Object.create(null),
|
|
159
|
-
0,
|
|
160
|
-
8
|
|
161
|
-
/* NodeFlag.Anonymous */
|
|
162
|
-
);
|
|
163
|
-
class NodeSet {
|
|
164
|
-
/**
|
|
165
|
-
Create a set with the given types. The `id` property of each
|
|
166
|
-
type should correspond to its position within the array.
|
|
167
|
-
*/
|
|
168
|
-
constructor(types) {
|
|
169
|
-
this.types = types;
|
|
170
|
-
for (let i = 0; i < types.length; i++)
|
|
171
|
-
if (types[i].id != i)
|
|
172
|
-
throw new RangeError("Node type ids should correspond to array positions when creating a node set");
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
Create a copy of this set with some node properties added. The
|
|
176
|
-
arguments to this method can be created with
|
|
177
|
-
[`NodeProp.add`](#common.NodeProp.add).
|
|
178
|
-
*/
|
|
179
|
-
extend(...props) {
|
|
180
|
-
let newTypes = [];
|
|
181
|
-
for (let type of this.types) {
|
|
182
|
-
let newProps = null;
|
|
183
|
-
for (let source of props) {
|
|
184
|
-
let add = source(type);
|
|
185
|
-
if (add) {
|
|
186
|
-
if (!newProps)
|
|
187
|
-
newProps = Object.assign({}, type.props);
|
|
188
|
-
newProps[add[0].id] = add[1];
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
|
|
192
|
-
}
|
|
193
|
-
return new NodeSet(newTypes);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const CachedNode = /* @__PURE__ */ new WeakMap(), CachedInnerNode = /* @__PURE__ */ new WeakMap();
|
|
197
|
-
var IterMode;
|
|
198
|
-
(function(IterMode2) {
|
|
199
|
-
IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
|
|
200
|
-
IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
|
|
201
|
-
IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
|
|
202
|
-
IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
|
|
203
|
-
})(IterMode || (IterMode = {}));
|
|
204
|
-
class Tree {
|
|
205
|
-
/**
|
|
206
|
-
Construct a new tree. See also [`Tree.build`](#common.Tree^build).
|
|
207
|
-
*/
|
|
208
|
-
constructor(type, children, positions, length, props) {
|
|
209
|
-
this.type = type;
|
|
210
|
-
this.children = children;
|
|
211
|
-
this.positions = positions;
|
|
212
|
-
this.length = length;
|
|
213
|
-
this.props = null;
|
|
214
|
-
if (props && props.length) {
|
|
215
|
-
this.props = /* @__PURE__ */ Object.create(null);
|
|
216
|
-
for (let [prop, value] of props)
|
|
217
|
-
this.props[typeof prop == "number" ? prop : prop.id] = value;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
@internal
|
|
222
|
-
*/
|
|
223
|
-
toString() {
|
|
224
|
-
let mounted = MountedTree.get(this);
|
|
225
|
-
if (mounted && !mounted.overlay)
|
|
226
|
-
return mounted.tree.toString();
|
|
227
|
-
let children = "";
|
|
228
|
-
for (let ch of this.children) {
|
|
229
|
-
let str = ch.toString();
|
|
230
|
-
if (str) {
|
|
231
|
-
if (children)
|
|
232
|
-
children += ",";
|
|
233
|
-
children += str;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
Get a [tree cursor](#common.TreeCursor) positioned at the top of
|
|
240
|
-
the tree. Mode can be used to [control](#common.IterMode) which
|
|
241
|
-
nodes the cursor visits.
|
|
242
|
-
*/
|
|
243
|
-
cursor(mode = 0) {
|
|
244
|
-
return new TreeCursor(this.topNode, mode);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
Get a [tree cursor](#common.TreeCursor) pointing into this tree
|
|
248
|
-
at the given position and side (see
|
|
249
|
-
[`moveTo`](#common.TreeCursor.moveTo).
|
|
250
|
-
*/
|
|
251
|
-
cursorAt(pos, side = 0, mode = 0) {
|
|
252
|
-
let scope = CachedNode.get(this) || this.topNode;
|
|
253
|
-
let cursor = new TreeCursor(scope);
|
|
254
|
-
cursor.moveTo(pos, side);
|
|
255
|
-
CachedNode.set(this, cursor._tree);
|
|
256
|
-
return cursor;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
Get a [syntax node](#common.SyntaxNode) object for the top of the
|
|
260
|
-
tree.
|
|
261
|
-
*/
|
|
262
|
-
get topNode() {
|
|
263
|
-
return new TreeNode(this, 0, 0, null);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
Get the [syntax node](#common.SyntaxNode) at the given position.
|
|
267
|
-
If `side` is -1, this will move into nodes that end at the
|
|
268
|
-
position. If 1, it'll move into nodes that start at the
|
|
269
|
-
position. With 0, it'll only enter nodes that cover the position
|
|
270
|
-
from both sides.
|
|
271
|
-
|
|
272
|
-
Note that this will not enter
|
|
273
|
-
[overlays](#common.MountedTree.overlay), and you often want
|
|
274
|
-
[`resolveInner`](#common.Tree.resolveInner) instead.
|
|
275
|
-
*/
|
|
276
|
-
resolve(pos, side = 0) {
|
|
277
|
-
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
278
|
-
CachedNode.set(this, node);
|
|
279
|
-
return node;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
Like [`resolve`](#common.Tree.resolve), but will enter
|
|
283
|
-
[overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
|
|
284
|
-
pointing into the innermost overlaid tree at the given position
|
|
285
|
-
(with parent links going through all parent structure, including
|
|
286
|
-
the host trees).
|
|
287
|
-
*/
|
|
288
|
-
resolveInner(pos, side = 0) {
|
|
289
|
-
let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
|
|
290
|
-
CachedInnerNode.set(this, node);
|
|
291
|
-
return node;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
In some situations, it can be useful to iterate through all
|
|
295
|
-
nodes around a position, including those in overlays that don't
|
|
296
|
-
directly cover the position. This method gives you an iterator
|
|
297
|
-
that will produce all nodes, from small to big, around the given
|
|
298
|
-
position.
|
|
299
|
-
*/
|
|
300
|
-
resolveStack(pos, side = 0) {
|
|
301
|
-
return stackIterator(this, pos, side);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
Iterate over the tree and its children, calling `enter` for any
|
|
305
|
-
node that touches the `from`/`to` region (if given) before
|
|
306
|
-
running over such a node's children, and `leave` (if given) when
|
|
307
|
-
leaving the node. When `enter` returns `false`, that node will
|
|
308
|
-
not have its children iterated over (or `leave` called).
|
|
309
|
-
*/
|
|
310
|
-
iterate(spec) {
|
|
311
|
-
let { enter, leave, from = 0, to = this.length } = spec;
|
|
312
|
-
let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
|
|
313
|
-
for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
|
|
314
|
-
let entered = false;
|
|
315
|
-
if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
|
|
316
|
-
if (c.firstChild())
|
|
317
|
-
continue;
|
|
318
|
-
entered = true;
|
|
319
|
-
}
|
|
320
|
-
for (; ; ) {
|
|
321
|
-
if (entered && leave && (anon || !c.type.isAnonymous))
|
|
322
|
-
leave(c);
|
|
323
|
-
if (c.nextSibling())
|
|
324
|
-
break;
|
|
325
|
-
if (!c.parent())
|
|
326
|
-
return;
|
|
327
|
-
entered = true;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
Get the value of the given [node prop](#common.NodeProp) for this
|
|
333
|
-
node. Works with both per-node and per-type props.
|
|
334
|
-
*/
|
|
335
|
-
prop(prop) {
|
|
336
|
-
return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
Returns the node's [per-node props](#common.NodeProp.perNode) in a
|
|
340
|
-
format that can be passed to the [`Tree`](#common.Tree)
|
|
341
|
-
constructor.
|
|
342
|
-
*/
|
|
343
|
-
get propValues() {
|
|
344
|
-
let result = [];
|
|
345
|
-
if (this.props)
|
|
346
|
-
for (let id in this.props)
|
|
347
|
-
result.push([+id, this.props[id]]);
|
|
348
|
-
return result;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
Balance the direct children of this tree, producing a copy of
|
|
352
|
-
which may have children grouped into subtrees with type
|
|
353
|
-
[`NodeType.none`](#common.NodeType^none).
|
|
354
|
-
*/
|
|
355
|
-
balance(config = {}) {
|
|
356
|
-
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)));
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
Build a tree from a postfix-ordered buffer of node information,
|
|
360
|
-
or a cursor over such a buffer.
|
|
361
|
-
*/
|
|
362
|
-
static build(data) {
|
|
363
|
-
return buildTree(data);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
Tree.empty = new Tree(NodeType.none, [], [], 0);
|
|
367
|
-
class FlatBufferCursor {
|
|
368
|
-
constructor(buffer, index) {
|
|
369
|
-
this.buffer = buffer;
|
|
370
|
-
this.index = index;
|
|
371
|
-
}
|
|
372
|
-
get id() {
|
|
373
|
-
return this.buffer[this.index - 4];
|
|
374
|
-
}
|
|
375
|
-
get start() {
|
|
376
|
-
return this.buffer[this.index - 3];
|
|
377
|
-
}
|
|
378
|
-
get end() {
|
|
379
|
-
return this.buffer[this.index - 2];
|
|
380
|
-
}
|
|
381
|
-
get size() {
|
|
382
|
-
return this.buffer[this.index - 1];
|
|
383
|
-
}
|
|
384
|
-
get pos() {
|
|
385
|
-
return this.index;
|
|
386
|
-
}
|
|
387
|
-
next() {
|
|
388
|
-
this.index -= 4;
|
|
389
|
-
}
|
|
390
|
-
fork() {
|
|
391
|
-
return new FlatBufferCursor(this.buffer, this.index);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
class TreeBuffer {
|
|
395
|
-
/**
|
|
396
|
-
Create a tree buffer.
|
|
397
|
-
*/
|
|
398
|
-
constructor(buffer, length, set) {
|
|
399
|
-
this.buffer = buffer;
|
|
400
|
-
this.length = length;
|
|
401
|
-
this.set = set;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
@internal
|
|
405
|
-
*/
|
|
406
|
-
get type() {
|
|
407
|
-
return NodeType.none;
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
@internal
|
|
411
|
-
*/
|
|
412
|
-
toString() {
|
|
413
|
-
let result = [];
|
|
414
|
-
for (let index = 0; index < this.buffer.length; ) {
|
|
415
|
-
result.push(this.childString(index));
|
|
416
|
-
index = this.buffer[index + 3];
|
|
417
|
-
}
|
|
418
|
-
return result.join(",");
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
@internal
|
|
422
|
-
*/
|
|
423
|
-
childString(index) {
|
|
424
|
-
let id = this.buffer[index], endIndex = this.buffer[index + 3];
|
|
425
|
-
let type = this.set.types[id], result = type.name;
|
|
426
|
-
if (/\W/.test(result) && !type.isError)
|
|
427
|
-
result = JSON.stringify(result);
|
|
428
|
-
index += 4;
|
|
429
|
-
if (endIndex == index)
|
|
430
|
-
return result;
|
|
431
|
-
let children = [];
|
|
432
|
-
while (index < endIndex) {
|
|
433
|
-
children.push(this.childString(index));
|
|
434
|
-
index = this.buffer[index + 3];
|
|
435
|
-
}
|
|
436
|
-
return result + "(" + children.join(",") + ")";
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
@internal
|
|
440
|
-
*/
|
|
441
|
-
findChild(startIndex, endIndex, dir, pos, side) {
|
|
442
|
-
let { buffer } = this, pick = -1;
|
|
443
|
-
for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
|
|
444
|
-
if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
|
|
445
|
-
pick = i;
|
|
446
|
-
if (dir > 0)
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return pick;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
@internal
|
|
454
|
-
*/
|
|
455
|
-
slice(startI, endI, from) {
|
|
456
|
-
let b = this.buffer;
|
|
457
|
-
let copy = new Uint16Array(endI - startI), len = 0;
|
|
458
|
-
for (let i = startI, j = 0; i < endI; ) {
|
|
459
|
-
copy[j++] = b[i++];
|
|
460
|
-
copy[j++] = b[i++] - from;
|
|
461
|
-
let to = copy[j++] = b[i++] - from;
|
|
462
|
-
copy[j++] = b[i++] - startI;
|
|
463
|
-
len = Math.max(len, to);
|
|
464
|
-
}
|
|
465
|
-
return new TreeBuffer(copy, len, this.set);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
function checkSide(side, pos, from, to) {
|
|
469
|
-
switch (side) {
|
|
470
|
-
case -2:
|
|
471
|
-
return from < pos;
|
|
472
|
-
case -1:
|
|
473
|
-
return to >= pos && from < pos;
|
|
474
|
-
case 0:
|
|
475
|
-
return from < pos && to > pos;
|
|
476
|
-
case 1:
|
|
477
|
-
return from <= pos && to > pos;
|
|
478
|
-
case 2:
|
|
479
|
-
return to > pos;
|
|
480
|
-
case 4:
|
|
481
|
-
return true;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
function resolveNode(node, pos, side, overlays) {
|
|
485
|
-
var _a;
|
|
486
|
-
while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
|
|
487
|
-
let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
|
|
488
|
-
if (!parent)
|
|
489
|
-
return node;
|
|
490
|
-
node = parent;
|
|
491
|
-
}
|
|
492
|
-
let mode = overlays ? 0 : IterMode.IgnoreOverlays;
|
|
493
|
-
if (overlays)
|
|
494
|
-
for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
|
|
495
|
-
if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
|
|
496
|
-
node = parent;
|
|
497
|
-
}
|
|
498
|
-
for (; ; ) {
|
|
499
|
-
let inner = node.enter(pos, side, mode);
|
|
500
|
-
if (!inner)
|
|
501
|
-
return node;
|
|
502
|
-
node = inner;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
class BaseNode {
|
|
506
|
-
cursor(mode = 0) {
|
|
507
|
-
return new TreeCursor(this, mode);
|
|
508
|
-
}
|
|
509
|
-
getChild(type, before = null, after = null) {
|
|
510
|
-
let r = getChildren(this, type, before, after);
|
|
511
|
-
return r.length ? r[0] : null;
|
|
512
|
-
}
|
|
513
|
-
getChildren(type, before = null, after = null) {
|
|
514
|
-
return getChildren(this, type, before, after);
|
|
515
|
-
}
|
|
516
|
-
resolve(pos, side = 0) {
|
|
517
|
-
return resolveNode(this, pos, side, false);
|
|
518
|
-
}
|
|
519
|
-
resolveInner(pos, side = 0) {
|
|
520
|
-
return resolveNode(this, pos, side, true);
|
|
521
|
-
}
|
|
522
|
-
matchContext(context) {
|
|
523
|
-
return matchNodeContext(this, context);
|
|
524
|
-
}
|
|
525
|
-
enterUnfinishedNodesBefore(pos) {
|
|
526
|
-
let scan = this.childBefore(pos), node = this;
|
|
527
|
-
while (scan) {
|
|
528
|
-
let last = scan.lastChild;
|
|
529
|
-
if (!last || last.to != scan.to)
|
|
530
|
-
break;
|
|
531
|
-
if (last.type.isError && last.from == last.to) {
|
|
532
|
-
node = scan;
|
|
533
|
-
scan = last.prevSibling;
|
|
534
|
-
} else {
|
|
535
|
-
scan = last;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
return node;
|
|
539
|
-
}
|
|
540
|
-
get node() {
|
|
541
|
-
return this;
|
|
542
|
-
}
|
|
543
|
-
get next() {
|
|
544
|
-
return this.parent;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
class TreeNode extends BaseNode {
|
|
548
|
-
constructor(_tree, from, index, _parent) {
|
|
549
|
-
super();
|
|
550
|
-
this._tree = _tree;
|
|
551
|
-
this.from = from;
|
|
552
|
-
this.index = index;
|
|
553
|
-
this._parent = _parent;
|
|
554
|
-
}
|
|
555
|
-
get type() {
|
|
556
|
-
return this._tree.type;
|
|
557
|
-
}
|
|
558
|
-
get name() {
|
|
559
|
-
return this._tree.type.name;
|
|
560
|
-
}
|
|
561
|
-
get to() {
|
|
562
|
-
return this.from + this._tree.length;
|
|
563
|
-
}
|
|
564
|
-
nextChild(i, dir, pos, side, mode = 0) {
|
|
565
|
-
for (let parent = this; ; ) {
|
|
566
|
-
for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
|
|
567
|
-
let next = children[i], start = positions[i] + parent.from;
|
|
568
|
-
if (!checkSide(side, pos, start, start + next.length))
|
|
569
|
-
continue;
|
|
570
|
-
if (next instanceof TreeBuffer) {
|
|
571
|
-
if (mode & IterMode.ExcludeBuffers)
|
|
572
|
-
continue;
|
|
573
|
-
let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
|
|
574
|
-
if (index > -1)
|
|
575
|
-
return new BufferNode(new BufferContext(parent, next, i, start), null, index);
|
|
576
|
-
} else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
|
|
577
|
-
let mounted;
|
|
578
|
-
if (!(mode & IterMode.IgnoreMounts) && (mounted = MountedTree.get(next)) && !mounted.overlay)
|
|
579
|
-
return new TreeNode(mounted.tree, start, i, parent);
|
|
580
|
-
let inner = new TreeNode(next, start, i, parent);
|
|
581
|
-
return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
|
|
585
|
-
return null;
|
|
586
|
-
if (parent.index >= 0)
|
|
587
|
-
i = parent.index + dir;
|
|
588
|
-
else
|
|
589
|
-
i = dir < 0 ? -1 : parent._parent._tree.children.length;
|
|
590
|
-
parent = parent._parent;
|
|
591
|
-
if (!parent)
|
|
592
|
-
return null;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
get firstChild() {
|
|
596
|
-
return this.nextChild(
|
|
597
|
-
0,
|
|
598
|
-
1,
|
|
599
|
-
0,
|
|
600
|
-
4
|
|
601
|
-
/* Side.DontCare */
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
|
-
get lastChild() {
|
|
605
|
-
return this.nextChild(
|
|
606
|
-
this._tree.children.length - 1,
|
|
607
|
-
-1,
|
|
608
|
-
0,
|
|
609
|
-
4
|
|
610
|
-
/* Side.DontCare */
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
childAfter(pos) {
|
|
614
|
-
return this.nextChild(
|
|
615
|
-
0,
|
|
616
|
-
1,
|
|
617
|
-
pos,
|
|
618
|
-
2
|
|
619
|
-
/* Side.After */
|
|
620
|
-
);
|
|
621
|
-
}
|
|
622
|
-
childBefore(pos) {
|
|
623
|
-
return this.nextChild(
|
|
624
|
-
this._tree.children.length - 1,
|
|
625
|
-
-1,
|
|
626
|
-
pos,
|
|
627
|
-
-2
|
|
628
|
-
/* Side.Before */
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
|
-
enter(pos, side, mode = 0) {
|
|
632
|
-
let mounted;
|
|
633
|
-
if (!(mode & IterMode.IgnoreOverlays) && (mounted = MountedTree.get(this._tree)) && mounted.overlay) {
|
|
634
|
-
let rPos = pos - this.from;
|
|
635
|
-
for (let { from, to } of mounted.overlay) {
|
|
636
|
-
if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
|
|
637
|
-
return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return this.nextChild(0, 1, pos, side, mode);
|
|
641
|
-
}
|
|
642
|
-
nextSignificantParent() {
|
|
643
|
-
let val = this;
|
|
644
|
-
while (val.type.isAnonymous && val._parent)
|
|
645
|
-
val = val._parent;
|
|
646
|
-
return val;
|
|
647
|
-
}
|
|
648
|
-
get parent() {
|
|
649
|
-
return this._parent ? this._parent.nextSignificantParent() : null;
|
|
650
|
-
}
|
|
651
|
-
get nextSibling() {
|
|
652
|
-
return this._parent && this.index >= 0 ? this._parent.nextChild(
|
|
653
|
-
this.index + 1,
|
|
654
|
-
1,
|
|
655
|
-
0,
|
|
656
|
-
4
|
|
657
|
-
/* Side.DontCare */
|
|
658
|
-
) : null;
|
|
659
|
-
}
|
|
660
|
-
get prevSibling() {
|
|
661
|
-
return this._parent && this.index >= 0 ? this._parent.nextChild(
|
|
662
|
-
this.index - 1,
|
|
663
|
-
-1,
|
|
664
|
-
0,
|
|
665
|
-
4
|
|
666
|
-
/* Side.DontCare */
|
|
667
|
-
) : null;
|
|
668
|
-
}
|
|
669
|
-
get tree() {
|
|
670
|
-
return this._tree;
|
|
671
|
-
}
|
|
672
|
-
toTree() {
|
|
673
|
-
return this._tree;
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
@internal
|
|
677
|
-
*/
|
|
678
|
-
toString() {
|
|
679
|
-
return this._tree.toString();
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
function getChildren(node, type, before, after) {
|
|
683
|
-
let cur = node.cursor(), result = [];
|
|
684
|
-
if (!cur.firstChild())
|
|
685
|
-
return result;
|
|
686
|
-
if (before != null) {
|
|
687
|
-
while (!cur.type.is(before))
|
|
688
|
-
if (!cur.nextSibling())
|
|
689
|
-
return result;
|
|
690
|
-
}
|
|
691
|
-
for (; ; ) {
|
|
692
|
-
if (after != null && cur.type.is(after))
|
|
693
|
-
return result;
|
|
694
|
-
if (cur.type.is(type))
|
|
695
|
-
result.push(cur.node);
|
|
696
|
-
if (!cur.nextSibling())
|
|
697
|
-
return after == null ? result : [];
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
function matchNodeContext(node, context, i = context.length - 1) {
|
|
701
|
-
for (let p = node.parent; i >= 0; p = p.parent) {
|
|
702
|
-
if (!p)
|
|
703
|
-
return false;
|
|
704
|
-
if (!p.type.isAnonymous) {
|
|
705
|
-
if (context[i] && context[i] != p.name)
|
|
706
|
-
return false;
|
|
707
|
-
i--;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return true;
|
|
711
|
-
}
|
|
712
|
-
class BufferContext {
|
|
713
|
-
constructor(parent, buffer, index, start) {
|
|
714
|
-
this.parent = parent;
|
|
715
|
-
this.buffer = buffer;
|
|
716
|
-
this.index = index;
|
|
717
|
-
this.start = start;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
class BufferNode extends BaseNode {
|
|
721
|
-
get name() {
|
|
722
|
-
return this.type.name;
|
|
723
|
-
}
|
|
724
|
-
get from() {
|
|
725
|
-
return this.context.start + this.context.buffer.buffer[this.index + 1];
|
|
726
|
-
}
|
|
727
|
-
get to() {
|
|
728
|
-
return this.context.start + this.context.buffer.buffer[this.index + 2];
|
|
729
|
-
}
|
|
730
|
-
constructor(context, _parent, index) {
|
|
731
|
-
super();
|
|
732
|
-
this.context = context;
|
|
733
|
-
this._parent = _parent;
|
|
734
|
-
this.index = index;
|
|
735
|
-
this.type = context.buffer.set.types[context.buffer.buffer[index]];
|
|
736
|
-
}
|
|
737
|
-
child(dir, pos, side) {
|
|
738
|
-
let { buffer } = this.context;
|
|
739
|
-
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
|
|
740
|
-
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
741
|
-
}
|
|
742
|
-
get firstChild() {
|
|
743
|
-
return this.child(
|
|
744
|
-
1,
|
|
745
|
-
0,
|
|
746
|
-
4
|
|
747
|
-
/* Side.DontCare */
|
|
748
|
-
);
|
|
749
|
-
}
|
|
750
|
-
get lastChild() {
|
|
751
|
-
return this.child(
|
|
752
|
-
-1,
|
|
753
|
-
0,
|
|
754
|
-
4
|
|
755
|
-
/* Side.DontCare */
|
|
756
|
-
);
|
|
757
|
-
}
|
|
758
|
-
childAfter(pos) {
|
|
759
|
-
return this.child(
|
|
760
|
-
1,
|
|
761
|
-
pos,
|
|
762
|
-
2
|
|
763
|
-
/* Side.After */
|
|
764
|
-
);
|
|
765
|
-
}
|
|
766
|
-
childBefore(pos) {
|
|
767
|
-
return this.child(
|
|
768
|
-
-1,
|
|
769
|
-
pos,
|
|
770
|
-
-2
|
|
771
|
-
/* Side.Before */
|
|
772
|
-
);
|
|
773
|
-
}
|
|
774
|
-
enter(pos, side, mode = 0) {
|
|
775
|
-
if (mode & IterMode.ExcludeBuffers)
|
|
776
|
-
return null;
|
|
777
|
-
let { buffer } = this.context;
|
|
778
|
-
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
|
|
779
|
-
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
780
|
-
}
|
|
781
|
-
get parent() {
|
|
782
|
-
return this._parent || this.context.parent.nextSignificantParent();
|
|
783
|
-
}
|
|
784
|
-
externalSibling(dir) {
|
|
785
|
-
return this._parent ? null : this.context.parent.nextChild(
|
|
786
|
-
this.context.index + dir,
|
|
787
|
-
dir,
|
|
788
|
-
0,
|
|
789
|
-
4
|
|
790
|
-
/* Side.DontCare */
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
get nextSibling() {
|
|
794
|
-
let { buffer } = this.context;
|
|
795
|
-
let after = buffer.buffer[this.index + 3];
|
|
796
|
-
if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
|
|
797
|
-
return new BufferNode(this.context, this._parent, after);
|
|
798
|
-
return this.externalSibling(1);
|
|
799
|
-
}
|
|
800
|
-
get prevSibling() {
|
|
801
|
-
let { buffer } = this.context;
|
|
802
|
-
let parentStart = this._parent ? this._parent.index + 4 : 0;
|
|
803
|
-
if (this.index == parentStart)
|
|
804
|
-
return this.externalSibling(-1);
|
|
805
|
-
return new BufferNode(this.context, this._parent, buffer.findChild(
|
|
806
|
-
parentStart,
|
|
807
|
-
this.index,
|
|
808
|
-
-1,
|
|
809
|
-
0,
|
|
810
|
-
4
|
|
811
|
-
/* Side.DontCare */
|
|
812
|
-
));
|
|
813
|
-
}
|
|
814
|
-
get tree() {
|
|
815
|
-
return null;
|
|
816
|
-
}
|
|
817
|
-
toTree() {
|
|
818
|
-
let children = [], positions = [];
|
|
819
|
-
let { buffer } = this.context;
|
|
820
|
-
let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
|
|
821
|
-
if (endI > startI) {
|
|
822
|
-
let from = buffer.buffer[this.index + 1];
|
|
823
|
-
children.push(buffer.slice(startI, endI, from));
|
|
824
|
-
positions.push(0);
|
|
825
|
-
}
|
|
826
|
-
return new Tree(this.type, children, positions, this.to - this.from);
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
@internal
|
|
830
|
-
*/
|
|
831
|
-
toString() {
|
|
832
|
-
return this.context.buffer.childString(this.index);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
function iterStack(heads) {
|
|
836
|
-
if (!heads.length)
|
|
837
|
-
return null;
|
|
838
|
-
if (heads.length == 1)
|
|
839
|
-
return heads[0];
|
|
840
|
-
let pick = 0, picked = heads[0];
|
|
841
|
-
for (let i = 1; i < heads.length; i++) {
|
|
842
|
-
let node = heads[i];
|
|
843
|
-
if (node.from > picked.from || node.to < picked.to) {
|
|
844
|
-
picked = node;
|
|
845
|
-
pick = i;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
let next = picked instanceof TreeNode && picked.index < 0 ? null : picked.parent;
|
|
849
|
-
let newHeads = heads.slice();
|
|
850
|
-
if (next)
|
|
851
|
-
newHeads[pick] = next;
|
|
852
|
-
else
|
|
853
|
-
newHeads.splice(pick, 1);
|
|
854
|
-
return new StackIterator(newHeads, picked);
|
|
855
|
-
}
|
|
856
|
-
class StackIterator {
|
|
857
|
-
constructor(heads, node) {
|
|
858
|
-
this.heads = heads;
|
|
859
|
-
this.node = node;
|
|
860
|
-
}
|
|
861
|
-
get next() {
|
|
862
|
-
return iterStack(this.heads);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
function stackIterator(tree, pos, side) {
|
|
866
|
-
let inner = tree.resolveInner(pos, side), layers = null;
|
|
867
|
-
for (let scan = inner instanceof TreeNode ? inner : inner.context.parent; scan; scan = scan.parent) {
|
|
868
|
-
if (scan.index < 0) {
|
|
869
|
-
let parent = scan.parent;
|
|
870
|
-
(layers || (layers = [inner])).push(parent.resolve(pos, side));
|
|
871
|
-
scan = parent;
|
|
872
|
-
} else {
|
|
873
|
-
let mount = MountedTree.get(scan.tree);
|
|
874
|
-
if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
|
|
875
|
-
let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, 0, null);
|
|
876
|
-
(layers || (layers = [inner])).push(resolveNode(root, pos, side, false));
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
return layers ? iterStack(layers) : inner;
|
|
881
|
-
}
|
|
882
|
-
class TreeCursor {
|
|
883
|
-
/**
|
|
884
|
-
Shorthand for `.type.name`.
|
|
885
|
-
*/
|
|
886
|
-
get name() {
|
|
887
|
-
return this.type.name;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
@internal
|
|
891
|
-
*/
|
|
892
|
-
constructor(node, mode = 0) {
|
|
893
|
-
this.mode = mode;
|
|
894
|
-
this.buffer = null;
|
|
895
|
-
this.stack = [];
|
|
896
|
-
this.index = 0;
|
|
897
|
-
this.bufferNode = null;
|
|
898
|
-
if (node instanceof TreeNode) {
|
|
899
|
-
this.yieldNode(node);
|
|
900
|
-
} else {
|
|
901
|
-
this._tree = node.context.parent;
|
|
902
|
-
this.buffer = node.context;
|
|
903
|
-
for (let n = node._parent; n; n = n._parent)
|
|
904
|
-
this.stack.unshift(n.index);
|
|
905
|
-
this.bufferNode = node;
|
|
906
|
-
this.yieldBuf(node.index);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
yieldNode(node) {
|
|
910
|
-
if (!node)
|
|
911
|
-
return false;
|
|
912
|
-
this._tree = node;
|
|
913
|
-
this.type = node.type;
|
|
914
|
-
this.from = node.from;
|
|
915
|
-
this.to = node.to;
|
|
916
|
-
return true;
|
|
917
|
-
}
|
|
918
|
-
yieldBuf(index, type) {
|
|
919
|
-
this.index = index;
|
|
920
|
-
let { start, buffer } = this.buffer;
|
|
921
|
-
this.type = type || buffer.set.types[buffer.buffer[index]];
|
|
922
|
-
this.from = start + buffer.buffer[index + 1];
|
|
923
|
-
this.to = start + buffer.buffer[index + 2];
|
|
924
|
-
return true;
|
|
925
|
-
}
|
|
926
|
-
yield(node) {
|
|
927
|
-
if (!node)
|
|
928
|
-
return false;
|
|
929
|
-
if (node instanceof TreeNode) {
|
|
930
|
-
this.buffer = null;
|
|
931
|
-
return this.yieldNode(node);
|
|
932
|
-
}
|
|
933
|
-
this.buffer = node.context;
|
|
934
|
-
return this.yieldBuf(node.index, node.type);
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
@internal
|
|
938
|
-
*/
|
|
939
|
-
toString() {
|
|
940
|
-
return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
|
|
941
|
-
}
|
|
942
|
-
/**
|
|
943
|
-
@internal
|
|
944
|
-
*/
|
|
945
|
-
enterChild(dir, pos, side) {
|
|
946
|
-
if (!this.buffer)
|
|
947
|
-
return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
|
|
948
|
-
let { buffer } = this.buffer;
|
|
949
|
-
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
|
|
950
|
-
if (index < 0)
|
|
951
|
-
return false;
|
|
952
|
-
this.stack.push(this.index);
|
|
953
|
-
return this.yieldBuf(index);
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
Move the cursor to this node's first child. When this returns
|
|
957
|
-
false, the node has no child, and the cursor has not been moved.
|
|
958
|
-
*/
|
|
959
|
-
firstChild() {
|
|
960
|
-
return this.enterChild(
|
|
961
|
-
1,
|
|
962
|
-
0,
|
|
963
|
-
4
|
|
964
|
-
/* Side.DontCare */
|
|
965
|
-
);
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
Move the cursor to this node's last child.
|
|
969
|
-
*/
|
|
970
|
-
lastChild() {
|
|
971
|
-
return this.enterChild(
|
|
972
|
-
-1,
|
|
973
|
-
0,
|
|
974
|
-
4
|
|
975
|
-
/* Side.DontCare */
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
Move the cursor to the first child that ends after `pos`.
|
|
980
|
-
*/
|
|
981
|
-
childAfter(pos) {
|
|
982
|
-
return this.enterChild(
|
|
983
|
-
1,
|
|
984
|
-
pos,
|
|
985
|
-
2
|
|
986
|
-
/* Side.After */
|
|
987
|
-
);
|
|
988
|
-
}
|
|
989
|
-
/**
|
|
990
|
-
Move to the last child that starts before `pos`.
|
|
991
|
-
*/
|
|
992
|
-
childBefore(pos) {
|
|
993
|
-
return this.enterChild(
|
|
994
|
-
-1,
|
|
995
|
-
pos,
|
|
996
|
-
-2
|
|
997
|
-
/* Side.Before */
|
|
998
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
Move the cursor to the child around `pos`. If side is -1 the
|
|
1002
|
-
child may end at that position, when 1 it may start there. This
|
|
1003
|
-
will also enter [overlaid](#common.MountedTree.overlay)
|
|
1004
|
-
[mounted](#common.NodeProp^mounted) trees unless `overlays` is
|
|
1005
|
-
set to false.
|
|
1006
|
-
*/
|
|
1007
|
-
enter(pos, side, mode = this.mode) {
|
|
1008
|
-
if (!this.buffer)
|
|
1009
|
-
return this.yield(this._tree.enter(pos, side, mode));
|
|
1010
|
-
return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
Move to the node's parent node, if this isn't the top node.
|
|
1014
|
-
*/
|
|
1015
|
-
parent() {
|
|
1016
|
-
if (!this.buffer)
|
|
1017
|
-
return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
|
|
1018
|
-
if (this.stack.length)
|
|
1019
|
-
return this.yieldBuf(this.stack.pop());
|
|
1020
|
-
let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
|
|
1021
|
-
this.buffer = null;
|
|
1022
|
-
return this.yieldNode(parent);
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
@internal
|
|
1026
|
-
*/
|
|
1027
|
-
sibling(dir) {
|
|
1028
|
-
if (!this.buffer)
|
|
1029
|
-
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));
|
|
1030
|
-
let { buffer } = this.buffer, d = this.stack.length - 1;
|
|
1031
|
-
if (dir < 0) {
|
|
1032
|
-
let parentStart = d < 0 ? 0 : this.stack[d] + 4;
|
|
1033
|
-
if (this.index != parentStart)
|
|
1034
|
-
return this.yieldBuf(buffer.findChild(
|
|
1035
|
-
parentStart,
|
|
1036
|
-
this.index,
|
|
1037
|
-
-1,
|
|
1038
|
-
0,
|
|
1039
|
-
4
|
|
1040
|
-
/* Side.DontCare */
|
|
1041
|
-
));
|
|
1042
|
-
} else {
|
|
1043
|
-
let after = buffer.buffer[this.index + 3];
|
|
1044
|
-
if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
|
|
1045
|
-
return this.yieldBuf(after);
|
|
1046
|
-
}
|
|
1047
|
-
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
|
|
1048
|
-
}
|
|
1049
|
-
/**
|
|
1050
|
-
Move to this node's next sibling, if any.
|
|
1051
|
-
*/
|
|
1052
|
-
nextSibling() {
|
|
1053
|
-
return this.sibling(1);
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
Move to this node's previous sibling, if any.
|
|
1057
|
-
*/
|
|
1058
|
-
prevSibling() {
|
|
1059
|
-
return this.sibling(-1);
|
|
1060
|
-
}
|
|
1061
|
-
atLastNode(dir) {
|
|
1062
|
-
let index, parent, { buffer } = this;
|
|
1063
|
-
if (buffer) {
|
|
1064
|
-
if (dir > 0) {
|
|
1065
|
-
if (this.index < buffer.buffer.buffer.length)
|
|
1066
|
-
return false;
|
|
1067
|
-
} else {
|
|
1068
|
-
for (let i = 0; i < this.index; i++)
|
|
1069
|
-
if (buffer.buffer.buffer[i + 3] < this.index)
|
|
1070
|
-
return false;
|
|
1071
|
-
}
|
|
1072
|
-
({ index, parent } = buffer);
|
|
1073
|
-
} else {
|
|
1074
|
-
({ index, _parent: parent } = this._tree);
|
|
1075
|
-
}
|
|
1076
|
-
for (; parent; { index, _parent: parent } = parent) {
|
|
1077
|
-
if (index > -1)
|
|
1078
|
-
for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
|
|
1079
|
-
let child = parent._tree.children[i];
|
|
1080
|
-
if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
|
|
1081
|
-
return false;
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
return true;
|
|
1085
|
-
}
|
|
1086
|
-
move(dir, enter) {
|
|
1087
|
-
if (enter && this.enterChild(
|
|
1088
|
-
dir,
|
|
1089
|
-
0,
|
|
1090
|
-
4
|
|
1091
|
-
/* Side.DontCare */
|
|
1092
|
-
))
|
|
1093
|
-
return true;
|
|
1094
|
-
for (; ; ) {
|
|
1095
|
-
if (this.sibling(dir))
|
|
1096
|
-
return true;
|
|
1097
|
-
if (this.atLastNode(dir) || !this.parent())
|
|
1098
|
-
return false;
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
Move to the next node in a
|
|
1103
|
-
[pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
|
|
1104
|
-
traversal, going from a node to its first child or, if the
|
|
1105
|
-
current node is empty or `enter` is false, its next sibling or
|
|
1106
|
-
the next sibling of the first parent node that has one.
|
|
1107
|
-
*/
|
|
1108
|
-
next(enter = true) {
|
|
1109
|
-
return this.move(1, enter);
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
Move to the next node in a last-to-first pre-order traveral. A
|
|
1113
|
-
node is followed by its last child or, if it has none, its
|
|
1114
|
-
previous sibling or the previous sibling of the first parent
|
|
1115
|
-
node that has one.
|
|
1116
|
-
*/
|
|
1117
|
-
prev(enter = true) {
|
|
1118
|
-
return this.move(-1, enter);
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
Move the cursor to the innermost node that covers `pos`. If
|
|
1122
|
-
`side` is -1, it will enter nodes that end at `pos`. If it is 1,
|
|
1123
|
-
it will enter nodes that start at `pos`.
|
|
1124
|
-
*/
|
|
1125
|
-
moveTo(pos, side = 0) {
|
|
1126
|
-
while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
|
|
1127
|
-
if (!this.parent())
|
|
1128
|
-
break;
|
|
1129
|
-
while (this.enterChild(1, pos, side)) {
|
|
1130
|
-
}
|
|
1131
|
-
return this;
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
Get a [syntax node](#common.SyntaxNode) at the cursor's current
|
|
1135
|
-
position.
|
|
1136
|
-
*/
|
|
1137
|
-
get node() {
|
|
1138
|
-
if (!this.buffer)
|
|
1139
|
-
return this._tree;
|
|
1140
|
-
let cache = this.bufferNode, result = null, depth = 0;
|
|
1141
|
-
if (cache && cache.context == this.buffer) {
|
|
1142
|
-
scan: for (let index = this.index, d = this.stack.length; d >= 0; ) {
|
|
1143
|
-
for (let c = cache; c; c = c._parent)
|
|
1144
|
-
if (c.index == index) {
|
|
1145
|
-
if (index == this.index)
|
|
1146
|
-
return c;
|
|
1147
|
-
result = c;
|
|
1148
|
-
depth = d + 1;
|
|
1149
|
-
break scan;
|
|
1150
|
-
}
|
|
1151
|
-
index = this.stack[--d];
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
for (let i = depth; i < this.stack.length; i++)
|
|
1155
|
-
result = new BufferNode(this.buffer, result, this.stack[i]);
|
|
1156
|
-
return this.bufferNode = new BufferNode(this.buffer, result, this.index);
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
Get the [tree](#common.Tree) that represents the current node, if
|
|
1160
|
-
any. Will return null when the node is in a [tree
|
|
1161
|
-
buffer](#common.TreeBuffer).
|
|
1162
|
-
*/
|
|
1163
|
-
get tree() {
|
|
1164
|
-
return this.buffer ? null : this._tree._tree;
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
Iterate over the current node and all its descendants, calling
|
|
1168
|
-
`enter` when entering a node and `leave`, if given, when leaving
|
|
1169
|
-
one. When `enter` returns `false`, any children of that node are
|
|
1170
|
-
skipped, and `leave` isn't called for it.
|
|
1171
|
-
*/
|
|
1172
|
-
iterate(enter, leave) {
|
|
1173
|
-
for (let depth = 0; ; ) {
|
|
1174
|
-
let mustLeave = false;
|
|
1175
|
-
if (this.type.isAnonymous || enter(this) !== false) {
|
|
1176
|
-
if (this.firstChild()) {
|
|
1177
|
-
depth++;
|
|
1178
|
-
continue;
|
|
1179
|
-
}
|
|
1180
|
-
if (!this.type.isAnonymous)
|
|
1181
|
-
mustLeave = true;
|
|
1182
|
-
}
|
|
1183
|
-
for (; ; ) {
|
|
1184
|
-
if (mustLeave && leave)
|
|
1185
|
-
leave(this);
|
|
1186
|
-
mustLeave = this.type.isAnonymous;
|
|
1187
|
-
if (this.nextSibling())
|
|
1188
|
-
break;
|
|
1189
|
-
if (!depth)
|
|
1190
|
-
return;
|
|
1191
|
-
this.parent();
|
|
1192
|
-
depth--;
|
|
1193
|
-
mustLeave = true;
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
Test whether the current node matches a given context—a sequence
|
|
1199
|
-
of direct parent node names. Empty strings in the context array
|
|
1200
|
-
are treated as wildcards.
|
|
1201
|
-
*/
|
|
1202
|
-
matchContext(context) {
|
|
1203
|
-
if (!this.buffer)
|
|
1204
|
-
return matchNodeContext(this.node, context);
|
|
1205
|
-
let { buffer } = this.buffer, { types } = buffer.set;
|
|
1206
|
-
for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
|
|
1207
|
-
if (d < 0)
|
|
1208
|
-
return matchNodeContext(this.node, context, i);
|
|
1209
|
-
let type = types[buffer.buffer[this.stack[d]]];
|
|
1210
|
-
if (!type.isAnonymous) {
|
|
1211
|
-
if (context[i] && context[i] != type.name)
|
|
1212
|
-
return false;
|
|
1213
|
-
i--;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
return true;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
function hasChild(tree) {
|
|
1220
|
-
return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
|
|
1221
|
-
}
|
|
1222
|
-
function buildTree(data) {
|
|
1223
|
-
var _a;
|
|
1224
|
-
let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
|
|
1225
|
-
let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
|
|
1226
|
-
let types = nodeSet.types;
|
|
1227
|
-
let contextHash = 0, lookAhead = 0;
|
|
1228
|
-
function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
|
|
1229
|
-
let { id, start, end, size } = cursor;
|
|
1230
|
-
let lookAheadAtStart = lookAhead;
|
|
1231
|
-
while (size < 0) {
|
|
1232
|
-
cursor.next();
|
|
1233
|
-
if (size == -1) {
|
|
1234
|
-
let node2 = reused[id];
|
|
1235
|
-
children2.push(node2);
|
|
1236
|
-
positions2.push(start - parentStart);
|
|
1237
|
-
return;
|
|
1238
|
-
} else if (size == -3) {
|
|
1239
|
-
contextHash = id;
|
|
1240
|
-
return;
|
|
1241
|
-
} else if (size == -4) {
|
|
1242
|
-
lookAhead = id;
|
|
1243
|
-
return;
|
|
1244
|
-
} else {
|
|
1245
|
-
throw new RangeError(`Unrecognized record size: ${size}`);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
let type = types[id], node, buffer2;
|
|
1249
|
-
let startPos = start - parentStart;
|
|
1250
|
-
if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
|
|
1251
|
-
let data2 = new Uint16Array(buffer2.size - buffer2.skip);
|
|
1252
|
-
let endPos = cursor.pos - buffer2.size, index = data2.length;
|
|
1253
|
-
while (cursor.pos > endPos)
|
|
1254
|
-
index = copyToBuffer(buffer2.start, data2, index);
|
|
1255
|
-
node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
|
|
1256
|
-
startPos = buffer2.start - parentStart;
|
|
1257
|
-
} else {
|
|
1258
|
-
let endPos = cursor.pos - size;
|
|
1259
|
-
cursor.next();
|
|
1260
|
-
let localChildren = [], localPositions = [];
|
|
1261
|
-
let localInRepeat = id >= minRepeatType ? id : -1;
|
|
1262
|
-
let lastGroup = 0, lastEnd = end;
|
|
1263
|
-
while (cursor.pos > endPos) {
|
|
1264
|
-
if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
|
|
1265
|
-
if (cursor.end <= lastEnd - maxBufferLength) {
|
|
1266
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1267
|
-
lastGroup = localChildren.length;
|
|
1268
|
-
lastEnd = cursor.end;
|
|
1269
|
-
}
|
|
1270
|
-
cursor.next();
|
|
1271
|
-
} else {
|
|
1272
|
-
takeNode(start, endPos, localChildren, localPositions, localInRepeat);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
|
|
1276
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1277
|
-
localChildren.reverse();
|
|
1278
|
-
localPositions.reverse();
|
|
1279
|
-
if (localInRepeat > -1 && lastGroup > 0) {
|
|
1280
|
-
let make = makeBalanced(type);
|
|
1281
|
-
node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
|
|
1282
|
-
} else {
|
|
1283
|
-
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
children2.push(node);
|
|
1287
|
-
positions2.push(startPos);
|
|
1288
|
-
}
|
|
1289
|
-
function makeBalanced(type) {
|
|
1290
|
-
return (children2, positions2, length2) => {
|
|
1291
|
-
let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
|
|
1292
|
-
if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
|
|
1293
|
-
if (!lastI && last.type == type && last.length == length2)
|
|
1294
|
-
return last;
|
|
1295
|
-
if (lookAheadProp = last.prop(NodeProp.lookAhead))
|
|
1296
|
-
lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
|
|
1297
|
-
}
|
|
1298
|
-
return makeTree(type, children2, positions2, length2, lookAhead2);
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
|
|
1302
|
-
let localChildren = [], localPositions = [];
|
|
1303
|
-
while (children2.length > i) {
|
|
1304
|
-
localChildren.push(children2.pop());
|
|
1305
|
-
localPositions.push(positions2.pop() + base - from);
|
|
1306
|
-
}
|
|
1307
|
-
children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
|
|
1308
|
-
positions2.push(from - base);
|
|
1309
|
-
}
|
|
1310
|
-
function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
|
|
1311
|
-
if (contextHash) {
|
|
1312
|
-
let pair = [NodeProp.contextHash, contextHash];
|
|
1313
|
-
props = props ? [pair].concat(props) : [pair];
|
|
1314
|
-
}
|
|
1315
|
-
if (lookAhead2 > 25) {
|
|
1316
|
-
let pair = [NodeProp.lookAhead, lookAhead2];
|
|
1317
|
-
props = props ? [pair].concat(props) : [pair];
|
|
1318
|
-
}
|
|
1319
|
-
return new Tree(type, children2, positions2, length2, props);
|
|
1320
|
-
}
|
|
1321
|
-
function findBufferSize(maxSize, inRepeat) {
|
|
1322
|
-
let fork = cursor.fork();
|
|
1323
|
-
let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
|
|
1324
|
-
let result = { size: 0, start: 0, skip: 0 };
|
|
1325
|
-
scan: for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
|
|
1326
|
-
let nodeSize2 = fork.size;
|
|
1327
|
-
if (fork.id == inRepeat && nodeSize2 >= 0) {
|
|
1328
|
-
result.size = size;
|
|
1329
|
-
result.start = start;
|
|
1330
|
-
result.skip = skip;
|
|
1331
|
-
skip += 4;
|
|
1332
|
-
size += 4;
|
|
1333
|
-
fork.next();
|
|
1334
|
-
continue;
|
|
1335
|
-
}
|
|
1336
|
-
let startPos = fork.pos - nodeSize2;
|
|
1337
|
-
if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
|
|
1338
|
-
break;
|
|
1339
|
-
let localSkipped = fork.id >= minRepeatType ? 4 : 0;
|
|
1340
|
-
let nodeStart = fork.start;
|
|
1341
|
-
fork.next();
|
|
1342
|
-
while (fork.pos > startPos) {
|
|
1343
|
-
if (fork.size < 0) {
|
|
1344
|
-
if (fork.size == -3)
|
|
1345
|
-
localSkipped += 4;
|
|
1346
|
-
else
|
|
1347
|
-
break scan;
|
|
1348
|
-
} else if (fork.id >= minRepeatType) {
|
|
1349
|
-
localSkipped += 4;
|
|
1350
|
-
}
|
|
1351
|
-
fork.next();
|
|
1352
|
-
}
|
|
1353
|
-
start = nodeStart;
|
|
1354
|
-
size += nodeSize2;
|
|
1355
|
-
skip += localSkipped;
|
|
1356
|
-
}
|
|
1357
|
-
if (inRepeat < 0 || size == maxSize) {
|
|
1358
|
-
result.size = size;
|
|
1359
|
-
result.start = start;
|
|
1360
|
-
result.skip = skip;
|
|
1361
|
-
}
|
|
1362
|
-
return result.size > 4 ? result : void 0;
|
|
1363
|
-
}
|
|
1364
|
-
function copyToBuffer(bufferStart, buffer2, index) {
|
|
1365
|
-
let { id, start, end, size } = cursor;
|
|
1366
|
-
cursor.next();
|
|
1367
|
-
if (size >= 0 && id < minRepeatType) {
|
|
1368
|
-
let startIndex = index;
|
|
1369
|
-
if (size > 4) {
|
|
1370
|
-
let endPos = cursor.pos - (size - 4);
|
|
1371
|
-
while (cursor.pos > endPos)
|
|
1372
|
-
index = copyToBuffer(bufferStart, buffer2, index);
|
|
1373
|
-
}
|
|
1374
|
-
buffer2[--index] = startIndex;
|
|
1375
|
-
buffer2[--index] = end - bufferStart;
|
|
1376
|
-
buffer2[--index] = start - bufferStart;
|
|
1377
|
-
buffer2[--index] = id;
|
|
1378
|
-
} else if (size == -3) {
|
|
1379
|
-
contextHash = id;
|
|
1380
|
-
} else if (size == -4) {
|
|
1381
|
-
lookAhead = id;
|
|
1382
|
-
}
|
|
1383
|
-
return index;
|
|
1384
|
-
}
|
|
1385
|
-
let children = [], positions = [];
|
|
1386
|
-
while (cursor.pos > 0)
|
|
1387
|
-
takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
|
|
1388
|
-
let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
|
|
1389
|
-
return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
|
|
1390
|
-
}
|
|
1391
|
-
const nodeSizeCache = /* @__PURE__ */ new WeakMap();
|
|
1392
|
-
function nodeSize(balanceType, node) {
|
|
1393
|
-
if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
|
|
1394
|
-
return 1;
|
|
1395
|
-
let size = nodeSizeCache.get(node);
|
|
1396
|
-
if (size == null) {
|
|
1397
|
-
size = 1;
|
|
1398
|
-
for (let child of node.children) {
|
|
1399
|
-
if (child.type != balanceType || !(child instanceof Tree)) {
|
|
1400
|
-
size = 1;
|
|
1401
|
-
break;
|
|
1402
|
-
}
|
|
1403
|
-
size += nodeSize(balanceType, child);
|
|
1404
|
-
}
|
|
1405
|
-
nodeSizeCache.set(node, size);
|
|
1406
|
-
}
|
|
1407
|
-
return size;
|
|
1408
|
-
}
|
|
1409
|
-
function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
|
|
1410
|
-
let total = 0;
|
|
1411
|
-
for (let i = from; i < to; i++)
|
|
1412
|
-
total += nodeSize(balanceType, children[i]);
|
|
1413
|
-
let maxChild = Math.ceil(
|
|
1414
|
-
total * 1.5 / 8
|
|
1415
|
-
/* Balance.BranchFactor */
|
|
1416
|
-
);
|
|
1417
|
-
let localChildren = [], localPositions = [];
|
|
1418
|
-
function divide(children2, positions2, from2, to2, offset) {
|
|
1419
|
-
for (let i = from2; i < to2; ) {
|
|
1420
|
-
let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
|
|
1421
|
-
i++;
|
|
1422
|
-
for (; i < to2; i++) {
|
|
1423
|
-
let nextSize = nodeSize(balanceType, children2[i]);
|
|
1424
|
-
if (groupSize + nextSize >= maxChild)
|
|
1425
|
-
break;
|
|
1426
|
-
groupSize += nextSize;
|
|
1427
|
-
}
|
|
1428
|
-
if (i == groupFrom + 1) {
|
|
1429
|
-
if (groupSize > maxChild) {
|
|
1430
|
-
let only = children2[groupFrom];
|
|
1431
|
-
divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
|
|
1432
|
-
continue;
|
|
1433
|
-
}
|
|
1434
|
-
localChildren.push(children2[groupFrom]);
|
|
1435
|
-
} else {
|
|
1436
|
-
let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
|
|
1437
|
-
localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
|
|
1438
|
-
}
|
|
1439
|
-
localPositions.push(groupStart + offset - start);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
divide(children, positions, from, to, 0);
|
|
1443
|
-
return (mkTop || mkTree)(localChildren, localPositions, length);
|
|
1444
|
-
}
|
|
1445
|
-
class NodeWeakMap {
|
|
1446
|
-
constructor() {
|
|
1447
|
-
this.map = /* @__PURE__ */ new WeakMap();
|
|
1448
|
-
}
|
|
1449
|
-
setBuffer(buffer, index, value) {
|
|
1450
|
-
let inner = this.map.get(buffer);
|
|
1451
|
-
if (!inner)
|
|
1452
|
-
this.map.set(buffer, inner = /* @__PURE__ */ new Map());
|
|
1453
|
-
inner.set(index, value);
|
|
1454
|
-
}
|
|
1455
|
-
getBuffer(buffer, index) {
|
|
1456
|
-
let inner = this.map.get(buffer);
|
|
1457
|
-
return inner && inner.get(index);
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
Set the value for this syntax node.
|
|
1461
|
-
*/
|
|
1462
|
-
set(node, value) {
|
|
1463
|
-
if (node instanceof BufferNode)
|
|
1464
|
-
this.setBuffer(node.context.buffer, node.index, value);
|
|
1465
|
-
else if (node instanceof TreeNode)
|
|
1466
|
-
this.map.set(node.tree, value);
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
Retrieve value for this syntax node, if it exists in the map.
|
|
1470
|
-
*/
|
|
1471
|
-
get(node) {
|
|
1472
|
-
return node instanceof BufferNode ? this.getBuffer(node.context.buffer, node.index) : node instanceof TreeNode ? this.map.get(node.tree) : void 0;
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
Set the value for the node that a cursor currently points to.
|
|
1476
|
-
*/
|
|
1477
|
-
cursorSet(cursor, value) {
|
|
1478
|
-
if (cursor.buffer)
|
|
1479
|
-
this.setBuffer(cursor.buffer.buffer, cursor.index, value);
|
|
1480
|
-
else
|
|
1481
|
-
this.map.set(cursor.tree, value);
|
|
1482
|
-
}
|
|
1483
|
-
/**
|
|
1484
|
-
Retrieve the value for the node that a cursor currently points
|
|
1485
|
-
to.
|
|
1486
|
-
*/
|
|
1487
|
-
cursorGet(cursor) {
|
|
1488
|
-
return cursor.buffer ? this.getBuffer(cursor.buffer.buffer, cursor.index) : this.map.get(cursor.tree);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
class TreeFragment {
|
|
1492
|
-
/**
|
|
1493
|
-
Construct a tree fragment. You'll usually want to use
|
|
1494
|
-
[`addTree`](#common.TreeFragment^addTree) and
|
|
1495
|
-
[`applyChanges`](#common.TreeFragment^applyChanges) instead of
|
|
1496
|
-
calling this directly.
|
|
1497
|
-
*/
|
|
1498
|
-
constructor(from, to, tree, offset, openStart = false, openEnd = false) {
|
|
1499
|
-
this.from = from;
|
|
1500
|
-
this.to = to;
|
|
1501
|
-
this.tree = tree;
|
|
1502
|
-
this.offset = offset;
|
|
1503
|
-
this.open = (openStart ? 1 : 0) | (openEnd ? 2 : 0);
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
Whether the start of the fragment represents the start of a
|
|
1507
|
-
parse, or the end of a change. (In the second case, it may not
|
|
1508
|
-
be safe to reuse some nodes at the start, depending on the
|
|
1509
|
-
parsing algorithm.)
|
|
1510
|
-
*/
|
|
1511
|
-
get openStart() {
|
|
1512
|
-
return (this.open & 1) > 0;
|
|
1513
|
-
}
|
|
1514
|
-
/**
|
|
1515
|
-
Whether the end of the fragment represents the end of a
|
|
1516
|
-
full-document parse, or the start of a change.
|
|
1517
|
-
*/
|
|
1518
|
-
get openEnd() {
|
|
1519
|
-
return (this.open & 2) > 0;
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
Create a set of fragments from a freshly parsed tree, or update
|
|
1523
|
-
an existing set of fragments by replacing the ones that overlap
|
|
1524
|
-
with a tree with content from the new tree. When `partial` is
|
|
1525
|
-
true, the parse is treated as incomplete, and the resulting
|
|
1526
|
-
fragment has [`openEnd`](#common.TreeFragment.openEnd) set to
|
|
1527
|
-
true.
|
|
1528
|
-
*/
|
|
1529
|
-
static addTree(tree, fragments = [], partial = false) {
|
|
1530
|
-
let result = [new TreeFragment(0, tree.length, tree, 0, false, partial)];
|
|
1531
|
-
for (let f of fragments)
|
|
1532
|
-
if (f.to > tree.length)
|
|
1533
|
-
result.push(f);
|
|
1534
|
-
return result;
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
|
-
Apply a set of edits to an array of fragments, removing or
|
|
1538
|
-
splitting fragments as necessary to remove edited ranges, and
|
|
1539
|
-
adjusting offsets for fragments that moved.
|
|
1540
|
-
*/
|
|
1541
|
-
static applyChanges(fragments, changes, minGap = 128) {
|
|
1542
|
-
if (!changes.length)
|
|
1543
|
-
return fragments;
|
|
1544
|
-
let result = [];
|
|
1545
|
-
let fI = 1, nextF = fragments.length ? fragments[0] : null;
|
|
1546
|
-
for (let cI = 0, pos = 0, off = 0; ; cI++) {
|
|
1547
|
-
let nextC = cI < changes.length ? changes[cI] : null;
|
|
1548
|
-
let nextPos = nextC ? nextC.fromA : 1e9;
|
|
1549
|
-
if (nextPos - pos >= minGap)
|
|
1550
|
-
while (nextF && nextF.from < nextPos) {
|
|
1551
|
-
let cut = nextF;
|
|
1552
|
-
if (pos >= cut.from || nextPos <= cut.to || off) {
|
|
1553
|
-
let fFrom = Math.max(cut.from, pos) - off, fTo = Math.min(cut.to, nextPos) - off;
|
|
1554
|
-
cut = fFrom >= fTo ? null : new TreeFragment(fFrom, fTo, cut.tree, cut.offset + off, cI > 0, !!nextC);
|
|
1555
|
-
}
|
|
1556
|
-
if (cut)
|
|
1557
|
-
result.push(cut);
|
|
1558
|
-
if (nextF.to > nextPos)
|
|
1559
|
-
break;
|
|
1560
|
-
nextF = fI < fragments.length ? fragments[fI++] : null;
|
|
1561
|
-
}
|
|
1562
|
-
if (!nextC)
|
|
1563
|
-
break;
|
|
1564
|
-
pos = nextC.toA;
|
|
1565
|
-
off = nextC.toA - nextC.toB;
|
|
1566
|
-
}
|
|
1567
|
-
return result;
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
class Parser {
|
|
1571
|
-
/**
|
|
1572
|
-
Start a parse, returning a [partial parse](#common.PartialParse)
|
|
1573
|
-
object. [`fragments`](#common.TreeFragment) can be passed in to
|
|
1574
|
-
make the parse incremental.
|
|
1575
|
-
|
|
1576
|
-
By default, the entire input is parsed. You can pass `ranges`,
|
|
1577
|
-
which should be a sorted array of non-empty, non-overlapping
|
|
1578
|
-
ranges, to parse only those ranges. The tree returned in that
|
|
1579
|
-
case will start at `ranges[0].from`.
|
|
1580
|
-
*/
|
|
1581
|
-
startParse(input, fragments, ranges) {
|
|
1582
|
-
if (typeof input == "string")
|
|
1583
|
-
input = new StringInput(input);
|
|
1584
|
-
ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r) => new Range(r.from, r.to)) : [new Range(0, 0)];
|
|
1585
|
-
return this.createParse(input, fragments || [], ranges);
|
|
1586
|
-
}
|
|
1587
|
-
/**
|
|
1588
|
-
Run a full parse, returning the resulting tree.
|
|
1589
|
-
*/
|
|
1590
|
-
parse(input, fragments, ranges) {
|
|
1591
|
-
let parse = this.startParse(input, fragments, ranges);
|
|
1592
|
-
for (; ; ) {
|
|
1593
|
-
let done = parse.advance();
|
|
1594
|
-
if (done)
|
|
1595
|
-
return done;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
class StringInput {
|
|
1600
|
-
constructor(string) {
|
|
1601
|
-
this.string = string;
|
|
1602
|
-
}
|
|
1603
|
-
get length() {
|
|
1604
|
-
return this.string.length;
|
|
1605
|
-
}
|
|
1606
|
-
chunk(from) {
|
|
1607
|
-
return this.string.slice(from);
|
|
1608
|
-
}
|
|
1609
|
-
get lineChunks() {
|
|
1610
|
-
return false;
|
|
1611
|
-
}
|
|
1612
|
-
read(from, to) {
|
|
1613
|
-
return this.string.slice(from, to);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
function parseMixed(nest) {
|
|
1617
|
-
return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
|
|
1618
|
-
}
|
|
1619
|
-
class InnerParse {
|
|
1620
|
-
constructor(parser, parse, overlay, target, ranges) {
|
|
1621
|
-
this.parser = parser;
|
|
1622
|
-
this.parse = parse;
|
|
1623
|
-
this.overlay = overlay;
|
|
1624
|
-
this.target = target;
|
|
1625
|
-
this.ranges = ranges;
|
|
1626
|
-
if (!ranges.length || ranges.some((r) => r.from >= r.to))
|
|
1627
|
-
throw new RangeError("Invalid inner parse ranges given: " + JSON.stringify(ranges));
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
class ActiveOverlay {
|
|
1631
|
-
constructor(parser, predicate, mounts, index, start, target, prev) {
|
|
1632
|
-
this.parser = parser;
|
|
1633
|
-
this.predicate = predicate;
|
|
1634
|
-
this.mounts = mounts;
|
|
1635
|
-
this.index = index;
|
|
1636
|
-
this.start = start;
|
|
1637
|
-
this.target = target;
|
|
1638
|
-
this.prev = prev;
|
|
1639
|
-
this.depth = 0;
|
|
1640
|
-
this.ranges = [];
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
const stoppedInner = new NodeProp({ perNode: true });
|
|
1644
|
-
class MixedParse {
|
|
1645
|
-
constructor(base, nest, input, fragments, ranges) {
|
|
1646
|
-
this.nest = nest;
|
|
1647
|
-
this.input = input;
|
|
1648
|
-
this.fragments = fragments;
|
|
1649
|
-
this.ranges = ranges;
|
|
1650
|
-
this.inner = [];
|
|
1651
|
-
this.innerDone = 0;
|
|
1652
|
-
this.baseTree = null;
|
|
1653
|
-
this.stoppedAt = null;
|
|
1654
|
-
this.baseParse = base;
|
|
1655
|
-
}
|
|
1656
|
-
advance() {
|
|
1657
|
-
if (this.baseParse) {
|
|
1658
|
-
let done2 = this.baseParse.advance();
|
|
1659
|
-
if (!done2)
|
|
1660
|
-
return null;
|
|
1661
|
-
this.baseParse = null;
|
|
1662
|
-
this.baseTree = done2;
|
|
1663
|
-
this.startInner();
|
|
1664
|
-
if (this.stoppedAt != null)
|
|
1665
|
-
for (let inner2 of this.inner)
|
|
1666
|
-
inner2.parse.stopAt(this.stoppedAt);
|
|
1667
|
-
}
|
|
1668
|
-
if (this.innerDone == this.inner.length) {
|
|
1669
|
-
let result = this.baseTree;
|
|
1670
|
-
if (this.stoppedAt != null)
|
|
1671
|
-
result = new Tree(result.type, result.children, result.positions, result.length, result.propValues.concat([[stoppedInner, this.stoppedAt]]));
|
|
1672
|
-
return result;
|
|
1673
|
-
}
|
|
1674
|
-
let inner = this.inner[this.innerDone], done = inner.parse.advance();
|
|
1675
|
-
if (done) {
|
|
1676
|
-
this.innerDone++;
|
|
1677
|
-
let props = Object.assign(/* @__PURE__ */ Object.create(null), inner.target.props);
|
|
1678
|
-
props[NodeProp.mounted.id] = new MountedTree(done, inner.overlay, inner.parser);
|
|
1679
|
-
inner.target.props = props;
|
|
1680
|
-
}
|
|
1681
|
-
return null;
|
|
1682
|
-
}
|
|
1683
|
-
get parsedPos() {
|
|
1684
|
-
if (this.baseParse)
|
|
1685
|
-
return 0;
|
|
1686
|
-
let pos = this.input.length;
|
|
1687
|
-
for (let i = this.innerDone; i < this.inner.length; i++) {
|
|
1688
|
-
if (this.inner[i].ranges[0].from < pos)
|
|
1689
|
-
pos = Math.min(pos, this.inner[i].parse.parsedPos);
|
|
1690
|
-
}
|
|
1691
|
-
return pos;
|
|
1692
|
-
}
|
|
1693
|
-
stopAt(pos) {
|
|
1694
|
-
this.stoppedAt = pos;
|
|
1695
|
-
if (this.baseParse)
|
|
1696
|
-
this.baseParse.stopAt(pos);
|
|
1697
|
-
else
|
|
1698
|
-
for (let i = this.innerDone; i < this.inner.length; i++)
|
|
1699
|
-
this.inner[i].parse.stopAt(pos);
|
|
1700
|
-
}
|
|
1701
|
-
startInner() {
|
|
1702
|
-
let fragmentCursor = new FragmentCursor(this.fragments);
|
|
1703
|
-
let overlay = null;
|
|
1704
|
-
let covered = null;
|
|
1705
|
-
let cursor = new TreeCursor(new TreeNode(this.baseTree, this.ranges[0].from, 0, null), IterMode.IncludeAnonymous | IterMode.IgnoreMounts);
|
|
1706
|
-
scan: for (let nest, isCovered; this.stoppedAt == null || cursor.from < this.stoppedAt; ) {
|
|
1707
|
-
let enter = true, range;
|
|
1708
|
-
if (fragmentCursor.hasNode(cursor)) {
|
|
1709
|
-
if (overlay) {
|
|
1710
|
-
let match = overlay.mounts.find((m) => m.frag.from <= cursor.from && m.frag.to >= cursor.to && m.mount.overlay);
|
|
1711
|
-
if (match)
|
|
1712
|
-
for (let r of match.mount.overlay) {
|
|
1713
|
-
let from = r.from + match.pos, to = r.to + match.pos;
|
|
1714
|
-
if (from >= cursor.from && to <= cursor.to && !overlay.ranges.some((r2) => r2.from < to && r2.to > from))
|
|
1715
|
-
overlay.ranges.push({ from, to });
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
enter = false;
|
|
1719
|
-
} else if (covered && (isCovered = checkCover(covered.ranges, cursor.from, cursor.to))) {
|
|
1720
|
-
enter = isCovered != 2;
|
|
1721
|
-
} else if (!cursor.type.isAnonymous && cursor.from < cursor.to && (nest = this.nest(cursor, this.input))) {
|
|
1722
|
-
if (!cursor.tree)
|
|
1723
|
-
materialize(cursor);
|
|
1724
|
-
let oldMounts = fragmentCursor.findMounts(cursor.from, nest.parser);
|
|
1725
|
-
if (typeof nest.overlay == "function") {
|
|
1726
|
-
overlay = new ActiveOverlay(nest.parser, nest.overlay, oldMounts, this.inner.length, cursor.from, cursor.tree, overlay);
|
|
1727
|
-
} else {
|
|
1728
|
-
let ranges = punchRanges(this.ranges, nest.overlay || [new Range(cursor.from, cursor.to)]);
|
|
1729
|
-
if (ranges.length)
|
|
1730
|
-
this.inner.push(new InnerParse(nest.parser, nest.parser.startParse(this.input, enterFragments(oldMounts, ranges), ranges), nest.overlay ? nest.overlay.map((r) => new Range(r.from - cursor.from, r.to - cursor.from)) : null, cursor.tree, ranges));
|
|
1731
|
-
if (!nest.overlay)
|
|
1732
|
-
enter = false;
|
|
1733
|
-
else if (ranges.length)
|
|
1734
|
-
covered = { ranges, depth: 0, prev: covered };
|
|
1735
|
-
}
|
|
1736
|
-
} else if (overlay && (range = overlay.predicate(cursor))) {
|
|
1737
|
-
if (range === true)
|
|
1738
|
-
range = new Range(cursor.from, cursor.to);
|
|
1739
|
-
if (range.from < range.to)
|
|
1740
|
-
overlay.ranges.push(range);
|
|
1741
|
-
}
|
|
1742
|
-
if (enter && cursor.firstChild()) {
|
|
1743
|
-
if (overlay)
|
|
1744
|
-
overlay.depth++;
|
|
1745
|
-
if (covered)
|
|
1746
|
-
covered.depth++;
|
|
1747
|
-
} else {
|
|
1748
|
-
for (; ; ) {
|
|
1749
|
-
if (cursor.nextSibling())
|
|
1750
|
-
break;
|
|
1751
|
-
if (!cursor.parent())
|
|
1752
|
-
break scan;
|
|
1753
|
-
if (overlay && !--overlay.depth) {
|
|
1754
|
-
let ranges = punchRanges(this.ranges, overlay.ranges);
|
|
1755
|
-
if (ranges.length)
|
|
1756
|
-
this.inner.splice(overlay.index, 0, new InnerParse(overlay.parser, overlay.parser.startParse(this.input, enterFragments(overlay.mounts, ranges), ranges), overlay.ranges.map((r) => new Range(r.from - overlay.start, r.to - overlay.start)), overlay.target, ranges));
|
|
1757
|
-
overlay = overlay.prev;
|
|
1758
|
-
}
|
|
1759
|
-
if (covered && !--covered.depth)
|
|
1760
|
-
covered = covered.prev;
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
function checkCover(covered, from, to) {
|
|
1767
|
-
for (let range of covered) {
|
|
1768
|
-
if (range.from >= to)
|
|
1769
|
-
break;
|
|
1770
|
-
if (range.to > from)
|
|
1771
|
-
return range.from <= from && range.to >= to ? 2 : 1;
|
|
1772
|
-
}
|
|
1773
|
-
return 0;
|
|
1774
|
-
}
|
|
1775
|
-
function sliceBuf(buf, startI, endI, nodes, positions, off) {
|
|
1776
|
-
if (startI < endI) {
|
|
1777
|
-
let from = buf.buffer[startI + 1];
|
|
1778
|
-
nodes.push(buf.slice(startI, endI, from));
|
|
1779
|
-
positions.push(from - off);
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
function materialize(cursor) {
|
|
1783
|
-
let { node } = cursor, depth = 0;
|
|
1784
|
-
do {
|
|
1785
|
-
cursor.parent();
|
|
1786
|
-
depth++;
|
|
1787
|
-
} while (!cursor.tree);
|
|
1788
|
-
let i = 0, base = cursor.tree, off = 0;
|
|
1789
|
-
for (; ; i++) {
|
|
1790
|
-
off = base.positions[i] + cursor.from;
|
|
1791
|
-
if (off <= node.from && off + base.children[i].length >= node.to)
|
|
1792
|
-
break;
|
|
1793
|
-
}
|
|
1794
|
-
let buf = base.children[i], b = buf.buffer;
|
|
1795
|
-
function split(startI, endI, type, innerOffset, length) {
|
|
1796
|
-
let i2 = startI;
|
|
1797
|
-
while (b[i2 + 2] + off <= node.from)
|
|
1798
|
-
i2 = b[i2 + 3];
|
|
1799
|
-
let children = [], positions = [];
|
|
1800
|
-
sliceBuf(buf, startI, i2, children, positions, innerOffset);
|
|
1801
|
-
let from = b[i2 + 1], to = b[i2 + 2];
|
|
1802
|
-
let isTarget = from + off == node.from && to + off == node.to && b[i2] == node.type.id;
|
|
1803
|
-
children.push(isTarget ? node.toTree() : split(i2 + 4, b[i2 + 3], buf.set.types[b[i2]], from, to - from));
|
|
1804
|
-
positions.push(from - innerOffset);
|
|
1805
|
-
sliceBuf(buf, b[i2 + 3], endI, children, positions, innerOffset);
|
|
1806
|
-
return new Tree(type, children, positions, length);
|
|
1807
|
-
}
|
|
1808
|
-
base.children[i] = split(0, b.length, NodeType.none, 0, buf.length);
|
|
1809
|
-
for (let d = 0; d <= depth; d++)
|
|
1810
|
-
cursor.childAfter(node.from);
|
|
1811
|
-
}
|
|
1812
|
-
class StructureCursor {
|
|
1813
|
-
constructor(root, offset) {
|
|
1814
|
-
this.offset = offset;
|
|
1815
|
-
this.done = false;
|
|
1816
|
-
this.cursor = root.cursor(IterMode.IncludeAnonymous | IterMode.IgnoreMounts);
|
|
1817
|
-
}
|
|
1818
|
-
// Move to the first node (in pre-order) that starts at or after `pos`.
|
|
1819
|
-
moveTo(pos) {
|
|
1820
|
-
let { cursor } = this, p = pos - this.offset;
|
|
1821
|
-
while (!this.done && cursor.from < p) {
|
|
1822
|
-
if (cursor.to >= pos && cursor.enter(p, 1, IterMode.IgnoreOverlays | IterMode.ExcludeBuffers)) ;
|
|
1823
|
-
else if (!cursor.next(false))
|
|
1824
|
-
this.done = true;
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
hasNode(cursor) {
|
|
1828
|
-
this.moveTo(cursor.from);
|
|
1829
|
-
if (!this.done && this.cursor.from + this.offset == cursor.from && this.cursor.tree) {
|
|
1830
|
-
for (let tree = this.cursor.tree; ; ) {
|
|
1831
|
-
if (tree == cursor.tree)
|
|
1832
|
-
return true;
|
|
1833
|
-
if (tree.children.length && tree.positions[0] == 0 && tree.children[0] instanceof Tree)
|
|
1834
|
-
tree = tree.children[0];
|
|
1835
|
-
else
|
|
1836
|
-
break;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
return false;
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
class FragmentCursor {
|
|
1843
|
-
constructor(fragments) {
|
|
1844
|
-
var _a;
|
|
1845
|
-
this.fragments = fragments;
|
|
1846
|
-
this.curTo = 0;
|
|
1847
|
-
this.fragI = 0;
|
|
1848
|
-
if (fragments.length) {
|
|
1849
|
-
let first = this.curFrag = fragments[0];
|
|
1850
|
-
this.curTo = (_a = first.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : first.to;
|
|
1851
|
-
this.inner = new StructureCursor(first.tree, -first.offset);
|
|
1852
|
-
} else {
|
|
1853
|
-
this.curFrag = this.inner = null;
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
hasNode(node) {
|
|
1857
|
-
while (this.curFrag && node.from >= this.curTo)
|
|
1858
|
-
this.nextFrag();
|
|
1859
|
-
return this.curFrag && this.curFrag.from <= node.from && this.curTo >= node.to && this.inner.hasNode(node);
|
|
1860
|
-
}
|
|
1861
|
-
nextFrag() {
|
|
1862
|
-
var _a;
|
|
1863
|
-
this.fragI++;
|
|
1864
|
-
if (this.fragI == this.fragments.length) {
|
|
1865
|
-
this.curFrag = this.inner = null;
|
|
1866
|
-
} else {
|
|
1867
|
-
let frag = this.curFrag = this.fragments[this.fragI];
|
|
1868
|
-
this.curTo = (_a = frag.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : frag.to;
|
|
1869
|
-
this.inner = new StructureCursor(frag.tree, -frag.offset);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
findMounts(pos, parser) {
|
|
1873
|
-
var _a;
|
|
1874
|
-
let result = [];
|
|
1875
|
-
if (this.inner) {
|
|
1876
|
-
this.inner.cursor.moveTo(pos, 1);
|
|
1877
|
-
for (let pos2 = this.inner.cursor.node; pos2; pos2 = pos2.parent) {
|
|
1878
|
-
let mount = (_a = pos2.tree) === null || _a === void 0 ? void 0 : _a.prop(NodeProp.mounted);
|
|
1879
|
-
if (mount && mount.parser == parser) {
|
|
1880
|
-
for (let i = this.fragI; i < this.fragments.length; i++) {
|
|
1881
|
-
let frag = this.fragments[i];
|
|
1882
|
-
if (frag.from >= pos2.to)
|
|
1883
|
-
break;
|
|
1884
|
-
if (frag.tree == this.curFrag.tree)
|
|
1885
|
-
result.push({
|
|
1886
|
-
frag,
|
|
1887
|
-
pos: pos2.from - frag.offset,
|
|
1888
|
-
mount
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
return result;
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
function punchRanges(outer, ranges) {
|
|
1898
|
-
let copy = null, current = ranges;
|
|
1899
|
-
for (let i = 1, j = 0; i < outer.length; i++) {
|
|
1900
|
-
let gapFrom = outer[i - 1].to, gapTo = outer[i].from;
|
|
1901
|
-
for (; j < current.length; j++) {
|
|
1902
|
-
let r = current[j];
|
|
1903
|
-
if (r.from >= gapTo)
|
|
1904
|
-
break;
|
|
1905
|
-
if (r.to <= gapFrom)
|
|
1906
|
-
continue;
|
|
1907
|
-
if (!copy)
|
|
1908
|
-
current = copy = ranges.slice();
|
|
1909
|
-
if (r.from < gapFrom) {
|
|
1910
|
-
copy[j] = new Range(r.from, gapFrom);
|
|
1911
|
-
if (r.to > gapTo)
|
|
1912
|
-
copy.splice(j + 1, 0, new Range(gapTo, r.to));
|
|
1913
|
-
} else if (r.to > gapTo) {
|
|
1914
|
-
copy[j--] = new Range(gapTo, r.to);
|
|
1915
|
-
} else {
|
|
1916
|
-
copy.splice(j--, 1);
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
return current;
|
|
1921
|
-
}
|
|
1922
|
-
function findCoverChanges(a, b, from, to) {
|
|
1923
|
-
let iA = 0, iB = 0, inA = false, inB = false, pos = -1e9;
|
|
1924
|
-
let result = [];
|
|
1925
|
-
for (; ; ) {
|
|
1926
|
-
let nextA = iA == a.length ? 1e9 : inA ? a[iA].to : a[iA].from;
|
|
1927
|
-
let nextB = iB == b.length ? 1e9 : inB ? b[iB].to : b[iB].from;
|
|
1928
|
-
if (inA != inB) {
|
|
1929
|
-
let start = Math.max(pos, from), end = Math.min(nextA, nextB, to);
|
|
1930
|
-
if (start < end)
|
|
1931
|
-
result.push(new Range(start, end));
|
|
1932
|
-
}
|
|
1933
|
-
pos = Math.min(nextA, nextB);
|
|
1934
|
-
if (pos == 1e9)
|
|
1935
|
-
break;
|
|
1936
|
-
if (nextA == pos) {
|
|
1937
|
-
if (!inA)
|
|
1938
|
-
inA = true;
|
|
1939
|
-
else {
|
|
1940
|
-
inA = false;
|
|
1941
|
-
iA++;
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
if (nextB == pos) {
|
|
1945
|
-
if (!inB)
|
|
1946
|
-
inB = true;
|
|
1947
|
-
else {
|
|
1948
|
-
inB = false;
|
|
1949
|
-
iB++;
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
return result;
|
|
1954
|
-
}
|
|
1955
|
-
function enterFragments(mounts, ranges) {
|
|
1956
|
-
let result = [];
|
|
1957
|
-
for (let { pos, mount, frag } of mounts) {
|
|
1958
|
-
let startPos = pos + (mount.overlay ? mount.overlay[0].from : 0), endPos = startPos + mount.tree.length;
|
|
1959
|
-
let from = Math.max(frag.from, startPos), to = Math.min(frag.to, endPos);
|
|
1960
|
-
if (mount.overlay) {
|
|
1961
|
-
let overlay = mount.overlay.map((r) => new Range(r.from + pos, r.to + pos));
|
|
1962
|
-
let changes = findCoverChanges(ranges, overlay, from, to);
|
|
1963
|
-
for (let i = 0, pos2 = from; ; i++) {
|
|
1964
|
-
let last = i == changes.length, end = last ? to : changes[i].from;
|
|
1965
|
-
if (end > pos2)
|
|
1966
|
-
result.push(new TreeFragment(pos2, end, mount.tree, -startPos, frag.from >= pos2 || frag.openStart, frag.to <= end || frag.openEnd));
|
|
1967
|
-
if (last)
|
|
1968
|
-
break;
|
|
1969
|
-
pos2 = changes[i].to;
|
|
1970
|
-
}
|
|
1971
|
-
} else {
|
|
1972
|
-
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
return result;
|
|
1976
|
-
}
|
|
1977
|
-
export {
|
|
1978
|
-
DefaultBufferLength as D,
|
|
1979
|
-
IterMode as I,
|
|
1980
|
-
NodeProp as N,
|
|
1981
|
-
Parser as P,
|
|
1982
|
-
Tree as T,
|
|
1983
|
-
NodeSet as a,
|
|
1984
|
-
NodeType as b,
|
|
1985
|
-
TreeFragment as c,
|
|
1986
|
-
NodeWeakMap as d,
|
|
1987
|
-
parseMixed as p
|
|
1988
|
-
};
|