@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.
- package/CHANGELOG.md +13 -0
- package/README.md +324 -0
- package/dist/all.d.ts +28 -0
- package/dist/all.d.ts.map +1 -0
- package/dist/all.js +105 -0
- package/dist/compat/hljs.d.ts +24 -0
- package/dist/compat/hljs.d.ts.map +1 -0
- package/dist/compat/hljs.js +95 -0
- package/dist/compat/index.d.ts +24 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +21 -0
- package/dist/compat/languages.d.ts +46 -0
- package/dist/compat/languages.d.ts.map +1 -0
- package/dist/compat/languages.js +236 -0
- package/dist/compat/syntax-highlight.d.ts +37 -0
- package/dist/compat/syntax-highlight.d.ts.map +1 -0
- package/dist/compat/syntax-highlight.js +133 -0
- package/dist/core/compile.d.ts +3 -0
- package/dist/core/compile.d.ts.map +1 -0
- package/dist/core/compile.js +142 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/registry.d.ts +14 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +77 -0
- package/dist/core/render.d.ts +67 -0
- package/dist/core/render.d.ts.map +1 -0
- package/dist/core/render.js +216 -0
- package/dist/core/scopes.d.ts +94 -0
- package/dist/core/scopes.d.ts.map +1 -0
- package/dist/core/scopes.js +113 -0
- package/dist/core/tokenize.d.ts +18 -0
- package/dist/core/tokenize.d.ts.map +1 -0
- package/dist/core/tokenize.js +131 -0
- package/dist/core/types.d.ts +99 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +10 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/langs/bash.d.ts +4 -0
- package/dist/langs/bash.d.ts.map +1 -0
- package/dist/langs/bash.js +123 -0
- package/dist/langs/c.d.ts +4 -0
- package/dist/langs/c.d.ts.map +1 -0
- package/dist/langs/c.js +196 -0
- package/dist/langs/clojure.d.ts +4 -0
- package/dist/langs/clojure.d.ts.map +1 -0
- package/dist/langs/clojure.js +213 -0
- package/dist/langs/cpp.d.ts +4 -0
- package/dist/langs/cpp.d.ts.map +1 -0
- package/dist/langs/cpp.js +391 -0
- package/dist/langs/csharp.d.ts +4 -0
- package/dist/langs/csharp.d.ts.map +1 -0
- package/dist/langs/csharp.js +307 -0
- package/dist/langs/css.d.ts +4 -0
- package/dist/langs/css.d.ts.map +1 -0
- package/dist/langs/css.js +94 -0
- package/dist/langs/dart.d.ts +4 -0
- package/dist/langs/dart.d.ts.map +1 -0
- package/dist/langs/dart.js +262 -0
- package/dist/langs/diff.d.ts +10 -0
- package/dist/langs/diff.d.ts.map +1 -0
- package/dist/langs/diff.js +26 -0
- package/dist/langs/dockerfile.d.ts +4 -0
- package/dist/langs/dockerfile.d.ts.map +1 -0
- package/dist/langs/dockerfile.js +308 -0
- package/dist/langs/elixir.d.ts +4 -0
- package/dist/langs/elixir.d.ts.map +1 -0
- package/dist/langs/elixir.js +343 -0
- package/dist/langs/fsharp.d.ts +4 -0
- package/dist/langs/fsharp.d.ts.map +1 -0
- package/dist/langs/fsharp.js +330 -0
- package/dist/langs/go.d.ts +5 -0
- package/dist/langs/go.d.ts.map +1 -0
- package/dist/langs/go.js +90 -0
- package/dist/langs/graphql.d.ts +4 -0
- package/dist/langs/graphql.d.ts.map +1 -0
- package/dist/langs/graphql.js +185 -0
- package/dist/langs/haskell.d.ts +4 -0
- package/dist/langs/haskell.d.ts.map +1 -0
- package/dist/langs/haskell.js +375 -0
- package/dist/langs/html.d.ts +14 -0
- package/dist/langs/html.d.ts.map +1 -0
- package/dist/langs/html.js +71 -0
- package/dist/langs/http.d.ts +4 -0
- package/dist/langs/http.d.ts.map +1 -0
- package/dist/langs/http.js +185 -0
- package/dist/langs/ini.d.ts +4 -0
- package/dist/langs/ini.d.ts.map +1 -0
- package/dist/langs/ini.js +227 -0
- package/dist/langs/java.d.ts +4 -0
- package/dist/langs/java.d.ts.map +1 -0
- package/dist/langs/java.js +178 -0
- package/dist/langs/javascript.d.ts +4 -0
- package/dist/langs/javascript.d.ts.map +1 -0
- package/dist/langs/javascript.js +226 -0
- package/dist/langs/json.d.ts +10 -0
- package/dist/langs/json.d.ts.map +1 -0
- package/dist/langs/json.js +46 -0
- package/dist/langs/kotlin.d.ts +4 -0
- package/dist/langs/kotlin.d.ts.map +1 -0
- package/dist/langs/kotlin.js +220 -0
- package/dist/langs/lua.d.ts +4 -0
- package/dist/langs/lua.d.ts.map +1 -0
- package/dist/langs/lua.js +330 -0
- package/dist/langs/makefile.d.ts +4 -0
- package/dist/langs/makefile.d.ts.map +1 -0
- package/dist/langs/makefile.js +266 -0
- package/dist/langs/markdown.d.ts +11 -0
- package/dist/langs/markdown.d.ts.map +1 -0
- package/dist/langs/markdown.js +71 -0
- package/dist/langs/matlab.d.ts +4 -0
- package/dist/langs/matlab.d.ts.map +1 -0
- package/dist/langs/matlab.js +352 -0
- package/dist/langs/mojo.d.ts +4 -0
- package/dist/langs/mojo.d.ts.map +1 -0
- package/dist/langs/mojo.js +337 -0
- package/dist/langs/nginx.d.ts +4 -0
- package/dist/langs/nginx.d.ts.map +1 -0
- package/dist/langs/nginx.js +168 -0
- package/dist/langs/objectivec.d.ts +4 -0
- package/dist/langs/objectivec.d.ts.map +1 -0
- package/dist/langs/objectivec.js +287 -0
- package/dist/langs/ocaml.d.ts +4 -0
- package/dist/langs/ocaml.d.ts.map +1 -0
- package/dist/langs/ocaml.js +309 -0
- package/dist/langs/perl.d.ts +4 -0
- package/dist/langs/perl.d.ts.map +1 -0
- package/dist/langs/perl.js +435 -0
- package/dist/langs/php.d.ts +4 -0
- package/dist/langs/php.d.ts.map +1 -0
- package/dist/langs/php.js +325 -0
- package/dist/langs/powershell.d.ts +4 -0
- package/dist/langs/powershell.d.ts.map +1 -0
- package/dist/langs/powershell.js +308 -0
- package/dist/langs/python.d.ts +4 -0
- package/dist/langs/python.d.ts.map +1 -0
- package/dist/langs/python.js +350 -0
- package/dist/langs/r.d.ts +4 -0
- package/dist/langs/r.d.ts.map +1 -0
- package/dist/langs/r.js +265 -0
- package/dist/langs/ruby.d.ts +4 -0
- package/dist/langs/ruby.d.ts.map +1 -0
- package/dist/langs/ruby.js +365 -0
- package/dist/langs/rust.d.ts +10 -0
- package/dist/langs/rust.d.ts.map +1 -0
- package/dist/langs/rust.js +116 -0
- package/dist/langs/scala.d.ts +4 -0
- package/dist/langs/scala.d.ts.map +1 -0
- package/dist/langs/scala.js +308 -0
- package/dist/langs/sql.d.ts +5 -0
- package/dist/langs/sql.d.ts.map +1 -0
- package/dist/langs/sql.js +57 -0
- package/dist/langs/swift.d.ts +33 -0
- package/dist/langs/swift.d.ts.map +1 -0
- package/dist/langs/swift.js +256 -0
- package/dist/langs/yaml.d.ts +11 -0
- package/dist/langs/yaml.d.ts.map +1 -0
- package/dist/langs/yaml.js +123 -0
- package/dist/lazy.d.ts +69 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +200 -0
- package/dist/style.css +308 -0
- package/package.json +86 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C#.
|
|
3
|
+
*
|
|
4
|
+
* The four things that make C# awkward for a regex tokenizer, and how this
|
|
5
|
+
* grammar answers them:
|
|
6
|
+
*
|
|
7
|
+
* - **Five string flavours.** `"…"`, verbatim `@"…"` where the only escape is a
|
|
8
|
+
* doubled quote, interpolated `$"…"`, the combination `$@"…"`, and C# 11 raw
|
|
9
|
+
* `"""…"""`. Each gets its own state, so a `\` in a verbatim string is text
|
|
10
|
+
* and a `{` in a plain string is not an interpolation.
|
|
11
|
+
* - **Everything is PascalCase.** Types, methods, properties and namespaces all
|
|
12
|
+
* share one casing convention, so casing alone cannot tell them apart the way
|
|
13
|
+
* it can in Python or Rust. Position does the work instead: what follows the
|
|
14
|
+
* name (`(`, `{`, `=>`, `.`) and what precedes it.
|
|
15
|
+
* - **A method definition looks exactly like a call**, right down to the parens.
|
|
16
|
+
* The separator is the return type in front of it, matched with a lookbehind
|
|
17
|
+
* so the type itself still gets scoped by the type rules.
|
|
18
|
+
* - **Contextual keywords.** `get`, `set`, `record`, `when`, `and` and the LINQ
|
|
19
|
+
* words are only keywords in some positions and ordinary identifiers in
|
|
20
|
+
* others. They are treated as keywords everywhere, which is right for
|
|
21
|
+
* idiomatic code — see the notes on the rules that make that trade.
|
|
22
|
+
*/
|
|
23
|
+
const ID = '[A-Za-z_]\\w*';
|
|
24
|
+
/** A dotted name: `System.Text.Json`. */
|
|
25
|
+
const DOTTED = `${ID}(?:\\.${ID})*`;
|
|
26
|
+
/**
|
|
27
|
+
* One level of type arguments, used only inside lookarounds.
|
|
28
|
+
*
|
|
29
|
+
* `<` is excluded from the body and the repetition is capped so a line of `<`
|
|
30
|
+
* cannot be rescanned from every column. Nested arguments (`List<List<int>>`)
|
|
31
|
+
* therefore fail the lookahead and fall through to the plainer rules, which is
|
|
32
|
+
* a missed colour rather than a wrong one.
|
|
33
|
+
*/
|
|
34
|
+
const GENERIC = '<[^<>()\\n]{0,120}>';
|
|
35
|
+
/** `\n`, `\t`, `\uFFFD`, `\U0001F600`, `\x41`, `\"`. */
|
|
36
|
+
const ESCAPE = '\\\\(?:u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|x[0-9a-fA-F]{1,4}|[0abfnrtve\'"\\\\])';
|
|
37
|
+
/**
|
|
38
|
+
* A name in a statement position that is not the start of a declaration.
|
|
39
|
+
*
|
|
40
|
+
* The definition and property rules key off "a word, a space, then the name",
|
|
41
|
+
* which is also the shape of `return Compute(x)` and `await Run()`. Excluding
|
|
42
|
+
* the keywords that can stand where a type would keeps those as calls. `=>` is
|
|
43
|
+
* excluded too, because a generic return type ends in `>` as well.
|
|
44
|
+
*/
|
|
45
|
+
const NOT_AFTER = '(?<=[\\w>\\]?][ \\t])(?<!=>[ \\t])' +
|
|
46
|
+
'(?<!\\b(?:return|new|await|throw|yield|is|as|in|out|ref|case|when|and|or|not|else|do|using|typeof|nameof|default)[ \\t])';
|
|
47
|
+
const csharp = {
|
|
48
|
+
name: 'csharp',
|
|
49
|
+
aliases: ['cs', 'c#'],
|
|
50
|
+
states: {
|
|
51
|
+
root: { rules: [{ include: 'expression' }] },
|
|
52
|
+
expression: {
|
|
53
|
+
rules: [
|
|
54
|
+
// `///` is the XML documentation comment; `//` is an ordinary one.
|
|
55
|
+
{ match: '///[^\\n]*', scope: 'comment.doc' },
|
|
56
|
+
{ match: '//[^\\n]*', scope: 'comment' },
|
|
57
|
+
// A state, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and fails
|
|
58
|
+
// once per opener, which is O(n2) on an unterminated `/*` — 123 KB of
|
|
59
|
+
// `/*a` measured 23.4 s. C# block comments do not nest.
|
|
60
|
+
{ match: '/\\*', scope: 'comment', push: 'block-comment' },
|
|
61
|
+
// Preprocessor directives. Only the directive itself is scoped so that
|
|
62
|
+
// `#if DEBUG` and `#pragma warning disable CS1591` keep their operands
|
|
63
|
+
// highlighted as the constants they are.
|
|
64
|
+
{ match: '^([ \\t]*)(#[ \\t]*[a-z]+)', scope: [null, 'decorator'] },
|
|
65
|
+
{ include: 'strings' },
|
|
66
|
+
// An attribute, recognised by sitting on its own line. `[` anywhere
|
|
67
|
+
// else is an indexer or an array, and a line that opens with `[` in the
|
|
68
|
+
// middle of an expression is rare enough to accept as the cost. Only
|
|
69
|
+
// the name is scoped, so `[Route("api/[controller]")]` still shows its
|
|
70
|
+
// string.
|
|
71
|
+
{
|
|
72
|
+
match: `(^[ \\t]*)(\\[)(${DOTTED})`,
|
|
73
|
+
scope: [null, 'punctuation.bracket', 'decorator'],
|
|
74
|
+
},
|
|
75
|
+
{ include: 'numbers' },
|
|
76
|
+
// `..` before the member rules, so `items[1..n]` does not read the
|
|
77
|
+
// second dot as access to a member named `n`.
|
|
78
|
+
{ match: '\\.\\.', scope: 'operator' },
|
|
79
|
+
{
|
|
80
|
+
match: `(\\??\\.)([ \\t]*)(${ID})(?=[ \\t]*(?:${GENERIC})?[ \\t]*\\()`,
|
|
81
|
+
scope: ['punctuation', null, 'function.method'],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
match: `(\\??\\.)([ \\t]*)(${ID})`,
|
|
85
|
+
scope: ['punctuation', null, 'variable.member'],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
match: `\\b(using)([ \\t]+)(?:(static)([ \\t]+))?(${DOTTED})(?=[ \\t]*;)`,
|
|
89
|
+
scope: ['keyword.import', null, 'keyword.declaration', null, 'namespace'],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
match: `\\b(namespace)([ \\t]+)(${DOTTED})`,
|
|
93
|
+
scope: ['keyword.declaration', null, 'namespace'],
|
|
94
|
+
},
|
|
95
|
+
// The optional `record ` prefix keeps `record struct Point` from
|
|
96
|
+
// scoping `struct` as if it were the type name.
|
|
97
|
+
{
|
|
98
|
+
match: `\\b((?:record[ \\t]+)?(?:class|struct|interface|enum|delegate|record))([ \\t]+)(${ID})`,
|
|
99
|
+
scope: ['keyword.declaration', null, 'class'],
|
|
100
|
+
},
|
|
101
|
+
// `new` names a type, never a function, so it comes before the rules
|
|
102
|
+
// that read `Name(` as a call.
|
|
103
|
+
{
|
|
104
|
+
match: `\\b(new)([ \\t]+)(${DOTTED})`,
|
|
105
|
+
scope: ['keyword.operator', null, 'type'],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
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
|
+
scope: 'keyword.control',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
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
|
+
scope: 'keyword.declaration',
|
|
114
|
+
},
|
|
115
|
+
{ match: '\\busing\\b', scope: 'keyword.import' },
|
|
116
|
+
{
|
|
117
|
+
match: '\\b(?:is|as|in|new|typeof|sizeof|nameof|stackalloc|checked|unchecked|with|and|or|not)\\b',
|
|
118
|
+
scope: 'keyword.operator',
|
|
119
|
+
},
|
|
120
|
+
{ match: '\\b(?:true|false)\\b', scope: 'boolean' },
|
|
121
|
+
{ match: '\\bnull\\b', scope: 'constant.builtin' },
|
|
122
|
+
{ match: '\\b(?:this|base)\\b', scope: 'variable.builtin' },
|
|
123
|
+
{
|
|
124
|
+
match: '\\b(?:bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|short|ushort|nint|nuint|object|string|void|dynamic)\\b',
|
|
125
|
+
scope: 'type.builtin',
|
|
126
|
+
},
|
|
127
|
+
// A verbatim identifier — `@class`, `@event` — is a name, not the
|
|
128
|
+
// keyword it spells.
|
|
129
|
+
{ match: `@${ID}`, scope: 'variable' },
|
|
130
|
+
// A type in a declaration, recognised by the name that follows it:
|
|
131
|
+
// `HttpClient _client;`, `List<int> xs = …`, `catch (IOException ex)`,
|
|
132
|
+
// `IClock Clock {`, `Task<string> RunAsync(`. Keywords are matched
|
|
133
|
+
// above, so `return Compute(x)` cannot read `return` as a type here;
|
|
134
|
+
// the inner guard is for the ones that can follow a value instead of
|
|
135
|
+
// introducing a name, as in `c is (…)` and `state switch {`.
|
|
136
|
+
{
|
|
137
|
+
match: `\\b${ID}(?=(?:${GENERIC})?(?:\\[\\])*\\??[ \\t]+(?!(?:is|as|in|when|and|or|not|switch|with)\\b)${ID}[ \\t]*[=;,){(])`,
|
|
138
|
+
scope: 'type',
|
|
139
|
+
},
|
|
140
|
+
// A definition, told from a call by the return type (or the access
|
|
141
|
+
// modifier of a constructor) sitting in front of it.
|
|
142
|
+
{
|
|
143
|
+
match: `${NOT_AFTER}${ID}(?=[ \\t]*(?:${GENERIC})?[ \\t]*\\()`,
|
|
144
|
+
scope: 'function',
|
|
145
|
+
},
|
|
146
|
+
// A property or expression-bodied member: same shape, but `{` or `=>`
|
|
147
|
+
// where a method has its parameter list. Scoped as a member so it looks
|
|
148
|
+
// the same at its declaration as it does at `obj.Name`.
|
|
149
|
+
{
|
|
150
|
+
match: `${NOT_AFTER}${ID}(?=[ \\t]*(?:\\{|=>))`,
|
|
151
|
+
scope: 'variable.member',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
match: `\\b${ID}(?=[ \\t]*(?:${GENERIC})?[ \\t]*\\()`,
|
|
155
|
+
scope: 'function.call',
|
|
156
|
+
},
|
|
157
|
+
{ match: `\\b${ID}(?=[ \\t]*=>)`, scope: 'variable.parameter' },
|
|
158
|
+
{ match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
|
|
159
|
+
// A PascalCase name in front of a dot is the receiver of a member
|
|
160
|
+
// access, and in C# that is almost always a type: locals and parameters
|
|
161
|
+
// are camelCase by convention. `Name.Length` on a property of `this` is
|
|
162
|
+
// what this gets wrong.
|
|
163
|
+
{ match: '\\b[A-Z]\\w*(?=\\.)', scope: 'type' },
|
|
164
|
+
{
|
|
165
|
+
match: '=>|\\?\\?=?|\\?\\.|::|\\+\\+|--|&&|\\|\\||<<=?|>>=?|[-+*/%&|^!=<>]=?|[?~^]',
|
|
166
|
+
scope: 'operator',
|
|
167
|
+
},
|
|
168
|
+
{ match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
|
|
169
|
+
{ match: '[,;:]', scope: 'punctuation.delimiter' },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
numbers: {
|
|
173
|
+
rules: [
|
|
174
|
+
{
|
|
175
|
+
match: '\\b0[xX](?:_?[0-9a-fA-F])+(?:[uU][lL]?|[lL][uU]?)?\\b',
|
|
176
|
+
scope: 'number',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
match: '\\b0[bB](?:_?[01])+(?:[uU][lL]?|[lL][uU]?)?\\b',
|
|
180
|
+
scope: 'number',
|
|
181
|
+
},
|
|
182
|
+
// Real literals carry a suffix (`10m`, `1.5f`) that is part of the
|
|
183
|
+
// number, and `.5f` may start with the dot.
|
|
184
|
+
{
|
|
185
|
+
match: '\\b\\d(?:_?\\d)*\\.\\d(?:_?\\d)*(?:[eE][-+]?\\d+)?[fFdDmM]?|\\.\\d(?:_?\\d)*(?:[eE][-+]?\\d+)?[fFdDmM]?|\\b\\d(?:_?\\d)*(?:[eE][-+]?\\d+)?(?:[fFdDmM]|[uU][lL]?|[lL][uU]?)?\\b',
|
|
186
|
+
scope: 'number',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
// ---- strings -------------------------------------------------------------
|
|
191
|
+
// Prefixes are scoped separately so `$@` reads as a modifier on the literal
|
|
192
|
+
// rather than as part of it. Longest opener first: `"""` before `"`.
|
|
193
|
+
strings: {
|
|
194
|
+
rules: [
|
|
195
|
+
{
|
|
196
|
+
match: '(\\$)(""")',
|
|
197
|
+
scope: ['string.special', 'string'],
|
|
198
|
+
push: 'raw-interpolated',
|
|
199
|
+
},
|
|
200
|
+
{ match: '"""', scope: 'string', push: 'raw' },
|
|
201
|
+
{
|
|
202
|
+
match: '(\\$@|@\\$)(")',
|
|
203
|
+
scope: ['string.special', 'string'],
|
|
204
|
+
push: 'verbatim-interpolated',
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
match: '(@)(")',
|
|
208
|
+
scope: ['string.special', 'string'],
|
|
209
|
+
push: 'verbatim',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
match: '(\\$)(")',
|
|
213
|
+
scope: ['string.special', 'string'],
|
|
214
|
+
push: 'interpolated',
|
|
215
|
+
},
|
|
216
|
+
{ match: '"', scope: 'string', push: 'string' },
|
|
217
|
+
// A char literal, escapes included. One rule rather than a state: it is
|
|
218
|
+
// always a single character and always closes on the same line.
|
|
219
|
+
{ match: `'(?:[^'\\\\\\n]|${ESCAPE})'`, scope: 'string' },
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
/** Block comments. C# does not nest them, so this does not push itself. */
|
|
223
|
+
'block-comment': {
|
|
224
|
+
default: 'comment',
|
|
225
|
+
rules: [{ match: '\\*/', pop: true }],
|
|
226
|
+
},
|
|
227
|
+
string: {
|
|
228
|
+
default: 'string',
|
|
229
|
+
rules: [
|
|
230
|
+
{ match: ESCAPE, scope: 'string.escape' },
|
|
231
|
+
{ match: '"', scope: 'string', pop: true },
|
|
232
|
+
// A plain literal cannot span lines, so an unterminated one ends at the
|
|
233
|
+
// line break instead of swallowing the rest of the file.
|
|
234
|
+
{ match: '$', pop: true },
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
interpolated: {
|
|
238
|
+
default: 'string',
|
|
239
|
+
rules: [
|
|
240
|
+
{ match: ESCAPE, scope: 'string.escape' },
|
|
241
|
+
{ include: 'holes' },
|
|
242
|
+
{ match: '"', scope: 'string', pop: true },
|
|
243
|
+
{ match: '$', pop: true },
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
// Verbatim literals span lines and have exactly one escape: `""`. A
|
|
247
|
+
// backslash in them is an ordinary character, which is the whole point of
|
|
248
|
+
// writing `@"C:\temp"`.
|
|
249
|
+
verbatim: {
|
|
250
|
+
default: 'string',
|
|
251
|
+
rules: [
|
|
252
|
+
{ match: '""', scope: 'string.escape' },
|
|
253
|
+
{ match: '"', scope: 'string', pop: true },
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
'verbatim-interpolated': {
|
|
257
|
+
default: 'string',
|
|
258
|
+
rules: [
|
|
259
|
+
{ match: '""', scope: 'string.escape' },
|
|
260
|
+
{ include: 'holes' },
|
|
261
|
+
{ match: '"', scope: 'string', pop: true },
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
// Raw literals have no escapes at all: the closing `"""` is the only thing
|
|
265
|
+
// that ends them, which is what lets them hold quotes verbatim.
|
|
266
|
+
raw: {
|
|
267
|
+
default: 'string',
|
|
268
|
+
rules: [{ match: '"""', scope: 'string', pop: true }],
|
|
269
|
+
},
|
|
270
|
+
'raw-interpolated': {
|
|
271
|
+
default: 'string',
|
|
272
|
+
rules: [{ include: 'holes' }, { match: '"""', scope: 'string', pop: true }],
|
|
273
|
+
},
|
|
274
|
+
/** The `{…}` holes shared by every interpolated flavour. */
|
|
275
|
+
holes: {
|
|
276
|
+
rules: [
|
|
277
|
+
// Doubled braces are literal text, not a hole.
|
|
278
|
+
{ match: '\\{\\{|\\}\\}', scope: 'string.escape' },
|
|
279
|
+
{ match: '\\{', scope: 'interpolation', push: 'interpolation' },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
interpolation: {
|
|
283
|
+
rules: [
|
|
284
|
+
{ match: '\\}', scope: 'interpolation', pop: true },
|
|
285
|
+
// `{total,-8:N2}` — the alignment and the format spec are string syntax,
|
|
286
|
+
// not expression syntax. Parens are excluded from the spec so the `:` of
|
|
287
|
+
// `{(ok ? "y" : "n")}` stays a ternary. The length cap keeps an unclosed
|
|
288
|
+
// `{` cheap: the scan runs to the end of the line and then fails the
|
|
289
|
+
// lookahead, once per `:`, so an uncapped one is quadratic on a run of
|
|
290
|
+
// colons. No real spec — `N2`, `yyyy-MM-dd HH:mm:ss` — is near the bound.
|
|
291
|
+
{ match: ',[ \\t]*-?\\d+(?=[:}])', scope: 'string.special' },
|
|
292
|
+
{ match: ':[^{}()"\\n]{0,120}(?=\\})', scope: 'string.special' },
|
|
293
|
+
{ match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
|
|
294
|
+
{ include: 'expression' },
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
/** Tracks brace depth so `$"{new Foo { A = 1 }}"` keeps its states straight. */
|
|
298
|
+
brace: {
|
|
299
|
+
rules: [
|
|
300
|
+
{ match: '\\}', scope: 'punctuation.bracket', pop: true },
|
|
301
|
+
{ match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
|
|
302
|
+
{ include: 'expression' },
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
export default csharp;
|
|
@@ -0,0 +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;AAW5C,QAAA,MAAM,GAAG,EAAE,OA0FV,CAAA;AAED,eAAe,GAAG,CAAA"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS, SCSS and Less.
|
|
3
|
+
*
|
|
4
|
+
* Selectors, property names and values are separated by state rather than by
|
|
5
|
+
* pattern guessing: entering `{` switches to a declaration state, so `color`
|
|
6
|
+
* as a property and `color` inside a selector cannot be confused.
|
|
7
|
+
*/
|
|
8
|
+
const IDENT = '-{0,2}[A-Za-z_\\u0080-\\uFFFF][\\w-\\u0080-\\uFFFF]*';
|
|
9
|
+
const css = {
|
|
10
|
+
name: 'css',
|
|
11
|
+
aliases: ['scss', 'less'],
|
|
12
|
+
states: {
|
|
13
|
+
root: {
|
|
14
|
+
rules: [
|
|
15
|
+
{ include: 'comments' },
|
|
16
|
+
{ include: 'strings' },
|
|
17
|
+
{ match: '@[A-Za-z-]+', scope: 'keyword' },
|
|
18
|
+
{ match: `\\$${IDENT}`, scope: 'variable' },
|
|
19
|
+
{ match: '\\{', scope: 'punctuation.bracket', push: 'declarations' },
|
|
20
|
+
// Selector pieces.
|
|
21
|
+
{ match: `[.#]${IDENT}`, scope: 'selector' },
|
|
22
|
+
{ match: '::?[A-Za-z-]+', scope: 'selector' },
|
|
23
|
+
// `[` is excluded as well as `]`: an attribute selector cannot contain a
|
|
24
|
+
// bare `[`, and allowing one makes a line of brackets cost O(n) each.
|
|
25
|
+
{ match: '\\[[^[\\]]*\\]', scope: 'selector' },
|
|
26
|
+
{ match: '\\b[a-z][\\w-]*\\b(?![\\w-]*\\s*:)', scope: 'tag' },
|
|
27
|
+
{ match: '[>~+*,]', scope: 'operator' },
|
|
28
|
+
{ match: '[{}();]', scope: 'punctuation' },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
declarations: {
|
|
32
|
+
rules: [
|
|
33
|
+
{ include: 'comments' },
|
|
34
|
+
{ match: '\\}', scope: 'punctuation.bracket', pop: true },
|
|
35
|
+
// A nested rule (SCSS, or a media query body) gets its own scope.
|
|
36
|
+
{ match: '\\{', scope: 'punctuation.bracket', push: 'declarations' },
|
|
37
|
+
{ match: ';', scope: 'punctuation.delimiter' },
|
|
38
|
+
{ match: '@[A-Za-z-]+', scope: 'keyword' },
|
|
39
|
+
{
|
|
40
|
+
match: `(${IDENT})(\\s*)(:)`,
|
|
41
|
+
scope: ['property', null, 'punctuation.delimiter'],
|
|
42
|
+
push: 'value',
|
|
43
|
+
},
|
|
44
|
+
{ match: `\\$${IDENT}`, scope: 'variable' },
|
|
45
|
+
{ match: `[.#&]${IDENT}`, scope: 'selector' },
|
|
46
|
+
{ match: '::?[A-Za-z-]+', scope: 'selector' },
|
|
47
|
+
// A bareword with no `:` after it is incomplete, but consuming it keeps
|
|
48
|
+
// the property rule above from being retried — and failing for want of a
|
|
49
|
+
// colon — at every position of a long identifier run, which is O(n) each.
|
|
50
|
+
{ match: IDENT },
|
|
51
|
+
{ include: 'strings' },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
value: {
|
|
55
|
+
rules: [
|
|
56
|
+
{ match: '(?=[;}])', pop: true },
|
|
57
|
+
{ include: 'comments' },
|
|
58
|
+
{ include: 'strings' },
|
|
59
|
+
{ match: '!important\\b', scope: 'keyword' },
|
|
60
|
+
{
|
|
61
|
+
match: '#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\\b',
|
|
62
|
+
scope: 'number',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
match: 'var\\(\\s*(--[\\w-]+)',
|
|
66
|
+
scope: ['variable'],
|
|
67
|
+
rest: 'function.builtin',
|
|
68
|
+
},
|
|
69
|
+
{ match: '--[\\w-]+', scope: 'variable' },
|
|
70
|
+
{ match: `\\b(${IDENT})(?=\\()`, scope: 'function.call' },
|
|
71
|
+
{
|
|
72
|
+
match: '(-?\\d*\\.?\\d+)((?:e[-+]?\\d+)?(?:%|[a-zA-Z]+)?)',
|
|
73
|
+
scope: ['number', 'unit'],
|
|
74
|
+
},
|
|
75
|
+
{ match: '\\b[a-zA-Z-]+\\b', scope: 'constant' },
|
|
76
|
+
{ match: '[(),/]', scope: 'punctuation' },
|
|
77
|
+
{ match: ';', scope: 'punctuation.delimiter', pop: true },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
comments: {
|
|
81
|
+
rules: [
|
|
82
|
+
{ match: '/\\*[\\s\\S]*?\\*/', scope: 'comment' },
|
|
83
|
+
{ match: '//[^\\n]*', scope: 'comment' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
strings: {
|
|
87
|
+
rules: [
|
|
88
|
+
{ match: '"(?:[^"\\\\\\n]|\\\\.)*"', scope: 'string' },
|
|
89
|
+
{ match: "'(?:[^'\\\\\\n]|\\\\.)*'", scope: 'string' },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
export default css;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dart.d.ts","sourceRoot":"","sources":["../../src/langs/dart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAmD5C,QAAA,MAAM,IAAI,EAAE,OA2OX,CAAA;AAED,eAAe,IAAI,CAAA"}
|