feelin 4.3.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.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +43 -0
  8. data/feelin.gemspec +22 -0
  9. data/lib/feelin/js/node_modules/.package-lock.json +67 -0
  10. data/lib/feelin/js/node_modules/@lezer/common/LICENSE +21 -0
  11. data/lib/feelin/js/node_modules/@lezer/common/README.md +14 -0
  12. data/lib/feelin/js/node_modules/@lezer/common/dist/index.cjs +2181 -0
  13. data/lib/feelin/js/node_modules/@lezer/common/dist/index.d.cts +1137 -0
  14. data/lib/feelin/js/node_modules/@lezer/common/dist/index.d.ts +1137 -0
  15. data/lib/feelin/js/node_modules/@lezer/common/dist/index.js +2168 -0
  16. data/lib/feelin/js/node_modules/@lezer/common/package.json +32 -0
  17. data/lib/feelin/js/node_modules/@lezer/highlight/LICENSE +21 -0
  18. data/lib/feelin/js/node_modules/@lezer/highlight/README.md +14 -0
  19. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.cjs +915 -0
  20. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.d.cts +621 -0
  21. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.d.ts +623 -0
  22. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.js +904 -0
  23. data/lib/feelin/js/node_modules/@lezer/highlight/package.json +31 -0
  24. data/lib/feelin/js/node_modules/@lezer/lr/LICENSE +21 -0
  25. data/lib/feelin/js/node_modules/@lezer/lr/README.md +25 -0
  26. data/lib/feelin/js/node_modules/@lezer/lr/dist/constants.d.ts +45 -0
  27. data/lib/feelin/js/node_modules/@lezer/lr/dist/constants.js +5 -0
  28. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.cjs +1890 -0
  29. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.d.cts +303 -0
  30. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.d.ts +303 -0
  31. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.js +1883 -0
  32. data/lib/feelin/js/node_modules/@lezer/lr/package.json +32 -0
  33. data/lib/feelin/js/node_modules/feelin/LICENSE +21 -0
  34. data/lib/feelin/js/node_modules/feelin/README.md +65 -0
  35. data/lib/feelin/js/node_modules/feelin/dist/builtins.d.ts +355 -0
  36. data/lib/feelin/js/node_modules/feelin/dist/index.cjs +2072 -0
  37. data/lib/feelin/js/node_modules/feelin/dist/index.cjs.map +1 -0
  38. data/lib/feelin/js/node_modules/feelin/dist/index.d.ts +3 -0
  39. data/lib/feelin/js/node_modules/feelin/dist/index.esm.js +2063 -0
  40. data/lib/feelin/js/node_modules/feelin/dist/index.esm.js.map +1 -0
  41. data/lib/feelin/js/node_modules/feelin/dist/interpreter.d.ts +26 -0
  42. data/lib/feelin/js/node_modules/feelin/dist/parser.d.ts +4 -0
  43. data/lib/feelin/js/node_modules/feelin/dist/temporal.d.ts +6 -0
  44. data/lib/feelin/js/node_modules/feelin/dist/types.d.ts +35 -0
  45. data/lib/feelin/js/node_modules/feelin/dist/utils.d.ts +12 -0
  46. data/lib/feelin/js/node_modules/feelin/package.json +63 -0
  47. data/lib/feelin/js/node_modules/lezer-feel/LICENSE +21 -0
  48. data/lib/feelin/js/node_modules/lezer-feel/README.md +94 -0
  49. data/lib/feelin/js/node_modules/lezer-feel/dist/index.cjs +1328 -0
  50. data/lib/feelin/js/node_modules/lezer-feel/dist/index.cjs.map +1 -0
  51. data/lib/feelin/js/node_modules/lezer-feel/dist/index.d.ts +32 -0
  52. data/lib/feelin/js/node_modules/lezer-feel/dist/index.js +1323 -0
  53. data/lib/feelin/js/node_modules/lezer-feel/dist/index.js.map +1 -0
  54. data/lib/feelin/js/node_modules/lezer-feel/package.json +61 -0
  55. data/lib/feelin/js/node_modules/luxon/LICENSE.md +7 -0
  56. data/lib/feelin/js/node_modules/luxon/README.md +55 -0
  57. data/lib/feelin/js/node_modules/luxon/build/amd/luxon.js +8623 -0
  58. data/lib/feelin/js/node_modules/luxon/build/amd/luxon.js.map +1 -0
  59. data/lib/feelin/js/node_modules/luxon/build/cjs-browser/luxon.js +8621 -0
  60. data/lib/feelin/js/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  61. data/lib/feelin/js/node_modules/luxon/build/es6/luxon.js +8011 -0
  62. data/lib/feelin/js/node_modules/luxon/build/es6/luxon.js.map +1 -0
  63. data/lib/feelin/js/node_modules/luxon/build/global/luxon.js +8626 -0
  64. data/lib/feelin/js/node_modules/luxon/build/global/luxon.js.map +1 -0
  65. data/lib/feelin/js/node_modules/luxon/build/global/luxon.min.js +1 -0
  66. data/lib/feelin/js/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  67. data/lib/feelin/js/node_modules/luxon/build/node/luxon.js +7679 -0
  68. data/lib/feelin/js/node_modules/luxon/build/node/luxon.js.map +1 -0
  69. data/lib/feelin/js/node_modules/luxon/package.json +87 -0
  70. data/lib/feelin/js/node_modules/luxon/src/datetime.js +2566 -0
  71. data/lib/feelin/js/node_modules/luxon/src/duration.js +990 -0
  72. data/lib/feelin/js/node_modules/luxon/src/errors.js +61 -0
  73. data/lib/feelin/js/node_modules/luxon/src/impl/conversions.js +206 -0
  74. data/lib/feelin/js/node_modules/luxon/src/impl/diff.js +95 -0
  75. data/lib/feelin/js/node_modules/luxon/src/impl/digits.js +90 -0
  76. data/lib/feelin/js/node_modules/luxon/src/impl/english.js +233 -0
  77. data/lib/feelin/js/node_modules/luxon/src/impl/formats.js +176 -0
  78. data/lib/feelin/js/node_modules/luxon/src/impl/formatter.js +409 -0
  79. data/lib/feelin/js/node_modules/luxon/src/impl/invalid.js +14 -0
  80. data/lib/feelin/js/node_modules/luxon/src/impl/locale.js +554 -0
  81. data/lib/feelin/js/node_modules/luxon/src/impl/regexParser.js +335 -0
  82. data/lib/feelin/js/node_modules/luxon/src/impl/tokenParser.js +505 -0
  83. data/lib/feelin/js/node_modules/luxon/src/impl/util.js +316 -0
  84. data/lib/feelin/js/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  85. data/lib/feelin/js/node_modules/luxon/src/info.js +205 -0
  86. data/lib/feelin/js/node_modules/luxon/src/interval.js +665 -0
  87. data/lib/feelin/js/node_modules/luxon/src/luxon.js +26 -0
  88. data/lib/feelin/js/node_modules/luxon/src/package.json +4 -0
  89. data/lib/feelin/js/node_modules/luxon/src/settings.js +180 -0
  90. data/lib/feelin/js/node_modules/luxon/src/zone.js +97 -0
  91. data/lib/feelin/js/node_modules/luxon/src/zones/IANAZone.js +231 -0
  92. data/lib/feelin/js/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  93. data/lib/feelin/js/node_modules/luxon/src/zones/invalidZone.js +53 -0
  94. data/lib/feelin/js/node_modules/luxon/src/zones/systemZone.js +61 -0
  95. data/lib/feelin/js/node_modules/min-dash/LICENSE +21 -0
  96. data/lib/feelin/js/node_modules/min-dash/README.md +38 -0
  97. data/lib/feelin/js/node_modules/min-dash/dist/array.d.ts +12 -0
  98. data/lib/feelin/js/node_modules/min-dash/dist/collection.d.ts +174 -0
  99. data/lib/feelin/js/node_modules/min-dash/dist/fn.d.ts +37 -0
  100. data/lib/feelin/js/node_modules/min-dash/dist/index.cjs +910 -0
  101. data/lib/feelin/js/node_modules/min-dash/dist/index.d.ts +5 -0
  102. data/lib/feelin/js/node_modules/min-dash/dist/index.esm.js +872 -0
  103. data/lib/feelin/js/node_modules/min-dash/dist/lang.d.ts +29 -0
  104. data/lib/feelin/js/node_modules/min-dash/dist/min-dash.js +916 -0
  105. data/lib/feelin/js/node_modules/min-dash/dist/min-dash.min.js +1 -0
  106. data/lib/feelin/js/node_modules/min-dash/dist/object.d.ts +112 -0
  107. data/lib/feelin/js/node_modules/min-dash/package.json +72 -0
  108. data/lib/feelin/js/package-lock.json +72 -0
  109. data/lib/feelin/js/package.json +5 -0
  110. data/lib/feelin/version.rb +3 -0
  111. data/lib/feelin.rb +63 -0
  112. data/spec/feelin/feelin_spec.rb +38 -0
  113. data/spec/spec_helper.rb +2 -0
  114. metadata +198 -0
