@scalar/highlight 0.3.1 → 0.5.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 (78) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +52 -13
  3. package/dist/all.d.ts.map +1 -1
  4. package/dist/all.js +2 -0
  5. package/dist/compat/languages.d.ts.map +1 -1
  6. package/dist/compat/languages.js +2 -4
  7. package/dist/compat/syntax-highlight.d.ts.map +1 -1
  8. package/dist/compat/syntax-highlight.js +101 -27
  9. package/dist/core/compile.d.ts +9 -1
  10. package/dist/core/compile.d.ts.map +1 -1
  11. package/dist/core/compile.js +168 -9
  12. package/dist/core/index.d.ts +1 -0
  13. package/dist/core/index.d.ts.map +1 -1
  14. package/dist/core/index.js +1 -0
  15. package/dist/core/tokenize.d.ts.map +1 -1
  16. package/dist/core/tokenize.js +147 -7
  17. package/dist/core/types.d.ts +76 -1
  18. package/dist/core/types.d.ts.map +1 -1
  19. package/dist/core/types.js +5 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +1 -0
  23. package/dist/langs/bash.d.ts.map +1 -1
  24. package/dist/langs/bash.js +60 -13
  25. package/dist/langs/cpp.d.ts.map +1 -1
  26. package/dist/langs/cpp.js +8 -0
  27. package/dist/langs/csharp.d.ts.map +1 -1
  28. package/dist/langs/csharp.js +11 -5
  29. package/dist/langs/css.d.ts.map +1 -1
  30. package/dist/langs/css.js +111 -9
  31. package/dist/langs/diff.d.ts +2 -1
  32. package/dist/langs/diff.d.ts.map +1 -1
  33. package/dist/langs/diff.js +19 -7
  34. package/dist/langs/go.d.ts.map +1 -1
  35. package/dist/langs/go.js +22 -1
  36. package/dist/langs/haskell.d.ts.map +1 -1
  37. package/dist/langs/haskell.js +33 -0
  38. package/dist/langs/html.d.ts +0 -10
  39. package/dist/langs/html.d.ts.map +1 -1
  40. package/dist/langs/html.js +63 -24
  41. package/dist/langs/http.d.ts.map +1 -1
  42. package/dist/langs/http.js +25 -9
  43. package/dist/langs/javascript.d.ts.map +1 -1
  44. package/dist/langs/javascript.js +279 -30
  45. package/dist/langs/json.d.ts.map +1 -1
  46. package/dist/langs/json.js +7 -1
  47. package/dist/langs/julia.d.ts +4 -0
  48. package/dist/langs/julia.d.ts.map +1 -0
  49. package/dist/langs/julia.js +181 -0
  50. package/dist/langs/kotlin.d.ts.map +1 -1
  51. package/dist/langs/kotlin.js +8 -1
  52. package/dist/langs/markdown.d.ts +9 -3
  53. package/dist/langs/markdown.d.ts.map +1 -1
  54. package/dist/langs/markdown.js +127 -6
  55. package/dist/langs/nginx.d.ts.map +1 -1
  56. package/dist/langs/nginx.js +26 -1
  57. package/dist/langs/ocaml.d.ts.map +1 -1
  58. package/dist/langs/ocaml.js +16 -7
  59. package/dist/langs/php.d.ts.map +1 -1
  60. package/dist/langs/php.js +69 -19
  61. package/dist/langs/python.d.ts.map +1 -1
  62. package/dist/langs/python.js +9 -2
  63. package/dist/langs/r.js +9 -9
  64. package/dist/langs/ruby.d.ts.map +1 -1
  65. package/dist/langs/ruby.js +8 -7
  66. package/dist/langs/rust.d.ts.map +1 -1
  67. package/dist/langs/rust.js +27 -11
  68. package/dist/langs/sql.d.ts.map +1 -1
  69. package/dist/langs/sql.js +9 -3
  70. package/dist/langs/swift.d.ts.map +1 -1
  71. package/dist/langs/swift.js +27 -1
  72. package/dist/langs/yaml.d.ts +0 -7
  73. package/dist/langs/yaml.d.ts.map +1 -1
  74. package/dist/langs/yaml.js +157 -28
  75. package/dist/lazy.d.ts +1 -0
  76. package/dist/lazy.d.ts.map +1 -1
  77. package/dist/lazy.js +2 -0
  78. package/package.json +2 -2
