@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,287 @@
1
+ /**
2
+ * Objective-C.
3
+ *
4
+ * The language is C plus a message-send syntax that reuses `[` and `:`, which
5
+ * is exactly where a flat rule list falls over. Three small states carry the
6
+ * weight:
7
+ *
8
+ * - `message` — pushed by every `[`, so a selector label (`doThing:`) and a
9
+ * no-argument message (`[obj description]`) can be told apart from a
10
+ * subscript (`dict[key]`) without a parser
11
+ * - `method-return` / `method-name` / `method-sig` — a `- (void)foo:(id)bar`
12
+ * declaration, so the selector reads as a *definition* while the same
13
+ * selector in a message send reads as a call, and parameter names are not
14
+ * confused with the method name
15
+ * - `property-attrs` — `nonatomic`, `copy` and friends are only keywords
16
+ * inside `@property (…)`; `copy` elsewhere is an ordinary message
17
+ *
18
+ * Ordinary identifiers deliberately match nothing and inherit the block's
19
+ * foreground, which keeps both the markup and the grammar small.
20
+ */
21
+ /** C identifiers; `\w` already covers digits and `_`. */
22
+ const ID = '[A-Za-z_]\\w*';
23
+ const objectivec = {
24
+ name: 'objectivec',
25
+ aliases: ['objc', 'obj-c', 'objective-c'],
26
+ states: {
27
+ root: {
28
+ rules: [{ include: 'code' }],
29
+ },
30
+ /**
31
+ * Everything that is legal wherever an expression is. `message`,
32
+ * `method-sig` and `property-attrs` all splice this in after their own
33
+ * rules, so a construct only has to be described once.
34
+ */
35
+ code: {
36
+ rules: [
37
+ // ---- comments ------------------------------------------------------
38
+ // Doc forms first: `//` would otherwise claim `///` as an ordinary
39
+ // comment. Block comments run through a state rather than a lazy
40
+ // `[\s\S]*?\*/`, so an unterminated one colours the rest of the file
41
+ // instead of costing a full-file scan at every `/*`.
42
+ { match: '//[/!][^\\n]*', scope: 'comment.doc' },
43
+ { match: '//[^\\n]*', scope: 'comment' },
44
+ // `(?!/)` keeps the empty comment `/**/` out of the doc branch.
45
+ { match: '/\\*[*!](?!/)', scope: 'comment.doc', push: 'block-doc' },
46
+ { match: '/\\*', scope: 'comment', push: 'block-comment' },
47
+ // ---- preprocessor --------------------------------------------------
48
+ // The header path is scoped as a string in both spellings; the `<…>`
49
+ // scan stops at the newline so a stray `<` cannot run away.
50
+ {
51
+ match: `^[ \\t]*(#[ \\t]*(?:import|include))([ \\t]*)(<[^>\\n]*>|"[^"\\n]*")`,
52
+ scope: ['keyword.import', null, 'string'],
53
+ },
54
+ // Every other directive: `#define`, `#if`, `#pragma mark`, `#endif`.
55
+ { match: '^[ \\t]*#[ \\t]*\\w+', scope: 'keyword' },
56
+ // ---- method declarations -------------------------------------------
57
+ // `- (void)foo` / `+ (instancetype)bar`. Anchored to the line start and
58
+ // required to be followed by the return type's `(`, so a continuation
59
+ // line beginning with a minus is still arithmetic. A statement that
60
+ // wraps onto a line starting with `- (` is read as a method, which is
61
+ // the trade every Objective-C highlighter makes.
62
+ {
63
+ match: '^[ \\t]*([-+])([ \\t]*)(\\()',
64
+ scope: ['keyword.declaration', null, 'punctuation.bracket'],
65
+ push: 'method-return',
66
+ },
67
+ // ---- @-directives ---------------------------------------------------
68
+ // The name after `@interface`/`@implementation` is the class being
69
+ // declared, which is worth telling apart from every other type name.
70
+ // `@class A, B;` only marks `A`; the rest fall back to the CapWords
71
+ // rule below, which lands on `type` anyway.
72
+ {
73
+ match: `(@(?:interface|implementation|protocol|class))([ \\t]+)(${ID})`,
74
+ scope: ['keyword.declaration', null, 'class'],
75
+ },
76
+ // Consume the `(` so the attribute list gets its own state.
77
+ {
78
+ match: '(@property)([ \\t]*)(\\()',
79
+ scope: ['keyword.declaration', null, 'punctuation.bracket'],
80
+ push: 'property-attrs',
81
+ },
82
+ // `@selector(imageForKey:retries:)` names a method, so the whole
83
+ // selector reads as one; the scan stops at `)` and at the newline.
84
+ {
85
+ match: '(@selector)([ \\t]*)(\\()([^)\\n]*)(\\))',
86
+ scope: ['keyword.operator', null, 'punctuation.bracket', 'function.method', 'punctuation.bracket'],
87
+ },
88
+ {
89
+ match: '@(?:try|catch|finally|throw|synchronized|autoreleasepool)\\b',
90
+ scope: 'keyword.control',
91
+ },
92
+ {
93
+ match: '@(?:interface|implementation|protocol|end|property|synthesize|dynamic|class|public|private|protected|optional|required)\\b',
94
+ scope: 'keyword.declaration',
95
+ },
96
+ { match: '@import\\b', scope: 'keyword.import' },
97
+ {
98
+ match: '@(?:selector|encode|available)\\b',
99
+ scope: 'keyword.operator',
100
+ },
101
+ // ---- literals -------------------------------------------------------
102
+ // The `@` of an NSString literal is a modifier on the literal, the way
103
+ // Python's `r"…"` prefix is — scoped apart so `@"x"` and "x" read
104
+ // differently.
105
+ {
106
+ match: '(@)(")',
107
+ scope: ['string.special', 'string'],
108
+ push: 'string',
109
+ },
110
+ { match: '"', scope: 'string', push: 'string' },
111
+ // The boxing `@` of `@42`, `@YES`, `@(x + 1)`, `@[…]` and `@{…}`.
112
+ { match: '@(?=[\\[({\\d]|YES\\b|NO\\b)', scope: 'operator' },
113
+ // Capped rather than open-ended: a char literal holds at most a few
114
+ // units (`'a'`, `'\n'`, the four-char codes Core Foundation still
115
+ // uses), and an uncapped scan would rescan the line at every quote.
116
+ { match: "'(?:[^'\\\\\\n]|\\\\.){1,8}'", scope: 'string' },
117
+ // Hex and the binary literal Clang accepts, with the C integer suffixes.
118
+ {
119
+ match: '\\b0(?:[xX][0-9a-fA-F]+|[bB][01]+)[uUlL]*\\b',
120
+ scope: 'number',
121
+ },
122
+ {
123
+ match: '\\b\\d+\\.?\\d*(?:[eE][-+]?\\d+)?[uUlLfF]*\\b',
124
+ scope: 'number',
125
+ },
126
+ { match: '\\.\\d+(?:[eE][-+]?\\d+)?[fF]?', scope: 'number' },
127
+ // ---- keywords -------------------------------------------------------
128
+ {
129
+ match: '\\b(?:break|case|continue|default|do|else|for|goto|if|return|switch|while)\\b',
130
+ scope: 'keyword.control',
131
+ },
132
+ {
133
+ match: '\\b(?:auto|const|enum|extern|inline|static|struct|typedef|union|volatile|nullable|nonnull|_Nullable|_Nonnull|__block|__weak|__strong|__kindof|__bridge(?:_retained|_transfer)?)\\b',
134
+ scope: 'keyword.declaration',
135
+ },
136
+ {
137
+ match: '\\b(?:sizeof|typeof|__typeof__)\\b',
138
+ scope: 'keyword.operator',
139
+ },
140
+ { match: '\\b(?:YES|NO)\\b', scope: 'boolean' },
141
+ { match: '\\b(?:nil|Nil|NULL)\\b', scope: 'constant.builtin' },
142
+ { match: '\\b(?:self|super|_cmd)\\b', scope: 'variable.builtin' },
143
+ // The language's own types plus the platform's scalar typedefs. Class
144
+ // names — `NSString`, `UIImage` — go through the CapWords rule instead
145
+ // and land on `type`: the framework is not the language.
146
+ {
147
+ match: '\\b(?:id|instancetype|Class|SEL|IMP|BOOL|void|char|short|int|long|float|double|signed|unsigned|size_t|u?int(?:8|16|32|64)_t|NSInteger|NSUInteger|NSTimeInterval|CGFloat)\\b',
148
+ scope: 'type.builtin',
149
+ },
150
+ // ---- names ----------------------------------------------------------
151
+ // Matched from the dot, so `foo.count` never reads as a bare builtin.
152
+ {
153
+ match: `(\\.)(${ID})(?=[ \\t]*\\()`,
154
+ scope: ['punctuation', 'function.method'],
155
+ },
156
+ { match: `(\\.)(${ID})`, scope: ['punctuation', 'variable.member'] },
157
+ // Before the CapWords rules, so `NSLog(…)` and `CGRectMake(…)` read as
158
+ // calls rather than as types. Keywords are already claimed above, which
159
+ // is what keeps `if (` and `sizeof(` out of this.
160
+ { match: `\\b${ID}(?=[ \\t]*\\()`, scope: 'function.call' },
161
+ // SCREAMING_CASE is a constant, CapWords a type. Between them these
162
+ // cover every framework class and macro without shipping a name list —
163
+ // at the price of reading an enum case such as `NSUTF8StringEncoding`
164
+ // as a type.
165
+ { match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
166
+ { match: '\\b[A-Z][A-Za-z0-9_]*\\b', scope: 'type' },
167
+ // ---- syntax ---------------------------------------------------------
168
+ {
169
+ match: '\\.{3}|->|\\+\\+|--|<<=?|>>=?|&&|\\|\\||[-+*/%!&|^<>=]=?|[~?]',
170
+ scope: 'operator',
171
+ },
172
+ // Every `[` opens a message state — see `message` for why a subscript
173
+ // survives the assumption.
174
+ { match: '\\[', scope: 'punctuation.bracket', push: 'message' },
175
+ { match: '[()\\]{}]', scope: 'punctuation.bracket' },
176
+ { match: '[,;:]', scope: 'punctuation.delimiter' },
177
+ ],
178
+ },
179
+ // ---- comments ---------------------------------------------------------
180
+ 'block-comment': {
181
+ default: 'comment',
182
+ rules: [{ match: '\\*/', pop: true }],
183
+ },
184
+ 'block-doc': {
185
+ default: 'comment.doc',
186
+ rules: [{ match: '\\*/', pop: true }],
187
+ },
188
+ // ---- strings ------------------------------------------------------------
189
+ string: {
190
+ default: 'string',
191
+ rules: [
192
+ {
193
+ match: '\\\\(?:u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|x[0-9a-fA-F]+|[0-7]{1,3}|.)',
194
+ scope: 'string.escape',
195
+ },
196
+ // printf placeholders, including Objective-C's `%@` and the positional
197
+ // `%1$@` that localized format strings use.
198
+ {
199
+ // The flag and width runs are capped. Uncapped, `[-+ #0]*` and
200
+ // `(?:\d+|\*)?` both accept `0`, so a `%` followed by a long run of
201
+ // zeros makes the engine enumerate every split point before failing
202
+ // on the missing conversion character — 64 KB of zeros took 17 s.
203
+ match: '%(?:\\d{1,3}\\$)?[-+ #0]{0,6}(?:\\d{1,6}|\\*)?(?:\\.(?:\\d{1,6}|\\*))?(?:hh?|ll?|[Lzjtq])?[@%a-zA-Z]',
204
+ scope: 'string.special',
205
+ },
206
+ { match: '"', scope: 'string', pop: true },
207
+ // An unterminated literal ends at the line break rather than swallowing
208
+ // the rest of the file.
209
+ { match: '$', pop: true },
210
+ ],
211
+ },
212
+ // ---- message sends ------------------------------------------------------
213
+ /**
214
+ * Pushed by every `[`, message send or subscript. `code` comes first so a
215
+ * `default:` inside a block argument stays a keyword, and the two rules
216
+ * below only fire where nothing else claimed the text — which is precisely
217
+ * where a selector piece lives.
218
+ */
219
+ message: {
220
+ rules: [
221
+ { match: '\\]', scope: 'punctuation.bracket', pop: true },
222
+ { include: 'code' },
223
+ // A keyword selector piece. The colon has to touch the identifier, so
224
+ // the spaced `a ? b : c` is safe; the unspaced `a?b:c` is not, and
225
+ // reads `b` as a selector.
226
+ { match: `\\b${ID}(?=:(?![:=]))`, scope: 'function.method' },
227
+ // A no-argument message: `[obj description]`. The receiver has to end
228
+ // the token before it, which is what keeps `dict[key]` (no space) and
229
+ // `arr[i + n]` (a `+` before the space) out.
230
+ {
231
+ match: `(?<=[\\w\\]"\\)])[ \\t]+(${ID})(?=[ \\t]*\\])`,
232
+ scope: ['function.method'],
233
+ },
234
+ ],
235
+ },
236
+ // ---- method declarations -------------------------------------------------
237
+ /**
238
+ * The return type, `(instancetype)`. Popped at the first `)`, so a block
239
+ * return type — `- (void (^)(NSError *))handler` — closes early and reads
240
+ * its second half as the selector; the state still ends where it should.
241
+ */
242
+ 'method-return': {
243
+ rules: [{ match: '\\)', scope: 'punctuation.bracket', set: 'method-name' }, { include: 'code' }],
244
+ },
245
+ /** The first identifier after the return type is always the selector. */
246
+ 'method-name': {
247
+ rules: [
248
+ { match: ID, scope: 'function', set: 'method-sig' },
249
+ // A malformed signature must not scope the next line's identifier.
250
+ { match: '\\n', pop: true },
251
+ ],
252
+ },
253
+ /**
254
+ * The rest of the signature: further selector pieces, and the parameters
255
+ * they take. This is the definition site, so the pieces are `function`
256
+ * where a message send would make them `function.method`.
257
+ */
258
+ 'method-sig': {
259
+ rules: [
260
+ { match: '\\{', scope: 'punctuation.bracket', pop: true },
261
+ { match: ';', scope: 'punctuation.delimiter', pop: true },
262
+ { match: `\\b${ID}(?=:)`, scope: 'function' },
263
+ // A parameter name is whatever follows its type's closing paren.
264
+ { match: `(?<=\\))[ \\t]*(${ID})`, scope: ['variable.parameter'] },
265
+ { include: 'code' },
266
+ ],
267
+ },
268
+ // ---- property attributes -------------------------------------------------
269
+ /** `nonatomic`, `copy` and `class` are keywords here and nowhere else. */
270
+ 'property-attrs': {
271
+ rules: [
272
+ { match: '\\)', scope: 'punctuation.bracket', pop: true },
273
+ {
274
+ match: '\\b(?:nonatomic|atomic|strong|weak|copy|assign|retain|readonly|readwrite|class|getter|setter)\\b',
275
+ scope: 'keyword',
276
+ },
277
+ // `getter=isEnabled` names a method, not a value.
278
+ {
279
+ match: `(=)([ \\t]*)(${ID}:?)`,
280
+ scope: ['operator', null, 'function.method'],
281
+ },
282
+ { include: 'code' },
283
+ ],
284
+ },
285
+ },
286
+ };
287
+ export default objectivec;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const ocaml: Grammar;
3
+ export default ocaml;
4
+ //# sourceMappingURL=ocaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ocaml.d.ts","sourceRoot":"","sources":["../../src/langs/ocaml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA2D5C,QAAA,MAAM,KAAK,EAAE,OAsRZ,CAAA;AAED,eAAe,KAAK,CAAA"}
@@ -0,0 +1,309 @@
1
+ /**
2
+ * OCaml.
3
+ *
4
+ * The apostrophe is the whole story in this language: it opens a char literal
5
+ * (`'a'`), it opens a type variable (`'a`), and it is a perfectly ordinary
6
+ * letter at the end of an identifier (`acc'`). The three are told apart by
7
+ * shape and by what precedes them:
8
+ *
9
+ * - a char literal always closes, a type variable never does — the same trick
10
+ * Rust needs for lifetimes
11
+ * - both are rejected when the character before is an identifier character, so
12
+ * the quote in `acc' 'x'` cannot pair with the one after it
13
+ *
14
+ * The other corners worth knowing about:
15
+ *
16
+ * - comments nest, so `(*` and `*)` run a state rather than a lazy `[\s\S]*?`
17
+ * - quoted string literals (`{|raw|}`) process no escapes at all
18
+ * - `let f x = …` defines a function and `let x = …` binds a value; the
19
+ * parameters between the two are scoped through a small state machine
20
+ *
21
+ * Ordinary identifiers deliberately match no rule and inherit the block's
22
+ * foreground, which keeps both the markup and the visual noise down.
23
+ */
24
+ /**
25
+ * A value identifier — and the tail is length-capped on purpose.
26
+ *
27
+ * `'` is legal inside an identifier but is not a `\w` character, so `\b` sits
28
+ * between every `'` and the letter after it. In `a'a'a'…` — one valid
29
+ * identifier — that is a word boundary every two characters, and the rules that
30
+ * match an identifier and then test a lookahead (`name(`) would restart at each
31
+ * one and rescan to the end of the line. The cap bounds that scan; names this
32
+ * long do not occur in real code, and one that did would render unscoped.
33
+ */
34
+ const LID = "[a-z_][A-Za-z0-9_']{0,128}";
35
+ /** A module, constructor or exception name. Capitalised, same cap as `LID`. */
36
+ const UID = "[A-Z][A-Za-z0-9_']{0,128}";
37
+ /**
38
+ * Guards the end of a keyword. `\b` is not enough on its own: `'` is not a word
39
+ * character, so `\blet\b` happily fires inside the identifier `let'`.
40
+ */
41
+ const END = "(?![\\w'])";
42
+ /**
43
+ * `\255`, `\xFF`, `\o377`, `\u{1F600}`, a `\` line continuation, and — last —
44
+ * any other escaped character.
45
+ *
46
+ * The catch-all matters more than the precise forms: it guarantees that `\\`
47
+ * and `\"` are consumed as a unit, so a closing quote can never be misread.
48
+ */
49
+ const ESCAPE = '\\\\(?:[0-9]{3}|x[0-9a-fA-F]{2}|o[0-3][0-7]{2}|u\\{[0-9a-fA-F]{1,6}\\}|\\r?\\n[ \\t]*|[\\s\\S])';
50
+ /** `Printf` conversions — `%s`, `%-10s`, `%04d`, `%.2f`, `%a`, `%!`. */
51
+ const FORMAT = '%[-0+ #]*(?:\\d+|\\*)?(?:\\.(?:\\d+|\\*))?[hlLn]?[diuxXosScCfFeEgGbBaltT%!,]';
52
+ const ocaml = {
53
+ name: 'ocaml',
54
+ aliases: ['ml', 'mli'],
55
+ states: {
56
+ root: { rules: [{ include: 'expression' }] },
57
+ expression: {
58
+ rules: [
59
+ { include: 'atoms' },
60
+ // Attributes (`[@inline]`, `[@@deriving show]`) and extension nodes
61
+ // (`[%sexp_of: t]`). Only the marker and its name are claimed — the
62
+ // payload is ordinary syntax, and scanning ahead for the `]` would cost
63
+ // a line rescan per `[`.
64
+ {
65
+ match: "\\[(?:@{1,3}|%{1,2})[A-Za-z_][\\w.']{0,64}",
66
+ scope: 'decorator',
67
+ },
68
+ { include: 'definitions' },
69
+ // A dotted path: `Buffer.add_string`, `Map.Make`. Claiming the dot here
70
+ // keeps the name after it available to the builtin and call rules, so
71
+ // `Printf.printf` still reads as a builtin.
72
+ { match: `(${UID})(\\.)`, scope: ['namespace', 'punctuation'] },
73
+ { match: `(\\.)(${LID})`, scope: ['punctuation', 'variable.member'] },
74
+ // Labelled and optional arguments: `~sku:`, `?verbose`. The letter is
75
+ // required, so the `~-` and `?` operators fall through.
76
+ { match: `[~?]${LID}`, scope: 'variable.parameter' },
77
+ // Polymorphic variant tags. The backtick has no other use in OCaml.
78
+ { match: "`[A-Za-z_][\\w']{0,128}", scope: 'constant' },
79
+ {
80
+ match: `\\b(?:if|then|else|match|when|with|for|to|downto|while|do|done|begin|end|try|assert)${END}`,
81
+ scope: 'keyword.control',
82
+ },
83
+ // `in` closes the `let` it belongs to, so it reads as part of the
84
+ // binding rather than as control flow.
85
+ {
86
+ match: `\\b(?:let|rec|and|in|fun|function|type|val|external|module|struct|sig|object|class|method|inherit|initializer|constraint|mutable|private|virtual|nonrec|exception|new|lazy)${END}`,
87
+ scope: 'keyword.declaration',
88
+ },
89
+ { match: `\\b(?:open|include)${END}`, scope: 'keyword.import' },
90
+ {
91
+ match: `\\b(?:mod|land|lor|lxor|lsl|lsr|asr|or)${END}`,
92
+ scope: 'keyword.operator',
93
+ },
94
+ { match: `\\b(?:as|of)${END}`, scope: 'keyword' },
95
+ { include: 'types' },
96
+ // `ref` is a builtin rather than a builtin type, because `ref 0` turns
97
+ // up far more often in code than `int ref` does.
98
+ {
99
+ match: `\\b(?:printf|sprintf|eprintf|fprintf|print_endline|print_string|print_newline|prerr_endline|failwith|invalid_arg|raise|ignore|ref|incr|decr|not|fst|snd|compare|min|max|exit)${END}`,
100
+ scope: 'function.builtin',
101
+ },
102
+ // OCaml has no overloading, so every primitive conversion is spelled
103
+ // `<to>_of_<from>`. One pattern is smaller than the sixteen names.
104
+ {
105
+ match: `\\b(?:int|float|string|char|bool|bytes)_of_(?:int|float|string|char|bool|bytes)${END}`,
106
+ scope: 'function.builtin',
107
+ },
108
+ // Everything capitalised that is not a module path is a constructor —
109
+ // variants, exceptions, `Node`, `Leaf`. They are values, so they read as
110
+ // constants rather than as types.
111
+ { match: `\\b${UID}`, scope: 'constant' },
112
+ // OCaml applies functions without parentheses, so only a parenthesised
113
+ // call site is recognisable at all — and even then the name has to be
114
+ // the head of the application: the lookbehind is what keeps the `sku`
115
+ // in `Map.add sku (v + 1) m` from reading as a call. `f x y` stays
116
+ // unscoped, which is the honest answer, because nothing in the syntax
117
+ // separates it from `a b c`.
118
+ {
119
+ match: `(?<![\\w'\\)\\]] )\\b${LID}(?=[ \\t]*\\()`,
120
+ scope: 'function.call',
121
+ },
122
+ { match: '[,;]', scope: 'punctuation.delimiter' },
123
+ // A lone `:` annotates; `::`, `:=` and `:>` are operators.
124
+ { match: ':(?![:=>])', scope: 'punctuation.delimiter' },
125
+ // One rule for every operator, because OCaml lets users define their
126
+ // own out of these characters — `>>=`, `|>`, `+.`, `@@` and friends are
127
+ // not a fixed list.
128
+ { match: '[!$%&*+\\-./:<>=?@^|~]+', scope: 'operator' },
129
+ { match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
130
+ ],
131
+ },
132
+ // ---- literals and other self-contained tokens ----------------------------
133
+ // Shared with the parameter states, which have to see a literal before they
134
+ // see a name: without this, the `false` in `?(verbose = false)` would read
135
+ // as another parameter.
136
+ atoms: {
137
+ rules: [
138
+ { include: 'comments' },
139
+ { include: 'strings' },
140
+ { include: 'numbers' },
141
+ { match: `\\b(?:true|false)${END}`, scope: 'boolean' },
142
+ { match: `\\b(?:None|Some|Ok|Error)${END}`, scope: 'constant.builtin' },
143
+ ],
144
+ },
145
+ // ---- comments ------------------------------------------------------------
146
+ comments: {
147
+ rules: [
148
+ // `(**)` is an empty comment, not the start of a doc comment.
149
+ {
150
+ match: '\\(\\*\\*(?!\\))',
151
+ scope: 'comment.doc',
152
+ push: 'comment-doc',
153
+ },
154
+ { match: '\\(\\*', scope: 'comment', push: 'comment' },
155
+ ],
156
+ },
157
+ // Comments nest, so the opener pushes another copy of this state and only
158
+ // the matching `*)` pops. A `"*)"` inside a string inside a comment ends the
159
+ // comment early — OCaml lexes strings in comments, we do not.
160
+ comment: {
161
+ default: 'comment',
162
+ rules: [
163
+ { match: '\\(\\*', push: 'comment' },
164
+ { match: '\\*\\)', pop: true },
165
+ ],
166
+ },
167
+ 'comment-doc': {
168
+ default: 'comment.doc',
169
+ rules: [
170
+ { match: '\\(\\*', push: 'comment-doc' },
171
+ { match: '\\*\\)', pop: true },
172
+ ],
173
+ },
174
+ // ---- strings, chars and numbers ------------------------------------------
175
+ strings: {
176
+ rules: [
177
+ // `{id|raw|id}`. Matching the identifier on both ends needs a
178
+ // backreference, so any closing delimiter is accepted: a body
179
+ // containing `|other}` ends the literal early.
180
+ { match: '\\{[a-z_]*\\|', scope: 'string', push: 'quoted-string' },
181
+ { match: '"', scope: 'string', push: 'string' },
182
+ // A char literal closes; a type variable does not. The lookbehind is
183
+ // what keeps the trailing quote of `acc'` from opening one.
184
+ { match: `(?<![\\w'])'(?:[^'\\\\\\n]|${ESCAPE})'`, scope: 'string' },
185
+ ],
186
+ },
187
+ string: {
188
+ default: 'string',
189
+ rules: [
190
+ { match: ESCAPE, scope: 'string.escape' },
191
+ { match: FORMAT, scope: 'string.special' },
192
+ { match: '"', scope: 'string', pop: true },
193
+ ],
194
+ },
195
+ // Deliberately no escape rule: a quoted string literal is raw.
196
+ 'quoted-string': {
197
+ default: 'string',
198
+ rules: [{ match: '\\|[a-z_]*\\}', scope: 'string', pop: true }],
199
+ },
200
+ numbers: {
201
+ rules: [
202
+ // Hex covers hex floats too (`0x1.8p3`). `l`/`L`/`n` are the Int32,
203
+ // Int64 and nativeint suffixes.
204
+ {
205
+ match: '\\b0[xX][0-9a-fA-F_]+(?:\\.[0-9a-fA-F_]*)?(?:[pP][-+]?\\d+)?[lLn]?',
206
+ scope: 'number',
207
+ },
208
+ { match: '\\b0[oO][0-7_]+[lLn]?', scope: 'number' },
209
+ { match: '\\b0[bB][01_]+[lLn]?', scope: 'number' },
210
+ // No closing boundary, so the trailing dot of a float like `1.` stays
211
+ // part of the literal instead of being backtracked away.
212
+ {
213
+ match: '\\b\\d[\\d_]*(?:\\.[\\d_]*)?(?:[eE][-+]?\\d[\\d_]*)?[lLn]?',
214
+ scope: 'number',
215
+ },
216
+ ],
217
+ },
218
+ types: {
219
+ rules: [
220
+ // A type variable: `'a`, `'_weak1`. The char rule ran first, so
221
+ // anything that closes has already been claimed.
222
+ { match: `(?<![\\w'])'${LID}`, scope: 'type' },
223
+ {
224
+ match: `\\b(?:int|float|string|char|bool|unit|list|array|option|result|bytes|exn|int32|int64|nativeint)${END}`,
225
+ scope: 'type.builtin',
226
+ },
227
+ // A lowercase name straight after an annotation colon is a user type —
228
+ // `(it : item)`, `sku : sku_id`. The space is required, which is what
229
+ // keeps a labelled argument (`~key:value`) out of it.
230
+ { match: `(?<=: )${LID}`, scope: 'type' },
231
+ ],
232
+ },
233
+ // ---- definitions ---------------------------------------------------------
234
+ definitions: {
235
+ rules: [
236
+ // `let open M in`, `let module M = …` and `let exception E in` are
237
+ // keyword pairs, not a name being bound.
238
+ {
239
+ match: `\\b(let|and)([ \\t]+)(?:(rec)([ \\t]+))?(?!(?:open|module|exception)${END})(${LID})(?=[ \\t]*[=:])`,
240
+ scope: ['keyword.declaration', null, 'keyword.declaration', null, 'variable'],
241
+ },
242
+ // Anything else after the name is a parameter list, which is what makes
243
+ // this a function definition rather than a value binding.
244
+ {
245
+ match: `\\b(let|and)([ \\t]+)(?:(rec)([ \\t]+))?(?!(?:open|module|exception)${END})(${LID})`,
246
+ scope: ['keyword.declaration', null, 'keyword.declaration', null, 'function'],
247
+ push: 'params',
248
+ },
249
+ { match: `\\bfun${END}`, scope: 'keyword.declaration', push: 'params' },
250
+ // In a signature, an arrow in the type makes the entry a function.
251
+ //
252
+ // The lookahead's scan is capped. Uncapped, `[^\n]*->` rescans to end
253
+ // of line whenever there is no arrow, and it is retried at every `val`
254
+ // on the line: one 64 KB line of `val a:` cost 3.8 s. The cap makes it
255
+ // linear per line at the price of missing the arrow in a signature
256
+ // whose type is longer than the cap. It also gets
257
+ // `val apply : (int -> int) t` wrong, reading a nested arrow as the
258
+ // entry's own.
259
+ {
260
+ match: `\\b(val|external)([ \\t]+)(${LID})(?=[ \\t]*:[^\\n]{0,200}->)`,
261
+ scope: ['keyword.declaration', null, 'function'],
262
+ },
263
+ {
264
+ match: `\\b(val|external)([ \\t]+)(${LID})`,
265
+ scope: ['keyword.declaration', null, 'variable'],
266
+ },
267
+ // `type t`, `type 'a tree`. A multi-parameter head (`type ('a, 'b) t`)
268
+ // falls through to the plain keyword rule and leaves the name unscoped.
269
+ {
270
+ match: `\\b(type)([ \\t]+)('${LID})?([ \\t]*)(${LID})`,
271
+ scope: ['keyword.declaration', null, 'type', null, 'type'],
272
+ },
273
+ {
274
+ match: `\\b(module)([ \\t]+)(?:(type)([ \\t]+))?(${UID})`,
275
+ scope: ['keyword.declaration', null, 'keyword.declaration', null, 'namespace'],
276
+ },
277
+ {
278
+ match: `\\b(open!?|include)([ \\t]+)(${UID}(?:\\.${UID})*)`,
279
+ scope: ['keyword.import', null, 'namespace'],
280
+ },
281
+ ],
282
+ },
283
+ // ---- parameters ----------------------------------------------------------
284
+ // Entered after `let name` and after `fun`, left at the `=` or `->` that
285
+ // starts the body. Parentheses get their own state so that the arrow in
286
+ // `(g : int -> int)` and the `=` in `?(n = 10)` do not end the list early.
287
+ params: {
288
+ rules: [
289
+ { match: '=(?![=<>|&])', scope: 'operator', pop: true },
290
+ { match: '->', scope: 'operator', pop: true },
291
+ { include: 'param-atoms' },
292
+ ],
293
+ },
294
+ 'params-paren': {
295
+ rules: [{ match: '\\)', scope: 'punctuation.bracket', pop: true }, { include: 'param-atoms' }],
296
+ },
297
+ 'param-atoms': {
298
+ rules: [
299
+ { match: '\\(', scope: 'punctuation.bracket', push: 'params-paren' },
300
+ { include: 'atoms' },
301
+ // Types first: an annotation's `int` is a type, not another parameter.
302
+ { include: 'types' },
303
+ { match: `[~?]?${LID}`, scope: 'variable.parameter' },
304
+ { include: 'expression' },
305
+ ],
306
+ },
307
+ },
308
+ };
309
+ export default ocaml;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const perl: Grammar;
3
+ export default perl;
4
+ //# sourceMappingURL=perl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perl.d.ts","sourceRoot":"","sources":["../../src/langs/perl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA2F5C,QAAA,MAAM,IAAI,EAAE,OA8XX,CAAA;AAED,eAAe,IAAI,CAAA"}