@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,262 @@
1
+ /**
2
+ * Dart.
3
+ *
4
+ * The four places a regex-based highlighter usually goes wrong in this
5
+ * language, and what this grammar does about them:
6
+ *
7
+ * - Interpolation nests, and the inner literal may reuse the outer quote —
8
+ * `'${map['key']}'` is legal Dart. The interpolation body is a real
9
+ * expression state, so the inner string opens and closes on its own instead
10
+ * of the outer one ending early.
11
+ * - Raw strings switch escapes and interpolation off, so they get their own
12
+ * rules rather than sharing the interpolating states.
13
+ * - Block comments nest. One comment can contain a whole commented-out block
14
+ * with comments of its own, which needs a state, not a scan to the first
15
+ * closing delimiter.
16
+ * - `1.toString()` is a method call on an int, so the double pattern insists on
17
+ * a digit after the decimal point rather than treating `1.` as a literal.
18
+ *
19
+ * Ordinary identifiers deliberately match no rule and inherit the block's
20
+ * foreground, which keeps both the markup and the visual noise down.
21
+ */
22
+ /**
23
+ * An identifier.
24
+ *
25
+ * `$` is legal in a Dart identifier but is not a `\w` character, so `\b` sits
26
+ * between every `$` and the letter after it. In `$a$a$a…` — one identifier —
27
+ * that is a boundary every two characters, and the rules that match a name and
28
+ * then test a lookahead would restart at each one and rescan the line. The cap
29
+ * bounds that; a longer name simply renders unscoped.
30
+ */
31
+ const ID = '[A-Za-z_$][\\w$]{0,128}';
32
+ /** `\n`, `\$`, `\x41`, `\u2603`, `\u{1F600}`. */
33
+ const ESCAPE = '\\\\(?:u\\{[0-9a-fA-F]+\\}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|.)';
34
+ /**
35
+ * Keywords that can sit directly in front of a call and would otherwise look
36
+ * like the return type of a definition (`return foo()`, `const Text()`).
37
+ *
38
+ * The `\b` is load-bearing: without it the alternation also matches the *tail*
39
+ * of an ordinary type name, so `Canvas paint(…)` (ends in `as`) or
40
+ * `Axis resolve(…)` (ends in `is`) would suppress their own definition rule.
41
+ * `=>` gets its own lookbehind because `\b` cannot anchor a non-word token; it
42
+ * is excluded for the same reason the keywords are — it ends in `>`, exactly
43
+ * like the type arguments a real definition would end with.
44
+ */
45
+ const NOT_A_RETURN_TYPE = '(?<!=>[ \\t])(?<!\\b(?:return|await|yield|throw|new|const|case|else|in|is|as)[ \\t])';
46
+ const dart = {
47
+ name: 'dart',
48
+ states: {
49
+ root: {
50
+ rules: [{ match: '^#!.*', scope: 'comment' }, { include: 'expression' }],
51
+ },
52
+ expression: {
53
+ rules: [
54
+ // ---- comments ------------------------------------------------------
55
+ { match: '///[^\\n]*', scope: 'comment.doc' },
56
+ { match: '//[^\\n]*', scope: 'comment' },
57
+ // `(?![/*])` keeps `/**/` and `/***` out of the doc state, matching how
58
+ // dartdoc reads them.
59
+ { match: '/\\*\\*(?![/*])', scope: 'comment.doc', push: 'comment-doc' },
60
+ { match: '/\\*', scope: 'comment', push: 'comment-block' },
61
+ { include: 'strings' },
62
+ { include: 'numbers' },
63
+ // Metadata. `@override` and `@JsonKey(name: 'a')` both read as
64
+ // annotations, dotted path included.
65
+ { match: `@${ID}(?:\\.${ID})*`, scope: 'decorator' },
66
+ // ---- member access -------------------------------------------------
67
+ // Spread first: `..` would otherwise claim the first two dots of `...`.
68
+ { match: '\\.\\.\\.\\??', scope: 'operator' },
69
+ // A cascade is an operator and a plain access is punctuation, but both
70
+ // are followed by the same two shapes, so each needs its own pair.
71
+ {
72
+ match: `(\\?\\.\\.|\\.\\.)([ \\t]*)(${ID})(?=[ \\t]*\\()`,
73
+ scope: ['operator', null, 'function.method'],
74
+ },
75
+ {
76
+ match: `(\\?\\.\\.|\\.\\.)([ \\t]*)(${ID})`,
77
+ scope: ['operator', null, 'variable.member'],
78
+ },
79
+ {
80
+ match: `(\\?\\.|\\.)([ \\t]*)(${ID})(?=[ \\t]*\\()`,
81
+ scope: ['punctuation', null, 'function.method'],
82
+ },
83
+ {
84
+ match: `(\\?\\.|\\.)([ \\t]*)(${ID})`,
85
+ scope: ['punctuation', null, 'variable.member'],
86
+ },
87
+ // ---- keywords ------------------------------------------------------
88
+ {
89
+ match: '\\b(?:if|else|for|while|do|switch|case|default|break|continue|return|yield|await|throw|rethrow|try|catch|finally|assert)\\b',
90
+ scope: 'keyword.control',
91
+ },
92
+ {
93
+ match: '\\b(?:abstract|async|base|class|const|covariant|enum|extends|extension|external|factory|final|get|implements|interface|late|mixin|operator|required|sealed|set|static|sync|typedef|var|with|on)\\b',
94
+ scope: 'keyword.declaration',
95
+ },
96
+ // `show`, `hide`, `of` and `part` are contextual: Dart only reserves
97
+ // them inside a directive. Used as plain names they read as keywords
98
+ // here, which is wrong but vanishingly rare in real code.
99
+ {
100
+ match: '\\b(?:import|export|library|part|deferred|show|hide|of)\\b',
101
+ scope: 'keyword.import',
102
+ },
103
+ { match: '\\b(?:is|as|in|new)\\b', scope: 'keyword.operator' },
104
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
105
+ { match: '\\bnull\\b', scope: 'constant.builtin' },
106
+ { match: '\\b(?:this|super)\\b', scope: 'variable.builtin' },
107
+ // ---- names ---------------------------------------------------------
108
+ // Only the types the language itself special-cases — literal types, the
109
+ // top and bottom of the hierarchy, and the collection and async types
110
+ // with their own syntax. The rest of `dart:core` is CapWords and lands
111
+ // on `type` a rule below, which is the right fallback anyway.
112
+ {
113
+ match: '\\b(?:int|double|num|bool|String|List|Map|Set|Iterable|Future|Stream|Object|Function|Never|Null|dynamic|void)\\b',
114
+ scope: 'type.builtin',
115
+ },
116
+ // SCREAMING_CASE reads as a constant and CapWords as a type. Dart style
117
+ // prefers lowerCamelCase for constants, so the first rule mostly earns
118
+ // its keep on generated and ported code.
119
+ { match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
120
+ { match: '\\b[A-Z][A-Za-z0-9_$]*\\b', scope: 'type' },
121
+ // `print` is the one top-level function in `dart:core` a reader expects
122
+ // to stand out. Gated on the call to keep `logger.print` a method.
123
+ { match: '\\bprint\\b(?=[ \\t]*\\()', scope: 'function.builtin' },
124
+ // `Type name(` is a definition; a bare `name(` is a call.
125
+ //
126
+ // The lookbehind wants the token in front to end the way a type does: a
127
+ // word character, the `>` of type arguments, or the `?` of a nullable
128
+ // type. That alone would also accept `cond ? run()` and `=> run()`, so
129
+ // the ternary is excluded by requiring a type character before the `?`
130
+ // and the rest by name. What survives and is still wrong: a definition
131
+ // whose return type is omitted, and a call written as `foo bar()`,
132
+ // which is not valid Dart anyway.
133
+ {
134
+ match: `(?<=[\\w>]\\??[ \\t])${NOT_A_RETURN_TYPE}[a-z_$][\\w$]{0,128}(?=[ \\t]*[(<])`,
135
+ scope: 'function',
136
+ },
137
+ { match: `\\b${ID}(?=[ \\t]*\\()`, scope: 'function.call' },
138
+ // A named argument, record field or map key. Requiring no space before
139
+ // the colon is what keeps `cond ? a : b` out; `cond ? a:b` still slips
140
+ // through, and a statement label reads as one of these too.
141
+ { match: `\\b${ID}(?=:)`, scope: 'variable.parameter' },
142
+ // ---- syntax --------------------------------------------------------
143
+ {
144
+ match: '=>|\\?\\?=?|~/=?|\\+\\+|--|&&|\\|\\||<<=?|>>>?=?|[!=]=|[-+*/%&|^]=?|[<>]=?|[?!~=]',
145
+ scope: 'operator',
146
+ },
147
+ { match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
148
+ { match: '[,;:]', scope: 'punctuation.delimiter' },
149
+ ],
150
+ },
151
+ numbers: {
152
+ rules: [
153
+ { match: '\\b0[xX][0-9a-fA-F_]+\\b', scope: 'number' },
154
+ // A digit is required after the point so `1.toString()` stays an int
155
+ // and a method call. Digit separators arrived in Dart 3.6.
156
+ {
157
+ match: '\\b\\d[\\d_]*(?:\\.\\d[\\d_]*)?(?:[eE][-+]?\\d+)?\\b',
158
+ scope: 'number',
159
+ },
160
+ ],
161
+ },
162
+ // ---- strings -----------------------------------------------------------
163
+ strings: {
164
+ rules: [
165
+ // The `r` is scoped separately so it reads as a modifier on the literal
166
+ // rather than as part of it. A single-line raw string cannot contain
167
+ // its own quote — there is no escape to write one with — so those two
168
+ // forms are one bounded scan each and never need a state; only the
169
+ // triple-quoted forms, which do span lines, get one.
170
+ {
171
+ match: "\\b(r)(''')",
172
+ scope: ['string.special', 'string'],
173
+ push: 'raw-triple-single',
174
+ },
175
+ {
176
+ match: '\\b(r)(""")',
177
+ scope: ['string.special', 'string'],
178
+ push: 'raw-triple-double',
179
+ },
180
+ { match: "\\b(r)('[^'\\n]*')", scope: ['string.special', 'string'] },
181
+ { match: '\\b(r)("[^"\\n]*")', scope: ['string.special', 'string'] },
182
+ { match: "'''", scope: 'string', push: 'triple-single' },
183
+ { match: '"""', scope: 'string', push: 'triple-double' },
184
+ { match: "'", scope: 'string', push: 'single' },
185
+ { match: '"', scope: 'string', push: 'double' },
186
+ ],
187
+ },
188
+ 'string-body': {
189
+ rules: [
190
+ { match: ESCAPE, scope: 'string.escape' },
191
+ { match: '\\$\\{', scope: 'interpolation', push: 'interpolation' },
192
+ // `$name` takes the bare identifier and nothing else: `'$a.b'`
193
+ // interpolates `a` and then prints a literal `.b`.
194
+ { match: `(\\$)(${ID})`, scope: ['interpolation', 'variable'] },
195
+ ],
196
+ },
197
+ single: {
198
+ default: 'string',
199
+ rules: [
200
+ { include: 'string-body' },
201
+ { match: "'", scope: 'string', pop: true },
202
+ // An unterminated single-line string ends at the line break instead of
203
+ // swallowing the rest of the file.
204
+ { match: '$', pop: true },
205
+ ],
206
+ },
207
+ double: {
208
+ default: 'string',
209
+ rules: [{ include: 'string-body' }, { match: '"', scope: 'string', pop: true }, { match: '$', pop: true }],
210
+ },
211
+ 'triple-single': {
212
+ default: 'string',
213
+ rules: [{ include: 'string-body' }, { match: "'''", scope: 'string', pop: true }],
214
+ },
215
+ 'triple-double': {
216
+ default: 'string',
217
+ rules: [{ include: 'string-body' }, { match: '"""', scope: 'string', pop: true }],
218
+ },
219
+ // No escape or interpolation rules: that is the whole point of the `r`.
220
+ 'raw-triple-single': {
221
+ default: 'string',
222
+ rules: [{ match: "'''", scope: 'string', pop: true }],
223
+ },
224
+ 'raw-triple-double': {
225
+ default: 'string',
226
+ rules: [{ match: '"""', scope: 'string', pop: true }],
227
+ },
228
+ interpolation: {
229
+ rules: [
230
+ { match: '\\}', scope: 'interpolation', pop: true },
231
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
232
+ { include: 'expression' },
233
+ ],
234
+ },
235
+ /** Tracks brace depth so a map literal or closure cannot end an interpolation. */
236
+ brace: {
237
+ rules: [
238
+ { match: '\\}', scope: 'punctuation.bracket', pop: true },
239
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
240
+ { include: 'expression' },
241
+ ],
242
+ },
243
+ // ---- comments ----------------------------------------------------------
244
+ // Both states push themselves on a nested opener, so the comment ends at
245
+ // the delimiter that actually balances it.
246
+ 'comment-block': {
247
+ default: 'comment',
248
+ rules: [
249
+ { match: '/\\*', push: 'comment-block' },
250
+ { match: '\\*/', pop: true },
251
+ ],
252
+ },
253
+ 'comment-doc': {
254
+ default: 'comment.doc',
255
+ rules: [
256
+ { match: '/\\*', push: 'comment-doc' },
257
+ { match: '\\*/', pop: true },
258
+ ],
259
+ },
260
+ },
261
+ };
262
+ export default dart;
@@ -0,0 +1,10 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ /**
3
+ * Unified diffs and `git diff` output.
4
+ *
5
+ * Whole lines are scoped, which lets a theme give added and removed lines a
6
+ * background tint rather than only recoloring the leading sign.
7
+ */
8
+ declare const diff: Grammar;
9
+ export default diff;
10
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/langs/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,QAAA,MAAM,IAAI,EAAE,OAkBX,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Unified diffs and `git diff` output.
3
+ *
4
+ * Whole lines are scoped, which lets a theme give added and removed lines a
5
+ * background tint rather than only recoloring the leading sign.
6
+ */
7
+ const diff = {
8
+ name: 'diff',
9
+ aliases: ['patch'],
10
+ states: {
11
+ root: {
12
+ rules: [
13
+ {
14
+ match: '^(?:diff|index|new file|deleted file|old mode|new mode|similarity index|rename) [^\\n]*',
15
+ scope: 'comment',
16
+ },
17
+ { match: '^(?:---|\\+\\+\\+)[^\\n]*', scope: 'heading' },
18
+ { match: '^@@[^\\n]*', scope: 'keyword' },
19
+ { match: '^\\+[^\\n]*', scope: 'diff.plus' },
20
+ { match: '^-[^\\n]*', scope: 'diff.minus' },
21
+ { match: '^\\\\[^\\n]*', scope: 'comment' },
22
+ ],
23
+ },
24
+ },
25
+ };
26
+ export default diff;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const dockerfile: Grammar;
3
+ export default dockerfile;
4
+ //# sourceMappingURL=dockerfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dockerfile.d.ts","sourceRoot":"","sources":["../../src/langs/dockerfile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAmC5C,QAAA,MAAM,UAAU,EAAE,OA4SjB,CAAA;AAED,eAAe,UAAU,CAAA"}
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Dockerfile.
3
+ *
4
+ * A Dockerfile is two languages stacked on top of each other: a thin
5
+ * line-oriented instruction format, and whatever the shell makes of the rest of
6
+ * the line. The grammar is a state machine over that split:
7
+ *
8
+ * - an instruction keyword is only recognised at the start of a logical line,
9
+ * so the `run` in `RUN docker run …` stays a bare word
10
+ * - a logical line ends at the first line break that is not preceded by a
11
+ * backslash, which is what keeps a continued `RUN` in its own state
12
+ * - `${VAR:-default}` comes apart into braces, name, modifier and default
13
+ * - `--mount=type=cache,target=…` reads as a flag with named parts rather than
14
+ * as one long argument
15
+ * - the JSON exec form of `CMD`/`ENTRYPOINT` gets its brackets and commas
16
+ *
17
+ * What it deliberately does not model: shell builtins and command names inside
18
+ * a `RUN` body are left unscoped, because a list of them would be a list of
19
+ * every program in Debian.
20
+ */
21
+ /**
22
+ * The start of a logical line, plus the optional `ONBUILD` that can prefix any
23
+ * instruction. The indent is left ungrouped so it falls through unscoped.
24
+ */
25
+ const START = '^[ \\t]*(?:(ONBUILD)([ \\t]+))?';
26
+ /** Capture scopes for `START`, spread in front of each instruction's own. */
27
+ const START_SCOPES = ['keyword', null];
28
+ /** Instructions whose arguments need nothing beyond the generic shell body. */
29
+ const PLAIN = 'RUN|CMD|ENTRYPOINT|COPY|ADD|EXPOSE|USER|WORKDIR|VOLUME|SHELL|STOPSIGNAL|MAINTAINER';
30
+ const dockerfile = {
31
+ name: 'dockerfile',
32
+ aliases: ['docker', 'containerfile'],
33
+ states: {
34
+ root: {
35
+ // Instructions are uppercase by convention only — the parser accepts any
36
+ // case, and `from … as build` turns up in hand-written files often enough
37
+ // to be worth the flag.
38
+ ignoreCase: true,
39
+ rules: [
40
+ // A parser directive is a comment to everything except the builder, so
41
+ // the `#` keeps its comment colour and the setting reads as code.
42
+ // Directives are only legal above the first instruction; one written
43
+ // further down is an ordinary comment, and this grammar still lights it
44
+ // up.
45
+ {
46
+ match: '^(#)([ \\t]*)(syntax|escape|check)(=)([^\\n]*)',
47
+ scope: ['comment', null, 'keyword', 'operator', 'string'],
48
+ },
49
+ { match: '#[^\\n]*', scope: 'comment' },
50
+ {
51
+ match: `${START}(FROM)\\b`,
52
+ scope: [...START_SCOPES, 'keyword.import'],
53
+ push: 'from',
54
+ },
55
+ // The first name is captured here rather than in `env`, because
56
+ // `ARG PORT` and the legacy `ENV TZ Etc/UTC` have no `=` to key off.
57
+ // The whitespace is optional so a half-typed `ENV` on its own line is
58
+ // still the instruction it is about to become — that is what an editor
59
+ // asks for on every keystroke.
60
+ {
61
+ match: `${START}(ARG|ENV)\\b([ \\t]*)([A-Za-z_]\\w*)?`,
62
+ scope: [...START_SCOPES, 'keyword.declaration', null, 'variable'],
63
+ push: 'env',
64
+ },
65
+ {
66
+ match: `${START}(LABEL)\\b([ \\t]*)([\\w.-]+)?`,
67
+ scope: [...START_SCOPES, 'keyword.declaration', null, 'property'],
68
+ push: 'label',
69
+ },
70
+ {
71
+ match: `${START}(HEALTHCHECK)\\b`,
72
+ scope: [...START_SCOPES, 'keyword'],
73
+ push: 'healthcheck',
74
+ },
75
+ {
76
+ match: `${START}(${PLAIN})\\b`,
77
+ scope: [...START_SCOPES, 'keyword'],
78
+ push: 'args',
79
+ },
80
+ ],
81
+ },
82
+ /**
83
+ * The body of an instruction. Shell-shaped, and it lives exactly as long as
84
+ * the logical line: every state that highlights arguments ends up here.
85
+ */
86
+ args: {
87
+ rules: [
88
+ // Before the redirection operator, or `<<EOF` reads as two `<`.
89
+ {
90
+ match: '(<<-?)([\'"]?)([A-Za-z_]\\w*)([\'"]?)',
91
+ scope: ['operator', 'string', 'string.special', 'string'],
92
+ push: 'heredoc-head',
93
+ },
94
+ // `--from=` names a build stage declared by a `FROM … AS <name>`
95
+ // above, which makes it the one flag value worth colouring. A `$`
96
+ // value falls through to the generic flag rule below. It takes the same
97
+ // leading space as that rule, or the shorter match would start one
98
+ // column later and lose.
99
+ {
100
+ match: '(?:^|[ \\t])(--from)(=)([\\w.-]+)',
101
+ scope: ['constant', 'operator', 'type'],
102
+ },
103
+ // A flag opens a word, and the space or line start that proves it is
104
+ // consumed rather than looked behind at — a lookbehind anywhere in a
105
+ // state costs JavaScriptCore twenty times the throughput of that whole
106
+ // state. `\B` was the cheaper stand-in until it turned out to hold
107
+ // after every non-word character, so `--opt=-value` and `${X}-y` came
108
+ // out as flags; only whitespace and the line start may precede one.
109
+ { match: '(?:^|[ \\t])(--?[A-Za-z][\\w-]*)', scope: ['constant'] },
110
+ // The named parts of a compound flag value: `type=cache,target=/x`.
111
+ // Two rules, because the separator has to be consumed to anchor the
112
+ // name and `,` and `=` do not read the same way.
113
+ {
114
+ match: '(=)([\\w.-]+)(?==)',
115
+ scope: ['operator', 'variable.parameter'],
116
+ },
117
+ {
118
+ match: '(,)([\\w.-]+)(?==)',
119
+ scope: ['punctuation.delimiter', 'variable.parameter'],
120
+ },
121
+ // A trailing backslash continues the logical line, so it must be eaten
122
+ // before the `$` rule at the bottom can end the instruction.
123
+ { match: '\\\\\\r?\\n', scope: 'operator' },
124
+ // `\$HOME` reaches the shell as a literal, so the escape has to win
125
+ // over the expansion rules.
126
+ { match: '\\\\[\\\\$"\'`]', scope: 'string.escape' },
127
+ { include: 'expansion' },
128
+ { match: '"', scope: 'string', push: 'string-double' },
129
+ { match: "'", scope: 'string', push: 'string-single' },
130
+ // Comments are legal between the lines of a continued instruction, and
131
+ // the shell strips one from the tail of a `RUN`.
132
+ { match: '(?:^|[ \\t])#[^\\n]*', scope: 'comment' },
133
+ // Ports, uids and `--interval=30s` durations. A number is only one when
134
+ // it starts a word, and the character that proves it is consumed rather
135
+ // than looked behind at — which is why there are two rules: whitespace
136
+ // and `:` carry no scope of their own, an operator does. Everything a
137
+ // version or a path is built from is missing from both, so the `3` of
138
+ // `python3.11` and the `04` of `18.04` stay part of their word.
139
+ {
140
+ match: '(?:^|[ \\t:])(\\d+)(ms|[smh])?(?![\\w.-])',
141
+ scope: ['number', 'unit'],
142
+ },
143
+ {
144
+ match: '([;=&<>|])(\\d+)(ms|[smh])?(?![\\w.-])',
145
+ scope: ['operator', 'number', 'unit'],
146
+ },
147
+ { match: '&&|\\|\\|?|>>?|[;=&<]', scope: 'operator' },
148
+ // `[` and `]` are the JSON exec form of CMD, ENTRYPOINT, SHELL and
149
+ // VOLUME; `{` and `}` turn up in `find -exec` and awk programs.
150
+ { match: '[[\\]{}]', scope: 'punctuation.bracket' },
151
+ { match: ',', scope: 'punctuation.delimiter' },
152
+ // The instruction is over. Zero width, so `root` still sees the break.
153
+ { match: '$', pop: true },
154
+ ],
155
+ },
156
+ /**
157
+ * `FROM [--platform=…] <image> [AS <stage>]`.
158
+ *
159
+ * Case-insensitivity is spelled into the two words that need it rather than
160
+ * set on the state: `ignoreCase` also applies to every rule `args` brings
161
+ * in, and `--interval=30S` splitting into a number and a unit while
162
+ * `EXPOSE 30S` does not is a difference nobody asked for.
163
+ */
164
+ from: {
165
+ rules: [
166
+ // `AS` binds a stage name that `COPY --from=` and a later `FROM` refer
167
+ // to, so it is scoped the same way as the flag value that names it.
168
+ {
169
+ match: '(?:^|[ \\t])([Aa][Ss])([ \\t]+)([\\w.-]+)',
170
+ scope: ['keyword.operator', null, 'type'],
171
+ },
172
+ // The image reference is a state, not a pattern: `node:${TAG}-alpine`
173
+ // is one reference with an expansion in the middle of it, and only a
174
+ // state carries the string colour across the braces. A reference may
175
+ // also start with the expansion — `${REGISTRY}/node:18` — so `$` opens
176
+ // one; a flag never does, which is all `(?!--)` is left to say.
177
+ // Zero width, so `image` sees the reference from its first character.
178
+ { match: '(?:^|[ \\t])(?!--)(?=[\\w.:/@$-])', push: 'image' },
179
+ { include: 'args' },
180
+ ],
181
+ },
182
+ /** One image reference: text, and any expansion written inside it. */
183
+ image: {
184
+ default: 'string',
185
+ rules: [
186
+ // The reference ends at whitespace; the break itself is left for `args`
187
+ // to end the instruction on.
188
+ { match: '(?=\\s)', pop: true },
189
+ { include: 'expansion' },
190
+ ],
191
+ },
192
+ /** `ENV`/`ARG`: every `NAME=` after the first one the root rule caught. */
193
+ env: {
194
+ rules: [
195
+ // The preceding space is consumed, so an `=` inside a value cannot
196
+ // start a second name.
197
+ { match: '(?:^|[ \\t])([A-Za-z_]\\w*)(?==)', scope: ['variable'] },
198
+ { include: 'args' },
199
+ ],
200
+ },
201
+ /** `LABEL`: same shape as `env`, but the keys are dotted namespaced names. */
202
+ label: {
203
+ rules: [{ match: '(?:^|[ \\t])([\\w.-]+)(?==)', scope: ['property'] }, { include: 'args' }],
204
+ },
205
+ /**
206
+ * `HEALTHCHECK` is the one instruction that carries another one.
207
+ *
208
+ * The word is its first argument and nothing else: handing the rest of the
209
+ * line to `args` is what keeps the `cmd` of `… || cmd` and a literal `none`
210
+ * from being read as a second one. Taking the space in front of it leaves
211
+ * the `/cmd` of a probe URL alone.
212
+ */
213
+ healthcheck: {
214
+ rules: [
215
+ {
216
+ match: '(?:^|[ \\t])([Cc][Mm][Dd])\\b',
217
+ scope: ['keyword'],
218
+ set: 'args',
219
+ },
220
+ {
221
+ match: '(?:^|[ \\t])([Nn][Oo][Nn][Ee])\\b',
222
+ scope: ['constant.builtin'],
223
+ set: 'args',
224
+ },
225
+ { include: 'args' },
226
+ ],
227
+ },
228
+ // ---- expansions ---------------------------------------------------------
229
+ expansion: {
230
+ rules: [
231
+ { match: '\\$\\{', scope: 'interpolation', push: 'expansion-brace' },
232
+ { match: '\\$[A-Za-z_]\\w*', scope: 'variable' },
233
+ ],
234
+ },
235
+ 'expansion-brace': {
236
+ default: 'variable',
237
+ rules: [
238
+ { match: '\\}', scope: 'interpolation', pop: true },
239
+ // Everything past a modifier is a value, not more of the name.
240
+ {
241
+ match: ':[-+?]|#{1,2}|%{1,2}',
242
+ scope: 'operator',
243
+ push: 'expansion-value',
244
+ },
245
+ // An expansion never spans a line, so a stray `${` cannot colour the
246
+ // rest of the file.
247
+ { match: '$', pop: true },
248
+ ],
249
+ },
250
+ /** The `latest` of `${TAG:-latest}` — text, and possibly another expansion. */
251
+ 'expansion-value': {
252
+ default: 'string',
253
+ rules: [{ match: '(?=\\})', pop: true }, { include: 'expansion' }, { match: '$', pop: true }],
254
+ },
255
+ // ---- strings ------------------------------------------------------------
256
+ 'string-double': {
257
+ default: 'string',
258
+ rules: [
259
+ // A quoted argument can still be continued onto the next line.
260
+ { match: '\\\\\\r?\\n', scope: 'operator' },
261
+ { match: '\\\\.', scope: 'string.escape' },
262
+ { include: 'expansion' },
263
+ { match: '"', scope: 'string', pop: true },
264
+ // Only a continuation carries a quote across a break, so an
265
+ // unterminated one ends with the line instead of the file.
266
+ { match: '$', pop: true },
267
+ ],
268
+ },
269
+ // Single quotes are literal to the shell, so neither escapes nor expansions
270
+ // apply — only the line continuation the Dockerfile parser handles first.
271
+ 'string-single': {
272
+ default: 'string',
273
+ rules: [
274
+ { match: '\\\\\\r?\\n', scope: 'operator' },
275
+ { match: "'", scope: 'string', pop: true },
276
+ { match: '$', pop: true },
277
+ ],
278
+ },
279
+ // ---- heredocs -----------------------------------------------------------
280
+ /**
281
+ * The tail of the line that opened a heredoc: `COPY <<EOT /etc/motd` still
282
+ * has a destination on it. The body only starts at the break, so the break
283
+ * is what switches states.
284
+ */
285
+ 'heredoc-head': {
286
+ rules: [{ match: '\\r?\\n', set: 'heredoc' }, { include: 'args' }],
287
+ },
288
+ heredoc: {
289
+ default: 'string',
290
+ rules: [
291
+ // Matching the terminator the opener named would need a backreference,
292
+ // which the compiler rejects, so any line holding a single bare word
293
+ // ends the body — a lone `done` inside a shell loop ends it early.
294
+ // Popping two states lands back in `root`: a heredoc is always the last
295
+ // thing on its logical line.
296
+ {
297
+ match: '^[ \\t]*[A-Za-z_]\\w*[ \\t]*$',
298
+ scope: 'string.special',
299
+ pop: 2,
300
+ },
301
+ // Expansions are live unless the opener quoted the terminator, which is
302
+ // the same thing a backreference would be needed to know.
303
+ { include: 'expansion' },
304
+ ],
305
+ },
306
+ },
307
+ };
308
+ export default dockerfile;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const elixir: Grammar;
3
+ export default elixir;
4
+ //# sourceMappingURL=elixir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elixir.d.ts","sourceRoot":"","sources":["../../src/langs/elixir.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAoD5C,QAAA,MAAM,MAAM,EAAE,OA6Tb,CAAA;AAED,eAAe,MAAM,CAAA"}