@scalar/highlight 0.4.0 → 0.6.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.
- package/CHANGELOG.md +40 -0
- package/README.md +26 -8
- package/dist/all.d.ts.map +1 -1
- package/dist/all.js +2 -0
- package/dist/compat/hljs.d.ts.map +1 -1
- package/dist/compat/hljs.js +1 -0
- package/dist/compat/languages.d.ts.map +1 -1
- package/dist/compat/languages.js +1 -4
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +50 -5
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +11 -4
- package/dist/core/scopes.d.ts +3 -1
- package/dist/core/scopes.d.ts.map +1 -1
- package/dist/core/scopes.js +3 -1
- package/dist/core/tokenize.d.ts.map +1 -1
- package/dist/core/tokenize.js +5 -1
- package/dist/core/types.d.ts +3 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/langs/cpp.d.ts.map +1 -1
- package/dist/langs/cpp.js +8 -0
- package/dist/langs/csharp.d.ts.map +1 -1
- package/dist/langs/csharp.js +16 -11
- package/dist/langs/css.d.ts.map +1 -1
- package/dist/langs/css.js +27 -2
- package/dist/langs/curl.d.ts +4 -0
- package/dist/langs/curl.d.ts.map +1 -0
- package/dist/langs/curl.js +60 -0
- package/dist/langs/diff.d.ts +2 -1
- package/dist/langs/diff.d.ts.map +1 -1
- package/dist/langs/diff.js +19 -7
- package/dist/langs/go.d.ts.map +1 -1
- package/dist/langs/go.js +23 -0
- package/dist/langs/haskell.d.ts.map +1 -1
- package/dist/langs/haskell.js +33 -0
- package/dist/langs/java.d.ts.map +1 -1
- package/dist/langs/java.js +17 -10
- package/dist/langs/javascript.d.ts.map +1 -1
- package/dist/langs/javascript.js +149 -4
- package/dist/langs/kotlin.d.ts.map +1 -1
- package/dist/langs/kotlin.js +8 -1
- package/dist/langs/nginx.d.ts.map +1 -1
- package/dist/langs/nginx.js +26 -1
- package/dist/langs/powershell.d.ts.map +1 -1
- package/dist/langs/powershell.js +4 -1
- package/dist/langs/python.d.ts.map +1 -1
- package/dist/langs/python.js +9 -2
- package/dist/langs/ruby.d.ts.map +1 -1
- package/dist/langs/ruby.js +8 -7
- package/dist/langs/rust.d.ts.map +1 -1
- package/dist/langs/rust.js +15 -1
- package/dist/langs/swift.d.ts.map +1 -1
- package/dist/langs/swift.js +27 -1
- package/dist/lazy.d.ts +1 -0
- package/dist/lazy.d.ts.map +1 -1
- package/dist/lazy.js +1 -1
- package/dist/style.css +1 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @scalar/highlight
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#9939](https://github.com/scalar/scalar/pull/9939): Add a dedicated `curl` grammar, so curl command lines keep the colouring they had under `@scalar/code-highlight`.
|
|
8
|
+
|
|
9
|
+
`curl` was mapped to the bash grammar. That is a defensible reading — a curl invocation is a shell command line — but it loses the two tokens a reader actually looks for. `@scalar/code-highlight` ships a bespoke curl grammar, and `code.css` is written against it: `.hljs.language-curl .hljs-literal` and `.hljs.language-curl .hljs-string` both have curl-specific rules. Under bash, `curl` and the request method came out unscoped, so the command name lost its keyword colour and `POST` lost its symbol colour entirely.
|
|
10
|
+
|
|
11
|
+
The new grammar mirrors the reference: the command is a keyword, `--request`/`-X` and other flags are literals, the method they carry is a symbol, and `$(…)` inside a double-quoted value reads as a variable. Output now matches the reference class for class.
|
|
12
|
+
|
|
13
|
+
This also adds a `symbol` scope to the vocabulary, mapped to `hljs-symbol` in the compat layer — a scope highlight.js has and `code.css` already styles, and the natural home for Ruby symbols and Erlang atoms too.
|
|
14
|
+
|
|
15
|
+
A curl sample joins the shared test corpus, so the differential suites compare this grammar against the reference on every run.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#9939](https://github.com/scalar/scalar/pull/9939): feat(highlight): colour the names declarations bind in Java, C#, Go and Rust, and PowerShell parameters like shell flags
|
|
20
|
+
- [#10721](https://github.com/scalar/scalar/pull/10721): Update compatible dependencies while retaining the existing Node.js support and five-day release-age policy.
|
|
21
|
+
- [#9939](https://github.com/scalar/scalar/pull/9939): Fix JavaScript comparisons read as generic calls, and keep compiled grammars when a grammar is registered again
|
|
22
|
+
|
|
23
|
+
An identifier followed by `<` read as the start of a generic call, so `count` in `if (count <= max)` and `b` in `b <= 10` were painted as function names. The generic branch now requires a type argument list that closes and is followed by `(`, so `useState<number>(0)` still scopes and a comparison does not.
|
|
24
|
+
|
|
25
|
+
`registerLanguage` also evicted a grammar's compiled form whenever it was called, even with the grammar already registered under every one of its names. A caller that registers on every render recompiled on every render, which cost close to twenty times the highlight itself. Registering the same grammar again is now a no-op.
|
|
26
|
+
|
|
27
|
+
## 0.5.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- [#10668](https://github.com/scalar/scalar/pull/10668): feat: close more gaps with TextMate grammars, and highlight faster
|
|
32
|
+
- Engine: only the wrapper group around each rule captures in a state's merged regex. Past 63 capture groups V8 allocates on every match, which cost large grammars such as C, C++, C#, PHP, Ruby and Python a third of their throughput or more.
|
|
33
|
+
- CSS: `var(--brand)` has the same scope as the `--brand:` it refers to. SCSS `$name` and Less `@name` read whole where they are used, and `$brand: red` at the top level reads as a value rather than a selector.
|
|
34
|
+
- JavaScript/TypeScript: the names in a parameter list read as parameters, destructuring and annotations included; `function f()` names a definition; `with { type: 'json' }` on an import is a keyword.
|
|
35
|
+
- Swift: `#/…/#` and `/…/` regex literals, and the `nonisolated`, `isolated`, `distributed`, `borrowing`, `consuming`, `sending` and `macro` modifiers.
|
|
36
|
+
- Diff: context (`diff -c`) and normal (`diff`) formats, svn `Index:` headers, and `#` comment lines.
|
|
37
|
+
- Ruby: a method called without parentheses, `list.length`, reads as a call, and `p`, `printf`, `warn` and friends as builtins.
|
|
38
|
+
- Go: a package-qualified type, `w http.ResponseWriter` or `*testing.T`, reads as a type where a type goes.
|
|
39
|
+
- nginx: log levels, event methods, rewrite flags, and the names of `upstream` and `map` blocks.
|
|
40
|
+
- Haskell: the names in an import list. Kotlin: `package` and `import` paths, and `tailrec`, `external` and `value class`. C++: calls with explicit template arguments, `any_cast<int>(x)`.
|
|
41
|
+
- Rust: `.await` is a keyword, `self` the receiver and `Self` a type, and `r#type` stays a name. Python: `case 200: return x` with its body on the same line is a keyword. TypeScript: `const id = <T,>(x: T) => x` names a function.
|
|
42
|
+
|
|
3
43
|
## 0.4.0
|
|
4
44
|
|
|
5
45
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
# @scalar/highlight
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@scalar/highlight)
|
|
4
|
+
[](https://www.npmjs.com/package/@scalar/highlight)
|
|
5
|
+
[](https://www.npmjs.com/package/@scalar/highlight)
|
|
6
|
+
[](https://discord.gg/scalar)
|
|
7
|
+
|
|
3
8
|
Scalar's code highlighter.
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
<picture>
|
|
11
|
+
<source
|
|
12
|
+
media="(prefers-color-scheme: dark)"
|
|
13
|
+
srcset="https://github.com/user-attachments/assets/380abb34-8814-4b34-8926-19ab84a91d79">
|
|
14
|
+
<img
|
|
15
|
+
alt="Python, TypeScript, Rust and HTTP highlighted by @scalar/highlight"
|
|
16
|
+
src="https://github.com/user-attachments/assets/8ac62023-f56c-4dcd-a7e3-d0272a43c610">
|
|
17
|
+
</picture>
|
|
18
|
+
|
|
19
|
+
- **Small.** 3.5 KB core, ~1.7 KB for Python, gzipped. Nothing you do not import.
|
|
6
20
|
- **No theme system.** Colors come from the `--scalar-*` variables `@scalar/themes` already defines, so a code block follows the app's theme and switches with `.light-mode` / `.dark-mode` — without being re-highlighted.
|
|
7
21
|
- **Zero runtime dependencies.**
|
|
8
22
|
|
|
@@ -43,7 +57,7 @@ highlight(source, 'rust');
|
|
|
43
57
|
```
|
|
44
58
|
|
|
45
59
|
Every entry in the loader is a static `import()`, so bundlers split each language into its
|
|
46
|
-
own chunk. The initial chunk with the loader and no languages is
|
|
60
|
+
own chunk. The initial chunk with the loader and no languages is 5.0 KB.
|
|
47
61
|
|
|
48
62
|
### Entry points
|
|
49
63
|
|
|
@@ -83,12 +97,12 @@ re-exporting it, so tree-shaking runs the way it does in a real app.
|
|
|
83
97
|
|
|
84
98
|
| Bundle | Gzipped |
|
|
85
99
|
| --- | ---: |
|
|
86
|
-
| `@scalar/highlight` core | 3.
|
|
87
|
-
| …+ Python | 5.
|
|
88
|
-
| …lazy loader, initial chunk |
|
|
100
|
+
| `@scalar/highlight` core | 3.50 KB |
|
|
101
|
+
| …+ Python | 5.44 KB |
|
|
102
|
+
| …lazy loader, initial chunk | 5.05 KB |
|
|
89
103
|
| …`style.css` | 1.26 KB |
|
|
90
104
|
|
|
91
|
-
Per language, on top of the core: `diff` 0.
|
|
105
|
+
Per language, on top of the core: `diff` 0.21 KB · `json` 0.29 KB · `html` 0.53 KB · `http` 0.67 KB · `nginx` 0.69 KB · `ini` 0.70 KB · `graphql` 0.73 KB · `css` 0.79 KB · `yaml` 0.82 KB · `rust` 0.88 KB · `go` 0.90 KB · `makefile` 0.90 KB · `markdown` 0.91 KB · `dockerfile` 0.95 KB · `bash` 1.03 KB · `sql` 1.11 KB · `java` 1.15 KB · `dart` 1.17 KB · `lua` 1.19 KB · `r` 1.28 KB · `c` 1.31 KB · `clojure` 1.32 KB · `scala` 1.36 KB · `julia` 1.37 KB · `elixir` 1.38 KB · `kotlin` 1.38 KB · `powershell` 1.38 KB · `matlab` 1.43 KB · `objectivec` 1.43 KB · `swift` 1.44 KB · `ocaml` 1.45 KB · `haskell` 1.50 KB · `csharp` 1.52 KB · `mojo` 1.54 KB · `fsharp` 1.68 KB · `python` 1.71 KB · `ruby` 1.74 KB · `cpp` 1.78 KB · `perl` 1.87 KB · `php` 2.01 KB · `javascript` 2.11 KB.
|
|
92
106
|
|
|
93
107
|
Reproduce with `pnpm size`.
|
|
94
108
|
|
|
@@ -297,7 +311,7 @@ For the same three languages `ScalarCodeBlock` shows most often:
|
|
|
297
311
|
| | gzipped |
|
|
298
312
|
| --- | ---: |
|
|
299
313
|
| `@scalar/code-highlight` | 127.58 KB |
|
|
300
|
-
| `@scalar/highlight/compat` | 7.
|
|
314
|
+
| `@scalar/highlight/compat` | 7.67 KB |
|
|
301
315
|
|
|
302
316
|
## Trade-offs
|
|
303
317
|
|
|
@@ -358,6 +372,10 @@ devDependencies and neither reaches consumers.
|
|
|
358
372
|
|
|
359
373
|
Repository-wide conventions live in the root [`AGENTS.md`](../../AGENTS.md).
|
|
360
374
|
|
|
375
|
+
## Community
|
|
376
|
+
|
|
377
|
+
We are API nerds. You too? Let's chat on Discord: <https://discord.gg/scalar>
|
|
378
|
+
|
|
361
379
|
## License
|
|
362
380
|
|
|
363
|
-
MIT
|
|
381
|
+
The source code in this repository is licensed under [MIT](https://github.com/scalar/scalar/blob/main/LICENSE).
|
package/dist/all.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../src/all.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../src/all.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AA4C3C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,OAAO,EA2C9B,CAAA;AAID;;;;;;;GAOG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3E,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5D,YAAY,EACV,eAAe,EACf,IAAI,EACJ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,SAAS,EACT,KAAK,GACN,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/all.js
CHANGED
|
@@ -5,6 +5,7 @@ import clojure from './langs/clojure.js';
|
|
|
5
5
|
import cpp from './langs/cpp.js';
|
|
6
6
|
import csharp from './langs/csharp.js';
|
|
7
7
|
import css from './langs/css.js';
|
|
8
|
+
import curl from './langs/curl.js';
|
|
8
9
|
import dart from './langs/dart.js';
|
|
9
10
|
import diff from './langs/diff.js';
|
|
10
11
|
import dockerfile from './langs/dockerfile.js';
|
|
@@ -54,6 +55,7 @@ export const languages = [
|
|
|
54
55
|
cpp,
|
|
55
56
|
csharp,
|
|
56
57
|
css,
|
|
58
|
+
curl,
|
|
57
59
|
dart,
|
|
58
60
|
diff,
|
|
59
61
|
dockerfile,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hljs.d.ts","sourceRoot":"","sources":["../../src/compat/hljs.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"hljs.d.ts","sourceRoot":"","sources":["../../src/compat/hljs.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAoE/C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,IAYlD,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/compat/hljs.js
CHANGED
|
@@ -33,6 +33,7 @@ const HLJS_CLASSES = {
|
|
|
33
33
|
'variable.parameter': 'hljs-params',
|
|
34
34
|
'variable.member': 'hljs-property',
|
|
35
35
|
'variable.special': 'hljs-variable',
|
|
36
|
+
symbol: 'hljs-symbol',
|
|
36
37
|
// --- keywords -------------------------------------------------------------
|
|
37
38
|
keyword: 'hljs-keyword',
|
|
38
39
|
'keyword.control': 'hljs-keyword',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"languages.d.ts","sourceRoot":"","sources":["../../src/compat/languages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQ3D,CAAA;
|
|
1
|
+
{"version":3,"file":"languages.d.ts","sourceRoot":"","sources":["../../src/compat/languages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQ3D,CAAA;AA0HD;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,keAoD1B,CAAA;AAEV,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,EAEzB,MAAM,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;AAE/C,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAAiE,CAAA;AAE1G;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAK5C,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,eAAe,GAAG,SAG3D,CAAA"}
|
package/dist/compat/languages.js
CHANGED
|
@@ -36,10 +36,7 @@ const GRAMMAR_FOR = {
|
|
|
36
36
|
cs: 'csharp',
|
|
37
37
|
csharp: 'csharp',
|
|
38
38
|
css: 'css',
|
|
39
|
-
|
|
40
|
-
// honest answer. `code.css` still targets `.hljs.language-curl` by name —
|
|
41
|
-
// the class comes from what the caller asked for, not from the grammar.
|
|
42
|
-
curl: 'bash',
|
|
39
|
+
curl: 'curl',
|
|
43
40
|
cxx: 'cpp',
|
|
44
41
|
dart: 'dart',
|
|
45
42
|
diff: 'diff',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/core/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgB,aAAa,EAAE,OAAO,EAAmB,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/core/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgB,aAAa,EAAE,OAAO,EAAmB,MAAM,SAAS,CAAA;AA+QrG;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,aAAa,EAAE,OAAO,MAAM,KAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;CAmBxG,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,KAAG,eAmC1C,CAAA"}
|
package/dist/core/compile.js
CHANGED
|
@@ -8,7 +8,8 @@ import { REMEMBERED } from './types.js';
|
|
|
8
8
|
* is skipped inside the regex engine rather than by a JS loop.
|
|
9
9
|
*
|
|
10
10
|
* Each rule is wrapped in its own group so that, after a match, we can tell
|
|
11
|
-
* which alternative won by finding the first defined wrapper group.
|
|
11
|
+
* which alternative won by finding the first defined wrapper group. That
|
|
12
|
+
* wrapper is the only group that captures; see `uncapture`.
|
|
12
13
|
*/
|
|
13
14
|
const BACKREF = /\\(?:[1-9]|k<)/;
|
|
14
15
|
/** Counts capture groups in a pattern, ignoring escapes and character classes. */
|
|
@@ -47,6 +48,50 @@ const countGroups = (src) => {
|
|
|
47
48
|
}
|
|
48
49
|
return count;
|
|
49
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Turns every capture group in a pattern into a non-capturing one.
|
|
53
|
+
*
|
|
54
|
+
* Only the wrapper group around each rule has to capture in the merged regex,
|
|
55
|
+
* to say which rule won. A rule's own groups are read back from its sticky
|
|
56
|
+
* `own` pattern, so in the merged regex they would only cost: V8 keeps the
|
|
57
|
+
* match offsets of up to 63 groups in a preallocated buffer and allocates a
|
|
58
|
+
* fresh one on every `exec` past that, which is a fifth of the throughput of
|
|
59
|
+
* a large state such as JavaScript's.
|
|
60
|
+
*/
|
|
61
|
+
const uncapture = (src) => {
|
|
62
|
+
let out = '';
|
|
63
|
+
let inClass = false;
|
|
64
|
+
for (let i = 0; i < src.length; i++) {
|
|
65
|
+
const c = src[i];
|
|
66
|
+
if (c === '\\') {
|
|
67
|
+
out += c + (src[i + 1] ?? '');
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
else if (inClass) {
|
|
71
|
+
inClass = c !== ']';
|
|
72
|
+
out += c;
|
|
73
|
+
}
|
|
74
|
+
else if (c === '[') {
|
|
75
|
+
inClass = true;
|
|
76
|
+
out += c;
|
|
77
|
+
}
|
|
78
|
+
else if (c !== '(') {
|
|
79
|
+
out += c;
|
|
80
|
+
}
|
|
81
|
+
else if (src[i + 1] !== '?') {
|
|
82
|
+
out += '(?:';
|
|
83
|
+
}
|
|
84
|
+
else if (src[i + 2] === '<' && src[i + 3] !== '=' && src[i + 3] !== '!' && src.includes('>', i)) {
|
|
85
|
+
// `(?<name>` — drop the name along with the capture.
|
|
86
|
+
i = src.indexOf('>', i);
|
|
87
|
+
out += '(?:';
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
out += c;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
};
|
|
50
95
|
const patternSource = (match) => {
|
|
51
96
|
return typeof match === 'string' ? match : match.source;
|
|
52
97
|
};
|
|
@@ -163,7 +208,7 @@ const compileState = (grammar, name) => {
|
|
|
163
208
|
captures,
|
|
164
209
|
// Sticky, so it can be re-run at the position the merged regex chose.
|
|
165
210
|
// A pattern that depends on the remembered text is built per value.
|
|
166
|
-
own: captures && !usesMemory ? new RegExp(src, `ymd${caseFlag}`) : null,
|
|
211
|
+
own: (captures || rule.remember) && !usesMemory ? new RegExp(src, `ymd${caseFlag}`) : null,
|
|
167
212
|
rest: rule.rest ?? null,
|
|
168
213
|
group,
|
|
169
214
|
push: rule.push ?? null,
|
|
@@ -172,9 +217,9 @@ const compileState = (grammar, name) => {
|
|
|
172
217
|
remember: rule.remember ?? 0,
|
|
173
218
|
rememberIndent: rule.rememberAs === 'indent',
|
|
174
219
|
});
|
|
175
|
-
ownSources.push(captures && usesMemory ? src : null);
|
|
176
|
-
sources.push(`(${src})`);
|
|
177
|
-
group += 1
|
|
220
|
+
ownSources.push((captures || rule.remember) && usesMemory ? src : null);
|
|
221
|
+
sources.push(`(${uncapture(src)})`);
|
|
222
|
+
group += 1;
|
|
178
223
|
}
|
|
179
224
|
// `m` so grammars can anchor to lines. Deliberately no `d`: offsets are
|
|
180
225
|
// resolved per rule instead, which keeps the scan free of that cost.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAYvD,eAAO,MAAM,gBAAgB,GAAI,GAAG,UAAU,OAAO,EAAE,KAAG,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAYvD,eAAO,MAAM,gBAAgB,GAAI,GAAG,UAAU,OAAO,EAAE,KAAG,IAiCzD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,OAE3C,CAAA;AAED,gEAAgE;AAChE,eAAO,MAAM,aAAa,QAAO,MAAM,EAEtC,CAAA;AAMD,qEAAqE;AACrE,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,eAAe,GAAG,SAkB5D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,GAAG,OAAO,GAAG,eAAe,KAAG,eAgBzE,CAAA"}
|
package/dist/core/registry.js
CHANGED
|
@@ -11,6 +11,14 @@ const cache = new Map();
|
|
|
11
11
|
export const registerLanguage = (...grammars) => {
|
|
12
12
|
for (const grammar of grammars) {
|
|
13
13
|
const name = grammar.name.toLowerCase();
|
|
14
|
+
const keys = [name, ...(grammar.aliases ?? [])].map((key) => key.toLowerCase());
|
|
15
|
+
// Registering the same grammar again changes nothing, so it keeps its
|
|
16
|
+
// compiled form. Evicting it here made a caller that registers on every
|
|
17
|
+
// render — a component's setup, say — recompile on every call, which is
|
|
18
|
+
// close to twenty times the cost of the highlight itself.
|
|
19
|
+
if (keys.every((key) => sources.get(key) === grammar)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
14
22
|
// Re-registering replaces a language outright, so retire every name the
|
|
15
23
|
// previous grammar answered to before claiming the new one's. Evicting only
|
|
16
24
|
// the canonical name would leave each alias pointing at, and cached as, the
|
|
@@ -25,10 +33,9 @@ export const registerLanguage = (...grammars) => {
|
|
|
25
33
|
cache.delete(lower);
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
|
-
for (const key of
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
cache.delete(lower);
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
sources.set(key, grammar);
|
|
38
|
+
cache.delete(key);
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
};
|
package/dist/core/scopes.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* without knowing anything about them.
|
|
7
7
|
*
|
|
8
8
|
* Each scope maps to a short CSS class so the rendered HTML stays small
|
|
9
|
-
* (`<span class="
|
|
9
|
+
* (`<span class="shl-kd">def</span>`). Themes never mention these codes — they
|
|
10
10
|
* are written against the readable scope names and the codes are applied here.
|
|
11
11
|
*
|
|
12
12
|
* Scopes are hierarchical: `function.builtin` falls back to `function` when a
|
|
@@ -36,6 +36,8 @@ export declare const SCOPES: {
|
|
|
36
36
|
readonly 'variable.member': "vm";
|
|
37
37
|
/** `__name__`, `__init__` — dunder / magic names. */
|
|
38
38
|
readonly 'variable.special': "vs";
|
|
39
|
+
/** `:name` in Ruby, an atom in Erlang, an HTTP method in a curl line. */
|
|
40
|
+
readonly symbol: "sy";
|
|
39
41
|
readonly keyword: "k";
|
|
40
42
|
/** `if`, `for`, `return`, `await`, `yield`. */
|
|
41
43
|
readonly 'keyword.control': "kc";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/core/scopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM;;;;;IAQjB,kFAAkF;;IAElF,0DAA0D;;;;;;IAQ1D,0CAA0C;;;IAG1C,sCAAsC;;;IAGtC,sCAAsC;;IAEtC,qDAAqD;;;
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/core/scopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM;;;;;IAQjB,kFAAkF;;IAElF,0DAA0D;;;;;;IAQ1D,0CAA0C;;;IAG1C,sCAAsC;;;IAGtC,sCAAsC;;IAEtC,qDAAqD;;IAGrD,yEAAyE;;;IAKzE,+CAA+C;;IAE/C,qDAAqD;;;IAGrD,yEAAyE;;IAIzE,iCAAiC;;IAEjC,2BAA2B;;IAE3B,kCAAkC;;;;IAIlC,gDAAgD;;;;;;;;;;;IAehD,8CAA8C;;;IAG9C,4BAA4B;;;;;;;;;;;CAYpB,CAAA;AAEV,MAAM,MAAM,KAAK,GAAG,MAAM,OAAO,MAAM,CAAA;AAEvC,6EAA6E;AAC7E,eAAO,MAAM,WAAW,EAA0B,KAAK,EAAE,CAAA;AAEzD;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAM1C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAAM,EAQhD,CAAA"}
|
package/dist/core/scopes.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* without knowing anything about them.
|
|
7
7
|
*
|
|
8
8
|
* Each scope maps to a short CSS class so the rendered HTML stays small
|
|
9
|
-
* (`<span class="
|
|
9
|
+
* (`<span class="shl-kd">def</span>`). Themes never mention these codes — they
|
|
10
10
|
* are written against the readable scope names and the codes are applied here.
|
|
11
11
|
*
|
|
12
12
|
* Scopes are hierarchical: `function.builtin` falls back to `function` when a
|
|
@@ -39,6 +39,8 @@ export const SCOPES = {
|
|
|
39
39
|
'variable.member': 'vm',
|
|
40
40
|
/** `__name__`, `__init__` — dunder / magic names. */
|
|
41
41
|
'variable.special': 'vs',
|
|
42
|
+
/** `:name` in Ruby, an atom in Erlang, an HTTP method in a curl line. */
|
|
43
|
+
symbol: 'sy',
|
|
42
44
|
// --- keywords -------------------------------------------------------------
|
|
43
45
|
keyword: 'k',
|
|
44
46
|
/** `if`, `for`, `return`, `await`, `yield`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../src/core/tokenize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAA+B,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGxF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,SAAS,eAAe,EAAE,MAAM,IAAI,KAAG,
|
|
1
|
+
{"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../src/core/tokenize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAA+B,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGxF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,SAAS,eAAe,EAAE,MAAM,IAAI,KAAG,IAgH7E,CAAA;AAgLD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,SAAS,eAAe,KAAG,KAAK,EAM7E,CAAA"}
|
package/dist/core/tokenize.js
CHANGED
|
@@ -73,7 +73,11 @@ export const tokenize = (code, grammar, emit) => {
|
|
|
73
73
|
// the state that entered it unless the rule remembers something new.
|
|
74
74
|
let remembered = memory[memory.length - 1];
|
|
75
75
|
if (rule.remember > 0) {
|
|
76
|
-
|
|
76
|
+
// The merged regex captures only which rule won, so the group comes from
|
|
77
|
+
// the rule's own pattern, re-run where the merged one matched.
|
|
78
|
+
const own = dyn?.own[index] ?? rule.own;
|
|
79
|
+
own.lastIndex = start;
|
|
80
|
+
const text = own.exec(code)?.[rule.remember] ?? '';
|
|
77
81
|
remembered = rule.rememberIndent ? ' '.repeat(text.length) : text;
|
|
78
82
|
}
|
|
79
83
|
if (rule.pop > 0) {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -122,7 +122,8 @@ export type CompiledRule = {
|
|
|
122
122
|
captures: (ScopeName | null)[] | null;
|
|
123
123
|
/**
|
|
124
124
|
* This rule alone, sticky and with `hasIndices`, used to locate its capture
|
|
125
|
-
* groups after the merged regex has
|
|
125
|
+
* groups — and to read the one it remembers — after the merged regex has
|
|
126
|
+
* already picked it. The merged regex does not capture them at all.
|
|
126
127
|
*
|
|
127
128
|
* Asking the merged regex for indices would make every match in the state
|
|
128
129
|
* pay to have offsets computed for every group of every rule; re-running one
|
|
@@ -135,7 +136,7 @@ export type CompiledRule = {
|
|
|
135
136
|
push: string | null;
|
|
136
137
|
set: string | null;
|
|
137
138
|
pop: number;
|
|
138
|
-
/** Capture group to remember,
|
|
139
|
+
/** Capture group of `own` to remember, 1-based; `0` for none. */
|
|
139
140
|
remember: number;
|
|
140
141
|
rememberIndent: boolean;
|
|
141
142
|
};
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,MAAM,MAAM,IAAI,GAAG;IACjB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAEtB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,CAAA;IAExC,kEAAkE;IAClE,IAAI,CAAC,EAAE,SAAS,CAAA;IAEhB,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,uCAAuC;IACvC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAA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aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,OAAO,EAAE,SAAS,GAAG,IAAI,CAAA;IACzB;;;OAGG;IACH,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;QACb,wEAAwE;QACxE,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;QACtB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;SAAE,CAAC,CAAA;KAC3D,GAAG,IAAI,CAAA;IACR,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;CAC3E,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IACrC,IAAI,EAAE,aAAa,CAAA;CACpB,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { CompiledGrammar, Grammar, Token } from './core/types.js';
|
|
|
4
4
|
export type LanguageInput = string | Grammar | CompiledGrammar;
|
|
5
5
|
/** Highlights to an HTML fragment (the inside of a `<code>` element). */
|
|
6
6
|
export declare const highlight: (code: string, lang: LanguageInput, options?: RenderOptions) => string;
|
|
7
|
-
/** Highlights to a complete `<pre class="
|
|
7
|
+
/** Highlights to a complete `<pre class="shl-code">` block. */
|
|
8
8
|
export declare const highlightBlock: (code: string, lang: LanguageInput, options?: BlockOptions) => string;
|
|
9
9
|
/** Tokenizes to an array — for rendering somewhere other than HTML. */
|
|
10
10
|
export declare const tokenize: (code: string, lang: LanguageInput) => Token[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAGhE,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEnE,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,eAAe,CAAA;AAE9D,yEAAyE;AACzE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,EAAE,UAAU,aAAa,KAAG,MAEtF,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAGhE,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEnE,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,eAAe,CAAA;AAE9D,yEAAyE;AACzE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,EAAE,UAAU,aAAa,KAAG,MAEtF,CAAA;AAED,+DAA+D;AAC/D,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,EAAE,UAAU,YAAY,KAAG,MAE1F,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,KAAG,KAAK,EAEjE,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3E,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5D,YAAY,EACV,eAAe,EACf,IAAI,EACJ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,SAAS,EACT,KAAK,GACN,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { tokenizeToArray } from './core/tokenize.js';
|
|
|
5
5
|
export const highlight = (code, lang, options) => {
|
|
6
6
|
return render(code, resolveGrammar(lang), options);
|
|
7
7
|
};
|
|
8
|
-
/** Highlights to a complete `<pre class="
|
|
8
|
+
/** Highlights to a complete `<pre class="shl-code">` block. */
|
|
9
9
|
export const highlightBlock = (code, lang, options) => {
|
|
10
10
|
return renderBlock(code, resolveGrammar(lang), options);
|
|
11
11
|
};
|
package/dist/langs/cpp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cpp.d.ts","sourceRoot":"","sources":["../../src/langs/cpp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAgG5C,QAAA,MAAM,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"cpp.d.ts","sourceRoot":"","sources":["../../src/langs/cpp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAgG5C,QAAA,MAAM,GAAG,EAAE,OAgVV,CAAA;AAED,eAAe,GAAG,CAAA"}
|
package/dist/langs/cpp.js
CHANGED
|
@@ -263,6 +263,14 @@ const cpp = {
|
|
|
263
263
|
// Before the constant and type rules, so a SCREAMING_CASE macro used as
|
|
264
264
|
// `CLAMP(x, 0, 9)` reads as the call it expands to.
|
|
265
265
|
{ match: `\\b${ID}(?=[ \\t]*\\()`, scope: 'function.call' },
|
|
266
|
+
// A call with explicit template arguments: `any_cast<int>(x)`,
|
|
267
|
+
// `get<std::vector<int>>(t)`. One level of nesting covers real code and
|
|
268
|
+
// keeps the scan bounded; `std::vector<int> v(3)` has a name between
|
|
269
|
+
// the `>` and the `(`, so it stays a declaration.
|
|
270
|
+
{
|
|
271
|
+
match: `\\b${ID}(?=<[^<>;(){}\\n]{0,80}(?:<[^<>;(){}\\n]{0,80}>[^<>;(){}\\n]{0,40})?>[ \\t]*\\()`,
|
|
272
|
+
scope: 'function.call',
|
|
273
|
+
},
|
|
266
274
|
// SCREAMING_CASE is a macro or an enumerator; `_t` and CapWords are the
|
|
267
275
|
// two ways a C++ codebase spells a type.
|
|
268
276
|
{ match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/langs/csharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAuD5C,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/langs/csharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAuD5C,QAAA,MAAM,MAAM,EAAE,OAuSb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/langs/csharp.js
CHANGED
|
@@ -108,6 +108,12 @@ const csharp = {
|
|
|
108
108
|
match: '\\b(?:if|else|for|foreach|while|do|switch|case|default|break|continue|return|goto|throw|try|catch|finally|yield|await|lock|when|from|select|orderby|join|into)\\b',
|
|
109
109
|
scope: 'keyword.control',
|
|
110
110
|
},
|
|
111
|
+
// `var client = …` binds a name; matched before `var` alone so the name
|
|
112
|
+
// is not left to the rules below.
|
|
113
|
+
{
|
|
114
|
+
match: `\\b(var)([ \\t]+)(${ID})(?=[ \\t]*[=;])`,
|
|
115
|
+
scope: ['keyword.declaration', null, 'variable'],
|
|
116
|
+
},
|
|
111
117
|
{
|
|
112
118
|
match: '\\b(?:class|struct|interface|enum|record|delegate|namespace|var|const|readonly|volatile|static|public|private|protected|internal|abstract|sealed|virtual|override|partial|async|event|extern|unsafe|fixed|implicit|explicit|operator|params|ref|out|where|get|set|init|required|global)\\b',
|
|
113
119
|
scope: 'keyword.declaration',
|
|
@@ -137,18 +143,17 @@ const csharp = {
|
|
|
137
143
|
match: `\\b${ID}(?=(?:${GENERIC})?(?:\\[\\])*\\??[ \\t]+(?!(?:is|as|in|when|and|or|not|switch|with)\\b)${ID}[ \\t]*[=;,){(])`,
|
|
138
144
|
scope: 'type',
|
|
139
145
|
},
|
|
140
|
-
// A
|
|
141
|
-
//
|
|
142
|
-
{
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
// the same at its declaration as it does at `obj.Name`.
|
|
146
|
+
// A name sitting after a type (or the access modifier of a
|
|
147
|
+
// constructor) is being declared, and what follows says what it is:
|
|
148
|
+
// `(` a method, `{` or `=>` a property or expression-bodied member,
|
|
149
|
+
// scoped as a member so it looks the same as it does at `obj.Name`,
|
|
150
|
+
// and `=` or `;` a variable, `HttpClient client = …`, `int count;`. One
|
|
151
|
+
// rule with three endings, because each extra rule with these
|
|
152
|
+
// lookbehinds costs a pass at every position. A name after a spaced
|
|
153
|
+
// `>` is a comparison, `t = a > b;`, so the variable ending skips it.
|
|
149
154
|
{
|
|
150
|
-
match: `${NOT_AFTER}${ID}(?=[ \\t]*(?:\\{|=>))`,
|
|
151
|
-
scope: 'variable.member',
|
|
155
|
+
match: `${NOT_AFTER}(?:(${ID})(?=[ \\t]*(?:${GENERIC})?[ \\t]*\\()|(${ID})(?=[ \\t]*(?:\\{|=>))|(?<![ \\t]>[ \\t])(${ID})(?=[ \\t]*(?:=(?![=>])|;)))`,
|
|
156
|
+
scope: ['function', 'variable.member', 'variable'],
|
|
152
157
|
},
|
|
153
158
|
{
|
|
154
159
|
match: `\\b${ID}(?=[ \\t]*(?:${GENERIC})?[ \\t]*\\()`,
|
package/dist/langs/css.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/langs/css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAc5C,QAAA,MAAM,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/langs/css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAc5C,QAAA,MAAM,GAAG,EAAE,OAkMV,CAAA;AAED,eAAe,GAAG,CAAA"}
|
package/dist/langs/css.js
CHANGED
|
@@ -17,6 +17,9 @@ const css = {
|
|
|
17
17
|
{ include: 'comments' },
|
|
18
18
|
{ include: 'strings' },
|
|
19
19
|
{ match: AT_CONDITION, scope: 'keyword', push: 'condition' },
|
|
20
|
+
// An SCSS `$name:` or Less `@name:` definition takes a value, not a
|
|
21
|
+
// selector, so `red` in `$brand: red` is a color rather than a tag.
|
|
22
|
+
{ include: 'variable-definition' },
|
|
20
23
|
{ match: '@[A-Za-z-]+', scope: 'keyword' },
|
|
21
24
|
{ match: `\\$${IDENT}`, scope: 'variable' },
|
|
22
25
|
{ match: '\\{', scope: 'punctuation.bracket', push: 'declarations' },
|
|
@@ -39,6 +42,7 @@ const css = {
|
|
|
39
42
|
{ match: '\\{', scope: 'punctuation.bracket', push: 'declarations' },
|
|
40
43
|
{ match: ';', scope: 'punctuation.delimiter' },
|
|
41
44
|
{ match: AT_CONDITION, scope: 'keyword', push: 'condition' },
|
|
45
|
+
{ include: 'variable-definition' },
|
|
42
46
|
{ match: '@[A-Za-z-]+', scope: 'keyword' },
|
|
43
47
|
{
|
|
44
48
|
match: `(${IDENT})(\\s*)(:)`,
|
|
@@ -65,12 +69,16 @@ const css = {
|
|
|
65
69
|
match: '#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\\b',
|
|
66
70
|
scope: 'number',
|
|
67
71
|
},
|
|
72
|
+
// A custom property reads the same where it is used as where it is
|
|
73
|
+
// defined, so `var(--brand)` and `--brand: …` share the property color.
|
|
68
74
|
{
|
|
69
75
|
match: 'var\\(\\s*(--[\\w-]+)',
|
|
70
|
-
scope: ['
|
|
76
|
+
scope: ['property'],
|
|
71
77
|
rest: 'function.builtin',
|
|
72
78
|
},
|
|
73
|
-
{ match: '--[\\w-]+', scope: '
|
|
79
|
+
{ match: '--[\\w-]+', scope: 'property' },
|
|
80
|
+
// SCSS `$brand` and Less `@brand` used in a value.
|
|
81
|
+
{ match: `[$@]${IDENT}`, scope: 'variable' },
|
|
74
82
|
// An unquoted `url(…)` is a string up to the `)`. Without its own state
|
|
75
83
|
// the `//` in `url(https://…)` reads as an SCSS line comment and takes
|
|
76
84
|
// the rest of the declaration with it.
|
|
@@ -105,6 +113,23 @@ const css = {
|
|
|
105
113
|
{ match: '[(),/<>=]', scope: 'punctuation' },
|
|
106
114
|
],
|
|
107
115
|
},
|
|
116
|
+
'variable-definition': {
|
|
117
|
+
rules: [
|
|
118
|
+
// CSS permits `@page:first` without whitespace before the pseudo-class.
|
|
119
|
+
{ match: '@page(?=:(?:first|left|right|blank)\\b)', scope: 'keyword' },
|
|
120
|
+
{
|
|
121
|
+
match: `(\\$${IDENT})(\\s*)(:)`,
|
|
122
|
+
scope: ['variable', null, 'punctuation.delimiter'],
|
|
123
|
+
push: 'value',
|
|
124
|
+
},
|
|
125
|
+
// No space before the colon for Less, so `@page :first` stays an at-rule.
|
|
126
|
+
{
|
|
127
|
+
match: `(@${IDENT})(:)`,
|
|
128
|
+
scope: ['variable', 'punctuation.delimiter'],
|
|
129
|
+
push: 'value',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
108
133
|
'value-tokens': {
|
|
109
134
|
rules: [
|
|
110
135
|
{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/langs/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAgB5C,QAAA,MAAM,IAAI,EAAE,OAoDX,CAAA;AAED,eAAe,IAAI,CAAA"}
|