package/dist/langs/php.js CHANGED
@@ -8,9 +8,11 @@
8
8
  *
9
9
  * Things worth knowing about:
10
10
  *
11
- * - Heredocs and nowdocs cannot match their own terminator (that needs a
12
- * backreference, which the compiler rejects), so any identifier alone on a
13
- * line closes them. See the `heredoc-end` note.
11
+ * - A snippet that does not open with markup is code. Code samples and
12
+ * docs routinely leave out `<?php`, and reading them as HTML would render
13
+ * the whole sample unscoped.
14
+ * - Heredocs and nowdocs remember their marker, so only the matching marker
15
+ * closes them.
14
16
  * - `#` starts a comment but `#[` starts an attribute, so the attribute rule
15
17
  * runs first and lets the argument list tokenize as ordinary PHP.
16
18
  * - A line comment stops at `?>`, because PHP itself leaves code mode there.
@@ -23,20 +25,38 @@ const ID = '[A-Za-z_\\u0080-\\uFFFF][\\w\\u0080-\\uFFFF]*';
23
25
  const NAME = `\\\\?${ID}(?:\\\\${ID})*`;
24
26
  /** An HTML tag or attribute name, for the inline-markup mode. */
25
27
  const TAG = '[A-Za-z_][\\w:.-]*';
