@scalar/highlight 0.2.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 (166) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +324 -0
  3. package/dist/all.d.ts +28 -0
  4. package/dist/all.d.ts.map +1 -0
  5. package/dist/all.js +105 -0
  6. package/dist/compat/hljs.d.ts +24 -0
  7. package/dist/compat/hljs.d.ts.map +1 -0
  8. package/dist/compat/hljs.js +95 -0
  9. package/dist/compat/index.d.ts +24 -0
  10. package/dist/compat/index.d.ts.map +1 -0
  11. package/dist/compat/index.js +21 -0
  12. package/dist/compat/languages.d.ts +46 -0
  13. package/dist/compat/languages.d.ts.map +1 -0
  14. package/dist/compat/languages.js +236 -0
  15. package/dist/compat/syntax-highlight.d.ts +37 -0
  16. package/dist/compat/syntax-highlight.d.ts.map +1 -0
  17. package/dist/compat/syntax-highlight.js +133 -0
  18. package/dist/core/compile.d.ts +3 -0
  19. package/dist/core/compile.d.ts.map +1 -0
  20. package/dist/core/compile.js +142 -0
  21. package/dist/core/index.d.ts +9 -0
  22. package/dist/core/index.d.ts.map +1 -0
  23. package/dist/core/index.js +5 -0
  24. package/dist/core/registry.d.ts +14 -0
  25. package/dist/core/registry.d.ts.map +1 -0
  26. package/dist/core/registry.js +77 -0
  27. package/dist/core/render.d.ts +67 -0
  28. package/dist/core/render.d.ts.map +1 -0
  29. package/dist/core/render.js +216 -0
  30. package/dist/core/scopes.d.ts +94 -0
  31. package/dist/core/scopes.d.ts.map +1 -0
  32. package/dist/core/scopes.js +113 -0
  33. package/dist/core/tokenize.d.ts +18 -0
  34. package/dist/core/tokenize.d.ts.map +1 -0
  35. package/dist/core/tokenize.js +131 -0
  36. package/dist/core/types.d.ts +99 -0
  37. package/dist/core/types.d.ts.map +1 -0
  38. package/dist/core/types.js +10 -0
  39. package/dist/index.d.ts +19 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +20 -0
  42. package/dist/langs/bash.d.ts +4 -0
  43. package/dist/langs/bash.d.ts.map +1 -0
  44. package/dist/langs/bash.js +123 -0
  45. package/dist/langs/c.d.ts +4 -0
  46. package/dist/langs/c.d.ts.map +1 -0
  47. package/dist/langs/c.js +196 -0
  48. package/dist/langs/clojure.d.ts +4 -0
  49. package/dist/langs/clojure.d.ts.map +1 -0
  50. package/dist/langs/clojure.js +213 -0
  51. package/dist/langs/cpp.d.ts +4 -0
  52. package/dist/langs/cpp.d.ts.map +1 -0
  53. package/dist/langs/cpp.js +391 -0
  54. package/dist/langs/csharp.d.ts +4 -0
  55. package/dist/langs/csharp.d.ts.map +1 -0
  56. package/dist/langs/csharp.js +307 -0
  57. package/dist/langs/css.d.ts +4 -0
  58. package/dist/langs/css.d.ts.map +1 -0
  59. package/dist/langs/css.js +94 -0
  60. package/dist/langs/dart.d.ts +4 -0
  61. package/dist/langs/dart.d.ts.map +1 -0
  62. package/dist/langs/dart.js +262 -0
  63. package/dist/langs/diff.d.ts +10 -0
  64. package/dist/langs/diff.d.ts.map +1 -0
  65. package/dist/langs/diff.js +26 -0
  66. package/dist/langs/dockerfile.d.ts +4 -0
  67. package/dist/langs/dockerfile.d.ts.map +1 -0
  68. package/dist/langs/dockerfile.js +308 -0
  69. package/dist/langs/elixir.d.ts +4 -0
  70. package/dist/langs/elixir.d.ts.map +1 -0
  71. package/dist/langs/elixir.js +343 -0
  72. package/dist/langs/fsharp.d.ts +4 -0
  73. package/dist/langs/fsharp.d.ts.map +1 -0
  74. package/dist/langs/fsharp.js +330 -0
  75. package/dist/langs/go.d.ts +5 -0
  76. package/dist/langs/go.d.ts.map +1 -0
  77. package/dist/langs/go.js +90 -0
  78. package/dist/langs/graphql.d.ts +4 -0
  79. package/dist/langs/graphql.d.ts.map +1 -0
  80. package/dist/langs/graphql.js +185 -0
  81. package/dist/langs/haskell.d.ts +4 -0
  82. package/dist/langs/haskell.d.ts.map +1 -0
  83. package/dist/langs/haskell.js +375 -0
  84. package/dist/langs/html.d.ts +14 -0
  85. package/dist/langs/html.d.ts.map +1 -0
  86. package/dist/langs/html.js +71 -0
  87. package/dist/langs/http.d.ts +4 -0
  88. package/dist/langs/http.d.ts.map +1 -0
  89. package/dist/langs/http.js +185 -0
  90. package/dist/langs/ini.d.ts +4 -0
  91. package/dist/langs/ini.d.ts.map +1 -0
  92. package/dist/langs/ini.js +227 -0
  93. package/dist/langs/java.d.ts +4 -0
  94. package/dist/langs/java.d.ts.map +1 -0
  95. package/dist/langs/java.js +178 -0
  96. package/dist/langs/javascript.d.ts +4 -0
  97. package/dist/langs/javascript.d.ts.map +1 -0
  98. package/dist/langs/javascript.js +226 -0
  99. package/dist/langs/json.d.ts +10 -0
  100. package/dist/langs/json.d.ts.map +1 -0
  101. package/dist/langs/json.js +46 -0
  102. package/dist/langs/kotlin.d.ts +4 -0
  103. package/dist/langs/kotlin.d.ts.map +1 -0
  104. package/dist/langs/kotlin.js +220 -0
  105. package/dist/langs/lua.d.ts +4 -0
  106. package/dist/langs/lua.d.ts.map +1 -0
  107. package/dist/langs/lua.js +330 -0
  108. package/dist/langs/makefile.d.ts +4 -0
  109. package/dist/langs/makefile.d.ts.map +1 -0
  110. package/dist/langs/makefile.js +266 -0
  111. package/dist/langs/markdown.d.ts +11 -0
  112. package/dist/langs/markdown.d.ts.map +1 -0
  113. package/dist/langs/markdown.js +71 -0
  114. package/dist/langs/matlab.d.ts +4 -0
  115. package/dist/langs/matlab.d.ts.map +1 -0
  116. package/dist/langs/matlab.js +352 -0
  117. package/dist/langs/mojo.d.ts +4 -0
  118. package/dist/langs/mojo.d.ts.map +1 -0
  119. package/dist/langs/mojo.js +337 -0
  120. package/dist/langs/nginx.d.ts +4 -0
  121. package/dist/langs/nginx.d.ts.map +1 -0
  122. package/dist/langs/nginx.js +168 -0
  123. package/dist/langs/objectivec.d.ts +4 -0
  124. package/dist/langs/objectivec.d.ts.map +1 -0
  125. package/dist/langs/objectivec.js +287 -0
  126. package/dist/langs/ocaml.d.ts +4 -0
  127. package/dist/langs/ocaml.d.ts.map +1 -0
  128. package/dist/langs/ocaml.js +309 -0
  129. package/dist/langs/perl.d.ts +4 -0
  130. package/dist/langs/perl.d.ts.map +1 -0
  131. package/dist/langs/perl.js +435 -0
  132. package/dist/langs/php.d.ts +4 -0
  133. package/dist/langs/php.d.ts.map +1 -0
  134. package/dist/langs/php.js +325 -0
  135. package/dist/langs/powershell.d.ts +4 -0
  136. package/dist/langs/powershell.d.ts.map +1 -0
  137. package/dist/langs/powershell.js +308 -0
  138. package/dist/langs/python.d.ts +4 -0
  139. package/dist/langs/python.d.ts.map +1 -0
  140. package/dist/langs/python.js +350 -0
  141. package/dist/langs/r.d.ts +4 -0
  142. package/dist/langs/r.d.ts.map +1 -0
  143. package/dist/langs/r.js +265 -0
  144. package/dist/langs/ruby.d.ts +4 -0
  145. package/dist/langs/ruby.d.ts.map +1 -0
  146. package/dist/langs/ruby.js +365 -0
  147. package/dist/langs/rust.d.ts +10 -0
  148. package/dist/langs/rust.d.ts.map +1 -0
  149. package/dist/langs/rust.js +116 -0
  150. package/dist/langs/scala.d.ts +4 -0
  151. package/dist/langs/scala.d.ts.map +1 -0
  152. package/dist/langs/scala.js +308 -0
  153. package/dist/langs/sql.d.ts +5 -0
  154. package/dist/langs/sql.d.ts.map +1 -0
  155. package/dist/langs/sql.js +57 -0
  156. package/dist/langs/swift.d.ts +33 -0
  157. package/dist/langs/swift.d.ts.map +1 -0
  158. package/dist/langs/swift.js +256 -0
  159. package/dist/langs/yaml.d.ts +11 -0
  160. package/dist/langs/yaml.d.ts.map +1 -0
  161. package/dist/langs/yaml.js +123 -0
  162. package/dist/lazy.d.ts +69 -0
  163. package/dist/lazy.d.ts.map +1 -0
  164. package/dist/lazy.js +200 -0
  165. package/dist/style.css +308 -0
  166. package/package.json +86 -0
