@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,352 @@
1
+ /**
2
+ * MATLAB (and, near enough, Octave).
3
+ *
4
+ * Four things make MATLAB awkward for a regex tokenizer, and each one is
5
+ * handled explicitly here:
6
+ *
7
+ * - The apostrophe is both the transpose operator and the char-array quote.
8
+ * `A'` transposes, `'A'` is a literal. What separates them is only what came
9
+ * *before*, so a lookbehind decides: an apostrophe following an identifier
10
+ * character, `)`, `]`, `}`, `"` or another `'` is transpose, and everything
11
+ * else opens a literal. That rule sits ahead of the string rules so the
12
+ * operator wins the tie.
13
+ * - `end` closes a block *and* names the last index. Every bracket pushes a
14
+ * state, and inside one `end` is a value rather than a keyword — which is
15
+ * exactly the distinction MATLAB itself makes.
16
+ * - Block comments are delimited by `%{` and `%}` alone on their own lines, and
17
+ * the same characters mid-line are an ordinary comment. Both delimiters are
18
+ * line-anchored, and the body is a state rather than a backreferenced scan.
19
+ * - `properties`, `methods` and `arguments` are contextual: `properties(obj)`
20
+ * is a function call. They only read as keywords when they open a block,
21
+ * which here means they end their line (an attribute list aside).
22
+ *
23
+ * Ordinary identifiers deliberately match no rule. MATLAB has no naming
24
+ * convention a highlighter can lean on — `A` and `B` are matrices far more
25
+ * often than they are classes — so the CapWords/SCREAMING_CASE heuristics other
26
+ * grammars here use would be wrong more often than right.
27
+ *
28
+ * What it knowingly gets wrong: command syntax. In `hold on` and `warning off`
29
+ * the bare words are string arguments, and nothing in the line says so, so they
30
+ * render as plain identifiers.
31
+ */
32
+ /** MATLAB names start with a letter; the cap bounds lookahead rules. */
33
+ const ID = '[A-Za-z]\\w{0,63}';
34
+ /**
35
+ * Integers, floats, exponents, the `i`/`j` imaginary suffix and the `0x`/`0b`
36
+ * literals added in R2019b. Their `u8`/`s16` type suffixes are left out: they
37
+ * are vanishingly rare, and a suffixed literal simply renders unscoped.
38
+ *
39
+ * The trailing guard is `(?!\w)` rather than `(?![\w.])` on purpose: `1.5.^2`
40
+ * is a real expression, and a dot-excluding guard would refuse to see the
41
+ * number in front of the element-wise operator.
42
+ *
43
+ * A trailing dot joins the literal only when no dot operator follows it, which
44
+ * is what `(?![*\/\\^'])` guards. `2./x` therefore splits the way MATLAB itself
45
+ * splits it, as `2` and `./`, and — the reason the guard is not optional —
46
+ * `2.'` reads as `2` and the non-conjugate transpose. Letting the literal eat
47
+ * the dot there leaves the `'` with a `.` behind it, which the transpose
48
+ * lookbehind rejects, so the apostrophe would open a char array and swallow the
49
+ * rest of the line.
50
+ */
51
+ const NUMBER = '(?<![\\w.])(?:0[xX][0-9a-fA-F]+|0[bB][01]+|' +
52
+ "(?:\\d+(?:\\.(?:\\d+|(?![*/\\\\^'])))?|\\.\\d+)(?:[eE][-+]?\\d+)?[ijIJ]?)(?!\\w)";
53
+ /** The block-opening keywords, plus Octave's `do`/`until`. */
54
+ const CONTROL = '\\b(?:if|elseif|else|end|switch|case|otherwise|for|parfor|while|do|until|' + 'break|continue|return|try|catch)\\b';
55
+ /** What `class()` answers for a builtin, and the constructor of the same name. */
56
+ const TYPES = '\\b(?:double|single|u?int(?:8|16|32|64)|logical|char|string|cell|struct|table|datetime)\\b';
57
+ /**
58
+ * Base functions worth their bytes.
59
+ *
60
+ * The list is deliberately short. Anything left out still reads as a call
61
+ * wherever a `(` follows, so a name only earns a place if a reader expects to
62
+ * recognise it even when it is passed by handle — `cellfun(@numel, c)`. The
63
+ * graphics and toolbox families are left out entirely for that reason.
64
+ */
65
+ const BUILTINS = '\\b(?:' +
66
+ 'zeros|ones|eye|rand[in]?|linspace|size|numel|length|reshape|repmat|' +
67
+ 'sum|prod|mean|std|min|max|abs|sqrt|exp|log(?:2|10)?|sin|cos|tan|' +
68
+ 'floor|ceil|round|mod|sort|unique|find|any|all|' +
69
+ 'is(?:empty|nan|inf|a|field|char|numeric|logical|string|struct|cell|equal|member)|' +
70
+ 'class|cellfun|arrayfun|disp|fprintf|sprintf|error|warning|assert|' +
71
+ 'str(?:cmpi?|rep|split|join|trim|cat|2double|2func)|(?:num|mat)2str|' +
72
+ 'regexp(?:rep)?|contains|upper|lower|inv|diff|plot|figure|tic|toc' +
73
+ ')\\b';
74
+ /**
75
+ * printf placeholders. MATLAB itself never interprets them, but `fprintf`,
76
+ * `sprintf` and `error` are where format strings live, so they are worth
77
+ * calling out wherever they appear.
78
+ *
79
+ * Every repetition is capped. `0` is both a flag and a digit, so with `*`
80
+ * quantifiers a long run of them backtracks against the width group at every
81
+ * split — seconds of work for `'%00000…'`, on a string an untrusted document
82
+ * can contain.
83
+ */
84
+ const FORMAT = '%[-+ #0]{0,8}(?:\\d{1,6}|\\*)?(?:\\.(?:\\d{1,6}|\\*))?[diouxXeEfgGcs%]';
85
+ /**
86
+ * `.*`, `./`, `.\`, `.^` and the non-conjugate transpose `.'` all begin with a
87
+ * dot, so they are one alternative; the trailing `[&|:@.]` picks up `:` (a
88
+ * range, not a delimiter), `@` and the bare dot of `s.(name)`.
89
+ */
90
+ const OPERATOR = "\\.[*/\\\\^']|&&|\\|\\||[-+*/\\\\^~<>=]=?|[&|:@.]";
91
+ const matlab = {
92
+ name: 'matlab',
93
+ aliases: ['m', 'octave'],
94
+ states: {
95
+ root: {
96
+ rules: [{ include: 'statement' }, { include: 'expression' }, { include: 'brackets' }],
97
+ },
98
+ // ---- statement-level constructs ----------------------------------------
99
+ statement: {
100
+ rules: [
101
+ // Contextual block keywords. `properties(obj)` and `methods(obj)` are
102
+ // ordinary calls, so these only count when the name opens its own line
103
+ // and nothing but an attribute list and a comment follow it.
104
+ //
105
+ // The trailing whitespace run is written once, with the second one
106
+ // tucked inside the optional attribute list behind the mandatory `)`.
107
+ // Two `[ \t]*` in a row with an optional group between them let the
108
+ // engine enumerate every split of a whitespace run whenever `$` fails,
109
+ // which is quadratic on `properties` followed by spaces and one more
110
+ // character — a line an untrusted document can contain.
111
+ {
112
+ match: '^([ \\t]*)(arguments|properties|methods|events|enumeration)\\b' +
113
+ '(?=[ \\t]*(?:\\([^)\\n]{0,120}\\)[ \\t]*)?(?:[%#][^\\n]*)?$)',
114
+ scope: [null, 'keyword.declaration'],
115
+ },
116
+ // The superclass list is its own state so `handle` and a dotted mixin
117
+ // read as types rather than as variables.
118
+ {
119
+ match: `\\b(classdef)([ \\t]+)(${ID})`,
120
+ scope: ['keyword.declaration', null, 'class'],
121
+ push: 'superclass',
122
+ },
123
+ // `classdef (Sealed) Foo` puts attributes before the name; the name is
124
+ // left unscoped there rather than growing the rule.
125
+ { match: '\\bclassdef\\b', scope: 'keyword.declaration' },
126
+ {
127
+ match: '\\bfunction\\b',
128
+ scope: 'keyword.declaration',
129
+ push: 'func-decl',
130
+ },
131
+ // `import pkg.Class`. The path falls through to the member rules rather
132
+ // than getting a namespace rule of its own — MATLAB code imports rarely
133
+ // enough that the extra pattern is not worth its bytes.
134
+ { match: '\\bimport\\b', scope: 'keyword.import' },
135
+ ],
136
+ },
137
+ // ---- expressions -------------------------------------------------------
138
+ expression: {
139
+ rules: [
140
+ { include: 'comments' },
141
+ // The whole transpose-versus-quote decision, and it has to come before
142
+ // the string rules so the operator wins when both could match. `"` is
143
+ // in the class because `"abc"'` transposes a string scalar; the only
144
+ // way to reach a `'` with a `"` behind it is straight after a
145
+ // double-quoted literal closed, so it cannot open one either.
146
+ { match: "(?<=[\\w)\\]}'\"])'", scope: 'operator' },
147
+ { match: "'", scope: 'string', push: 'char-array' },
148
+ { match: '"', scope: 'string', push: 'string-double' },
149
+ { match: NUMBER, scope: 'number' },
150
+ // Matched at the dot so `obj.size` never reads as the builtin. MATLAB
151
+ // cannot tell `obj.method(x)` from indexing a property, and neither can
152
+ // this: a following `(` wins and the property reads as a method.
153
+ {
154
+ match: `(\\.)(${ID})(?=\\()`,
155
+ scope: ['punctuation', 'function.method'],
156
+ },
157
+ { match: `(\\.)(${ID})`, scope: ['punctuation', 'variable.member'] },
158
+ // `@(x) …` — the parameter list gets the same state a signature does.
159
+ {
160
+ match: '(@)([ \\t]*)(\\()',
161
+ scope: ['keyword.declaration', null, 'punctuation.bracket'],
162
+ push: 'params',
163
+ },
164
+ { match: CONTROL, scope: 'keyword.control' },
165
+ { match: '\\b(?:global|persistent)\\b', scope: 'keyword.declaration' },
166
+ { match: '\\b(?:true|false)\\b', scope: 'boolean' },
167
+ {
168
+ match: '\\b(?:pi|Inf|inf|NaN|nan|NaT|eps)\\b',
169
+ scope: 'constant.builtin',
170
+ },
171
+ {
172
+ match: '\\b(?:nargin|nargout|varargin|varargout|ans)\\b',
173
+ scope: 'variable.builtin',
174
+ },
175
+ { match: TYPES, scope: 'type.builtin' },
176
+ { match: BUILTINS, scope: 'function.builtin' },
177
+ // A named handle, `@myfun`. Listed after the builtins so `@mean` keeps
178
+ // its builtin colour; the `@` itself is consumed by the operator rule.
179
+ { match: `(?<=@)${ID}`, scope: 'function.call' },
180
+ // MATLAB spells indexing and calling the same way, so `x(3)` on an
181
+ // array reads as a call. Every highlighter makes this trade; requiring
182
+ // the `(` to be adjacent at least keeps `size (1,1)` in an `arguments`
183
+ // block from looking like one.
184
+ { match: `\\b${ID}(?=\\()`, scope: 'function.call' },
185
+ { match: OPERATOR, scope: 'operator' },
186
+ ],
187
+ },
188
+ /**
189
+ * Bracket openers push, so the state stack knows whether an `end` is
190
+ * closing a block or naming the last index.
191
+ */
192
+ brackets: {
193
+ rules: [
194
+ { match: '[(\\[{]', scope: 'punctuation.bracket', push: 'group' },
195
+ // A closer with no opener — mismatched source, or a prefix an editor is
196
+ // still typing. Scoped, but it must not pop past the state it is in.
197
+ { match: '[)\\]}]', scope: 'punctuation.bracket' },
198
+ // Inside `[…]` a `;` ends a matrix row rather than a statement, but it
199
+ // separates either way.
200
+ { match: '[,;]', scope: 'punctuation.delimiter' },
201
+ ],
202
+ },
203
+ /**
204
+ * Anything inside `(…)`, `[…]` or `{…}`, where `end` is the last index.
205
+ *
206
+ * One state serves all three: which closer arrives is only interesting on
207
+ * malformed source, and paying for three near-identical states to notice
208
+ * `f(x]` is not worth it.
209
+ */
210
+ group: {
211
+ rules: [
212
+ { match: '[)\\]}]', scope: 'punctuation.bracket', pop: true },
213
+ // `[~, idx] = max(v)` discards an output. A `~` immediately followed by
214
+ // a separator cannot be negating anything, so it is a placeholder name
215
+ // rather than the not operator.
216
+ { match: '~(?=[ \\t]*[,\\]])', scope: 'variable.parameter' },
217
+ { include: 'nested' },
218
+ ],
219
+ },
220
+ nested: {
221
+ rules: [{ match: '\\bend\\b', scope: 'constant.builtin' }, { include: 'expression' }, { include: 'brackets' }],
222
+ },
223
+ // ---- declarations ------------------------------------------------------
224
+ /**
225
+ * A `function` signature, up to the end of its line. Both output forms live
226
+ * here: `[a, b] = f(x)` and `y = f(x)`, plus the bare `function f(x)`.
227
+ */
228
+ 'func-decl': {
229
+ rules: [
230
+ { include: 'comments' },
231
+ // The signature ends with its line. A `...` continuation is matched by
232
+ // `comments` above, and that rule swallows the newline, so this cannot
233
+ // pop in the middle of a wrapped parameter list.
234
+ { match: '$', pop: true },
235
+ // `function y = f(x), y = 1; end` puts the whole definition on one
236
+ // line. Every comma inside the output or parameter list belongs to the
237
+ // `params` state, so a separator seen here is already past the
238
+ // signature and the body starts after it.
239
+ { match: '[,;]', scope: 'punctuation.delimiter', pop: true },
240
+ { match: '\\[', scope: 'punctuation.bracket', push: 'params' },
241
+ // A name in front of the `=` is the single output, not the function.
242
+ { match: `(${ID})(?=[ \\t]*=(?!=))`, scope: ['variable.parameter'] },
243
+ { match: '=', scope: 'operator' },
244
+ {
245
+ match: `(${ID})([ \\t]*)(\\()`,
246
+ scope: ['function', null, 'punctuation.bracket'],
247
+ push: 'params',
248
+ },
249
+ { match: ID, scope: 'function' },
250
+ // Keeps the bracket balanced for shapes this state does not model, such
251
+ // as the `function v = get.Prop(obj)` property getter.
252
+ { match: '\\(', scope: 'punctuation.bracket', push: 'params' },
253
+ ],
254
+ },
255
+ /**
256
+ * Names in a signature: the `[a, b]` output list, and the parameters of both
257
+ * `function f(a, b)` and `@(a, b)`. One state covers both because MATLAB
258
+ * puts defaults in an `arguments` block rather than the signature, so every
259
+ * bare name in either list is a name and nothing else. A `~` stands in for
260
+ * one that is being discarded.
261
+ */
262
+ params: {
263
+ rules: [
264
+ { match: '[)\\]]', scope: 'punctuation.bracket', pop: true },
265
+ { include: 'comments' },
266
+ { match: `[~]|${ID}`, scope: 'variable.parameter' },
267
+ { match: ',', scope: 'punctuation.delimiter' },
268
+ // An unclosed list must not turn the rest of the file into parameters.
269
+ { match: '$', pop: true },
270
+ ],
271
+ },
272
+ /** Everything after `classdef Name`: `< handle & pkg.Mixin`. */
273
+ superclass: {
274
+ rules: [
275
+ { include: 'comments' },
276
+ { match: '$', pop: true },
277
+ // A superclass list is separated by `&`, so a `,` or `;` here ends the
278
+ // header — `classdef Foo < handle, end` is a legal one-line class and
279
+ // its `end` closes the block rather than naming a mixin.
280
+ { match: '[,;]', scope: 'punctuation.delimiter', pop: true },
281
+ { match: '[<&]', scope: 'operator' },
282
+ { match: `${ID}(?:\\.${ID}){0,8}`, scope: 'type' },
283
+ ],
284
+ },
285
+ // ---- comments ----------------------------------------------------------
286
+ comments: {
287
+ rules: [
288
+ // `%{` only opens a block when it is alone on its line; anywhere else it
289
+ // is an ordinary comment. Nesting is not modelled — the first `%}` on
290
+ // its own line closes the block.
291
+ {
292
+ match: '^([ \\t]*)([%#]\\{[ \\t]*)$',
293
+ scope: [null, 'comment'],
294
+ push: 'block-comment',
295
+ },
296
+ // `%%` at the start of a line opens a code section, which editors treat
297
+ // as a heading rather than as a note.
298
+ { match: '^([ \\t]*)((?:%%|##)[^\\n]*)', scope: [null, 'comment.doc'] },
299
+ // `#` is Octave's comment character and means nothing in MATLAB, so
300
+ // accepting it costs one character and cannot misfire.
301
+ { match: '[%#][^\\n]*', scope: 'comment' },
302
+ // A `...` continuation comments out the rest of its line. The newline is
303
+ // consumed with it so states that end at `$` see the logical line, not
304
+ // the physical one.
305
+ {
306
+ match: '(\\.\\.\\.)([^\\n]*)(\\n?)',
307
+ scope: ['punctuation', 'comment', null],
308
+ },
309
+ ],
310
+ },
311
+ 'block-comment': {
312
+ default: 'comment',
313
+ rules: [{ match: '^[ \\t]*[%#]\\}[ \\t]*$', pop: true }],
314
+ },
315
+ // ---- strings -----------------------------------------------------------
316
+ 'string-body': {
317
+ rules: [
318
+ // MATLAB does not interpret backslash escapes in a literal — only the
319
+ // printf family does, and that is where they overwhelmingly appear, so
320
+ // showing them is right on ordinary code and wrong on `disp('a\nb')`.
321
+ {
322
+ match: '\\\\(?:x[0-9a-fA-F]{1,2}|[0-7]{1,3}|[nrtfvab0\\\\\'"%])',
323
+ scope: 'string.escape',
324
+ },
325
+ { match: FORMAT, scope: 'string.special' },
326
+ ],
327
+ },
328
+ /** A single-quoted char array. The quote is escaped by doubling it. */
329
+ 'char-array': {
330
+ default: 'string',
331
+ rules: [
332
+ { match: "''", scope: 'string.escape' },
333
+ { include: 'string-body' },
334
+ { match: "'", scope: 'string', pop: true },
335
+ // A literal cannot span lines, so an unterminated one ends with its
336
+ // line instead of swallowing the file.
337
+ { match: '$', pop: true },
338
+ ],
339
+ },
340
+ /** A double-quoted string, escaping its quote the same way. */
341
+ 'string-double': {
342
+ default: 'string',
343
+ rules: [
344
+ { match: '""', scope: 'string.escape' },
345
+ { include: 'string-body' },
346
+ { match: '"', scope: 'string', pop: true },
347
+ { match: '$', pop: true },
348
+ ],
349
+ },
350
+ },
351
+ };
352
+ export default matlab;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const mojo: Grammar;
3
+ export default mojo;
4
+ //# sourceMappingURL=mojo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mojo.d.ts","sourceRoot":"","sources":["../../src/langs/mojo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAoC5C,QAAA,MAAM,IAAI,EAAE,OAiVX,CAAA;AAED,eAAe,IAAI,CAAA"}