@@ -0,0 +1,904 @@
1
+ import { NodeProp } from '@lezer/common';
2
+
3
+ let nextTagID = 0;
4
+ /**
5
+ Highlighting tags are markers that denote a highlighting category.
6
+ They are [associated](#highlight.styleTags) with parts of a syntax
7
+ tree by a language mode, and then mapped to an actual CSS style by
8
+ a [highlighter](#highlight.Highlighter).
9
+
10
+ Because syntax tree node types and highlight styles have to be
11
+ able to talk the same language, CodeMirror uses a mostly _closed_
12
+ [vocabulary](#highlight.tags) of syntax tags (as opposed to
13
+ traditional open string-based systems, which make it hard for
14
+ highlighting themes to cover all the tokens produced by the
15
+ various languages).
16
+
17
+ It _is_ possible to [define](#highlight.Tag^define) your own
18
+ highlighting tags for system-internal use (where you control both
19
+ the language package and the highlighter), but such tags will not
20
+ be picked up by regular highlighters (though you can derive them
21
+ from standard tags to allow highlighters to fall back to those).
22
+ */
23
+ class Tag {
24
+ /**
25
+ @internal
26
+ */
27
+ constructor(
28
+ /**
29
+ The optional name of the base tag @internal
30
+ */
31
+ name,
32
+ /**
33
+ The set of this tag and all its parent tags, starting with
34
+ this one itself and sorted in order of decreasing specificity.
35
+ */
36
+ set,
37
+ /**
38
+ The base unmodified tag that this one is based on, if it's
39
+ modified @internal
40
+ */
41
+ base,
42
+ /**
43
+ The modifiers applied to this.base @internal
44
+ */
45
+ modified) {
46
+ this.name = name;
47
+ this.set = set;
48
+ this.base = base;
49
+ this.modified = modified;
50
+ /**
51
+ @internal
52
+ */
53
+ this.id = nextTagID++;
54
+ }
55
+ toString() {
56
+ let { name } = this;
57
+ for (let mod of this.modified)
58
+ if (mod.name)
59
+ name = `${mod.name}(${name})`;
60
+ return name;
61
+ }
62
+ static define(nameOrParent, parent) {
63
+ let name = typeof nameOrParent == "string" ? nameOrParent : "?";
64
+ if (nameOrParent instanceof Tag)
65
+ parent = nameOrParent;
66
+ if (parent === null || parent === void 0 ? void 0 : parent.base)
67
+ throw new Error("Can not derive from a modified tag");
68
+ let tag = new Tag(name, [], null, []);
69
+ tag.set.push(tag);
70
+ if (parent)
71
+ for (let t of parent.set)
72
+ tag.set.push(t);
73
+ return tag;
74
+ }
75
+ /**
76
+ Define a tag _modifier_, which is a function that, given a tag,
77
+ will return a tag that is a subtag of the original. Applying the
78
+ same modifier to a twice tag will return the same value (`m1(t1)
79
+ == m1(t1)`) and applying multiple modifiers will, regardless or
80
+ order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
81
+
82
+ When multiple modifiers are applied to a given base tag, each
83
+ smaller set of modifiers is registered as a parent, so that for
84
+ example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
85
+ `m1(m3(t1)`, and so on.
86
+ */
87
+ static defineModifier(name) {
88
+ let mod = new Modifier(name);
89
+ return (tag) => {
90
+ if (tag.modified.indexOf(mod) > -1)
91
+ return tag;
92
+ return Modifier.get(tag.base || tag, tag.modified.concat(mod).sort((a, b) => a.id - b.id));
93
+ };
94
+ }
95
+ }
96
+ let nextModifierID = 0;
97
+ class Modifier {
98
+ constructor(name) {
99
+ this.name = name;
100
+ this.instances = [];
101
+ this.id = nextModifierID++;
102
+ }
103
+ static get(base, mods) {
104
+ if (!mods.length)
105
+ return base;
106
+ let exists = mods[0].instances.find(t => t.base == base && sameArray(mods, t.modified));
107
+ if (exists)
108
+ return exists;
109
+ let set = [], tag = new Tag(base.name, set, base, mods);
110
+ for (let m of mods)
111
+ m.instances.push(tag);
112
+ let configs = powerSet(mods);
113
+ for (let parent of base.set)
114
+ if (!parent.modified.length)
115
+ for (let config of configs)
116
+ set.push(Modifier.get(parent, config));
117
+ return tag;
118
+ }
119
+ }
120
+ function sameArray(a, b) {
121
+ return a.length == b.length && a.every((x, i) => x == b[i]);
122
+ }
123
+ function powerSet(array) {
124
+ let sets = [[]];
125
+ for (let i = 0; i < array.length; i++) {
126
+ for (let j = 0, e = sets.length; j < e; j++) {
127
+ sets.push(sets[j].concat(array[i]));
128
+ }
129
+ }
130
+ return sets.sort((a, b) => b.length - a.length);
131
+ }
132
+ /**
133
+ This function is used to add a set of tags to a language syntax
134
+ via [`NodeSet.extend`](#common.NodeSet.extend) or
135
+ [`LRParser.configure`](#lr.LRParser.configure).
136
+
137
+ The argument object maps node selectors to [highlighting
138
+ tags](#highlight.Tag) or arrays of tags.
139
+
140
+ Node selectors may hold one or more (space-separated) node paths.
141
+ Such a path can be a [node name](#common.NodeType.name), or
142
+ multiple node names (or `*` wildcards) separated by slash
143
+ characters, as in `"Block/Declaration/VariableName"`. Such a path
144
+ matches the final node but only if its direct parent nodes are the
145
+ other nodes mentioned. A `*` in such a path matches any parent,
146
+ but only a single level—wildcards that match multiple parents
147
+ aren't supported, both for efficiency reasons and because Lezer
148
+ trees make it rather hard to reason about what they would match.)
149
+
150
+ A path can be ended with `/...` to indicate that the tag assigned
151
+ to the node should also apply to all child nodes, even if they
152
+ match their own style (by default, only the innermost style is
153
+ used).
154
+
155
+ When a path ends in `!`, as in `Attribute!`, no further matching
156
+ happens for the node's child nodes, and the entire node gets the
157
+ given style.
158
+
159
+ In this notation, node names that contain `/`, `!`, `*`, or `...`
160
+ must be quoted as JSON strings.
161
+
162
+ For example:
163
+
164
+ ```javascript
165
+ parser.withProps(
166
+ styleTags({
167
+ // Style Number and BigNumber nodes
168
+ "Number BigNumber": tags.number,
169
+ // Style Escape nodes whose parent is String
170
+ "String/Escape": tags.escape,
171
+ // Style anything inside Attributes nodes
172
+ "Attributes!": tags.meta,
173
+ // Add a style to all content inside Italic nodes
174
+ "Italic/...": tags.emphasis,
175
+ // Style InvalidString nodes as both `string` and `invalid`
176
+ "InvalidString": [tags.string, tags.invalid],
177
+ // Style the node named "/" as punctuation
178
+ '"/"': tags.punctuation
179
+ })
180
+ )
181
+ ```
182
+ */
183
+ function styleTags(spec) {
184
+ let byName = Object.create(null);
185
+ for (let prop in spec) {
186
+ let tags = spec[prop];
187
+ if (!Array.isArray(tags))
188
+ tags = [tags];
189
+ for (let part of prop.split(" "))
190
+ if (part) {
191
+ let pieces = [], mode = 2 /* Mode.Normal */, rest = part;
192
+ for (let pos = 0;;) {
193
+ if (rest == "..." && pos > 0 && pos + 3 == part.length) {
194
+ mode = 1 /* Mode.Inherit */;
195
+ break;
196
+ }
197
+ let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
198
+ if (!m)
199
+ throw new RangeError("Invalid path: " + part);
200
+ pieces.push(m[0] == "*" ? "" : m[0][0] == '"' ? JSON.parse(m[0]) : m[0]);
201
+ pos += m[0].length;
202
+ if (pos == part.length)
203
+ break;
204
+ let next = part[pos++];
205
+ if (pos == part.length && next == "!") {
206
+ mode = 0 /* Mode.Opaque */;
207
+ break;
208
+ }
209
+ if (next != "/")
210
+ throw new RangeError("Invalid path: " + part);
211
+ rest = part.slice(pos);
212
+ }
213
+ let last = pieces.length - 1, inner = pieces[last];
214
+ if (!inner)
215
+ throw new RangeError("Invalid path: " + part);
216
+ let rule = new Rule(tags, mode, last > 0 ? pieces.slice(0, last) : null);
217
+ byName[inner] = rule.sort(byName[inner]);
218
+ }
219
+ }
220
+ return ruleNodeProp.add(byName);
221
+ }
222
+ const ruleNodeProp = new NodeProp();
223
+ class Rule {
224
+ constructor(tags, mode, context, next) {
225
+ this.tags = tags;
226
+ this.mode = mode;
227
+ this.context = context;
228
+ this.next = next;
229
+ }
230
+ get opaque() { return this.mode == 0 /* Mode.Opaque */; }
231
+ get inherit() { return this.mode == 1 /* Mode.Inherit */; }
232
+ sort(other) {
233
+ if (!other || other.depth < this.depth) {
234
+ this.next = other;
235
+ return this;
236
+ }
237
+ other.next = this.sort(other.next);
238
+ return other;
239
+ }
240
+ get depth() { return this.context ? this.context.length : 0; }
241
+ }
242
+ Rule.empty = new Rule([], 2 /* Mode.Normal */, null);
243
+ /**
244
+ Define a [highlighter](#highlight.Highlighter) from an array of
245
+ tag/class pairs. Classes associated with more specific tags will
246
+ take precedence.
247
+ */
248
+ function tagHighlighter(tags, options) {
249
+ let map = Object.create(null);
250
+ for (let style of tags) {
251
+ if (!Array.isArray(style.tag))
252
+ map[style.tag.id] = style.class;
253
+ else
254
+ for (let tag of style.tag)
255
+ map[tag.id] = style.class;
256
+ }
257
+ let { scope, all = null } = options || {};
258
+ return {
259
+ style: (tags) => {
260
+ let cls = all;
261
+ for (let tag of tags) {
262
+ for (let sub of tag.set) {
263
+ let tagClass = map[sub.id];
264
+ if (tagClass) {
265
+ cls = cls ? cls + " " + tagClass : tagClass;
266
+ break;
267
+ }
268
+ }
269
+ }
270
+ return cls;
271
+ },
272
+ scope
273
+ };
274
+ }
275
+ function highlightTags(highlighters, tags) {
276
+ let result = null;
277
+ for (let highlighter of highlighters) {
278
+ let value = highlighter.style(tags);
279
+ if (value)
280
+ result = result ? result + " " + value : value;
281
+ }
282
+ return result;
283
+ }
284
+ /**
285
+ Highlight the given [tree](#common.Tree) with the given
286
+ [highlighter](#highlight.Highlighter). Often, the higher-level
287
+ [`highlightCode`](#highlight.highlightCode) function is easier to
288
+ use.
289
+ */
290
+ function highlightTree(tree, highlighter,
291
+ /**
292
+ Assign styling to a region of the text. Will be called, in order
293
+ of position, for any ranges where more than zero classes apply.
294
+ `classes` is a space separated string of CSS classes.
295
+ */
296
+ putStyle,
297
+ /**
298
+ The start of the range to highlight.
299
+ */
300
+ from = 0,
301
+ /**
302
+ The end of the range.
303
+ */
304
+ to = tree.length) {
305
+ let builder = new HighlightBuilder(from, Array.isArray(highlighter) ? highlighter : [highlighter], putStyle);
306
+ builder.highlightRange(tree.cursor(), from, to, "", builder.highlighters);
307
+ builder.flush(to);
308
+ }
309
+ /**
310
+ Highlight the given tree with the given highlighter, calling
311
+ `putText` for every piece of text, either with a set of classes or
312
+ with the empty string when unstyled, and `putBreak` for every line
313
+ break.
314
+ */
315
+ function highlightCode(code, tree, highlighter, putText, putBreak, from = 0, to = code.length) {
316
+ let pos = from;
317
+ function writeTo(p, classes) {
318
+ if (p <= pos)
319
+ return;
320
+ for (let text = code.slice(pos, p), i = 0;;) {
321
+ let nextBreak = text.indexOf("\n", i);
322
+ let upto = nextBreak < 0 ? text.length : nextBreak;
323
+ if (upto > i)
324
+ putText(text.slice(i, upto), classes);
325
+ if (nextBreak < 0)
326
+ break;
327
+ putBreak();
328
+ i = nextBreak + 1;
329
+ }
330
+ pos = p;
331
+ }
332
+ highlightTree(tree, highlighter, (from, to, classes) => {
333
+ writeTo(from, "");
334
+ writeTo(to, classes);
335
+ }, from, to);
336
+ writeTo(to, "");
337
+ }
338
+ class HighlightBuilder {
339
+ constructor(at, highlighters, span) {
340
+ this.at = at;
341
+ this.highlighters = highlighters;
342
+ this.span = span;
343
+ this.class = "";
344
+ }
345
+ startSpan(at, cls) {
346
+ if (cls != this.class) {
347
+ this.flush(at);
348
+ if (at > this.at)
349
+ this.at = at;
350
+ this.class = cls;
351
+ }
352
+ }
353
+ flush(to) {
354
+ if (to > this.at && this.class)
355
+ this.span(this.at, to, this.class);
356
+ }
357
+ highlightRange(cursor, from, to, inheritedClass, highlighters) {
358
+ let { type, from: start, to: end } = cursor;
359
+ if (start >= to || end <= from)
360
+ return;
361
+ if (type.isTop)
362
+ highlighters = this.highlighters.filter(h => !h.scope || h.scope(type));
363
+ let cls = inheritedClass;
364
+ let rule = getStyleTags(cursor) || Rule.empty;
365
+ let tagCls = highlightTags(highlighters, rule.tags);
366
+ if (tagCls) {
367
+ if (cls)
368
+ cls += " ";
369
+ cls += tagCls;
370
+ if (rule.mode == 1 /* Mode.Inherit */)
371
+ inheritedClass += (inheritedClass ? " " : "") + tagCls;
372
+ }
373
+ this.startSpan(Math.max(from, start), cls);
374
+ if (rule.opaque)
375
+ return;
376
+ let mounted = cursor.tree && cursor.tree.prop(NodeProp.mounted);
377
+ if (mounted && mounted.overlay) {
378
+ let inner = cursor.node.enter(mounted.overlay[0].from + start, 1);
379
+ let innerHighlighters = this.highlighters.filter(h => !h.scope || h.scope(mounted.tree.type));
380
+ let hasChild = cursor.firstChild();
381
+ for (let i = 0, pos = start;; i++) {
382
+ let next = i < mounted.overlay.length ? mounted.overlay[i] : null;
383
+ let nextPos = next ? next.from + start : end;
384
+ let rangeFrom = Math.max(from, pos), rangeTo = Math.min(to, nextPos);
385
+ if (rangeFrom < rangeTo && hasChild) {
386
+ while (cursor.from < rangeTo) {
387
+ this.highlightRange(cursor, rangeFrom, rangeTo, inheritedClass, highlighters);
388
+ this.startSpan(Math.min(rangeTo, cursor.to), cls);
389
+ if (cursor.to >= nextPos || !cursor.nextSibling())
390
+ break;
391
+ }
392
+ }
393
+ if (!next || nextPos > to)
394
+ break;
395
+ pos = next.to + start;
396
+ if (pos > from) {
397
+ this.highlightRange(inner.cursor(), Math.max(from, next.from + start), Math.min(to, pos), "", innerHighlighters);
398
+ this.startSpan(Math.min(to, pos), cls);
399
+ }
400
+ }
401
+ if (hasChild)
402
+ cursor.parent();
403
+ }
404
+ else if (cursor.firstChild()) {
405
+ if (mounted)
406
+ inheritedClass = "";
407
+ do {
408
+ if (cursor.to <= from)
409
+ continue;
410
+ if (cursor.from >= to)
411
+ break;
412
+ this.highlightRange(cursor, from, to, inheritedClass, highlighters);
413
+ this.startSpan(Math.min(to, cursor.to), cls);
414
+ } while (cursor.nextSibling());
415
+ cursor.parent();
416
+ }
417
+ }
418
+ }
419
+ /**
420
+ Match a syntax node's [highlight rules](#highlight.styleTags). If
421
+ there's a match, return its set of tags, and whether it is
422
+ opaque (uses a `!`) or applies to all child nodes (`/...`).
423
+ */
424
+ function getStyleTags(node) {
425
+ let rule = node.type.prop(ruleNodeProp);
426
+ while (rule && rule.context && !node.matchContext(rule.context))
427
+ rule = rule.next;
428
+ return rule || null;
429
+ }
430
+ const t = Tag.define;
431
+ const comment = t(), name = t(), typeName = t(name), propertyName = t(name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
432
+ /**
433
+ The default set of highlighting [tags](#highlight.Tag).
434
+
435
+ This collection is heavily biased towards programming languages,
436
+ and necessarily incomplete. A full ontology of syntactic
437
+ constructs would fill a stack of books, and be impractical to
438
+ write themes for. So try to make do with this set. If all else
439
+ fails, [open an
440
+ issue](https://github.com/codemirror/codemirror.next) to propose a
441
+ new tag, or [define](#highlight.Tag^define) a local custom tag for
442
+ your use case.
443
+
444
+ Note that it is not obligatory to always attach the most specific
445
+ tag possible to an element—if your grammar can't easily
446
+ distinguish a certain type of element (such as a local variable),
447
+ it is okay to style it as its more general variant (a variable).
448
+
449
+ For tags that extend some parent tag, the documentation links to
450
+ the parent.
451
+ */
452
+ const tags = {
453
+ /**
454
+ A comment.
455
+ */
456
+ comment,
457
+ /**
458
+ A line [comment](#highlight.tags.comment).
459
+ */
460
+ lineComment: t(comment),
461
+ /**
462
+ A block [comment](#highlight.tags.comment).
463
+ */
464
+ blockComment: t(comment),
465
+ /**
466
+ A documentation [comment](#highlight.tags.comment).
467
+ */
468
+ docComment: t(comment),
469
+ /**
470
+ Any kind of identifier.
471
+ */
472
+ name,
473
+ /**
474
+ The [name](#highlight.tags.name) of a variable.
475
+ */
476
+ variableName: t(name),
477
+ /**
478
+ A type [name](#highlight.tags.name).
479
+ */
480
+ typeName: typeName,
481
+ /**
482
+ A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
483
+ */
484
+ tagName: t(typeName),
485
+ /**
486
+ A property or field [name](#highlight.tags.name).
487
+ */
488
+ propertyName: propertyName,
489
+ /**
490
+ An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
491
+ */
492
+ attributeName: t(propertyName),
493
+ /**
494
+ The [name](#highlight.tags.name) of a class.
495
+ */
496
+ className: t(name),
497
+ /**
498
+ A label [name](#highlight.tags.name).
499
+ */
500
+ labelName: t(name),
501
+ /**
502
+ A namespace [name](#highlight.tags.name).
503
+ */
504
+ namespace: t(name),
505
+ /**
506
+ The [name](#highlight.tags.name) of a macro.
507
+ */
508
+ macroName: t(name),
509
+ /**
510
+ A literal value.
511
+ */
512
+ literal,
513
+ /**
514
+ A string [literal](#highlight.tags.literal).
515
+ */
516
+ string,
517
+ /**
518
+ A documentation [string](#highlight.tags.string).
519
+ */
520
+ docString: t(string),
521
+ /**
522
+ A character literal (subtag of [string](#highlight.tags.string)).
523
+ */
524
+ character: t(string),
525
+ /**
526
+ An attribute value (subtag of [string](#highlight.tags.string)).
527
+ */
528
+ attributeValue: t(string),
529
+ /**
530
+ A number [literal](#highlight.tags.literal).
531
+ */
532
+ number,
533
+ /**
534
+ An integer [number](#highlight.tags.number) literal.
535
+ */
536
+ integer: t(number),
537
+ /**
538
+ A floating-point [number](#highlight.tags.number) literal.
539
+ */
540
+ float: t(number),
541
+ /**
542
+ A boolean [literal](#highlight.tags.literal).
543
+ */
544
+ bool: t(literal),
545
+ /**
546
+ Regular expression [literal](#highlight.tags.literal).
547
+ */
548
+ regexp: t(literal),
549
+ /**
550
+ An escape [literal](#highlight.tags.literal), for example a
551
+ backslash escape in a string.
552
+ */
553
+ escape: t(literal),
554
+ /**
555
+ A color [literal](#highlight.tags.literal).
556
+ */
557
+ color: t(literal),
558
+ /**
559
+ A URL [literal](#highlight.tags.literal).
560
+ */
561
+ url: t(literal),
562
+ /**
563
+ A language keyword.
564
+ */
565
+ keyword,
566
+ /**
567
+ The [keyword](#highlight.tags.keyword) for the self or this
568
+ object.
569
+ */
570
+ self: t(keyword),
571
+ /**
572
+ The [keyword](#highlight.tags.keyword) for null.
573
+ */
574
+ null: t(keyword),
575
+ /**
576
+ A [keyword](#highlight.tags.keyword) denoting some atomic value.
577
+ */
578
+ atom: t(keyword),
579
+ /**
580
+ A [keyword](#highlight.tags.keyword) that represents a unit.
581
+ */
582
+ unit: t(keyword),
583
+ /**
584
+ A modifier [keyword](#highlight.tags.keyword).
585
+ */
586
+ modifier: t(keyword),
587
+ /**
588
+ A [keyword](#highlight.tags.keyword) that acts as an operator.
589
+ */
590
+ operatorKeyword: t(keyword),
591
+ /**
592
+ A control-flow related [keyword](#highlight.tags.keyword).
593
+ */
594
+ controlKeyword: t(keyword),
595
+ /**
596
+ A [keyword](#highlight.tags.keyword) that defines something.
597
+ */
598
+ definitionKeyword: t(keyword),
599
+ /**
600
+ A [keyword](#highlight.tags.keyword) related to defining or
601
+ interfacing with modules.
602
+ */
603
+ moduleKeyword: t(keyword),
604
+ /**
605
+ An operator.
606
+ */
607
+ operator,
608
+ /**
609
+ An [operator](#highlight.tags.operator) that dereferences something.
610
+ */
611
+ derefOperator: t(operator),
612
+ /**
613
+ Arithmetic-related [operator](#highlight.tags.operator).
614
+ */
615
+ arithmeticOperator: t(operator),
616
+ /**
617
+ Logical [operator](#highlight.tags.operator).
618
+ */
619
+ logicOperator: t(operator),
620
+ /**
621
+ Bit [operator](#highlight.tags.operator).
622
+ */
623
+ bitwiseOperator: t(operator),
624
+ /**
625
+ Comparison [operator](#highlight.tags.operator).
626
+ */
627
+ compareOperator: t(operator),
628
+ /**
629
+ [Operator](#highlight.tags.operator) that updates its operand.
630
+ */
631
+ updateOperator: t(operator),
632
+ /**
633
+ [Operator](#highlight.tags.operator) that defines something.
634
+ */
635
+ definitionOperator: t(operator),
636
+ /**
637
+ Type-related [operator](#highlight.tags.operator).
638
+ */
639
+ typeOperator: t(operator),
640
+ /**
641
+ Control-flow [operator](#highlight.tags.operator).
642
+ */
643
+ controlOperator: t(operator),
644
+ /**
645
+ Program or markup punctuation.
646
+ */
647
+ punctuation,
648
+ /**
649
+ [Punctuation](#highlight.tags.punctuation) that separates
650
+ things.
651
+ */
652
+ separator: t(punctuation),
653
+ /**
654
+ Bracket-style [punctuation](#highlight.tags.punctuation).
655
+ */
656
+ bracket,
657
+ /**
658
+ Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
659
+ tokens).
660
+ */
661
+ angleBracket: t(bracket),
662
+ /**
663
+ Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
664
+ tokens).
665
+ */
666
+ squareBracket: t(bracket),
667
+ /**
668
+ Parentheses (usually `(` and `)` tokens). Subtag of
669
+ [bracket](#highlight.tags.bracket).
670
+ */
671
+ paren: t(bracket),
672
+ /**
673
+ Braces (usually `{` and `}` tokens). Subtag of
674
+ [bracket](#highlight.tags.bracket).
675
+ */
676
+ brace: t(bracket),
677
+ /**
678
+ Content, for example plain text in XML or markup documents.
679
+ */
680
+ content,
681
+ /**
682
+ [Content](#highlight.tags.content) that represents a heading.
683
+ */
684
+ heading,
685
+ /**
686
+ A level 1 [heading](#highlight.tags.heading).
687
+ */
688
+ heading1: t(heading),
689
+ /**
690
+ A level 2 [heading](#highlight.tags.heading).
691
+ */
692
+ heading2: t(heading),
693
+ /**
694
+ A level 3 [heading](#highlight.tags.heading).
695
+ */
696
+ heading3: t(heading),
697
+ /**
698
+ A level 4 [heading](#highlight.tags.heading).
699
+ */
700
+ heading4: t(heading),
701
+ /**
702
+ A level 5 [heading](#highlight.tags.heading).
703
+ */
704
+ heading5: t(heading),
705
+ /**
706
+ A level 6 [heading](#highlight.tags.heading).
707
+ */
708
+ heading6: t(heading),
709
+ /**
710
+ A prose [content](#highlight.tags.content) separator (such as a horizontal rule).
711
+ */
712
+ contentSeparator: t(content),
713
+ /**
714
+ [Content](#highlight.tags.content) that represents a list.
715
+ */
716
+ list: t(content),
717
+ /**
718
+ [Content](#highlight.tags.content) that represents a quote.
719
+ */
720
+ quote: t(content),
721
+ /**
722
+ [Content](#highlight.tags.content) that is emphasized.
723
+ */
724
+ emphasis: t(content),
725
+ /**
726
+ [Content](#highlight.tags.content) that is styled strong.
727
+ */
728
+ strong: t(content),
729
+ /**
730
+ [Content](#highlight.tags.content) that is part of a link.
731
+ */
732
+ link: t(content),
733
+ /**
734
+ [Content](#highlight.tags.content) that is styled as code or
735
+ monospace.
736
+ */
737
+ monospace: t(content),
738
+ /**
739
+ [Content](#highlight.tags.content) that has a strike-through
740
+ style.
741
+ */
742
+ strikethrough: t(content),
743
+ /**
744
+ Inserted text in a change-tracking format.
745
+ */
746
+ inserted: t(),
747
+ /**
748
+ Deleted text.
749
+ */
750
+ deleted: t(),
751
+ /**
752
+ Changed text.
753
+ */
754
+ changed: t(),
755
+ /**
756
+ An invalid or unsyntactic element.
757
+ */
758
+ invalid: t(),
759
+ /**
760
+ Metadata or meta-instruction.
761
+ */
762
+ meta,
763
+ /**
764
+ [Metadata](#highlight.tags.meta) that applies to the entire
765
+ document.
766
+ */
767
+ documentMeta: t(meta),
768
+ /**
769
+ [Metadata](#highlight.tags.meta) that annotates or adds
770
+ attributes to a given syntactic element.
771
+ */
772
+ annotation: t(meta),
773
+ /**
774
+ Processing instruction or preprocessor directive. Subtag of
775
+ [meta](#highlight.tags.meta).
776
+ */
777
+ processingInstruction: t(meta),
778
+ /**
779
+ [Modifier](#highlight.Tag^defineModifier) that indicates that a
780
+ given element is being defined. Expected to be used with the
781
+ various [name](#highlight.tags.name) tags.
782
+ */
783
+ definition: Tag.defineModifier("definition"),
784
+ /**
785
+ [Modifier](#highlight.Tag^defineModifier) that indicates that
786
+ something is constant. Mostly expected to be used with
787
+ [variable names](#highlight.tags.variableName).
788
+ */
789
+ constant: Tag.defineModifier("constant"),
790
+ /**
791
+ [Modifier](#highlight.Tag^defineModifier) used to indicate that
792
+ a [variable](#highlight.tags.variableName) or [property
793
+ name](#highlight.tags.propertyName) is being called or defined
794
+ as a function.
795
+ */
796
+ function: Tag.defineModifier("function"),
797
+ /**
798
+ [Modifier](#highlight.Tag^defineModifier) that can be applied to
799
+ [names](#highlight.tags.name) to indicate that they belong to
800
+ the language's standard environment.
801
+ */
802
+ standard: Tag.defineModifier("standard"),
803
+ /**
804
+ [Modifier](#highlight.Tag^defineModifier) that indicates a given
805
+ [names](#highlight.tags.name) is local to some scope.
806
+ */
807
+ local: Tag.defineModifier("local"),
808
+ /**
809
+ A generic variant [modifier](#highlight.Tag^defineModifier) that
810
+ can be used to tag language-specific alternative variants of
811
+ some common tag. It is recommended for themes to define special
812
+ forms of at least the [string](#highlight.tags.string) and
813
+ [variable name](#highlight.tags.variableName) tags, since those
814
+ come up a lot.
815
+ */
816
+ special: Tag.defineModifier("special")
817
+ };
818
+ for (let name in tags) {
819
+ let val = tags[name];
820
+ if (val instanceof Tag)
821
+ val.name = name;
822
+ }
823
+ /**
824
+ This is a highlighter that adds stable, predictable classes to
825
+ tokens, for styling with external CSS.
826
+
827
+ The following tags are mapped to their name prefixed with `"tok-"`
828
+ (for example `"tok-comment"`):
829
+
830
+ * [`link`](#highlight.tags.link)
831
+ * [`heading`](#highlight.tags.heading)
832
+ * [`emphasis`](#highlight.tags.emphasis)
833
+ * [`strong`](#highlight.tags.strong)
834
+ * [`keyword`](#highlight.tags.keyword)
835
+ * [`atom`](#highlight.tags.atom)
836
+ * [`bool`](#highlight.tags.bool)
837
+ * [`url`](#highlight.tags.url)
838
+ * [`labelName`](#highlight.tags.labelName)
839
+ * [`inserted`](#highlight.tags.inserted)
840
+ * [`deleted`](#highlight.tags.deleted)
841
+ * [`literal`](#highlight.tags.literal)
842
+ * [`string`](#highlight.tags.string)
843
+ * [`number`](#highlight.tags.number)
844
+ * [`variableName`](#highlight.tags.variableName)
845
+ * [`typeName`](#highlight.tags.typeName)
846
+ * [`namespace`](#highlight.tags.namespace)
847
+ * [`className`](#highlight.tags.className)
848
+ * [`macroName`](#highlight.tags.macroName)
849
+ * [`propertyName`](#highlight.tags.propertyName)
850
+ * [`operator`](#highlight.tags.operator)
851
+ * [`comment`](#highlight.tags.comment)
852
+ * [`meta`](#highlight.tags.meta)
853
+ * [`punctuation`](#highlight.tags.punctuation)
854
+ * [`invalid`](#highlight.tags.invalid)
855
+
856
+ In addition, these mappings are provided:
857
+
858
+ * [`regexp`](#highlight.tags.regexp),
859
+ [`escape`](#highlight.tags.escape), and
860
+ [`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
861
+ are mapped to `"tok-string2"`
862
+ * [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
863
+ to `"tok-variableName2"`
864
+ * [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
865
+ to `"tok-variableName tok-local"`
866
+ * [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
867
+ to `"tok-variableName tok-definition"`
868
+ * [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
869
+ to `"tok-propertyName tok-definition"`
870
+ */
871
+ const classHighlighter = tagHighlighter([
872
+ { tag: tags.link, class: "tok-link" },
873
+ { tag: tags.heading, class: "tok-heading" },
874
+ { tag: tags.emphasis, class: "tok-emphasis" },
875
+ { tag: tags.strong, class: "tok-strong" },
876
+ { tag: tags.keyword, class: "tok-keyword" },
877
+ { tag: tags.atom, class: "tok-atom" },
878
+ { tag: tags.bool, class: "tok-bool" },
879
+ { tag: tags.url, class: "tok-url" },
880
+ { tag: tags.labelName, class: "tok-labelName" },
881
+ { tag: tags.inserted, class: "tok-inserted" },
882
+ { tag: tags.deleted, class: "tok-deleted" },
883
+ { tag: tags.literal, class: "tok-literal" },
884
+ { tag: tags.string, class: "tok-string" },
885
+ { tag: tags.number, class: "tok-number" },
886
+ { tag: [tags.regexp, tags.escape, tags.special(tags.string)], class: "tok-string2" },
887
+ { tag: tags.variableName, class: "tok-variableName" },
888
+ { tag: tags.local(tags.variableName), class: "tok-variableName tok-local" },
889
+ { tag: tags.definition(tags.variableName), class: "tok-variableName tok-definition" },
890
+ { tag: tags.special(tags.variableName), class: "tok-variableName2" },
891
+ { tag: tags.definition(tags.propertyName), class: "tok-propertyName tok-definition" },
892
+ { tag: tags.typeName, class: "tok-typeName" },
893
+ { tag: tags.namespace, class: "tok-namespace" },
894
+ { tag: tags.className, class: "tok-className" },
895
+ { tag: tags.macroName, class: "tok-macroName" },
896
+ { tag: tags.propertyName, class: "tok-propertyName" },
897
+ { tag: tags.operator, class: "tok-operator" },
898
+ { tag: tags.comment, class: "tok-comment" },
899
+ { tag: tags.meta, class: "tok-meta" },
900
+ { tag: tags.invalid, class: "tok-invalid" },
901
+ { tag: tags.punctuation, class: "tok-punctuation" }
902
+ ]);
903
+
904
+ export { Tag, classHighlighter, getStyleTags, highlightCode, highlightTree, styleTags, tagHighlighter, tags };