@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,308 @@
1
+ /**
2
+ * Scala 2 and 3.
3
+ *
4
+ * The parts most highlighters flatten into one colour, and that this grammar
5
+ * keeps apart:
6
+ *
7
+ * - an interpolated literal is an expression. `s"…"`, `f"…"` and any custom
8
+ * interpolator scope their prefix apart from the quotes, `$name` and `${…}`
9
+ * read as interpolations, and the braced form tracks brace depth so a lambda
10
+ * inside it cannot end the literal early.
11
+ * - `case class` declares a type while every other `case` opens a match branch,
12
+ * so the two are scoped differently.
13
+ * - block comments nest in Scala, so they get a state rather than a lazy
14
+ * `[\s\S]*?` scan, which would stop at the first inner terminator.
15
+ * - operators are user-definable, so they are matched as a run of operator
16
+ * characters instead of a fixed list — which is also how `+:`, `<:`, `:::`
17
+ * and `?=>` all come out as single tokens without enumerating them.
18
+ * - a symbol literal (`'name`) is told from a char literal (`'a'`), the same
19
+ * way Rust tells a lifetime from one.
20
+ *
21
+ * The known wrong answers:
22
+ *
23
+ * - Scala 3's soft keywords (`extension`, `using`, `derives`, `opaque`,
24
+ * `infix`, `open`) are scoped as keywords wherever they appear, so a value
25
+ * named `extension` reads as one. Telling them apart needs to know where a
26
+ * declaration begins, which is a parser, not a state machine.
27
+ * - a name glued to a `:` reads as a parameter, which is right in a signature
28
+ * and wrong for the name a `given` binds.
29
+ * - `%s`-style format specifiers are scoped inside every interpolated literal,
30
+ * not just `f"…"`, because the state does not carry which interpolator
31
+ * opened it. In an `s"…"` a literal `%d` therefore reads as a spec.
32
+ * - `end` is left alone. Scala 3's end markers would need it as a keyword, and
33
+ * `end` is far too common a name to spend that on.
34
+ *
35
+ * Ordinary identifiers — locals, fields, receivers — deliberately match no rule
36
+ * and inherit the block's foreground, which keeps the markup small.
37
+ */
38
+ /**
39
+ * Everything an identifier may continue with, length-capped.
40
+ *
41
+ * The cap is what keeps the rules that match a name and then test a lookahead
42
+ * from rescanning the line at every column; names this long do not occur in
43
+ * real code. Shared by every rule that spells out a name, because a rule that
44
+ * quietly drops the non-ASCII range splits `naïve` after `na` and leaves the
45
+ * rest of the identifier unscoped.
46
+ */
47
+ const IDTAIL = '[A-Za-z0-9_\\u0080-\\uFFFF]{0,128}';
48
+ /** A Scala identifier. Unicode letters are allowed because Scala allows them. */
49
+ const ID = `[A-Za-z_\\u0080-\\uFFFF]${IDTAIL}`;
50
+ /** An identifier as it may be written at a declaration site, backticks and all. */
51
+ const NAME = `(?:\`[^\`\\n]*\`|${ID})`;
52
+ /**
53
+ * One operator character. `/` is handled separately everywhere this is used:
54
+ * a `/` followed by `/` or `*` opens a comment and must not be swallowed into
55
+ * the operator run before the comment rules ever get a look.
56
+ */
57
+ const OP = '(?:[!#%&*+\\-:<=>?@^|~]|/(?![/*]))';
58
+ /** `\n`, `\"`, `\\`, `\u2014`. Scala has no line continuation inside a literal. */
59
+ const ESCAPE = '\\\\(?:u[0-9a-fA-F]{4}|.)';
60
+ /**
61
+ * `java.util.Formatter` specs as `f"…"` uses them: `%s`, `%-20s`, `%.2f`, `%n`.
62
+ * The space flag is deliberately left out so ordinary prose — `s"50% off"` —
63
+ * does not read as a spec.
64
+ */
65
+ const FORMAT = '%[-#+0,(]{0,6}\\d{0,6}(?:\\.\\d{1,6})?[sSdxXeEfgGn%]';
66
+ const scala = {
67
+ name: 'scala',
68
+ aliases: ['sc', 'sbt'],
69
+ states: {
70
+ root: {
71
+ rules: [
72
+ { match: '//[^\\n]*', scope: 'comment' },
73
+ // `/**` only opens Scaladoc when something follows it, so the half-typed
74
+ // `/**` + `/` still reads as an ordinary block comment and closes.
75
+ { match: '/\\*\\*(?![/*])', scope: 'comment.doc', push: 'doc-comment' },
76
+ { match: '/\\*', scope: 'comment', push: 'block-comment' },
77
+ // An interpolator is an identifier glued to the quote, and any
78
+ // identifier may be one. The prefix is scoped apart from the literal so
79
+ // it reads as a modifier on it. Longest opener first: `s"""` has to
80
+ // beat `s"` + an empty string.
81
+ {
82
+ match: `\\b(${ID})(""")`,
83
+ scope: ['string.special', 'string'],
84
+ push: 'interp-triple',
85
+ },
86
+ // `raw"…"` interpolates but leaves escapes alone, so it gets a state of
87
+ // its own rather than sharing the one that scopes them. It sits below
88
+ // the triple-quote rule so `raw"""…"""` still opens a triple literal.
89
+ {
90
+ match: '\\b(raw)(")',
91
+ scope: ['string.special', 'string'],
92
+ push: 'interp-raw',
93
+ },
94
+ {
95
+ match: `\\b(${ID})(")`,
96
+ scope: ['string.special', 'string'],
97
+ push: 'interp-string',
98
+ },
99
+ { match: '"""', scope: 'string', push: 'triple-string' },
100
+ { match: '"', scope: 'string', push: 'string' },
101
+ // A char literal always closes; a symbol literal never does.
102
+ { match: `'(?:[^'\\\\\\n]|${ESCAPE})'`, scope: 'string' },
103
+ { match: "'[A-Za-z_]\\w{0,128}", scope: 'string.special' },
104
+ // The whole dotted path in one rule — Scala has no marker like Rust's
105
+ // `::` that would let a later rule recognise a package name on its own.
106
+ // A selector block (`import a.b.{c, d}`) stops the path at `b`.
107
+ {
108
+ match: `\\b(import|package|export)([ \\t]+)((?:${ID}\\.)*(?:${ID}|\\*|_))`,
109
+ scope: ['keyword.import', null, 'namespace'],
110
+ },
111
+ { match: '\\b(?:import|package|export)\\b', scope: 'keyword.import' },
112
+ // A pattern binder (`case x@Some(_)`) starts with the same character an
113
+ // annotation does. Matching the name in front of the `@` is what tells
114
+ // them apart — the same trick `kotlin.ts` uses for labels, and it keeps
115
+ // a lookbehind out of a rule that is tried at every position.
116
+ { match: `(\\b${ID})(@)`, scope: ['variable', 'operator'] },
117
+ { match: `@${ID}(?:\\.${ID})*`, scope: 'decorator' },
118
+ // Declaration sites, before the bare keywords so each claims the name
119
+ // after it. A `def` may be named with an operator (`def +:(…)`), which
120
+ // is why the name alternation is wider here than anywhere else.
121
+ {
122
+ match: `(\\bdef)([ \\t]+)(${NAME}|${OP}{1,16})`,
123
+ scope: ['keyword.declaration', null, 'function'],
124
+ },
125
+ {
126
+ match: `(\\b(?:class|trait|object|enum))([ \\t]+)(${NAME})`,
127
+ scope: ['keyword.declaration', null, 'class'],
128
+ },
129
+ {
130
+ match: `(\\btype)([ \\t]+)(${NAME})`,
131
+ scope: ['keyword.declaration', null, 'type'],
132
+ },
133
+ // Scala names constants in CapWords, so a bound name that starts with a
134
+ // capital is a constant rather than a type — but only when the name is
135
+ // followed straight by `:` or `=`, which is what keeps the destructuring
136
+ // `val Some(x) = opt` reading as the extractor it is.
137
+ {
138
+ match: `(\\b(?:val|var))([ \\t]+)([A-Z]${IDTAIL})(?=[ \\t]*[:=])`,
139
+ scope: ['keyword.declaration', null, 'constant'],
140
+ },
141
+ // The start of the name stays lowercase-or-underscore — widening it to
142
+ // every letter would claim the `Some` of `val Some(x) = opt`, which is
143
+ // an extractor and not a bound name. Non-ASCII initials land here
144
+ // rather than in the constant rule above, which is the right reading
145
+ // for a `val` either way.
146
+ {
147
+ match: `(\\b(?:val|var))([ \\t]+)(\`[^\`\\n]*\`|[a-z_\\u0080-\\uFFFF]${IDTAIL})`,
148
+ scope: ['keyword.declaration', null, 'variable'],
149
+ },
150
+ // `case class` and `case object` declare a type; every other `case`
151
+ // opens a match branch or names an enum member.
152
+ {
153
+ match: '\\bcase(?=[ \\t]+(?:class|object)\\b)',
154
+ scope: 'keyword.declaration',
155
+ },
156
+ {
157
+ match: '\\b(?:if|else|then|match|case|for|while|do|yield|try|catch|finally|throw|return)\\b',
158
+ scope: 'keyword.control',
159
+ },
160
+ {
161
+ match: '\\b(?:def|val|var|class|trait|object|enum|type|given|using|extension|implicit|lazy|sealed|abstract|final|override|private|protected|extends|with|derives|opaque|inline|transparent|infix|open)\\b',
162
+ scope: 'keyword.declaration',
163
+ },
164
+ { match: '\\bnew\\b', scope: 'keyword.operator' },
165
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
166
+ // `Nil` and `None` are values, not types, so they are scoped before the
167
+ // CapWords rule below would call them types.
168
+ { match: '\\b(?:null|None|Nil)\\b', scope: 'constant.builtin' },
169
+ { match: '\\b(?:this|super)\\b', scope: 'variable.builtin' },
170
+ {
171
+ match: '\\b(?:Int|Long|Short|Byte|Char|Float|Double|Boolean|Unit|String|Any(?:Ref|Val)?|Nothing|Null|Option|Some|Either|Left|Right|List|Seq|Vector|Array|Set|Map|Future|Try|Success|Failure)\\b',
172
+ scope: 'type.builtin',
173
+ },
174
+ {
175
+ match: '\\b(?:print(?:ln|f)?|require|assert|implicitly|summon)\\b',
176
+ scope: 'function.builtin',
177
+ },
178
+ // Matched at the dot, so `logger.map` never reads as a bare name. A
179
+ // capitalised member is an enum case, a nested type or a companion
180
+ // constant — never a method, since Scala methods are lowercase.
181
+ {
182
+ match: '(\\.)([A-Z][A-Z0-9_]{0,128})\\b',
183
+ scope: ['punctuation', 'constant'],
184
+ },
185
+ {
186
+ match: '(\\.)([A-Z][A-Za-z0-9_]{0,128})',
187
+ scope: ['punctuation', 'type'],
188
+ },
189
+ // A trailing block is a call too, so `xs.map { … }` scopes `map` the
190
+ // same way `xs.map(f)` does.
191
+ {
192
+ match: `(\\.)(${ID})(?=[ \\t]*[({])`,
193
+ scope: ['punctuation', 'function.method'],
194
+ },
195
+ { match: `(\\.)(${ID})`, scope: ['punctuation', 'variable.member'] },
196
+ // SCREAMING_CASE reads as a constant and CapWords as a type. Between
197
+ // them they cover classes, traits, enum cases, type parameters and the
198
+ // whole exception hierarchy without shipping a name list.
199
+ { match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
200
+ { match: '\\b[A-Z][A-Za-z0-9_]*\\b', scope: 'type' },
201
+ // A name glued to a `:` is being ascribed a type, which in a signature
202
+ // means a parameter. The colon has to be glued on: `xs :: ys` puts a
203
+ // list cons where the ascription would be, and it is far more common.
204
+ { match: `\\b${ID}(?=:(?![:=]))`, scope: 'variable.parameter' },
205
+ { match: `\\b[a-z_]${IDTAIL}(?=[ \\t]*[({])`, scope: 'function.call' },
206
+ { match: '`[^`\\n]*`', scope: 'variable' },
207
+ // Scala has no binary literals. Underscore separators are accepted
208
+ // wherever digits are, so a literal pasted from Java-flavoured code
209
+ // still reads as a number.
210
+ { match: '\\b0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?\\b', scope: 'number' },
211
+ // A digit is required after the point so `1.to(10)` keeps its method
212
+ // call instead of ending the literal at the dot.
213
+ {
214
+ match: '\\b\\d[\\d_]*(?:\\.\\d[\\d_]*)?(?:[eE][-+]?\\d+)?[fFdDlL]?\\b',
215
+ scope: 'number',
216
+ },
217
+ // A lone `:` delimits an ascription; a `:` in a run of operator
218
+ // characters (`::`, `<:`, `:+`) belongs to the operator.
219
+ { match: ':(?![!#%&*+\\-/:<=>?@^|~])', scope: 'punctuation.delimiter' },
220
+ { match: `${OP}+`, scope: 'operator' },
221
+ { match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
222
+ { match: '[,;]', scope: 'punctuation.delimiter' },
223
+ ],
224
+ },
225
+ // ---- comments ----------------------------------------------------------
226
+ // Two states rather than one, because the nesting has to preserve whether
227
+ // the outermost comment was documentation.
228
+ 'block-comment': {
229
+ default: 'comment',
230
+ rules: [
231
+ { match: '/\\*', push: 'block-comment' },
232
+ { match: '\\*/', pop: true },
233
+ ],
234
+ },
235
+ 'doc-comment': {
236
+ default: 'comment.doc',
237
+ rules: [
238
+ { match: '/\\*', push: 'doc-comment' },
239
+ { match: '\\*/', pop: true },
240
+ ],
241
+ },
242
+ // ---- strings -----------------------------------------------------------
243
+ /** The interpolation syntax both interpolated forms share. */
244
+ 'interp-body': {
245
+ rules: [
246
+ // `$$` is how an interpolated literal writes a dollar sign.
247
+ { match: '\\$\\$', scope: 'string.escape' },
248
+ { match: '\\$\\{', scope: 'interpolation', push: 'interpolation' },
249
+ // Only a bare identifier may follow `$`, so `s"$item.sku"` interpolates
250
+ // `item` and leaves `.sku` as text — which is what Scala does too.
251
+ { match: `(\\$)(${ID})`, scope: ['interpolation', 'variable'] },
252
+ { match: FORMAT, scope: 'string.special' },
253
+ ],
254
+ },
255
+ string: {
256
+ default: 'string',
257
+ rules: [
258
+ { match: ESCAPE, scope: 'string.escape' },
259
+ { match: '"', scope: 'string', pop: true },
260
+ // A single-quoted Scala literal cannot span a line, so an unterminated
261
+ // one ends at the line break instead of swallowing the rest of the file.
262
+ { match: '$', pop: true },
263
+ ],
264
+ },
265
+ 'interp-string': {
266
+ default: 'string',
267
+ rules: [
268
+ { match: ESCAPE, scope: 'string.escape' },
269
+ { include: 'interp-body' },
270
+ { match: '"', scope: 'string', pop: true },
271
+ { match: '$', pop: true },
272
+ ],
273
+ },
274
+ 'interp-raw': {
275
+ default: 'string',
276
+ rules: [{ include: 'interp-body' }, { match: '"', scope: 'string', pop: true }, { match: '$', pop: true }],
277
+ },
278
+ /**
279
+ * A triple-quoted literal has no escapes at all — `\n` in one is a
280
+ * backslash and an `n` — and ends only on `"""`, so a quote or a `//`
281
+ * inside it is text.
282
+ */
283
+ 'triple-string': {
284
+ default: 'string',
285
+ rules: [{ match: '"""', scope: 'string', pop: true }],
286
+ },
287
+ 'interp-triple': {
288
+ default: 'string',
289
+ rules: [{ include: 'interp-body' }, { match: '"""', scope: 'string', pop: true }],
290
+ },
291
+ interpolation: {
292
+ rules: [
293
+ { match: '\\}', scope: 'interpolation', pop: true },
294
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
295
+ { include: 'root' },
296
+ ],
297
+ },
298
+ /** Brace depth, so a lambda or a block cannot close the interpolation. */
299
+ brace: {
300
+ rules: [
301
+ { match: '\\}', scope: 'punctuation.bracket', pop: true },
302
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
303
+ { include: 'root' },
304
+ ],
305
+ },
306
+ },
307
+ };
308
+ export default scala;
@@ -0,0 +1,5 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ /** SQL, in a dialect-agnostic form. */
3
+ declare const sql: Grammar;
4
+ export default sql;
5
+ //# sourceMappingURL=sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/langs/sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,uCAAuC;AACvC,QAAA,MAAM,GAAG,EAAE,OA+DV,CAAA;AAED,eAAe,GAAG,CAAA"}
@@ -0,0 +1,57 @@
1
+ /** SQL, in a dialect-agnostic form. */
2
+ const sql = {
3
+ name: 'sql',
4
+ aliases: ['postgres', 'postgresql', 'mysql', 'sqlite'],
5
+ states: {
6
+ root: {
7
+ ignoreCase: true,
8
+ rules: [
9
+ { match: '--[^\\n]*', scope: 'comment' },
10
+ { match: '#[^\\n]*', scope: 'comment' },
11
+ { match: '/\\*[\\s\\S]*?\\*/', scope: 'comment' },
12
+ // Doubled quotes are the escape, so a literal never ends early.
13
+ { match: "'(?:[^']|'')*'", scope: 'string' },
14
+ { match: '"(?:[^"]|"")*"', scope: 'variable.member' },
15
+ { match: '`[^`]*`', scope: 'variable.member' },
16
+ // `[` is excluded as well as `]`: a bracketed identifier cannot nest,
17
+ // and allowing a bare `[` makes a line of brackets cost O(n) each.
18
+ { match: '\\[[^[\\]]*\\]', scope: 'variable.member' },
19
+ {
20
+ match: '\\b(?:select|from|where|group|by|order|having|limit|offset|join|inner|left|right|full|outer|cross|lateral|on|using|union|intersect|except|with|recursive|case|when|then|else|end|distinct|returning|fetch|next|rows?|only)\\b',
21
+ scope: 'keyword.control',
22
+ },
23
+ {
24
+ match: '\\b(?:insert|into|values|update|set|delete|create|alter|drop|truncate|table|view|index|sequence|schema|database|function|procedure|trigger|constraint|primary|foreign|key|references|unique|check|default|cascade|column|add|rename|grant|revoke|begin|commit|rollback|transaction|explain|analyze|vacuum|copy|temporary|temp|if|exists|replace|materialized)\\b',
25
+ scope: 'keyword.declaration',
26
+ },
27
+ {
28
+ match: '\\b(?:and|or|not|in|is|like|ilike|between|exists|any|all|some|as|asc|desc|nulls|first|last)\\b',
29
+ scope: 'keyword.operator',
30
+ },
31
+ { match: '\\b(?:null)\\b', scope: 'constant.builtin' },
32
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
33
+ {
34
+ match: '\\b(?:int|integer|bigint|smallint|serial|bigserial|decimal|numeric|real|double|precision|float|money|char|varchar|text|bytea|timestamp|timestamptz|date|time|interval|boolean|bool|uuid|json|jsonb|array|enum|blob)\\b',
35
+ scope: 'type.builtin',
36
+ },
37
+ {
38
+ match: '\\b(?:count|sum|avg|min|max|coalesce|nullif|cast|greatest|least|now|current_date|current_timestamp|extract|date_trunc|concat|substring|trim|upper|lower|length|round|abs|row_number|rank|dense_rank|lag|lead|over|partition|array_agg|string_agg|json_build_object|generate_series)\\b',
39
+ scope: 'function.builtin',
40
+ },
41
+ { match: '\\b[A-Za-z_]\\w*(?=\\s*\\()', scope: 'function.call' },
42
+ { match: '\\b\\d+(?:\\.\\d+)?(?:[eE][-+]?\\d+)?\\b', scope: 'number' },
43
+ { match: '\\$\\d+|[:@][A-Za-z_]\\w*|\\?', scope: 'variable' },
44
+ // Table, column and correlation names are deliberately left at the
45
+ // block foreground, the same as the quoted identifiers above and the
46
+ // same as `variable` everywhere else in the vocabulary. Scoping them
47
+ // reads better against shiki's coverage but is worse in practice: it
48
+ // paints most of a statement, and `@scalar/code-highlight` renders
49
+ // them muted, so colouring them here would break the compat floor.
50
+ { match: '::|<>|!=|>=|<=|\\|\\||[-+*/%<>=]', scope: 'operator' },
51
+ { match: '[()]', scope: 'punctuation.bracket' },
52
+ { match: '[,;.]', scope: 'punctuation.delimiter' },
53
+ ],
54
+ },
55
+ },
56
+ };
57
+ export default sql;
@@ -0,0 +1,33 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ /**
3
+ * Swift.
4
+ *
5
+ * The four things that make Swift awkward for a regex tokenizer, and what this
6
+ * grammar does about each:
7
+ *
8
+ * - Block comments nest. No single regex can count, so an opener pushes the
9
+ * comment state onto itself and a closer pops one level.
10
+ * - `\(…)` interpolations are real expressions and they nest, so the string
11
+ * states hand off to a paren-counting state rather than matching to the first
12
+ * `)`.
13
+ * - Raw strings change what an escape looks like — `\n` is two literal
14
+ * characters and `\#n` is the newline — which is a different state, not a
15
+ * flag on the ordinary one.
16
+ * - Argument labels are ordinary words in call position (`f(for: x)`,
17
+ * `f(in: y)`), so they are matched before the keyword lists and anchored to
18
+ * the `(` or `,` that introduces them.
19
+ *
20
+ * Identifiers are treated as ASCII. Swift allows most of Unicode in a name, but
21
+ * a non-ASCII name here simply renders unscoped rather than wrong, and the
22
+ * casing rules below — which is where the type/constant/call distinctions come
23
+ * from — only ever apply to the ASCII spelling anyway.
24
+ *
25
+ * Two readings are knowingly wrong, both where the shape is genuinely
26
+ * ambiguous: a trailing-closure call (`items.map { … }`) reads as a property
27
+ * access, because `if user.isActive { … }` is the same shape and more common;
28
+ * and an enum case with associated values (`case notFound(sku: String)`) reads
29
+ * as a call, which is what it looks like everywhere else it appears.
30
+ */
31
+ declare const swift: Grammar;
32
+ export default swift;
33
+ //# sourceMappingURL=swift.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swift.d.ts","sourceRoot":"","sources":["../../src/langs/swift.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,QAAA,MAAM,KAAK,EAAE,OAwPZ,CAAA;AAED,eAAe,KAAK,CAAA"}