@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,435 @@
1
+ /**
2
+ * Perl.
3
+ *
4
+ * Perl gives most of its punctuation several jobs, so nearly all of this
5
+ * grammar is about telling the readings apart:
6
+ *
7
+ * - `/` opens a pattern only where a term can start, and what says so is the
8
+ * token in front of it — an opener, a delimiter, an operator, or one of the
9
+ * list operators and statement keywords that take a pattern next. That token
10
+ * is matched and scoped along with the pattern rather than looked behind for.
11
+ * The cost is that a `/…/` nobody introduces, such as one opening a
12
+ * statement, reads as division; the gain is that no rule starts with a
13
+ * lookbehind, which is both faster and the only way to see past a newline.
14
+ * - `%` and `&` are sigils only when glued to a name, so `$a % $b` stays modulo
15
+ * and `$a && $b` stays a conjunction. `$total%$count` is read as a hash,
16
+ * which is the price of recognising `%ENV` without demanding a space.
17
+ * - `#` starts a comment unless it is the second character of `$#array`. The
18
+ * `$#` rule starts one character further left, and leftmost-match settles it
19
+ * whatever the rule order is.
20
+ * - `<<` opens a heredoc only when a marker follows it, and the body starts on
21
+ * the *next* line, so `my $sql = <<~SQL;` keeps the rest of the line as code.
22
+ * - Quote-likes get one state per closing delimiter. Matching the opener's
23
+ * partner in a single pattern needs a backreference, which the compiler
24
+ * rejects.
25
+ *
26
+ * Two deliberate gaps follow from that last point. Only `()`, `{}`, `[]` and
27
+ * `/` are recognised as quote-like delimiters: `q!…!`, `m|…|`, `s#…#…#` and the
28
+ * rest of the arbitrary-delimiter zoo render as ordinary code. And `s`/`tr`/`y`
29
+ * take a paired delimiter only as `s{…}{…}` — `s(…)(…)` and `s{…}[…]` leave the
30
+ * replacement half scoped as code.
31
+ *
32
+ * Ordinary barewords deliberately match no rule and inherit the block
33
+ * foreground, which keeps both the markup and the visual noise down.
34
+ */
35
+ /** A bareword, optionally package-qualified: `strict`, `Data::Dumper`. */
36
+ const NAME = '[A-Za-z_]\\w*(?:::\\w+)*';
37
+ /**
38
+ * Leading deref sigils, as in `$$ref` or `$$$ref`. Capped rather than `\$*`
39
+ * because a sigil rule is retried at every position a term could start: an
40
+ * uncapped run over a line of bare `$` backtracks the same way the pattern
41
+ * scans above do, so it is bounded for the same reason they are.
42
+ */
43
+ const DEREF = '\\${0,8}';
44
+ /**
45
+ * The body of a `/`-delimited pattern. The repetition is capped because the
46
+ * rule is retried at every position a term could start: an uncapped scan that
47
+ * runs to the end of a long line and then fails costs O(n²), which is a denial
48
+ * of service rather than a wrong colour. A pattern longer than the cap simply
49
+ * is not recognised.
50
+ */
51
+ const PAT = '(?:[^/\\\\\\n]|\\\\.){0,240}';
52
+ /** Trailing modifiers: `/gi`, `s///ee`, `tr///dr`. */
53
+ const MODS = '[a-z]*';
54
+ /**
55
+ * A bare `/…/` match against `$_`. At least one body character is required so
56
+ * `$x // 5` stays the defined-or operator, and the body is capped for the same
57
+ * reason `PAT` is.
58
+ */
59
+ const REGEX = `/(?:[^/\\\\\\n]|\\\\.){1,240}/${MODS}`;
60
+ /**
61
+ * The operators after which a `/` opens a pattern rather than dividing. `!` is
62
+ * in there for `if (!/x/)`, and `=~`/`!~` come first so the longer spelling
63
+ * wins over the `=` and `!` that start them.
64
+ */
65
+ const BEFORE_REGEX = '=~|!~|=>|&&|\\|\\||[=!]=|[=!?~]';
66
+ /** The single-part quote-likes. Longest first, so `qq(` is not read as `q`. */
67
+ const QUOTE = '\\b(?:qq|qw|qx|qr|q|m)';
68
+ /** The two-part quote-likes: pattern and replacement. */
69
+ const SUBST = '\\b(?:s|tr|y)';
70
+ /**
71
+ * printf-style placeholders, which Perl code is full of.
72
+ *
73
+ * Every quantifier is capped. `0` is both a flag and a width digit, so an
74
+ * uncapped `[-+ 0#]*` splits a run of zeros against the width group at every
75
+ * position and then fails on the missing conversion character — quadratic on a
76
+ * string of zeros, which is untrusted input like any other. The caps are wider
77
+ * than any real format spec.
78
+ */
79
+ const FORMAT = '%[-+ 0#]{0,8}(?:\\d{1,6}|\\*)?(?:\\.\\d{1,6})?[sdfgeExXobcu%]';
80
+ const perl = {
81
+ name: 'perl',
82
+ aliases: ['pl', 'pm'],
83
+ states: {
84
+ root: {
85
+ rules: [
86
+ { match: '^#!.*', scope: 'comment' },
87
+ // POD only starts at column 0, which is also the only place Perl
88
+ // accepts it. Everything up to `=cut` is documentation.
89
+ { match: '^=[a-zA-Z]\\w*', scope: 'comment.doc', push: 'pod' },
90
+ // Whatever follows is data for the script, not source.
91
+ { match: '^__(?:END|DATA)__', scope: 'keyword', push: 'data' },
92
+ { match: '#[^\\n]*', scope: 'comment' },
93
+ // ---- heredocs ------------------------------------------------------
94
+ // The marker is not remembered — that needs a backreference — so the
95
+ // body ends at the first line holding only a bare word.
96
+ {
97
+ match: '(<<~?)(")(\\w+)(")',
98
+ scope: ['operator', 'string', 'string.special', 'string'],
99
+ push: 'heredoc-line',
100
+ },
101
+ {
102
+ match: "(<<~?)(')(\\w+)(')",
103
+ scope: ['operator', 'string', 'string.special', 'string'],
104
+ push: 'heredoc-line-raw',
105
+ },
106
+ {
107
+ match: '(<<~)(\\w+)',
108
+ scope: ['operator', 'string.special'],
109
+ push: 'heredoc-line',
110
+ },
111
+ // An undecorated `<<` has to look like a marker, or `1 << $bits` would
112
+ // swallow the rest of the file.
113
+ {
114
+ match: '(<<)([A-Z_]\\w*)',
115
+ scope: ['operator', 'string.special'],
116
+ push: 'heredoc-line',
117
+ },
118
+ // ---- quoted literals -----------------------------------------------
119
+ { match: '"', scope: 'string', push: 'string-double' },
120
+ { match: "'", scope: 'string', push: 'string-single' },
121
+ { match: '`', scope: 'string', push: 'backtick' },
122
+ // One state per closing delimiter, each tracking its own nesting so
123
+ // `m{\\d{2}}` and `qw(a (b))` close where they should. A `qr{…}` body is
124
+ // scoped as a string rather than a regexp: `regexp` is reserved for the
125
+ // `/…/` forms, which are what read as a pattern at a glance.
126
+ {
127
+ match: `(${QUOTE})(\\()`,
128
+ scope: ['keyword.operator', 'string'],
129
+ push: 'q-paren',
130
+ },
131
+ {
132
+ match: `(${QUOTE})(\\{)`,
133
+ scope: ['keyword.operator', 'string'],
134
+ push: 'q-brace',
135
+ },
136
+ {
137
+ match: `(${QUOTE})(\\[)`,
138
+ scope: ['keyword.operator', 'string'],
139
+ push: 'q-bracket',
140
+ },
141
+ // `s{…}{…}` needs three states because the two halves are separate
142
+ // literals; the `/`-delimited form below fits in one pattern.
143
+ {
144
+ match: `(${SUBST})\\{`,
145
+ scope: ['keyword.operator'],
146
+ rest: 'string',
147
+ push: 'subst',
148
+ },
149
+ // ---- patterns -------------------------------------------------------
150
+ {
151
+ match: `(${SUBST})(/${PAT}/${PAT}/${MODS})`,
152
+ scope: ['keyword.operator', 'regexp'],
153
+ },
154
+ {
155
+ match: `(\\b(?:qr|m))(/${PAT}/${MODS})`,
156
+ scope: ['keyword.operator', 'regexp'],
157
+ },
158
+ // A bare `/…/` is an implicit match against `$_`, and what says it is
159
+ // one is the token in front of it. That token is matched and scoped
160
+ // here rather than looked behind for, the way `ruby.ts` does it: a
161
+ // lookbehind at the head of a rule costs the merged alternation its
162
+ // first-character scan — 10x on whitespace-heavy input — and a bounded
163
+ // one cannot see past a newline or a column-aligning run of spaces, so
164
+ // `$total / $count / 2` came out as a pattern. Anything not
165
+ // listed here ends a term, which makes the `/` a division.
166
+ //
167
+ // `{` is split out so it can still push `brace`. Consuming it without
168
+ // pushing would let a block's `}` close an enclosing `@{…}`.
169
+ {
170
+ match: `([(\\[])(\\s*)(${REGEX})`,
171
+ scope: ['punctuation.bracket', null, 'regexp'],
172
+ },
173
+ {
174
+ match: `(\\{)(\\s*)(${REGEX})`,
175
+ scope: ['punctuation.bracket', null, 'regexp'],
176
+ push: 'brace',
177
+ },
178
+ {
179
+ match: `([,;:])(\\s*)(${REGEX})`,
180
+ scope: ['punctuation.delimiter', null, 'regexp'],
181
+ },
182
+ // The list operators and statement keywords that take a pattern next.
183
+ // Each keeps the scope its own rule further down would have given it.
184
+ {
185
+ match: `(\\b(?:return|if|elsif|unless|while|until|when)\\b)(\\s*)(${REGEX})`,
186
+ scope: ['keyword.control', null, 'regexp'],
187
+ },
188
+ {
189
+ match: `(\\b(?:split|grep|map|push|join|print|die)\\b)(\\s*)(${REGEX})`,
190
+ scope: ['function.builtin', null, 'regexp'],
191
+ },
192
+ {
193
+ match: `(\\b(?:and|or|not)\\b)(\\s*)(${REGEX})`,
194
+ scope: ['keyword.operator', null, 'regexp'],
195
+ },
196
+ {
197
+ match: `(${BEFORE_REGEX})(\\s*)(${REGEX})`,
198
+ scope: ['operator', null, 'regexp'],
199
+ },
200
+ // ---- sigils ---------------------------------------------------------
201
+ // `$#{$ref}` and `$#array` both give the last index of an array.
202
+ { match: '\\$#\\{', scope: 'variable', push: 'deref' },
203
+ { match: `\\$#${DEREF}${NAME}`, scope: 'variable' },
204
+ { match: '[$@%]_(?!\\w)', scope: 'variable.builtin' },
205
+ {
206
+ match: '(?:[@%](?:ARGV|ENV|INC)|\\$(?:0|ARGV))(?!\\w)',
207
+ scope: 'variable.builtin',
208
+ },
209
+ // `${name}` and `@{name}` are just a fenced name; `@{$ref}`, `${\ … }`
210
+ // and the `@{[ … ]}` idiom hold an expression, so they push a state.
211
+ { match: '[$@%]\\{\\^?\\w+\\}', scope: 'variable' },
212
+ { match: `[$@%&]${DEREF}\\{`, scope: 'variable', push: 'deref' },
213
+ { match: `[$@%]${DEREF}${NAME}`, scope: 'variable' },
214
+ // Capture groups and the punctuation variables that show up in real
215
+ // code. `$'` and `` $` `` are left out: mistaking either for a sigil
216
+ // would take the following quote with it.
217
+ {
218
+ match: '\\$(?:\\d+|\\^\\w|[!@/\\\\,;.&+])',
219
+ scope: 'variable.builtin',
220
+ },
221
+ // `&` is a code sigil only when glued to a name and not sitting after
222
+ // something that could be its left operand, which is what keeps the
223
+ // second `&` of `$a && $b` out of it. The lookbehind sits after the
224
+ // `&` rather than in front: it says the same thing either way, but this
225
+ // order leaves the rule a known first character, so the merged
226
+ // alternation keeps its first-character scan.
227
+ { match: `&(?<![\\w$)\\]}&]&)${DEREF}${NAME}`, scope: 'function.call' },
228
+ // `<$fh>`, `<STDIN>`, `<>` — readline, not a comparison. The `\\w*`
229
+ // never spans a space, so `$a < $b > $c` is unaffected.
230
+ { match: '<\\$?\\w*>', scope: 'variable.builtin' },
231
+ // ---- names -----------------------------------------------------------
232
+ {
233
+ match: `(->)(${NAME})(?=[ \\t]*\\()`,
234
+ scope: ['operator', 'function.method'],
235
+ },
236
+ { match: `(->)(${NAME})`, scope: ['operator', 'variable.member'] },
237
+ // A bareword subscript is auto-quoted: `$row{sku}`. The rule cannot see
238
+ // what the `{` is glued to, so a space-free one-statement block —
239
+ // `if ($x) {next}` — reads as a subscript and colours `next` a
240
+ // property. A hash lookup is far more common than that spelling, and
241
+ // the usual `{ next }` keeps its keyword because a space is not a word
242
+ // character.
243
+ {
244
+ match: '(\\{)(-?\\w+)(\\})',
245
+ scope: ['punctuation.bracket', 'property', 'punctuation.bracket'],
246
+ },
247
+ // So is the left side of a fat comma. Before the keyword rules, so
248
+ // `(if => 1)` reads as a key.
249
+ { match: '\\b[A-Za-z_]\\w*(?=[ \\t]*=>)', scope: 'property' },
250
+ {
251
+ match: `(\\bpackage)([ \\t]+)(${NAME})`,
252
+ scope: ['keyword.declaration', null, 'namespace'],
253
+ },
254
+ // `(?!v\\d)` keeps `use v5.36` out, so the version stays a number.
255
+ {
256
+ match: `(\\b(?:use|no|require))([ \\t]+)((?!v\\d)${NAME})`,
257
+ scope: ['keyword.import', null, 'namespace'],
258
+ },
259
+ { match: '\\b(?:use|no|require)\\b', scope: 'keyword.import' },
260
+ // `NAME`, not `\w+`, so `sub Foo::bar {}` names the whole sub the way
261
+ // `package Foo::bar` already does.
262
+ {
263
+ match: `(\\bsub)([ \\t]+)(${NAME})`,
264
+ scope: ['keyword.declaration', null, 'function'],
265
+ },
266
+ {
267
+ match: '\\b(?:if|elsif|else|unless|while|until|foreach|for|do|last|next|redo|return|goto|given|when|eval)\\b',
268
+ scope: 'keyword.control',
269
+ },
270
+ {
271
+ match: '\\b(?:sub|my|our|local|state|package)\\b',
272
+ scope: 'keyword.declaration',
273
+ },
274
+ { match: '\\b(?:BEGIN|END|AUTOLOAD|DESTROY)\\b', scope: 'keyword' },
275
+ {
276
+ match: '\\b(?:xor|cmp|and|or|not|eq|ne|lt|gt|le|ge|x)\\b',
277
+ scope: 'keyword.operator',
278
+ },
279
+ { match: '\\bundef\\b', scope: 'constant.builtin' },
280
+ {
281
+ match: '\\b__(?:PACKAGE|FILE|LINE|SUB)__\\b',
282
+ scope: 'variable.special',
283
+ },
284
+ { match: '\\b(?:STDIN|STDOUT|STDERR)\\b', scope: 'variable.builtin' },
285
+ {
286
+ match: '\\b(?:sprintf|printf|print|say|push|pop|shift|unshift|splice|keys|values|each|exists|delete|defined' +
287
+ '|ref|bless|die|warn|join|split|grep|map|sort|reverse|scalar|wantarray|chomp|lcfirst|ucfirst|lc|uc' +
288
+ '|length|substr|index|open|close|abs|int|sqrt|time|localtime|exit)\\b',
289
+ scope: 'function.builtin',
290
+ },
291
+ // ---- numbers ---------------------------------------------------------
292
+ { match: '\\b0[xX][0-9a-fA-F_]+\\b', scope: 'number' },
293
+ { match: '\\b0[bB][01_]+\\b', scope: 'number' },
294
+ // `0o644` since 5.34, `0644` since forever.
295
+ { match: '\\b0[oO]?[0-7_]+\\b', scope: 'number' },
296
+ // A v-string: `use v5.36`, `our $VERSION = v1.2.3`.
297
+ { match: '\\bv\\d+(?:\\.\\d+)+\\b', scope: 'number' },
298
+ {
299
+ match: '\\b\\d[\\d_]*(?:\\.\\d[\\d_]*)?(?:[eE][-+]?\\d+)?\\b',
300
+ scope: 'number',
301
+ },
302
+ // A qualified name: `Data::Dumper->new`, `List::Util::sum`.
303
+ { match: '\\b[A-Za-z_]\\w*(?=::)', scope: 'namespace' },
304
+ // SCREAMING_CASE reads as a constant, CapWords as a class — between them
305
+ // that covers `use constant` names and every package name without
306
+ // shipping a list.
307
+ { match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
308
+ { match: '\\b[A-Z]\\w*', scope: 'type' },
309
+ { match: '\\b[a-z_]\\w*(?=[ \\t]*\\()', scope: 'function.call' },
310
+ // ---- syntax ----------------------------------------------------------
311
+ // Every `{` pushes, so a `}` always closes the thing that opened it and
312
+ // cannot end a `@{…}` dereference early.
313
+ { match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
314
+ {
315
+ match: '<=>|=~|!~|->|=>|\\+\\+|--|\\*\\*=?|\\|\\|=?|&&=?|//=?|<<=?|>>=?|\\.\\.\\.?|::' +
316
+ '|[-+*/%.^&|]=|[<>!=]=|[-+*/%.!~\\\\^&|<>=?]',
317
+ scope: 'operator',
318
+ },
319
+ { match: '[()\\[\\]}]', scope: 'punctuation.bracket' },
320
+ { match: '[,;:]', scope: 'punctuation.delimiter' },
321
+ ],
322
+ },
323
+ pod: {
324
+ default: 'comment.doc',
325
+ rules: [{ match: '^=cut[^\\n]*', pop: true }],
326
+ },
327
+ /** Everything after `__END__`. No rules: the whole tail is one run. */
328
+ data: {
329
+ default: 'comment',
330
+ rules: [],
331
+ },
332
+ // ---- string interiors ----------------------------------------------------
333
+ /**
334
+ * Shared by every interpolating literal. A non-interpolating one (`q{…}`,
335
+ * `'…'` aside) shares it too, so `q{$x}` shows `$x` as a variable — the
336
+ * price of three delimiter states instead of six.
337
+ */
338
+ interp: {
339
+ rules: [
340
+ {
341
+ match: '\\\\(?:x\\{[0-9a-fA-F]{1,8}\\}|x[0-9a-fA-F]{1,2}|[0-7]{1,3}|N\\{[^}\\n]{0,60}\\}|.)',
342
+ scope: 'string.escape',
343
+ },
344
+ { match: FORMAT, scope: 'string.special' },
345
+ { match: `\\$#${DEREF}${NAME}`, scope: 'variable' },
346
+ { match: '[$@]\\{\\^?\\w+\\}', scope: 'variable' },
347
+ { match: `[$@]${DEREF}\\{`, scope: 'variable', push: 'deref' },
348
+ // A subscript chain is part of the interpolation: `$row->{tags}[0]`.
349
+ // Every scan is capped so a line of `${` cannot go quadratic.
350
+ {
351
+ match: `[$@]${DEREF}(?:${NAME}|\\d+)(?:(?:->)?(?:\\[[^\\]\\n]{0,80}\\]|\\{[^}\\n]{0,80}\\})){0,6}`,
352
+ scope: 'variable',
353
+ },
354
+ ],
355
+ },
356
+ 'string-double': {
357
+ default: 'string',
358
+ // Nothing pops at the line break: a Perl string really does span lines.
359
+ rules: [{ include: 'interp' }, { match: '"', pop: true }],
360
+ },
361
+ 'string-single': {
362
+ default: 'string',
363
+ rules: [
364
+ { match: "\\\\['\\\\]", scope: 'string.escape' },
365
+ { match: "'", pop: true },
366
+ ],
367
+ },
368
+ backtick: {
369
+ default: 'string',
370
+ rules: [{ include: 'interp' }, { match: '`', pop: true }],
371
+ },
372
+ // Nesting is tracked per delimiter family so a balanced inner pair does not
373
+ // close the literal. Trailing modifiers on `m{…}i` are left unscoped: the
374
+ // same states serve `q{…}`, where a following letter is the `x` operator.
375
+ 'q-paren': {
376
+ default: 'string',
377
+ rules: [{ match: '\\(', push: 'q-paren' }, { match: '\\)', pop: true }, { include: 'interp' }],
378
+ },
379
+ 'q-brace': {
380
+ default: 'string',
381
+ rules: [{ match: '\\{', push: 'q-brace' }, { match: '\\}', pop: true }, { include: 'interp' }],
382
+ },
383
+ 'q-bracket': {
384
+ default: 'string',
385
+ rules: [{ match: '\\[', push: 'q-bracket' }, { match: '\\]', pop: true }, { include: 'interp' }],
386
+ },
387
+ /** The pattern half of `s{…}{…}`; its closer hands over to `subst-mid`. */
388
+ subst: {
389
+ default: 'string',
390
+ rules: [{ match: '\\{', push: 'q-brace' }, { match: '\\}', set: 'subst-mid' }, { include: 'interp' }],
391
+ },
392
+ /**
393
+ * Between the halves. Perl allows whitespace and even a newline here, so
394
+ * this waits for the second `{`; anything else means there was no second
395
+ * half and the literal is already over.
396
+ */
397
+ 'subst-mid': {
398
+ rules: [
399
+ { match: '([ \\t\\n]*)(\\{)', scope: [null, 'string'], set: 'subst-2' },
400
+ { match: '(?=[\\s\\S])', pop: true },
401
+ ],
402
+ },
403
+ 'subst-2': {
404
+ default: 'string',
405
+ rules: [{ match: '\\{', push: 'q-brace' }, { match: `\\}${MODS}`, pop: true }, { include: 'interp' }],
406
+ },
407
+ // ---- heredocs -------------------------------------------------------------
408
+ /** The rest of the opening line is code; the body starts after the newline. */
409
+ 'heredoc-line': {
410
+ rules: [{ match: '\\n', set: 'heredoc' }, { include: 'root' }],
411
+ },
412
+ 'heredoc-line-raw': {
413
+ rules: [{ match: '\\n', set: 'heredoc-raw' }, { include: 'root' }],
414
+ },
415
+ heredoc: {
416
+ default: 'string',
417
+ rules: [{ match: '^[ \\t]*\\w+[ \\t]*$', scope: 'string.special', pop: true }, { include: 'interp' }],
418
+ },
419
+ /** `<<'EOF'`: the body is literal, so no escapes and no interpolation. */
420
+ 'heredoc-raw': {
421
+ default: 'string',
422
+ rules: [{ match: '^[ \\t]*\\w+[ \\t]*$', scope: 'string.special', pop: true }],
423
+ },
424
+ // ---- balanced nesting -----------------------------------------------------
425
+ /** The inside of `@{…}` / `${…}` / `$#{…}`: an expression, then the closer. */
426
+ deref: {
427
+ rules: [{ match: '\\}', scope: 'variable', pop: true }, { include: 'root' }],
428
+ },
429
+ /** Tracks brace depth so a block or a hash cannot close an enclosing state. */
430
+ brace: {
431
+ rules: [{ match: '\\}', scope: 'punctuation.bracket', pop: true }, { include: 'root' }],
432
+ },
433
+ },
434
+ };
435
+ export default perl;
@@ -0,0 +1,4 @@
1
+ import type { Grammar } from '../core/types.js';
2
+ declare const php: Grammar;
3
+ export default php;
4
+ //# sourceMappingURL=php.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"php.d.ts","sourceRoot":"","sources":["../../src/langs/php.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA+B5C,QAAA,MAAM,GAAG,EAAE,OAyUV,CAAA;AAED,eAAe,GAAG,CAAA"}