@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,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clojure, ClojureScript and EDN.
|
|
3
|
+
*
|
|
4
|
+
* Clojure has no statement syntax to key off — everything is a list — so the
|
|
5
|
+
* one piece of structure this grammar leans on is *head position*: the symbol
|
|
6
|
+
* directly after `(` is the thing being called. Every head-position rule is a
|
|
7
|
+
* lookbehind (`(?<=\()`) rather than a rule that eats the paren, so the bracket
|
|
8
|
+
* keeps its own `punctuation.bracket` token and priority order still decides
|
|
9
|
+
* whether `(if …)` reads as control flow or as a call.
|
|
10
|
+
*
|
|
11
|
+
* What it keeps apart that a one-color-per-list highlighter does not:
|
|
12
|
+
*
|
|
13
|
+
* - a `def…` name at its definition site (`function`, `class` or `variable`,
|
|
14
|
+
* depending on which form introduced it) versus the same symbol at a call site
|
|
15
|
+
* - a `defn` docstring as documentation, versus a string used as a value
|
|
16
|
+
* - reader forms — `#"…"` regexes, `\newline` chars, `#(…)`, `#?(:clj …)`,
|
|
17
|
+
* `#_`, metadata — which all begin with a character that means something else
|
|
18
|
+
* on its own
|
|
19
|
+
* - Java interop: `System/nanoTime` splits into a builtin type, a separator and
|
|
20
|
+
* a method, and `.length` / `.-field` read as a method and a field
|
|
21
|
+
*
|
|
22
|
+
* Known gaps, all of them cases where a regex cannot know the answer:
|
|
23
|
+
*
|
|
24
|
+
* - `#_` scopes only the discard marker; the form it throws away still
|
|
25
|
+
* highlights, because skipping it means balancing an arbitrary form.
|
|
26
|
+
* - Binding vectors are not parsed, so `[x y]` parameters read as plain symbols.
|
|
27
|
+
* - Any head-position symbol starting with `def` reads as a declaration. That is
|
|
28
|
+
* right for the `def…` macro family (`defroutes`, `defstate`, …) and wrong for
|
|
29
|
+
* a symbol that merely starts with those three letters.
|
|
30
|
+
* - Keyword literals are always `constant`, including the ones used as map keys.
|
|
31
|
+
* - A quoted list is still a list, so the head of `'(a b c)` reads as a call.
|
|
32
|
+
*/
|
|
33
|
+
/** Characters allowed inside a symbol or keyword name. `/` and `:` separate names, so they stay out. */
|
|
34
|
+
const TAIL = "[\\w*+!?<>=&%$|.'#-]";
|
|
35
|
+
/** A name cannot start with a digit, `'` or `#` — those begin other reader forms. */
|
|
36
|
+
const NAME = `[A-Za-z*+!_?<>=&%$|.-]${TAIL}*`;
|
|
37
|
+
/**
|
|
38
|
+
* Word boundaries for a language whose symbols are full of punctuation, where
|
|
39
|
+
* `\b` means nothing useful. They also anchor every unanchored rule below to the
|
|
40
|
+
* start of a name, so no pattern can be retried at each character of a long one.
|
|
41
|
+
*/
|
|
42
|
+
const PREV = "(?<![\\w*+!?<>=&%$|.'#:/-])";
|
|
43
|
+
const NEXT = "(?![\\w*+!?<>=&%$|.'#:/-])";
|
|
44
|
+
/** `^:private` or `^String` sitting between a `def…` form and the name it introduces. */
|
|
45
|
+
const META = `(?:(\\^:?${TAIL}+)(\\s+))?`;
|
|
46
|
+
/** The string a `defn`/`ns` form may carry directly after its name. Anchored to that name, never scanned for on its own. */
|
|
47
|
+
const DOCSTRING = `(?:(\\s+)("(?:[^"\\\\]|\\\\[\\s\\S])*"))?`;
|
|
48
|
+
/** Java classes common enough in Clojure source to be worth telling from a user type. */
|
|
49
|
+
const JAVA = 'String|Integer|Long|Double|Boolean|Object|Number|Class|Exception|Throwable|Math|System|Thread';
|
|
50
|
+
const clojure = {
|
|
51
|
+
name: 'clojure',
|
|
52
|
+
aliases: ['clj', 'cljs', 'cljc', 'edn'],
|
|
53
|
+
states: {
|
|
54
|
+
root: {
|
|
55
|
+
rules: [
|
|
56
|
+
{ match: '^#!.*', scope: 'comment' },
|
|
57
|
+
{ match: ';[^\\n]*', scope: 'comment' },
|
|
58
|
+
// Only the marker: see the "known gaps" note above.
|
|
59
|
+
{ match: '#_', scope: 'comment' },
|
|
60
|
+
// A char literal can hold the character that starts a comment, a string
|
|
61
|
+
// or a list. It wins over all three because it starts one position
|
|
62
|
+
// earlier — at the backslash — and the scanner takes the leftmost match.
|
|
63
|
+
{
|
|
64
|
+
match: '\\\\(?:newline|space|tab|formfeed|backspace|return|u[0-9a-fA-F]{4}|o[0-7]{1,3}|\\S)',
|
|
65
|
+
scope: 'string',
|
|
66
|
+
},
|
|
67
|
+
{ match: '#"', scope: 'regexp', push: 'regexp' },
|
|
68
|
+
{ match: '"', scope: 'string', push: 'string' },
|
|
69
|
+
// `#?(:clj …)` / `#?@(:cljs …)` — reader conditionals pick a platform,
|
|
70
|
+
// so only the marker is a keyword; the branches highlight as usual.
|
|
71
|
+
{ match: '#\\?@?', scope: 'keyword' },
|
|
72
|
+
// `#'foo` is a var reference. Matched with its symbol because the `'`
|
|
73
|
+
// would otherwise block the symbol rules below.
|
|
74
|
+
{ match: `(#')(${NAME})`, scope: ['operator', 'variable'] },
|
|
75
|
+
// `#(` opens an anonymous function and `#{` a set; both are still brackets.
|
|
76
|
+
{ match: '#[({]', scope: 'punctuation.bracket' },
|
|
77
|
+
{ match: `#[A-Za-z]${TAIL}*`, scope: 'type' },
|
|
78
|
+
{ match: `\\^:?${TAIL}+`, scope: 'decorator' },
|
|
79
|
+
// `^{:doc "…"}` — the map form. Leaving the caret alone lets its contents highlight.
|
|
80
|
+
{ match: '\\^', scope: 'operator' },
|
|
81
|
+
{ match: '##(?:-?Inf|NaN)', scope: 'number' },
|
|
82
|
+
// Radix and ratio come first: `2r1011` and `22/7` both start with digits
|
|
83
|
+
// that the decimal branch would happily claim on its own.
|
|
84
|
+
{
|
|
85
|
+
match: `${PREV}[-+]?(?:\\d+[rR][0-9a-zA-Z]+|0[xX][0-9a-fA-F]+N?|\\d+/\\d+|(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][-+]?\\d+)?[MN]?)`,
|
|
86
|
+
scope: 'number',
|
|
87
|
+
},
|
|
88
|
+
// `[clojure.string :as str]` — the alias names a namespace, and every
|
|
89
|
+
// later `str/…` is scoped as one, so it should not read as a builtin.
|
|
90
|
+
{
|
|
91
|
+
match: `(:as)(\\s+)(${NAME})`,
|
|
92
|
+
scope: ['constant', null, 'namespace'],
|
|
93
|
+
},
|
|
94
|
+
// `:kw`, `::auto-resolved`, `:my.ns/kw`. Matched before the head-position
|
|
95
|
+
// rules so `(:name person)` reads as a keyword lookup, not as a call.
|
|
96
|
+
{ match: `${PREV}::?${TAIL}+(?:/${TAIL}+)?`, scope: 'constant' },
|
|
97
|
+
// ---- definition sites --------------------------------------------------
|
|
98
|
+
// The name is scoped by what introduced it, which is the whole reason
|
|
99
|
+
// these are four rules and not one.
|
|
100
|
+
{
|
|
101
|
+
match: `(?<=\\()(def(?:record|type|protocol|interface|struct))(\\s+)${META}(${NAME})`,
|
|
102
|
+
scope: ['keyword.declaration', null, 'decorator', null, 'class'],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
match: `(?<=\\()(def(?:n-?|m(?:acro|ulti|ethod)|test))(\\s+)${META}(${NAME})${DOCSTRING}`,
|
|
106
|
+
scope: ['keyword.declaration', null, 'decorator', null, 'function', null, 'comment.doc'],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
match: `(?<=\\()(def(?:once)?)(\\s+)${META}(${NAME})`,
|
|
110
|
+
scope: ['keyword.declaration', null, 'decorator', null, 'variable'],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
match: `(?<=\\()(ns)(\\s+)${META}(${NAME})${DOCSTRING}`,
|
|
114
|
+
scope: ['keyword.import', null, 'decorator', null, 'namespace', null, 'comment.doc'],
|
|
115
|
+
},
|
|
116
|
+
// Anything else in the `def…` family, including user macros.
|
|
117
|
+
{ match: `(?<=\\()def${TAIL}*${NEXT}`, scope: 'keyword.declaration' },
|
|
118
|
+
// ---- Java interop in head position -------------------------------------
|
|
119
|
+
{
|
|
120
|
+
match: `(?<=\\()(\\.-)(${NAME})`,
|
|
121
|
+
scope: ['punctuation', 'variable.member'],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
match: `(?<=\\()(\\.)(${NAME})`,
|
|
125
|
+
scope: ['punctuation', 'function.method'],
|
|
126
|
+
},
|
|
127
|
+
{ match: `${PREV}nil${NEXT}`, scope: 'constant.builtin' },
|
|
128
|
+
{ match: `${PREV}(?:true|false)${NEXT}`, scope: 'boolean' },
|
|
129
|
+
{
|
|
130
|
+
match: `${PREV}(?:if(?:-not|-let|-some)?|when(?:-not|-let|-some|-first)?|condp?|case|do(?:seq|times|all|run)?|for|loop|recur|while|try|catch|finally|throw)${NEXT}`,
|
|
131
|
+
scope: 'keyword.control',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
match: `${PREV}(?:fn|let(?:fn)?|binding|reify|proxy|declare|set!|var|new|extend-(?:type|protocol))${NEXT}`,
|
|
135
|
+
scope: 'keyword.declaration',
|
|
136
|
+
},
|
|
137
|
+
// Threading macros compose expressions, so they read as operators rather
|
|
138
|
+
// than as the calls they expand into.
|
|
139
|
+
{
|
|
140
|
+
match: `${PREV}(?:(?:some|cond)?->>?|as->|and|or|not)${NEXT}`,
|
|
141
|
+
scope: 'keyword.operator',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
match: `${PREV}(?:require|import|use|refer(?:-clojure)?|in-ns|load)${NEXT}`,
|
|
145
|
+
scope: 'keyword.import',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
match: `${PREV}(?:not=|[<>]=?|=|[-+*/]|rem|quot|mod)${NEXT}`,
|
|
149
|
+
scope: 'operator',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
match: `${PREV}(?:mapv?|filter|reduce|apply|into|conj|assoc(?:-in)?|dissoc|get(?:-in)?|update(?:-in)?|merge|count|first|second|rest|last|nth|take|drop|range|str|keyword|name|println|vec|vector|list|set|seq|sort(?:-by)?|concat|empty\\?|nil\\?|some|every\\?|contains\\?|inc|dec|swap!|reset!|atom|partial|comp|juxt)${NEXT}`,
|
|
153
|
+
scope: 'function.builtin',
|
|
154
|
+
},
|
|
155
|
+
// ---- types -------------------------------------------------------------
|
|
156
|
+
// `System/nanoTime` before bare `System`, so the member half is not lost.
|
|
157
|
+
{
|
|
158
|
+
match: `${PREV}(${JAVA})(/)(${NAME})`,
|
|
159
|
+
scope: ['type.builtin', 'punctuation.delimiter', 'function.method'],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
match: `${PREV}([A-Z]${TAIL}*)(/)(${NAME})`,
|
|
163
|
+
scope: ['type', 'punctuation.delimiter', 'function.method'],
|
|
164
|
+
},
|
|
165
|
+
{ match: `${PREV}(?:${JAVA})${NEXT}`, scope: 'type.builtin' },
|
|
166
|
+
// CapWords is a type by convention. `(Point. 1 2)` keeps its trailing dot
|
|
167
|
+
// in the same token, which is what makes it read as a constructor.
|
|
168
|
+
{ match: `${PREV}[A-Z]${TAIL}*`, scope: 'type' },
|
|
169
|
+
// A dotted lowercase symbol is a namespace or a Java package: `clojure.string`.
|
|
170
|
+
{ match: `${PREV}[a-z][\\w-]*(?:\\.[\\w-]+)+`, scope: 'namespace' },
|
|
171
|
+
// ---- head position -----------------------------------------------------
|
|
172
|
+
// Last of the name rules, so keywords, builtins and types have all had
|
|
173
|
+
// their turn: whatever is left in head position is a call.
|
|
174
|
+
{
|
|
175
|
+
match: `(?<=\\()(?:(${NAME})(/))?(${NAME})`,
|
|
176
|
+
scope: ['namespace', 'punctuation.delimiter', 'function.call'],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
match: `${PREV}(${NAME})(/)`,
|
|
180
|
+
scope: ['namespace', 'punctuation.delimiter'],
|
|
181
|
+
},
|
|
182
|
+
// `%`, `%1`, `%&` — the implicit parameters of `#(…)`.
|
|
183
|
+
{ match: `${PREV}%(?:\\d+|&)?`, scope: 'variable.parameter' },
|
|
184
|
+
{ match: `${PREV}&${NEXT}`, scope: 'operator' },
|
|
185
|
+
// Quote, syntax-quote, unquote and deref. `PREV` keeps the `'` inside a
|
|
186
|
+
// symbol like `x'` from reading as a quote of its own.
|
|
187
|
+
{ match: `${PREV}(?:~@|[~@'\`])`, scope: 'operator' },
|
|
188
|
+
{ match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
|
|
189
|
+
// Commas are whitespace in Clojure, and are used exactly like one.
|
|
190
|
+
{ match: ',', scope: 'punctuation.delimiter' },
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
string: {
|
|
194
|
+
default: 'string',
|
|
195
|
+
// Strings are multi-line, so there is no line-end escape hatch here.
|
|
196
|
+
rules: [
|
|
197
|
+
{ match: '\\\\(?:u[0-9a-fA-F]{4}|[\\s\\S])', scope: 'string.escape' },
|
|
198
|
+
{ match: '"', scope: 'string', pop: true },
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
regexp: {
|
|
202
|
+
default: 'regexp',
|
|
203
|
+
rules: [
|
|
204
|
+
{ match: '\\\\[\\s\\S]', scope: 'string.escape' },
|
|
205
|
+
{ match: '"', scope: 'regexp', pop: true },
|
|
206
|
+
// Regex literals are written on one line in practice; bailing at the line
|
|
207
|
+
// end keeps an unterminated `#"` from swallowing the rest of the file.
|
|
208
|
+
{ match: '$', pop: true },
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
export default clojure;
|
|
@@ -0,0 +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,OAwUV,CAAA;AAED,eAAe,GAAG,CAAA"}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C++.
|
|
3
|
+
*
|
|
4
|
+
* What this grammar spends its bytes on, and why:
|
|
5
|
+
*
|
|
6
|
+
* - Raw string literals get a state. `R"tag(...)tag"` can only be matched
|
|
7
|
+
* exactly with a backreference and the compiler rejects those, so the state
|
|
8
|
+
* closes on any `)tag"` — see `raw-string` for what that gets wrong.
|
|
9
|
+
* - `'` is both a character literal and a digit separator. The number rules
|
|
10
|
+
* accept `1'048'576` and win because they start at the digit, which is to the
|
|
11
|
+
* left of the quote the character rule would have opened on.
|
|
12
|
+
* - A definition is told from a call by the `{` that follows the parameter
|
|
13
|
+
* list, with room in between for `const noexcept`, a trailing return type and
|
|
14
|
+
* a constructor's member-initialiser list.
|
|
15
|
+
* - The preprocessor is a second language living at the start of a line, so its
|
|
16
|
+
* directives are anchored to `^`, exactly as in the C grammar.
|
|
17
|
+
*
|
|
18
|
+
* Angle brackets stay operators. Nothing local to a `<` says whether `a < b` is
|
|
19
|
+
* a comparison or `Ring<T>` a template argument list, and the guesses that get
|
|
20
|
+
* it right cost more than the colour is worth.
|
|
21
|
+
*
|
|
22
|
+
* Ordinary identifiers deliberately match no rule and inherit the block's
|
|
23
|
+
* foreground, which keeps both the markup and the grammar small.
|
|
24
|
+
*/
|
|
25
|
+
const ID = '[A-Za-z_]\\w*';
|
|
26
|
+
/** `\n`, `\0`, `\x41`, `\u00e9`, `\U0001F600`, `\033`, and a line continuation. */
|
|
27
|
+
const ESCAPE = '\\\\(?:x[0-9a-fA-F]+|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-7]{1,3}|\\r?\\n|.)';
|
|
28
|
+
/**
|
|
29
|
+
* printf conversions, length modifiers included (`%zu`, `%#06x`, `%.2f`).
|
|
30
|
+
*
|
|
31
|
+
* Every run is capped. An open-ended `[-+ #0']*` before a required conversion
|
|
32
|
+
* character means one `%` followed by a long flag run is rescanned from every
|
|
33
|
+
* column, which is quadratic on input nobody wrote by hand.
|
|
34
|
+
*/
|
|
35
|
+
const FORMAT = "%[-+ #0']{0,8}(?:\\d{1,10}|\\*)?(?:\\.(?:\\d{1,10}|\\*)?)?(?:hh|ll|[hljztL])?[diouxXeEfFgGaAcspn%]";
|
|
36
|
+
/**
|
|
37
|
+
* Any literal suffix. `u`, `ull`, `f` and `z` are the standard ones; `_km`,
|
|
38
|
+
* `ms` and `sv` are user-defined literals, which may be spelled as any
|
|
39
|
+
* identifier — so one open rule covers both, at the price of reading the `abc`
|
|
40
|
+
* in the ill-formed `123abc` as part of the number.
|
|
41
|
+
*/
|
|
42
|
+
const SUFFIX = '(?:[A-Za-z_]\\w*)?';
|
|
43
|
+
/** The `u8`/`u`/`U`/`L` prefix on a string, character or raw literal. */
|
|
44
|
+
const ENCODING = '(?:u8|[uUL])?';
|
|
45
|
+
/**
|
|
46
|
+
* What C++ lets a parameter list be followed by before the rest of the
|
|
47
|
+
* declaration: the cv- and ref-qualifiers, `noexcept`, and the `try` that opens
|
|
48
|
+
* a function-try-block.
|
|
49
|
+
*/
|
|
50
|
+
const QUALIFIER = '(?:const|noexcept|override|final|try|&&?)';
|
|
51
|
+
/**
|
|
52
|
+
* The widest run of whitespace the declaration rules step over.
|
|
53
|
+
*
|
|
54
|
+
* Twelve was not enough for ordinary code: three levels of four-space indent
|
|
55
|
+
* put thirteen characters between a `)` and the `:` on the next line, and the
|
|
56
|
+
* colouring changed with the indentation. Every run is still capped, because an
|
|
57
|
+
* open-ended one would be replayed from each position of a line of blanks.
|
|
58
|
+
*/
|
|
59
|
+
const GAP = '[ \\t\\r\\n]{0,32}';
|
|
60
|
+
/**
|
|
61
|
+
* Everything C++ allows between a parameter list and the `{` of a body:
|
|
62
|
+
* qualifiers, a trailing return type, then a constructor's member-initialiser
|
|
63
|
+
* list. Every scan excludes `{`, so each has exactly one place it can stop and
|
|
64
|
+
* the lookahead cannot backtrack its way into a quadratic rescan of the line.
|
|
65
|
+
*
|
|
66
|
+
* The member-initialiser scan has to end on the `)` of the last initialiser.
|
|
67
|
+
* Without that, a ternary whose false branch is brace-initialised — `ok ?
|
|
68
|
+
* parse(s) : Result{}` — satisfies the branch and turns the call into a
|
|
69
|
+
* definition. The price is that `: n_{0} {}` is not recognised, which the
|
|
70
|
+
* `{`-free scan already gave up on.
|
|
71
|
+
*/
|
|
72
|
+
const AFTER_PARAMS = `(?:[ \\t]*${QUALIFIER}){0,4}[ \\t]*` +
|
|
73
|
+
`(?:->[^;{}\\n]{0,60})?(?:${GAP}:[^;{}]{0,158}\\)[ \\t\\r\\n]{0,4})?(?:\\r?\\n[ \\t]*)?\\{`;
|
|
74
|
+
/**
|
|
75
|
+
* Qualifiers and whitespace, as they sit between the `)` of a constructor's
|
|
76
|
+
* parameter list and the `:` that opens its member-initialiser list — including
|
|
77
|
+
* the `try` of `Foo::Foo() try : n_(0) {}`.
|
|
78
|
+
*
|
|
79
|
+
* Each repetition has to consume a qualifier word, so the whitespace runs never
|
|
80
|
+
* compete for the same characters and a `)` followed by blanks costs one pass
|
|
81
|
+
* over them rather than one per split.
|
|
82
|
+
*/
|
|
83
|
+
const BEFORE_INIT = `(?:${GAP}${QUALIFIER}){0,4}${GAP}`;
|
|
84
|
+
const cpp = {
|
|
85
|
+
name: 'cpp',
|
|
86
|
+
aliases: ['c++', 'cc', 'cxx', 'hpp', 'hxx', 'h++', 'cppm'],
|
|
87
|
+
states: {
|
|
88
|
+
root: {
|
|
89
|
+
rules: [
|
|
90
|
+
// ---- comments --------------------------------------------------------
|
|
91
|
+
// Doxygen opens with `/**` or `/*!`; the lookahead keeps `/**/` and a
|
|
92
|
+
// `/***` banner out of the doc scope.
|
|
93
|
+
// States, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and fails
|
|
94
|
+
// once per opener, which is O(n2) on an unterminated `/*`.
|
|
95
|
+
{
|
|
96
|
+
match: '/\\*[*!](?![/*])',
|
|
97
|
+
scope: 'comment.doc',
|
|
98
|
+
push: 'doc-comment',
|
|
99
|
+
},
|
|
100
|
+
{ match: '/\\*', scope: 'comment', push: 'block-comment' },
|
|
101
|
+
{ match: '//[/!][^\\n]*', scope: 'comment.doc' },
|
|
102
|
+
{ match: '//[^\\n]*', scope: 'comment' },
|
|
103
|
+
// ---- preprocessor ----------------------------------------------------
|
|
104
|
+
// Indentation is captured rather than scoped, so `# if` inside a nest
|
|
105
|
+
// of conditionals keeps its leading whitespace unstyled.
|
|
106
|
+
{
|
|
107
|
+
match: '^([ \\t]*)(#[ \\t]*include(?:_next)?)([ \\t]*)(<[^>\\n]*>|"[^"\\n]*")',
|
|
108
|
+
scope: [null, 'keyword.import', null, 'string'],
|
|
109
|
+
},
|
|
110
|
+
// A macro is function-like exactly when `(` touches its name.
|
|
111
|
+
{
|
|
112
|
+
match: `^([ \\t]*)(#[ \\t]*define)([ \\t]+)(${ID})(?=\\()`,
|
|
113
|
+
scope: [null, 'keyword.declaration', null, 'function'],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
match: `^([ \\t]*)(#[ \\t]*(?:define|undef))([ \\t]+)(${ID})`,
|
|
117
|
+
scope: [null, 'keyword.declaration', null, 'constant'],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
// `elifdef`/`elifndef` are C++23, and they have to precede `elif` in
|
|
121
|
+
// the alternation or `\b` would never let the longer spelling match.
|
|
122
|
+
match: '^([ \\t]*)(#[ \\t]*(?:ifdef|ifndef|elifdef|elifndef|if|elif|else|endif))\\b',
|
|
123
|
+
scope: [null, 'keyword.control'],
|
|
124
|
+
},
|
|
125
|
+
// Everything else the preprocessor understands: pragma, error, line…
|
|
126
|
+
{ match: '^([ \\t]*)(#[ \\t]*[a-z_]+)', scope: [null, 'keyword'] },
|
|
127
|
+
// The backslash that splices a macro onto the next line.
|
|
128
|
+
{ match: '\\\\(?=\\r?\\n)', scope: 'operator' },
|
|
129
|
+
// ---- attributes ------------------------------------------------------
|
|
130
|
+
// `[[nodiscard]]`, `[[deprecated("use push")]]`. The scan excludes both
|
|
131
|
+
// brackets, so a run of `[[` costs O(1) each rather than O(line); an
|
|
132
|
+
// attribute holding a nested `[` renders unscoped.
|
|
133
|
+
{ match: '\\[\\[[^\\[\\]\\n]{0,120}\\]\\]', scope: 'decorator' },
|
|
134
|
+
// ---- literals --------------------------------------------------------
|
|
135
|
+
// Raw strings first: the opener is `R"`, and the plain-string rule would
|
|
136
|
+
// otherwise take the quote and read the body as ordinary escapes.
|
|
137
|
+
{
|
|
138
|
+
match: `(${ENCODING}R)("[^()\\\\\\s]{0,16}\\()`,
|
|
139
|
+
scope: ['string.special', 'string'],
|
|
140
|
+
push: 'raw-string',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
match: `${ENCODING}(")`,
|
|
144
|
+
scope: ['string'],
|
|
145
|
+
rest: 'string.special',
|
|
146
|
+
push: 'string',
|
|
147
|
+
},
|
|
148
|
+
// Bounded repetition: a stray apostrophe must not scan to end of line,
|
|
149
|
+
// and multi-character constants (`'ab'`) are still legal C++.
|
|
150
|
+
{
|
|
151
|
+
match: `${ENCODING}('(?:[^'\\\\\\n]|\\\\[^\\n]){1,8}')`,
|
|
152
|
+
scope: ['string'],
|
|
153
|
+
rest: 'string.special',
|
|
154
|
+
},
|
|
155
|
+
// ---- keywords --------------------------------------------------------
|
|
156
|
+
// The tag rule sits above the plain `class` keyword so the two are one
|
|
157
|
+
// match and the name introduced reads as a class.
|
|
158
|
+
{
|
|
159
|
+
match: `\\b(class|struct|union|enum(?:[ \\t]+(?:class|struct))?)([ \\t]+)(${ID})`,
|
|
160
|
+
scope: ['keyword.declaration', null, 'class'],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
match: `\\b(namespace)([ \\t]+)(${ID}(?:::${ID})*)`,
|
|
164
|
+
scope: ['keyword.declaration', null, 'namespace'],
|
|
165
|
+
},
|
|
166
|
+
// `using namespace` pulls names in; a bare `using` declares an alias.
|
|
167
|
+
// The path is claimed here so it reads the same way `namespace a::b`
|
|
168
|
+
// does — the `(?=::)` rule further down only reaches the segments that
|
|
169
|
+
// have a `::` after them, which leaves the last one unscoped.
|
|
170
|
+
{
|
|
171
|
+
match: `\\b(using)([ \\t]+)(namespace)([ \\t]+)(${ID}(?:::${ID})*)`,
|
|
172
|
+
scope: ['keyword.import', null, 'keyword.import', null, 'namespace'],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
match: '\\b(using)([ \\t]+)(namespace)\\b',
|
|
176
|
+
scope: ['keyword.import', null, 'keyword.import'],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
match: '\\b(?:if|else|for|while|do|switch|case|default|break|continue|return|goto|try|catch|throw|co_await|co_return|co_yield)\\b',
|
|
180
|
+
scope: 'keyword.control',
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
match: '\\b(?:class|struct|union|enum|typedef|using|template|typename|namespace|auto|const|constexpr|consteval|constinit|static|static_assert|extern|inline|virtual|override|final|explicit|friend|mutable|volatile|thread_local|public|private|protected|operator|concept)\\b',
|
|
184
|
+
scope: 'keyword.declaration',
|
|
185
|
+
},
|
|
186
|
+
// The cast operators end in `_cast`, and `_` is a word character, so
|
|
187
|
+
// `\b static \b` cannot reach inside `static_cast` — the two stay apart
|
|
188
|
+
// without any ordering trick.
|
|
189
|
+
{
|
|
190
|
+
match: '\\b(?:sizeof|alignof|alignas|typeid|decltype|noexcept|requires|new|delete|static_cast|dynamic_cast|const_cast|reinterpret_cast|and|or|not|xor|defined)\\b',
|
|
191
|
+
scope: 'keyword.operator',
|
|
192
|
+
},
|
|
193
|
+
{ match: '\\b(?:true|false)\\b', scope: 'boolean' },
|
|
194
|
+
{ match: '\\b(?:nullptr|NULL|EOF)\\b', scope: 'constant.builtin' },
|
|
195
|
+
// The iostream globals, plus the `endl` every program uses beside them.
|
|
196
|
+
{
|
|
197
|
+
match: '\\b(?:this|cout|cerr|clog|cin|endl|stdin|stdout|stderr|errno)\\b',
|
|
198
|
+
scope: 'variable.builtin',
|
|
199
|
+
},
|
|
200
|
+
// `map`, `set`, `array`, `pair`, `list` and `function` are missing on
|
|
201
|
+
// purpose: they are as often a variable's name as a type's.
|
|
202
|
+
{
|
|
203
|
+
match: '\\b(?:void|bool|char|char(?:8|16|32)_t|wchar_t|short|int|long|float|double|signed|unsigned|size_t|ssize_t|ptrdiff_t|nullptr_t|u?int(?:8|16|32|64|ptr|max)_t|string|string_view|vector|unordered_map|unordered_set|shared_ptr|unique_ptr|weak_ptr|optional|variant|tuple|ostream)\\b',
|
|
204
|
+
scope: 'type.builtin',
|
|
205
|
+
},
|
|
206
|
+
// ---- names -----------------------------------------------------------
|
|
207
|
+
// A leading underscore pair is reserved for the implementation, so
|
|
208
|
+
// `__FILE__`, `__VA_ARGS__` and `__attribute__` are all compiler magic.
|
|
209
|
+
{ match: '\\b__\\w+', scope: 'variable.special' },
|
|
210
|
+
// Matched at the accessor, so `obj.size` never reads as the free
|
|
211
|
+
// function and `ptr->count` never as a call.
|
|
212
|
+
{
|
|
213
|
+
match: `(->)(${ID})(?=[ \\t]*\\()`,
|
|
214
|
+
scope: ['operator', 'function.method'],
|
|
215
|
+
},
|
|
216
|
+
{ match: `(->)(${ID})`, scope: ['operator', 'variable.member'] },
|
|
217
|
+
{
|
|
218
|
+
match: `(\\.)(${ID})(?=[ \\t]*\\()`,
|
|
219
|
+
scope: ['punctuation', 'function.method'],
|
|
220
|
+
},
|
|
221
|
+
{ match: `(\\.)(${ID})`, scope: ['punctuation', 'variable.member'] },
|
|
222
|
+
// An entry in a constructor's member-initialiser list is spelled like a
|
|
223
|
+
// definition — `size_(0) {}` is an identifier, a parameter list and a
|
|
224
|
+
// brace — so the last one would otherwise read as one. What tells them
|
|
225
|
+
// apart is the `,` or the `:` that introduces the entry, and keying on
|
|
226
|
+
// that punctuation keeps the guard off the hot path: it is tried only
|
|
227
|
+
// where one of those appears, not at every position.
|
|
228
|
+
//
|
|
229
|
+
// The `:` half has to see the `)` of the parameter list too. A bare `:`
|
|
230
|
+
// is far more often a label, an access specifier or a ternary, and
|
|
231
|
+
// guarding on one of those demotes what follows: `public:` turned the
|
|
232
|
+
// constructor right under it into a call, and `case 1: printf(` and
|
|
233
|
+
// `a ? b : free(p)` lost their builtin colour. It is a state rather
|
|
234
|
+
// than one long rule because `noexcept` and `try` may sit between the
|
|
235
|
+
// two, and swallowing them here would cost them their keyword colour.
|
|
236
|
+
//
|
|
237
|
+
// The comma rule swallows its delimiter, so a builtin called straight
|
|
238
|
+
// after one — `f(a, move(b))` — reads as an ordinary call rather than
|
|
239
|
+
// as a builtin.
|
|
240
|
+
{
|
|
241
|
+
match: `(,)(${GAP})(${ID})(?=[ \\t]*\\()`,
|
|
242
|
+
scope: ['punctuation.delimiter', null, 'function.call'],
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
match: `\\)(?=${BEFORE_INIT}:${GAP}${ID}[ \\t]*\\()`,
|
|
246
|
+
scope: 'punctuation.bracket',
|
|
247
|
+
push: 'member-init',
|
|
248
|
+
},
|
|
249
|
+
// A definition is a parameter list followed by a body. The parameter
|
|
250
|
+
// scan excludes parens, so `if (ok(x)) {` and `while (next(it)) {` stay
|
|
251
|
+
// calls — and the keyword rules above have already claimed `if` and
|
|
252
|
+
// `while` anyway. A definition taking a function pointer, or one with
|
|
253
|
+
// more than 120 characters of parameters, falls back to `function.call`,
|
|
254
|
+
// and so does a prototype, which ends in `;` rather than a body.
|
|
255
|
+
{
|
|
256
|
+
match: `\\b${ID}(?=[ \\t]*\\([^;(){}]{0,120}\\)${AFTER_PARAMS})`,
|
|
257
|
+
scope: 'function',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
match: '\\b(?:move|forward|make_shared|make_unique|swap|begin|end|to_string|printf|snprintf|memcpy|strlen|malloc|free|exit|assert)\\b(?=[ \\t]*\\()',
|
|
261
|
+
scope: 'function.builtin',
|
|
262
|
+
},
|
|
263
|
+
// Before the constant and type rules, so a SCREAMING_CASE macro used as
|
|
264
|
+
// `CLAMP(x, 0, 9)` reads as the call it expands to.
|
|
265
|
+
{ match: `\\b${ID}(?=[ \\t]*\\()`, scope: 'function.call' },
|
|
266
|
+
// SCREAMING_CASE is a macro or an enumerator; `_t` and CapWords are the
|
|
267
|
+
// two ways a C++ codebase spells a type.
|
|
268
|
+
{ match: '\\b[A-Z][A-Z0-9_]+\\b', scope: 'constant' },
|
|
269
|
+
{ match: `\\b${ID}_t\\b`, scope: 'type' },
|
|
270
|
+
{ match: '\\b[A-Z]\\w*\\b', scope: 'type' },
|
|
271
|
+
// Below the type rules, so `Ring::make()` keeps `Ring` a type while
|
|
272
|
+
// `ring::detail::flush()` reads as the namespace path it is.
|
|
273
|
+
{ match: '\\b[a-z_]\\w*(?=::)', scope: 'namespace' },
|
|
274
|
+
// ---- numbers ---------------------------------------------------------
|
|
275
|
+
// `'` is a digit separator here. These rules start at the digit, which
|
|
276
|
+
// is to the left of the first quote, so the leftmost-match rule hands
|
|
277
|
+
// `1'048'576` to them rather than to the character literal above.
|
|
278
|
+
// Hex first: `0x1p-3` is a float, and the decimal rule would stop at the
|
|
279
|
+
// `0`. Octal needs no rule of its own — `0755` is a number either way.
|
|
280
|
+
{
|
|
281
|
+
match: `\\b0[xX][0-9a-fA-F']+(?:\\.[0-9a-fA-F']*)?(?:[pP][-+]?\\d+)?${SUFFIX}\\b`,
|
|
282
|
+
scope: 'number',
|
|
283
|
+
},
|
|
284
|
+
{ match: `\\b0[bB][01']+${SUFFIX}\\b`, scope: 'number' },
|
|
285
|
+
{
|
|
286
|
+
match: `\\b\\d[\\d']*(?:\\.[\\d']*)?(?:[eE][-+]?\\d+)?${SUFFIX}\\b`,
|
|
287
|
+
scope: 'number',
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
match: `\\.\\d[\\d']*(?:[eE][-+]?\\d+)?${SUFFIX}\\b`,
|
|
291
|
+
scope: 'number',
|
|
292
|
+
},
|
|
293
|
+
// ---- syntax ----------------------------------------------------------
|
|
294
|
+
// `<=>` before `<=`, and the pointer-to-member pair before plain `.`
|
|
295
|
+
// and `*`. The member rules above already took `.name`, so `.` only
|
|
296
|
+
// reaches here as an operator.
|
|
297
|
+
{
|
|
298
|
+
match: '<=>|->\\*|\\.\\*|->|::|\\+\\+|--|<<=?|>>=?|&&|\\|\\||\\.{3}|[-+*/%&|^!=<>]=?|[?~]',
|
|
299
|
+
scope: 'operator',
|
|
300
|
+
},
|
|
301
|
+
{ match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
|
|
302
|
+
{ match: '[,;:]', scope: 'punctuation.delimiter' },
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* From the `)` of a constructor's parameter list to the first entry of its
|
|
307
|
+
* member-initialiser list.
|
|
308
|
+
*
|
|
309
|
+
* Entered only on a lookahead that has already seen that whole shape, so
|
|
310
|
+
* these rules just have to name the pieces it allows — which is what keeps
|
|
311
|
+
* `noexcept` a keyword instead of unscoped filler. The entry name pops the
|
|
312
|
+
* state, and every later entry is caught by the `,` rule back in `root`.
|
|
313
|
+
*/
|
|
314
|
+
'member-init': {
|
|
315
|
+
rules: [
|
|
316
|
+
// Ahead of the name rule, so a qualifier is not read as the first
|
|
317
|
+
// entry. `final` and `override` are contextual keywords rather than
|
|
318
|
+
// reserved words, so they are also legal member names — the `(` guard
|
|
319
|
+
// is what lets `: final(f)` reach the entry rule below. `const` rides
|
|
320
|
+
// along in the same guard for symmetry — it cannot legally be a member
|
|
321
|
+
// name. `noexcept` and `try` stay unguarded because `noexcept(true)`
|
|
322
|
+
// is a real qualifier and neither can be named.
|
|
323
|
+
{
|
|
324
|
+
match: '\\b(?:const|override|final)\\b(?![ \\t]*\\()',
|
|
325
|
+
scope: 'keyword.declaration',
|
|
326
|
+
},
|
|
327
|
+
{ match: '\\bnoexcept\\b', scope: 'keyword.operator' },
|
|
328
|
+
{ match: '\\btry\\b', scope: 'keyword.control' },
|
|
329
|
+
{ match: '&&?', scope: 'operator' },
|
|
330
|
+
{ match: ':', scope: 'punctuation.delimiter' },
|
|
331
|
+
{ match: `${ID}(?=[ \\t]*\\()`, scope: 'function.call', pop: true },
|
|
332
|
+
// Nothing else can appear between the `)` and the first entry, so
|
|
333
|
+
// anything that does means the lookahead that pushed this state was
|
|
334
|
+
// wrong about the construct. Leave before the body rather than run to
|
|
335
|
+
// the end of the file with every later scope suppressed.
|
|
336
|
+
{ match: '(?=[{;])', pop: true },
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
/** Block comments. C++ does not nest them, so these do not push themselves. */
|
|
340
|
+
'block-comment': {
|
|
341
|
+
default: 'comment',
|
|
342
|
+
rules: [{ match: '\\*/', pop: true }],
|
|
343
|
+
},
|
|
344
|
+
'doc-comment': {
|
|
345
|
+
default: 'comment.doc',
|
|
346
|
+
rules: [{ match: '\\*/', pop: true }],
|
|
347
|
+
},
|
|
348
|
+
string: {
|
|
349
|
+
default: 'string',
|
|
350
|
+
rules: [
|
|
351
|
+
{ match: ESCAPE, scope: 'string.escape' },
|
|
352
|
+
{ match: FORMAT, scope: 'string.special' },
|
|
353
|
+
// The closer takes any user-defined literal suffix with it: `"a"s`,
|
|
354
|
+
// `"path"sv`. Doing it here rather than back in `root` is what keeps a
|
|
355
|
+
// lookbehind out of the root alternation — a rule that starts with one
|
|
356
|
+
// costs the merged regex its first-character scan, and that was worth
|
|
357
|
+
// 1.5-2x throughput across the whole grammar.
|
|
358
|
+
{
|
|
359
|
+
match: `(")(${ID})?`,
|
|
360
|
+
scope: ['string', 'string.special'],
|
|
361
|
+
pop: true,
|
|
362
|
+
},
|
|
363
|
+
// An unterminated literal ends at the line break instead of swallowing
|
|
364
|
+
// the rest of the file. A continued one does not reach here: the
|
|
365
|
+
// backslash-newline is an escape, and it matches first.
|
|
366
|
+
{ match: '$', pop: true },
|
|
367
|
+
],
|
|
368
|
+
},
|
|
369
|
+
/**
|
|
370
|
+
* The body of `R"tag(…)tag"`. Nothing in it is escaped, so the state has one
|
|
371
|
+
* rule — and that rule cannot check the delimiter, because tying the closer
|
|
372
|
+
* to the opener needs a backreference and the compiler rejects those. Any
|
|
373
|
+
* `)tag"` closes, which is exact for the common `R"(…)"` and wrong only for
|
|
374
|
+
* a tagged literal whose body contains a differently tagged closer. There is
|
|
375
|
+
* no `$` escape hatch: a raw string spanning lines is the point of one.
|
|
376
|
+
*/
|
|
377
|
+
'raw-string': {
|
|
378
|
+
default: 'string',
|
|
379
|
+
// The closer carries any user-defined literal suffix, exactly as the
|
|
380
|
+
// plain string state does.
|
|
381
|
+
rules: [
|
|
382
|
+
{
|
|
383
|
+
match: `(\\)[^()\\\\\\s]{0,16}")(${ID})?`,
|
|
384
|
+
scope: ['string', 'string.special'],
|
|
385
|
+
pop: true,
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
export default cpp;
|
|
@@ -0,0 +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,OA4Rb,CAAA;AAED,eAAe,MAAM,CAAA"}
|