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