@@ -0,0 +1,330 @@
1
+ /**
2
+ * F#.
3
+ *
4
+ * The apostrophe is the character that decides whether an F# highlighter is any
5
+ * good: it opens a char literal (`'a'`), it prefixes a generic parameter
6
+ * (`'T`), and it is a perfectly ordinary letter inside a name (`sum'`). Both
7
+ * quote rules are guarded by a lookbehind so they only fire where a name cannot
8
+ * already be running, which keeps `x' 'a'` from reading as one char literal.
9
+ *
10
+ * The other things worth knowing about:
11
+ *
12
+ * - Three string flavours with their own escaping rules — plain, verbatim
13
+ * (`@"…"`, where `""` is a quote) and triple-quoted (no escapes at all) —
14
+ * each with an interpolated `$` form on top. `%d`-style printf specifiers are
15
+ * scoped in all of them, because in F# they are typed and part of the API.
16
+ * - `(*` opens a comment that nests, so it needs a state rather than a lazy
17
+ * `[\s\S]*?`. `(*)` is the multiplication operator and is matched first.
18
+ * - A `let` binding is scoped as a value or as a function depending on what
19
+ * follows the name, which is as close as a regex gets to F#'s "everything is
20
+ * a function" story.
21
+ * - ``double-backtick names`` are ordinary identifiers with spaces in them.
22
+ */
23
+ /** An F# identifier. The trailing `'` is a normal letter here, as in `sum'`. */
24
+ const ID = "[A-Za-z_][\\w']*";
25
+ /** A binding name, including the ``quoted`` form that may hold anything but a backtick. */
26
+ const NAME = `(?:${ID}|\`\`[^\`\\n]*\`\`)`;
27
+ /**
28
+ * Modifiers that may sit between a binding keyword and the name it binds.
29
+ * Captured as one run — including the spaces between them — so a single rule
30
+ * covers `let rec inline`, `let private mutable` and `member val`.
31
+ */
32
+ const MODS = '((?:(?:rec|inline|mutable|private|internal|public|static|member|val)[ \\t]+)*)';
33
+ /**
34
+ * Blocks a rule from naming a modifier. Without it `let inline (+.) a b = …`
35
+ * backtracks: the modifier run gives up its match so that `inline` itself can
36
+ * satisfy the name the rule still needs.
37
+ */
38
+ const NOT_MOD = '(?!(?:rec|inline|mutable|private|internal|public|static|member|val)\\b)';
39
+ /** `\n`, `©`, `\x41`, `\233` (the decimal trigraph) and the `\<newline>` continuation. */
40
+ const ESCAPE = '\\\\(?:u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|x[0-9a-fA-F]{2}|[0-9]{3}|\\r?\\n|[\\\\"\'ntbrafv0])';
41
+ /** `%d`, `%.2f`, `%+A`, `%*i` — typed printf specifiers, checked by the compiler. */
42
+ const FORMAT = '%[-+ 0]*(?:\\d+|\\*)?(?:\\.\\d+)?[bscdiuxXoeEfFgGMOAat%]';
43
+ /** `42y`, `42uy`, `1UL`, `3I`, `1.0m` — the integer and numeric suffixes. */
44
+ const SUFFIX = '(?:[uU][yslLnN]?|[yslLnNIfFmM])?';
45
+ const fsharp = {
46
+ name: 'fsharp',
47
+ aliases: ['fs', 'fsx', 'fsi', 'f#'],
48
+ states: {
49
+ root: { rules: [{ include: 'expression' }] },
50
+ expression: {
51
+ rules: [
52
+ // `(*)` is multiplication used as a function — `List.reduce (*)` — and
53
+ // has to win over the comment opener sitting inside it.
54
+ { match: '\\(\\*\\)', scope: 'operator' },
55
+ { match: '///[^\\n]*', scope: 'comment.doc' },
56
+ { match: '//[^\\n]*', scope: 'comment' },
57
+ { match: '\\(\\*', scope: 'comment', push: 'block-comment' },
58
+ // Compiler directives: `#if`, `#nowarn`, `#r "nuget: …"`. Anchored to
59
+ // the start of a line, which is the only place they are legal — a `#`
60
+ // anywhere else is a flexible type (`#seq<int>`) and stays unscoped.
61
+ { match: '^([ \\t]*)(#[a-zA-Z]+)', scope: [null, 'keyword'] },
62
+ // `[<Obsolete("…")>]`. The scan excludes `[` so a run of openers cannot
63
+ // cost a line rescan each; an attribute holding a nested `[` or a line
64
+ // break renders unscoped instead.
65
+ { match: '\\[<[^[\\]\\n]*>\\]', scope: 'decorator' },
66
+ { include: 'strings' },
67
+ // The apostrophe rules. A char literal always closes on the same line;
68
+ // a generic parameter never closes at all. Both are blocked from firing
69
+ // mid-name by the lookbehind, so the `'` in `sum'` stays inert.
70
+ {
71
+ match: `(?<![\\w'])'(?:[^'\\\\\\n]|${ESCAPE})'B?`,
72
+ scope: 'string',
73
+ },
74
+ { match: `(?<![\\w'])'${ID}`, scope: 'type' },
75
+ // `^T` in an inline function's statically resolved constraints. The
76
+ // lookbehind keeps `a^b` — string concatenation — out of it.
77
+ { match: `(?<![\\w')\\]])\\^${ID}`, scope: 'type' },
78
+ { match: '``[^`\\n]*``', scope: 'variable' },
79
+ // An active pattern definition: `let (|Even|Odd|)`, `let (|Parsed|_|)`.
80
+ { match: "\\(\\|[A-Za-z_][\\w'|]*\\|_?\\)", scope: 'function' },
81
+ // An operator used as a value: `let (+.) a b = …`, `List.reduce (|>)`.
82
+ // Anything starting `(*` is a comment and was matched above, which is
83
+ // exactly why F# makes you write `( *. )` with spaces.
84
+ { match: '\\([!%&*+\\-./<=>@^|~?]+\\)', scope: 'operator' },
85
+ {
86
+ match: "\\b(open)([ \\t]+)([A-Za-z_][\\w'.]*)",
87
+ scope: ['keyword.import', null, 'namespace'],
88
+ },
89
+ {
90
+ match: "\\b(namespace|module)([ \\t]+)((?:rec|global)[ \\t]+)?([A-Za-z_][\\w'.]*)",
91
+ scope: ['keyword.declaration', null, 'keyword.declaration', 'namespace'],
92
+ },
93
+ {
94
+ match: `\\b(type)([ \\t]+)${MODS}(${NAME})`,
95
+ scope: ['keyword.declaration', null, 'keyword.declaration', 'class'],
96
+ },
97
+ // A binding whose name is followed by `=`, `:` or `,` binds a value;
98
+ // anything else means parameters follow, so it binds a function. That is
99
+ // the distinction F# itself does not make, and it is right on ordinary
100
+ // code — a curried `let add = fun a b -> …` still reads as a value.
101
+ {
102
+ match: `\\b(let|use|and)([ \\t]+)${MODS}(${NAME})(?=[ \\t]*[:=,](?!=))`,
103
+ scope: ['keyword.declaration', null, 'keyword.declaration', 'variable'],
104
+ },
105
+ {
106
+ match: `\\b(let|use|and)([ \\t]+)${MODS}${NOT_MOD}(${NAME})`,
107
+ scope: ['keyword.declaration', null, 'keyword.declaration', 'function'],
108
+ },
109
+ // `member this.Add`, `member _.Count`, `override x.ToString`. The
110
+ // self-identifier is a name the author picked, not a keyword, but in
111
+ // this position it is always the instance.
112
+ {
113
+ match: `\\b(member|override|abstract|default|val)([ \\t]+)${MODS}(?:(${ID})(\\.))?(${NAME})`,
114
+ scope: ['keyword.declaration', null, 'keyword.declaration', 'variable.builtin', 'punctuation', 'function'],
115
+ },
116
+ // Computation expressions. These have to beat the plain keyword rules,
117
+ // which would otherwise take `let` and leave the `!` behind.
118
+ { match: '\\b(?:return|yield|match|do)!', scope: 'keyword.control' },
119
+ { match: '\\b(?:let|use|and)!', scope: 'keyword.declaration' },
120
+ {
121
+ match: '\\b(?:if|then|elif|else|match|when|with|try|finally|for|to|downto|while|do|done|return|yield|assert)\\b',
122
+ scope: 'keyword.control',
123
+ },
124
+ {
125
+ match: '\\b(?:let|rec|and|use|fun|function|type|member|override|abstract|default|static|val|mutable|new|inherit|interface|class|struct|begin|end|module|exception|delegate|inline|private|public|internal|extern|lazy|global|fixed)\\b',
126
+ scope: 'keyword.declaration',
127
+ },
128
+ { match: '\\b(?:open|namespace)\\b', scope: 'keyword.import' },
129
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
130
+ {
131
+ match: '\\b(?:null|None|Some|Ok|Error|ValueNone|ValueSome|nan|infinity)\\b',
132
+ scope: 'constant.builtin',
133
+ },
134
+ {
135
+ match: '\\b(?:not|in|as|of|mod|land|lor|lxor|lsl|lsr|asr|upcast|downcast|box|unbox|typeof|nameof|sizeof)\\b',
136
+ scope: 'keyword.operator',
137
+ },
138
+ // `this` is a convention rather than a keyword, but no F# reader takes
139
+ // it for anything else; `base` really is one.
140
+ { match: '\\b(?:this|base)\\b', scope: 'variable.builtin' },
141
+ // `u?int(?:8|16|32|64)?` is the whole integer family in one branch —
142
+ // spelling all ten out costs bytes a shared prefix already covers.
143
+ {
144
+ match: '\\b(?:u?int(?:8|16|32|64)?|u?nativeint|s?byte|float(?:32)?|double|single|decimal|bigint|char|string|bool|unit|obj|exn|list|array|seq|v?option|Result|Option|Map|Set|Async|Task)\\b',
145
+ scope: 'type.builtin',
146
+ },
147
+ {
148
+ match: '\\b(?:e?printfn?|sprintf|failwithf?|raise|ignore|id|fst|snd)\\b',
149
+ scope: 'function.builtin',
150
+ },
151
+ // Matched from the dot, so a member never picks up the builtin colours.
152
+ {
153
+ match: `(\\.)(${ID})(?=[ \\t]*\\()`,
154
+ scope: ['punctuation', 'function.method'],
155
+ },
156
+ { match: `(\\.)(${ID})`, scope: ['punctuation', 'variable.member'] },
157
+ // Record fields. A field is a capitalised name followed by `:` in a
158
+ // declaration or `=` in a construction, and it is either the first
159
+ // thing on its line or the first thing after the brace. A record
160
+ // written `{ A: int; B: int }` on one line loses everything after the
161
+ // `;` to the type rule below, which is the price of not needing a
162
+ // parser to tell a field from a comparison.
163
+ {
164
+ match: "^([ \\t]*)([A-Z][\\w']*)(?=[ \\t]*[:=](?!=))",
165
+ scope: [null, 'property'],
166
+ },
167
+ {
168
+ match: "(\\{)([ \\t]*)([A-Z][\\w']*)(?=[ \\t]*[:=](?!=))",
169
+ scope: ['punctuation.bracket', null, 'property'],
170
+ },
171
+ // Modules, types, DU cases and .NET classes all look the same here, and
172
+ // all of them read fine as a type.
173
+ { match: "\\b[A-Z][\\w']*", scope: 'type' },
174
+ // An annotated parameter: `(name: string)`. Constructors and members
175
+ // annotate almost everything, which is where this pays off.
176
+ {
177
+ match: "(\\()([ \\t]*)([a-z_][\\w']*)(?=[ \\t]*:)",
178
+ scope: ['punctuation.bracket', null, 'variable.parameter'],
179
+ },
180
+ { match: `\\b0[xX][0-9a-fA-F_]+${SUFFIX}\\b`, scope: 'number' },
181
+ { match: `\\b0[bBoO][0-9_]+${SUFFIX}\\b`, scope: 'number' },
182
+ {
183
+ // `(?!\.)` on the fraction keeps the range `1..10` from starting as
184
+ // the float `1.` and leaving a stray dot behind.
185
+ match: `\\b\\d[\\d_]*\\.(?!\\.)(?:\\d[\\d_]*)?(?:[eE][-+]?\\d+)?[fFmM]?|\\b\\d[\\d_]*(?:[eE][-+]?\\d+)[fFmM]?|\\b\\d[\\d_]*${SUFFIX}\\b`,
186
+ scope: 'number',
187
+ },
188
+ // Array and anonymous-record delimiters, before the single brackets get
189
+ // a chance to split them.
190
+ { match: '\\[\\||\\|\\]|\\{\\||\\|\\}', scope: 'punctuation.bracket' },
191
+ // `->`, `||>` and friends need no branch of their own: they are made of
192
+ // operator characters, and adjacent ranges sharing a scope merge into
193
+ // one span downstream. Only the operators starting with `:` — a
194
+ // delimiter on its own — and `..` have to be spelled out.
195
+ {
196
+ match: '::|:\\?>|:>|:\\?|:=|\\.\\.|[-+*/%@^&|!~<>=?]=?',
197
+ scope: 'operator',
198
+ },
199
+ { match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
200
+ { match: '[;,:]', scope: 'punctuation.delimiter' },
201
+ ],
202
+ },
203
+ /** F# block comments nest, so this counts depth instead of scanning to the first `*)`. */
204
+ 'block-comment': {
205
+ default: 'comment',
206
+ rules: [
207
+ { match: '\\(\\*', push: 'block-comment' },
208
+ { match: '\\*\\)', pop: true },
209
+ ],
210
+ },
211
+ strings: {
212
+ rules: [
213
+ {
214
+ match: '(\\$)(""")',
215
+ scope: ['string.special', 'string'],
216
+ push: 'interp-triple',
217
+ },
218
+ { match: '"""', scope: 'string', push: 'triple' },
219
+ {
220
+ match: '(\\$@|@\\$)(")',
221
+ scope: ['string.special', 'string'],
222
+ push: 'interp-verbatim',
223
+ },
224
+ {
225
+ match: '(@)(")',
226
+ scope: ['string.special', 'string'],
227
+ push: 'verbatim',
228
+ },
229
+ {
230
+ match: '(\\$)(")',
231
+ scope: ['string.special', 'string'],
232
+ push: 'interp',
233
+ },
234
+ { match: '"', scope: 'string', push: 'string' },
235
+ ],
236
+ },
237
+ /** `{{`/`}}` are literal braces; a single `{` opens an expression. */
238
+ 'interp-body': {
239
+ rules: [
240
+ { match: '\\{\\{|\\}\\}', scope: 'string.escape' },
241
+ { match: '\\{', scope: 'interpolation', push: 'interp-expr' },
242
+ ],
243
+ },
244
+ /** Backslash escapes, plus the printf specifiers every flavour understands. */
245
+ 'string-body': {
246
+ rules: [
247
+ { match: ESCAPE, scope: 'string.escape' },
248
+ { match: FORMAT, scope: 'string.special' },
249
+ ],
250
+ },
251
+ /** A verbatim string has no backslash escapes; `""` is its only one. */
252
+ 'verbatim-body': {
253
+ rules: [
254
+ { match: '""', scope: 'string.escape' },
255
+ { match: FORMAT, scope: 'string.special' },
256
+ ],
257
+ },
258
+ string: {
259
+ default: 'string',
260
+ rules: [
261
+ { include: 'string-body' },
262
+ // `"…"B` is a byte string; the suffix belongs to the literal.
263
+ { match: '"B?', scope: 'string', pop: true },
264
+ // A plain string may legally hold a newline, but an unterminated one is
265
+ // the far more common reading — and popping keeps a stray quote from
266
+ // swallowing the rest of the file. The `\<newline>` continuation is an
267
+ // escape, so it is matched above and survives.
268
+ { match: '$', pop: true },
269
+ ],
270
+ },
271
+ interp: {
272
+ default: 'string',
273
+ rules: [
274
+ { include: 'string-body' },
275
+ { include: 'interp-body' },
276
+ { match: '"', scope: 'string', pop: true },
277
+ { match: '$', pop: true },
278
+ ],
279
+ },
280
+ // Verbatim and triple-quoted strings span lines on purpose, so neither pops
281
+ // at a line break.
282
+ verbatim: {
283
+ default: 'string',
284
+ rules: [{ include: 'verbatim-body' }, { match: '"', scope: 'string', pop: true }],
285
+ },
286
+ 'interp-verbatim': {
287
+ default: 'string',
288
+ rules: [{ include: 'verbatim-body' }, { include: 'interp-body' }, { match: '"', scope: 'string', pop: true }],
289
+ },
290
+ triple: {
291
+ default: 'string',
292
+ rules: [
293
+ { match: FORMAT, scope: 'string.special' },
294
+ { match: '"""', scope: 'string', pop: true },
295
+ ],
296
+ },
297
+ 'interp-triple': {
298
+ default: 'string',
299
+ rules: [
300
+ { match: FORMAT, scope: 'string.special' },
301
+ { include: 'interp-body' },
302
+ { match: '"""', scope: 'string', pop: true },
303
+ ],
304
+ },
305
+ 'interp-expr': {
306
+ rules: [
307
+ { match: '\\}', scope: 'interpolation', pop: true },
308
+ // `{value,10:N2}` — an alignment and a .NET format string. `(?![:=])`
309
+ // leaves the cons operator in `{a :: b}` alone, which is the one
310
+ // expression that otherwise looks exactly like a format spec. The length
311
+ // cap keeps an unclosed `{` cheap: the scan runs to the end of the line
312
+ // and then fails the lookahead, once per `:`, so an uncapped one is
313
+ // quadratic on a run of colons. `(?![:=])` alone does not bound it — it
314
+ // rejects `::` early, but `: ` clears the guard and starts the scan.
315
+ { match: ':(?![:=])[^{}"\\n]{0,120}(?=\\})', scope: 'string.special' },
316
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
317
+ { include: 'expression' },
318
+ ],
319
+ },
320
+ /** Tracks brace depth so a record inside an interpolation cannot end it. */
321
+ brace: {
322
+ rules: [
323
+ { match: '\\}', scope: 'punctuation.bracket', pop: true },
324
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
325
+ { include: 'expression' },
326
+ ],
327
+ },
328
+ },
329
+ };
330
+ export default fsharp;
@@ -0,0 +1,5 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ /** Go. */
3
+ declare const go: Grammar;
4
+ export default go;
5
+ //# sourceMappingURL=go.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/langs/go.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,UAAU;AACV,QAAA,MAAM,EAAE,EAAE,OAgGT,CAAA;AAED,eAAe,EAAE,CAAA"}
@@ -0,0 +1,90 @@
1
+ /** Go. */
2
+ const go = {
3
+ name: 'go',
4
+ aliases: ['golang'],
5
+ states: {
6
+ root: {
7
+ rules: [
8
+ { match: '//[^\\n]*', scope: 'comment' },
9
+ { match: '/\\*[\\s\\S]*?\\*/', scope: 'comment' },
10
+ { match: '`[^`]*`', scope: 'string' },
11
+ { match: '"', scope: 'string', push: 'string' },
12
+ {
13
+ match: "'(?:[^'\\\\]|\\\\(?:u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|.))'",
14
+ scope: 'string',
15
+ },
16
+ {
17
+ match: '\\b(?:if|else|for|range|switch|case|default|break|continue|return|goto|fallthrough|select|defer|go)\\b',
18
+ scope: 'keyword.control',
19
+ },
20
+ // Ahead of the bare keyword list, which also matches `func` and
21
+ // `package`. Rule order is priority order, so listing these after it
22
+ // would mean the keyword always won and the name never got scoped.
23
+ // The receiver is captured whole and left unscoped — its own name and
24
+ // type are picked up by the rules further down.
25
+ {
26
+ match: '(func)(\\s+)(\\([^)\\n]*\\))?(\\s*)([A-Za-z_]\\w*)',
27
+ scope: ['keyword.declaration', null, null, null, 'function'],
28
+ },
29
+ {
30
+ match: '(package)(\\s+)([A-Za-z_]\\w*)',
31
+ scope: ['keyword.declaration', null, 'namespace'],
32
+ },
33
+ {
34
+ match: '\\b(?:func|var|const|type|struct|interface|map|chan|package)\\b',
35
+ scope: 'keyword.declaration',
36
+ },
37
+ { match: '\\bimport\\b', scope: 'keyword.import' },
38
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
39
+ { match: '\\b(?:nil|iota)\\b', scope: 'constant.builtin' },
40
+ {
41
+ match: '\\b(?:append|cap|clear|close|complex|copy|delete|imag|len|make|max|min|new|panic|print|println|real|recover)\\b(?=\\s*\\()',
42
+ scope: 'function.builtin',
43
+ },
44
+ {
45
+ match: '\\b(?:bool|byte|complex64|complex128|error|float32|float64|int|int8|int16|int32|int64|rune|string|uint|uint8|uint16|uint32|uint64|uintptr|any)\\b',
46
+ scope: 'type.builtin',
47
+ },
48
+ {
49
+ match: '(\\.)([A-Za-z_]\\w*)(?=\\s*\\()',
50
+ scope: ['punctuation', 'function.method'],
51
+ },
52
+ {
53
+ match: '(\\.)([A-Za-z_]\\w*)',
54
+ scope: ['punctuation', 'variable.member'],
55
+ },
56
+ { match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
57
+ { match: '\\b[A-Z][A-Za-z0-9_]*\\b', scope: 'type' },
58
+ { match: '\\b[a-z_]\\w*(?=\\s*\\()', scope: 'function.call' },
59
+ { match: '\\b0[xX][0-9a-fA-F_]+\\b', scope: 'number' },
60
+ { match: '\\b0[bo][0-9_]+\\b', scope: 'number' },
61
+ {
62
+ match: '\\b\\d[\\d_]*(?:\\.\\d[\\d_]*)?(?:[eE][-+]?\\d+)?i?\\b',
63
+ scope: 'number',
64
+ },
65
+ {
66
+ match: ':=|\\.{3}|<-|&&|\\|\\||[-+*/%!&|^<>=]=?|\\+\\+|--',
67
+ scope: 'operator',
68
+ },
69
+ { match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
70
+ { match: '[,;:]', scope: 'punctuation.delimiter' },
71
+ ],
72
+ },
73
+ string: {
74
+ default: 'string',
75
+ rules: [
76
+ {
77
+ match: '\\\\(?:u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|x[0-9a-fA-F]{2}|[0-7]{3}|.)',
78
+ scope: 'string.escape',
79
+ },
80
+ {
81
+ match: '%[-+ #0]*(?:\\d+|\\*)?(?:\\.(?:\\d+|\\*))?[vTtbcdoOqxXUeEfFgGsp%]',
82
+ scope: 'string.special',
83
+ },
84
+ { match: '"', scope: 'string', pop: true },
85
+ { match: '$', pop: true },
86
+ ],
87
+ },
88
+ },
89
+ };
90
+ export default go;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const graphql: Grammar;
3
+ export default graphql;
4
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/langs/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA8B5C,QAAA,MAAM,OAAO,EAAE,OA6Kd,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * GraphQL — SDL schemas and executable documents in one grammar.
3
+ *
4
+ * Both halves of the language reuse the same shapes, so most of the work here
5
+ * is telling them apart without a parser:
6
+ *
7
+ * - a name followed by `:` names an output key — an SDL field or a query alias
8
+ * — and reads as a property, and so does the field being selected. An
9
+ * earlier version left the selected field plain so the alias would stand out
10
+ * on its own, but that leaves the body of a query — the part a reader is
11
+ * actually there for — at the block foreground. The alias is still legible
12
+ * from the `alias: field` shape.
13
+ * - argument names live in their own state, so `episode` in `hero(episode: $ep)`
14
+ * is a parameter and `hero` is not.
15
+ * - a string that starts a line is a description. Every string *value* in the
16
+ * language sits inside an argument list, so outside one a leading quote can
17
+ * only be documentation.
18
+ *
19
+ * Two things are recognised by convention rather than by syntax, because
20
+ * GraphQL puts none on them: PascalCase is a type and SCREAMING_CASE is an enum
21
+ * value or a directive location. A lowercase type name renders plain, and a
22
+ * field spelled `type`, `query` or `mutation` reads as the keyword when it is
23
+ * followed by a name or a selection set — the shapes are genuinely identical.
24
+ */
25
+ /** A GraphQL Name. The spec limits these to ASCII, so `\w` would be too wide. */
26
+ const NAME = '[_A-Za-z][_0-9A-Za-z]*';
27
+ const graphql = {
28
+ name: 'graphql',
29
+ aliases: ['gql'],
30
+ states: {
31
+ root: {
32
+ rules: [
33
+ // Descriptions are reachable from `root` only. An argument list is the
34
+ // one place a string value can begin a line, and that runs in `args`.
35
+ {
36
+ match: '(^[ \\t]*)(""")',
37
+ scope: [null, 'comment.doc'],
38
+ push: 'description',
39
+ },
40
+ {
41
+ match: '(^[ \\t]*)("(?:[^"\\\\\\n]|\\\\.)*")',
42
+ scope: [null, 'comment.doc'],
43
+ },
44
+ { include: 'common' },
45
+ // Whatever is left in a selection set or an SDL body is a field being
46
+ // selected or declared. Listed after `common`, so it only claims names
47
+ // no earlier rule wanted, and kept out of `args` — which includes
48
+ // `common` but not this — so an argument's value is not read as a field.
49
+ { match: `\\b${NAME}\\b`, scope: 'property' },
50
+ ],
51
+ },
52
+ /**
53
+ * Field arguments, directive arguments and variable definitions — every
54
+ * parenthesised list GraphQL has names its entries, which is what separates
55
+ * `episode:` from the field it belongs to.
56
+ */
57
+ args: {
58
+ rules: [
59
+ { match: '\\)', scope: 'punctuation.bracket', pop: true },
60
+ // The only brace an argument list can contain is an object value, whose
61
+ // fields are named the same way arguments are — so it re-enters this
62
+ // state rather than needing one of its own. Popping on `}` then doubles
63
+ // as the recovery an unclosed `(` needs: the brace must belong to an
64
+ // enclosing selection set, so the list ends there instead of turning the
65
+ // rest of the document into arguments.
66
+ { match: '\\}', scope: 'punctuation.bracket', pop: true },
67
+ { match: '\\{', scope: 'punctuation.bracket', push: 'args' },
68
+ // Variables only ever appear inside a list like this one, so `$` is not
69
+ // interesting anywhere else.
70
+ { match: `\\$${NAME}`, scope: 'variable' },
71
+ { match: `\\b${NAME}(?=[ \\t]*:)`, scope: 'variable.parameter' },
72
+ { include: 'common' },
73
+ ],
74
+ },
75
+ common: {
76
+ rules: [
77
+ { match: '#[^\\n]*', scope: 'comment' },
78
+ { match: '"""', scope: 'string', push: 'block-string' },
79
+ { match: '"', scope: 'string', push: 'string' },
80
+ // ---- definitions ----------------------------------------------------
81
+ // Every definition keyword is matched together with what follows it, so
82
+ // a field that happens to be named `type` or `input` keeps its own
83
+ // colour unless it is standing in a definition's shape.
84
+ {
85
+ match: `\\b(type|interface|input|enum|union|scalar)([ \\t]+)(${NAME})`,
86
+ scope: ['keyword.declaration', null, 'class'],
87
+ },
88
+ { match: '\\bextend\\b(?=[ \\t]+[a-z])', scope: 'keyword.declaration' },
89
+ { match: '\\bschema\\b(?=[ \\t]*[{@])', scope: 'keyword.declaration' },
90
+ { match: '\\bdirective\\b(?=[ \\t]*@)', scope: 'keyword.declaration' },
91
+ // An operation is a named, parameterised entry point, so its name reads
92
+ // as a function definition — and a fragment spread below reads as a call.
93
+ {
94
+ match: `\\b(query|mutation|subscription|fragment)([ \\t]+)(${NAME})`,
95
+ scope: ['keyword.declaration', null, 'function'],
96
+ },
97
+ {
98
+ match: '\\b(?:query|mutation|subscription)\\b(?=[ \\t]*[{(@])',
99
+ scope: 'keyword.declaration',
100
+ },
101
+ // `...on Droid` is legal without the space, so the `on` alternative has
102
+ // to win before the spread-name rule claims `on` as a fragment name.
103
+ {
104
+ match: '(\\.\\.\\.)([ \\t]*)(on)\\b',
105
+ scope: ['operator', null, 'keyword'],
106
+ },
107
+ {
108
+ match: `(\\.\\.\\.)([ \\t]*)(${NAME})`,
109
+ scope: ['operator', null, 'function.call'],
110
+ },
111
+ // A type condition, a supertype list and a directive location list are
112
+ // all followed by an uppercase name, which keeps a field called `on`
113
+ // from reading as a keyword.
114
+ { match: '\\b(?:on|implements)\\b(?=[ \\t]+[A-Z_])', scope: 'keyword' },
115
+ { match: '\\brepeatable\\b(?=[ \\t]+on\\b)', scope: 'keyword' },
116
+ { match: `@${NAME}`, scope: 'decorator' },
117
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
118
+ { match: '\\bnull\\b', scope: 'constant.builtin' },
119
+ // Introspection meta-fields belong to the runtime rather than to the
120
+ // type being selected from.
121
+ {
122
+ match: '\\b__(?:typename|schema|type)\\b',
123
+ scope: 'variable.special',
124
+ },
125
+ {
126
+ match: '\\b(?:Int|Float|String|Boolean|ID)\\b',
127
+ scope: 'type.builtin',
128
+ },
129
+ // Convention, not syntax: SCREAMING_CASE is an enum value or a directive
130
+ // location, anything else capitalised is a type. A type named `URL`
131
+ // reads as an enum value, which is the same trade Python's grammar makes.
132
+ { match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
133
+ { match: '\\b[A-Z][A-Za-z0-9_]*\\b', scope: 'type' },
134
+ // ---- fields ---------------------------------------------------------
135
+ { match: `\\b${NAME}(?=[ \\t]*:)`, scope: 'property' },
136
+ // A field definition whose arguments come first: `user(id: ID!): User`.
137
+ // The trailing `:` is what separates it from a query field with
138
+ // arguments, which is followed by a selection set instead. The scan
139
+ // cannot cross a parenthesis and is capped, so a line of `x(` cannot
140
+ // make this quadratic.
141
+ {
142
+ match: `\\b${NAME}(?=[ \\t]*\\([^()]{0,300}\\)[ \\t]*:)`,
143
+ scope: 'property',
144
+ },
145
+ {
146
+ match: '-?\\b\\d+(?:\\.\\d+)?(?:[eE][-+]?\\d+)?\\b',
147
+ scope: 'number',
148
+ },
149
+ { match: '\\(', scope: 'punctuation.bracket', push: 'args' },
150
+ { match: '[{}\\[\\]()]', scope: 'punctuation.bracket' },
151
+ // `!` non-null, `=` default, `|` union member, `&` supertype, and a
152
+ // spread that reached neither rule above.
153
+ { match: '\\.\\.\\.|[!=|&]', scope: 'operator' },
154
+ { match: '[,:]', scope: 'punctuation.delimiter' },
155
+ ],
156
+ },
157
+ string: {
158
+ default: 'string',
159
+ rules: [
160
+ {
161
+ match: '\\\\(?:u\\{[0-9a-fA-F]+\\}|u[0-9a-fA-F]{4}|["\\\\/bfnrt])',
162
+ scope: 'string.escape',
163
+ },
164
+ { match: '"', scope: 'string', pop: true },
165
+ // An ordinary string cannot span lines, so an unterminated one ends with
166
+ // its line instead of swallowing the rest of the document.
167
+ { match: '$', pop: true },
168
+ ],
169
+ },
170
+ 'block-string': {
171
+ default: 'string',
172
+ // `\"""` is the only escape a block string has; consuming it here keeps a
173
+ // literal triple quote from closing the literal.
174
+ rules: [
175
+ { match: '\\\\"""', scope: 'string.escape' },
176
+ { match: '"""', scope: 'string', pop: true },
177
+ ],
178
+ },
179
+ description: {
180
+ default: 'comment.doc',
181
+ rules: [{ match: '\\\\"""' }, { match: '"""', pop: true }],
182
+ },
183
+ },
184
+ };
185
+ export default graphql;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const haskell: Grammar;
3
+ export default haskell;
4
+ //# sourceMappingURL=haskell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"haskell.d.ts","sourceRoot":"","sources":["../../src/langs/haskell.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAwF5C,QAAA,MAAM,OAAO,EAAE,OA2Td,CAAA;AAED,eAAe,OAAO,CAAA"}