28
+ /**
29
+ * PHP strings and comments own their delimiters: a quoted `?>` cannot end
30
+ * the region, and a quoted `</script>` cannot end its surrounding embed.
31
+ * Each alternative consumes a distinct prefix so unclosed regions stay linear.
32
+ */
33
+ const PHP_REGION = String.raw `<\?(?:php\b|=)(?:"(?:\\[\s\S]|[^"\\])*(?:"|(?![\s\S]))|'(?:\\[\s\S]|[^'\\])*(?:'|(?![\s\S]))|/\*[^*]*(?:\*(?!/)[^*]*)*(?:\*/|(?![\s\S]))|(?:\/\/|#(?!\[))(?:(?!\?>)[^\n])*|[^"'/?#]|/(?![/*])|\?(?!>)|#(?=\[))*(?:\?>|(?![\s\S]))`;
26
34
  const php = {
27
35
  name: 'php',
28
36
  aliases: ['php3', 'php4', 'php5', 'php8'],
29
37
  states: {
30
38
  // ---- inline markup -----------------------------------------------------
31
- // Outside `<?php … ?>` a PHP file is HTML. It is scoped rather than
32
- // highlighted with the HTML grammar — cross-language embedding is not a
33
- // thing the engine does yet — so this covers tags, attributes and comments
34
- // and stops there.
39
+ // Outside `<?php … ?>` a PHP file is HTML. It is scoped here rather than
40
+ // handed to the HTML grammar, because a PHP region can open anywhere in
41
+ // it — inside a tag, inside an attribute value — and an embedded grammar
42
+ // cut off there would lose its place. Only `<script>` and `<style>` bodies,
43
+ // where nothing else in the markup applies, are handed to their languages.
44
+ // Picks the starting mode and is never seen again: input that opens with
45
+ // markup is a template, anything else is code without its `<?php`. Both
46
+ // rules are zero-width, so the first token is tokenized by the mode chosen.
35
47
  root: {
48
+ rules: [
49
+ { match: '(?=\\s*<(?!<<))', set: 'markup' },
50
+ { match: '(?=[\\s\\S])', set: 'code' },
51
+ ],
52
+ },
53
+ markup: {
36
54
  ignoreCase: true,
37
55
  rules: [
38
56
  { match: '<\\?(?:php\\b|=)', scope: 'tag', push: 'php' },
39
57
  { match: '<!--', scope: 'comment', push: 'html-comment' },
58
+ { match: '(<)(script)(?=[\\s/>])', scope: ['punctuation.bracket', 'tag'], push: 'script-tag' },
59
+ { match: '(<)(style)(?=[\\s/>])', scope: ['punctuation.bracket', 'tag'], push: 'style-tag' },
40
60
  {
41
61
  match: `(</?)(${TAG})`,
42
62
  scope: ['punctuation.bracket', 'tag'],
@@ -44,6 +64,36 @@ const php = {
44
64
  },
45
65
  ],
46
66
  },
67
+ // `<script>` and `<style>` bodies are JavaScript and CSS, when those are
68
+ // registered. A PHP region inside one is a hole: the embedded language
69
+ // reads straight across it, so `"<?= $name ?>"` stays inside its string,
70
+ // and the region itself is tokenized as PHP.
71
+ 'script-tag': {
72
+ ignoreCase: true,
73
+ rules: [
74
+ { match: '/>', scope: 'punctuation.bracket', pop: true },
75
+ { match: '>', scope: 'punctuation.bracket', set: 'script-body' },
76
+ { include: 'html-tag' },
77
+ ],
78
+ },
79
+ 'script-body': {
80
+ ignoreCase: true,
81
+ embed: { language: 'javascript', until: '</script(?=[\\s/>])', holes: PHP_REGION },
82
+ rules: [],
83
+ },
84
+ 'style-tag': {
85
+ ignoreCase: true,
86
+ rules: [
87
+ { match: '/>', scope: 'punctuation.bracket', pop: true },
88
+ { match: '>', scope: 'punctuation.bracket', set: 'style-body' },
89
+ { include: 'html-tag' },
90
+ ],
91
+ },
92
+ 'style-body': {
93
+ ignoreCase: true,
94
+ embed: { language: 'css', until: '</style(?=[\\s/>])', holes: PHP_REGION },
95
+ rules: [],
96
+ },
47
97
  /** Markup and PHP block comments. Neither form nests. */
48
98
  'html-comment': {
49
99
  default: 'comment',
@@ -75,6 +125,10 @@ const php = {
75
125
  php: {
76
126
  rules: [{ match: '\\?>', scope: 'tag', pop: true }, { include: 'expression' }],
77
127
  },
128
+ /** Code the input opened with. There is no markup below it to pop back to. */
129
+ code: {
130
+ rules: [{ match: '\\?>', scope: 'tag', set: 'markup' }, { include: 'expression' }],
131
+ },
78
132
  expression: {
79
133
  rules: [
80
134
  // Before the comment rules: `#[` opens an attribute, `#` a comment.
@@ -208,11 +262,12 @@ const php = {
208
262
  rules: [
209
263
  // Nowdoc before heredoc: they differ only by the quotes on the marker,
210
264
  // and only the heredoc interpolates.
211
- { match: `<<<[ \\t]*'${ID}'`, scope: 'string.special', push: 'nowdoc' },
265
+ { match: `<<<[ \\t]*'(${ID})'`, scope: 'string.special', push: 'nowdoc', remember: 1 },
212
266
  {
213
- match: `<<<[ \\t]*"?${ID}"?`,
267
+ match: `<<<[ \\t]*"?(${ID})"?`,
214
268
  scope: 'string.special',
215
269
  push: 'heredoc',
270
+ remember: 1,
216
271
  },
217
272
  { match: '"', scope: 'string', push: 'string-double' },
218
273
  { match: "'", scope: 'string', push: 'string-single' },
@@ -271,21 +326,16 @@ const php = {
271
326
  rules: [{ include: 'escapes' }, { include: 'interpolation' }, { match: '`', scope: 'string', pop: true }],
272
327
  },
273
328
  /**
274
- * The closing marker of a heredoc or a nowdoc.
275
- *
276
- * It cannot be matched against the opening one — that is a backreference,
277
- * and group numbers shift when rules merge — so any identifier alone on a
278
- * line, optionally trailed by the punctuation a heredoc can end with
279
- * (`;`, `,`, `)`, `]`), closes the body. A body line that is a single bare
280
- * word therefore ends it early. That is rare in the SQL, HTML and shell
281
- * text heredocs actually carry, and the alternative is not closing at all.
329
+ * The closing marker of a heredoc or a nowdoc: the remembered opening
330
+ * marker, alone on its line apart from the punctuation a heredoc can end
331
+ * with (`;`, `,`, `)`, `]`). PHP 7.3 lets it be indented with the body.
282
332
  */
283
333
  'heredoc-end': {
284
334
  rules: [
285
335
  // The indent stays string-coloured, so only the marker itself stands
286
- // out — PHP 7.3 lets the closing marker be indented with the body.
336
+ // out.
287
337
  {
288
- match: '^([ \\t]*)([A-Za-z_]\\w*)(?=[ \\t]*[;,)\\]]*[ \\t]*$)',
338
+ match: '^([ \\t]*)({{remembered}})(?![\\w\\u0080-\\uFFFF])',
289
339
  scope: [null, 'string.special'],
290
340
  pop: true,
291
341
  },
@@ -1 +1 @@
1
- {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/langs/python.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA6B5C,QAAA,MAAM,MAAM,EAAE,OAwWb,CAAA;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/langs/python.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA6B5C,QAAA,MAAM,MAAM,EAAE,OA+Wb,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -63,9 +63,16 @@ const python = {
63
63
  },
64
64
  { match: '\\b(?:import|from)\\b', scope: 'keyword.import' },
65
65
  // `match`/`case` are soft keywords: only treat them as control flow in
66
- // the statement shape that introduces a block.
66
+ // the statement shape that introduces a block. A `case` may put its
67
+ // body on the same line (`case 200: return r`). Exclude an assignment
68
+ // (plain, annotated or augmented) immediately after `case`, but allow
69
+ // `=` in class patterns and guards.
67
70
  {
68
- match: '^([ \\t]*)(match|case)\\b(?=[^\\n]*:[ \\t]*(?:#[^\\n]*)?$)',
71
+ match: '^([ \\t]*)(match)\\b(?=[^\\n]*:[ \\t]*(?:#[^\\n]*)?$)',
72
+ scope: [null, 'keyword.control'],
73
+ },
74
+ {
75
+ match: '^([ \\t]*)(case)\\b(?![ \\t]*(?::|(?:\\*\\*|//|<<|>>|[-+*/%@&|^])?=))(?=[ \\t]+[^\\n]*:)',
69
76
  scope: [null, 'keyword.control'],
70
77
  },
71
78
  ],
package/dist/langs/r.js CHANGED
@@ -209,12 +209,13 @@ const r = {
209
209
  strings: {
210
210
  rules: [
211
211
  // A raw string is `r"(…)"`, with any of three bracket pairs and any
212
- // number of dashes for padding. Matching the dashes exactly would need
213
- // a backreference, so the closer accepts any run of them.
212
+ // number of dashes for padding. The dashes are remembered, so only a
213
+ // closer with the same run ends the literal.
214
214
  {
215
- match: '([rR])(["\'][-]*[(\\[{])',
215
+ match: '([rR])(["\'](-*)[(\\[{])',
216
216
  scope: ['string.special', 'string'],
217
217
  push: 'raw-string',
218
+ remember: 3,
218
219
  },
219
220
  { match: '"', scope: 'string', push: 'string-double' },
220
221
  { match: "'", scope: 'string', push: 'string-single' },
@@ -240,7 +241,7 @@ const r = {
240
241
  // R strings may span lines, but an unterminated one should not swallow
241
242
  // the file. Stopping at a blank line is the compromise: it is never
242
243
  // inside a real literal, and it bounds the damage to one paragraph.
243
- { match: '\\n[ \\t]*\\n', pop: true },
244
+ { match: '\\n[ \\t\\r]*\\n', pop: true },
244
245
  ],
245
246
  },
246
247
  'string-single': {
@@ -248,17 +249,16 @@ const r = {
248
249
  rules: [
249
250
  { include: 'string-body' },
250
251
  { match: "'", scope: 'string', pop: true },
251
- { match: '\\n[ \\t]*\\n', pop: true },
252
+ { match: '\\n[ \\t\\r]*\\n', pop: true },
252
253
  ],
253
254
  },
254
255
  /**
255
- * Raw string contents: no escapes, and the closer is a bracket followed by
256
- * the opening quote character. A body holding `)"` — legal, if perverse —
257
- * ends the literal early.
256
+ * Raw string contents: no escapes, and the closer is a bracket, the
257
+ * remembered dashes and a quote.
258
258
  */
259
259
  'raw-string': {
260
260
  default: 'string',
261
- rules: [{ match: '[)\\]}][-]*["\']', pop: true }],
261
+ rules: [{ match: '[)\\]}]{{remembered}}["\']', pop: true }],
262
262
  },
263
263
  },
264
264
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ruby.d.ts","sourceRoot":"","sources":["../../src/langs/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA6D5C,QAAA,MAAM,IAAI,EAAE,OAkVX,CAAA;AAED,eAAe,IAAI,CAAA"}
1
+ {"version":3,"file":"ruby.d.ts","sourceRoot":"","sources":["../../src/langs/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA6D5C,QAAA,MAAM,IAAI,EAAE,OAmVX,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -192,24 +192,25 @@ const ruby = {
192
192
  scope: 'variable.special',
193
193
  },
194
194
  {
195
- match: '\\b(?:puts|pp|print|raise|fail|abort|loop|lambda|proc|format|sprintf|gets|exit|freeze|attr_accessor|attr_reader|attr_writer|define_method|block_given\\?)(?![\\w?!])',
195
+ match: '\\b(?:puts|pp|print|printf|putc|warn|raise|fail|abort|loop|lambda|proc|format|sprintf|gets|readlines?|sleep|rand|srand|exit|at_exit|freeze|attr_accessor|attr_reader|attr_writer|define_method|block_given\\?)(?![\\w?!])',
196
196
  scope: 'function.builtin',
197
197
  },
198
+ // `p x` prints, but `p` is also a common variable name, so it counts
199
+ // only when an argument follows it.
200
+ { match: '\\bp(?=\\(|[ \\t]+[\\w"\':\\[@$])', scope: 'function.builtin' },
198
201
  // A method with a block is still a call, so `.each do |x|` and
199
202
  // `.map { }` count alongside `.push(x)`.
200
203
  {
201
204
  match: `(&?\\.)([ \\t]*)(${ID}[?!]?)(?=[ \\t]*(?:\\(|\\{|do\\b))`,
202
205
  scope: ['punctuation', null, 'function.method'],
203
206
  },
204
- // A `?` or `!` suffix only ever ends a method name.
207
+ // Ruby has no public fields: `.length`, `.to_s` and `.name = x` all
208
+ // call a method, parentheses or not. A `?` or `!` suffix only ever ends
209
+ // a method name.
205
210
  {
206
- match: `(&?\\.)([ \\t]*)(${ID}[?!])`,
211
+ match: `(&?\\.)([ \\t]*)(${ID}[?!]?)`,
207
212
  scope: ['punctuation', null, 'function.method'],
208
213
  },
209
- {
210
- match: `(&?\\.)([ \\t]*)(${ID})`,
211
- scope: ['punctuation', null, 'variable.member'],
212
- },
213
214
  { match: '\\b[A-Z]\\w*(?=::)', scope: 'namespace' },
214
215
  // SCREAMING_CASE reads as a constant, CapWords as a type — between them
215
216
  // that covers module constants, classes and the exception hierarchy
@@ -1 +1 @@
1
- {"version":3,"file":"rust.d.ts","sourceRoot":"","sources":["../../src/langs/rust.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,QAAA,MAAM,IAAI,EAAE,OAsHX,CAAA;AAED,eAAe,IAAI,CAAA"}
1
+ {"version":3,"file":"rust.d.ts","sourceRoot":"","sources":["../../src/langs/rust.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,QAAA,MAAM,IAAI,EAAE,OAsIX,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -12,17 +12,15 @@ const rust = {
12
12
  rules: [
13
13
  { match: '//[/!][^\\n]*', scope: 'comment.doc' },
14
14
  { match: '//[^\\n]*', scope: 'comment' },
15
- { match: '/\\*[\\s\\S]*?\\*/', scope: 'comment' },
16
- // Raw strings, longest hash run first. Beyond two hashes is vanishingly
17
- // rare and would need a backreference to match exactly.
15
+ // Block comments nest in Rust, so the state pushes itself.
16
+ { match: '/\\*', scope: 'comment', push: 'block-comment' },
17
+ // Raw strings close with a quote and as many hashes as opened them,
18
+ // which the state remembers. No escapes inside.
18
19
  {
19
- match: '(b?r##)("[\\s\\S]*?"##)',
20
- scope: ['string.special', 'string'],
21
- },
22
- { match: '(b?r#)("[\\s\\S]*?"#)', scope: ['string.special', 'string'] },
23
- {
24
- match: '(b?r)("(?:[^"\\\\]|\\\\.)*")',
25
- scope: ['string.special', 'string'],
20
+ match: '(b?r)(#*)(")',
21
+ scope: ['string.special', 'string.special', 'string'],
22
+ push: 'raw-string',
23
+ remember: 2,
26
24
  },
27
25
  {
28
26
  match: '(b?)(")',
@@ -53,7 +51,12 @@ const rust = {
53
51
  match: '\\b(?:fn|let|const|static|struct|enum|trait|impl|type|mod|union|async|move|dyn|pub|crate|unsafe|extern|ref|mut|where)\\b',
54
52
  scope: 'keyword.declaration',
55
53
  },
56
- { match: '\\b(?:use|as|super|self|Self)\\b', scope: 'keyword.import' },
54
+ // `r#type` is an identifier spelled like a keyword; claiming it here,
55
+ // where it starts, keeps the keyword rules from matching its tail.
56
+ { match: 'r#[A-Za-z_]\\w*' },
57
+ { match: '\\b(?:use|as|super)\\b', scope: 'keyword.import' },
58
+ { match: '\\bself\\b', scope: 'variable.builtin' },
59
+ { match: '\\bSelf\\b', scope: 'type' },
57
60
  { match: '\\b(?:in|box)\\b', scope: 'keyword.operator' },
58
61
  { match: '\\b(?:true|false)\\b', scope: 'boolean' },
59
62
  { match: '\\b(?:None|Some|Ok|Err)\\b', scope: 'constant.builtin' },
@@ -68,6 +71,8 @@ const rust = {
68
71
  match: '\\b([A-Za-z_]\\w*)(!)',
69
72
  scope: ['function.builtin', 'function.builtin'],
70
73
  },
74
+ // `.await` is a keyword in field position, not a member.
75
+ { match: '(\\.)(await)\\b', scope: ['punctuation', 'keyword.control'] },
71
76
  {
72
77
  match: '(\\.)([A-Za-z_]\\w*)(?=\\s*\\()',
73
78
  scope: ['punctuation', 'function.method'],
@@ -111,6 +116,17 @@ const rust = {
111
116
  { match: '"', scope: 'string', pop: true },
112
117
  ],
113
118
  },
119
+ 'block-comment': {
120
+ default: 'comment',
121
+ rules: [
122
+ { match: '/\\*', scope: 'comment', push: 'block-comment' },
123
+ { match: '\\*/', scope: 'comment', pop: true },
124
+ ],
125
+ },
126
+ 'raw-string': {
127
+ default: 'string',
128
+ rules: [{ match: '"{{remembered}}', scope: 'string', pop: true }],
129
+ },
114
130
  },
115
131
  };
116
132
  export default rust;
@@ -1 +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"}
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,OAqEV,CAAA;AAED,eAAe,GAAG,CAAA"}
package/dist/langs/sql.js CHANGED
@@ -8,7 +8,9 @@ const sql = {
8
8
  rules: [
9
9
  { match: '--[^\\n]*', scope: 'comment' },
10
10
  { match: '#[^\\n]*', scope: 'comment' },
11
- { match: '/\\*[\\s\\S]*?\\*/', scope: 'comment' },
11
+ // A state, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and fails
12
+ // once per opener, which is O(n²) on a run of unterminated `/*`.
13
+ { match: '/\\*', scope: 'comment', push: 'block-comment' },
12
14
  // Doubled quotes are the escape, so a literal never ends early.
13
15
  { match: "'(?:[^']|'')*'", scope: 'string' },
14
16
  { match: '"(?:[^"]|"")*"', scope: 'variable.member' },
@@ -17,7 +19,7 @@ const sql = {
17
19
  // and allowing a bare `[` makes a line of brackets cost O(n) each.
18
20
  { match: '\\[[^[\\]]*\\]', scope: 'variable.member' },
19
21
  {
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',
22
+ 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|declare|print|go|exec|execute|return|returns|while|loop|for|call|connect|prior|merge|matched|raise|exception|elsif|immediate)\\b',
21
23
  scope: 'keyword.control',
22
24
  },
23
25
  {
@@ -31,7 +33,7 @@ const sql = {
31
33
  { match: '\\b(?:null)\\b', scope: 'constant.builtin' },
32
34
  { match: '\\b(?:true|false)\\b', scope: 'boolean' },
33
35
  {
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',
36
+ 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|varchar2|nvarchar2?|nchar|number|binary|varbinary|tinyint|datetime2?|bit|clob|nclob|character|dec|xml)\\b',
35
37
  scope: 'type.builtin',
36
38
  },
37
39
  {
@@ -52,6 +54,10 @@ const sql = {
52
54
  { match: '[,;.]', scope: 'punctuation.delimiter' },
53
55
  ],
54
56
  },
57
+ 'block-comment': {
58
+ default: 'comment',
59
+ rules: [{ match: '\\*/', scope: 'comment', pop: true }],
60
+ },
55
61
  },
56
62
  };
57
63
  export default sql;
@@ -1 +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"}
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,OAmRZ,CAAA;AAED,eAAe,KAAK,CAAA"}
@@ -35,6 +35,7 @@ const swift = {
35
35
  rules: [
36
36
  { include: 'comments' },
37
37
  { include: 'strings' },
38
+ { include: 'regex' },
38
39
  // `@escaping`, `@MainActor`, `@available(iOS 15, *)`. The argument list
39
40
  // is deliberately left as ordinary code so `iOS 15` still reads as one.
40
41
  { match: '@[A-Za-z_]\\w*', scope: 'decorator' },
@@ -72,7 +73,7 @@ const swift = {
72
73
  scope: 'keyword.control',
73
74
  },
74
75
  {
75
- match: '\\b(?:func|var|let|class|struct|enum|protocol|extension|actor|init|deinit|subscript|typealias|associatedtype|operator|precedencegroup|static|final|lazy|weak|unowned|mutating|nonmutating|override|open|public|internal|fileprivate|private|package|required|convenience|indirect|inout|dynamic|async|throws|rethrows|some|any|get|set|willSet|didSet)\\b',
76
+ match: '\\b(?:func|var|let|class|struct|enum|protocol|extension|actor|init|deinit|subscript|typealias|associatedtype|operator|precedencegroup|static|final|lazy|weak|unowned|mutating|nonmutating|override|open|public|internal|fileprivate|private|package|required|convenience|indirect|inout|dynamic|async|throws|rethrows|some|any|get|set|willSet|didSet|nonisolated|isolated|distributed|borrowing|consuming|sending|macro)\\b',
76
77
  scope: 'keyword.declaration',
77
78
  },
78
79
  { match: '\\b(?:is|as|in)\\b', scope: 'keyword.operator' },
@@ -176,6 +177,31 @@ const swift = {
176
177
  { match: '"', scope: 'string', push: 'string' },
177
178
  ],
178
179
  },
180
+ // ---- regex literals ------------------------------------------------------
181
+ regex: {
182
+ rules: [
183
+ // `#/…/#` can span lines and holds a bare `/`; only the `/` followed by
184
+ // as many `#` as opened it closes the literal.
185
+ // Only try at the start of a hash run; retrying each suffix is quadratic
186
+ // when a pasted or incomplete run has no opening slash.
187
+ { match: '(?<!#)(#+)/', scope: 'regexp', push: 'regex-extended', remember: 1 },
188
+ // A bare `/…/` is a regex only where an expression starts, and never
189
+ // with a space just inside either slash, which is how Swift itself
190
+ // tells it apart from division. The lookbehind sits after the `/` so the
191
+ // rule still starts with a literal character.
192
+ {
193
+ match: '/(?<=(?:[=(,:\\[!&|?{]|\\breturn|\\bcase)[ \\t]*/)(?![\\s/*])(?:[^/\\\\\\n]|\\\\.)+(?<!\\s)/',
194
+ scope: 'regexp',
195
+ },
196
+ ],
197
+ },
198
+ 'regex-extended': {
199
+ default: 'regexp',
200
+ rules: [
201
+ { match: '\\\\.', scope: 'regexp' },
202
+ { match: '/{{remembered}}', scope: 'regexp', pop: true },
203
+ ],
204
+ },
179
205
  /** Escape and interpolation rules shared by both ordinary string states. */
180
206
  'string-body': {
181
207
  rules: [
@@ -1,11 +1,4 @@
1
1
  import type { Grammar } from '../core/types.js';
2
- /**
3
- * YAML.
4
- *
5
- * Keys are the load-bearing thing in a YAML file, so they are matched from the
6
- * line start and scoped separately from their values. Block scalars (`|`, `>`)
7
- * switch into a literal state so their contents are not re-parsed as YAML.
8
- */
9
2
  declare const yaml: Grammar;
10
3
  export default yaml;
11
4
  //# sourceMappingURL=yaml.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../src/langs/yaml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,EAAE,OAmIX,CAAA;AAED,eAAe,IAAI,CAAA"}
1
+ {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../src/langs/yaml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAuC5C,QAAA,MAAM,IAAI,EAAE,OAiPX,CAAA;AAED,eAAe,IAAI,CAAA"}