@scalar/highlight 0.3.0 → 0.4.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 +49 -0
- package/README.md +52 -13
- package/dist/all.d.ts.map +1 -1
- package/dist/all.js +2 -0
- package/dist/compat/hast.d.ts.map +1 -1
- package/dist/compat/hast.js +4 -2
- package/dist/compat/hljs.d.ts.map +1 -1
- package/dist/compat/hljs.js +2 -1
- package/dist/compat/languages.d.ts.map +1 -1
- package/dist/compat/languages.js +2 -4
- package/dist/compat/syntax-highlight.d.ts.map +1 -1
- package/dist/compat/syntax-highlight.js +107 -29
- package/dist/core/compile.d.ts +9 -1
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +128 -10
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +8 -4
- package/dist/core/render.d.ts.map +1 -1
- package/dist/core/render.js +12 -6
- package/dist/core/tokenize.d.ts.map +1 -1
- package/dist/core/tokenize.js +161 -17
- package/dist/core/types.d.ts +74 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/langs/bash.d.ts.map +1 -1
- package/dist/langs/bash.js +60 -13
- package/dist/langs/csharp.d.ts.map +1 -1
- package/dist/langs/csharp.js +11 -5
- package/dist/langs/css.d.ts.map +1 -1
- package/dist/langs/css.js +84 -7
- package/dist/langs/go.d.ts.map +1 -1
- package/dist/langs/go.js +7 -1
- package/dist/langs/html.d.ts +0 -10
- package/dist/langs/html.d.ts.map +1 -1
- package/dist/langs/html.js +63 -24
- package/dist/langs/http.d.ts.map +1 -1
- package/dist/langs/http.js +25 -9
- package/dist/langs/javascript.d.ts.map +1 -1
- package/dist/langs/javascript.js +146 -30
- package/dist/langs/json.d.ts.map +1 -1
- package/dist/langs/json.js +7 -1
- package/dist/langs/julia.d.ts +4 -0
- package/dist/langs/julia.d.ts.map +1 -0
- package/dist/langs/julia.js +181 -0
- package/dist/langs/markdown.d.ts +9 -3
- package/dist/langs/markdown.d.ts.map +1 -1
- package/dist/langs/markdown.js +127 -6
- package/dist/langs/ocaml.d.ts.map +1 -1
- package/dist/langs/ocaml.js +16 -7
- package/dist/langs/php.d.ts.map +1 -1
- package/dist/langs/php.js +69 -19
- package/dist/langs/r.js +9 -9
- package/dist/langs/rust.d.ts.map +1 -1
- package/dist/langs/rust.js +19 -10
- package/dist/langs/sql.d.ts.map +1 -1
- package/dist/langs/sql.js +9 -3
- package/dist/langs/yaml.d.ts +0 -7
- package/dist/langs/yaml.d.ts.map +1 -1
- package/dist/langs/yaml.js +157 -28
- package/dist/lazy.d.ts +1 -0
- package/dist/lazy.d.ts.map +1 -1
- package/dist/lazy.js +6 -2
- package/package.json +3 -3
package/dist/langs/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/langs/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/langs/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA2C5C,QAAA,MAAM,IAAI,EAAE,OAgLX,CAAA;AAED,eAAe,IAAI,CAAA"}
|
package/dist/langs/http.js
CHANGED
|
@@ -9,21 +9,29 @@
|
|
|
9
9
|
* - a header name is only matched from the start of a line, which is the only
|
|
10
10
|
* way to tell it from the colons inside `Host: localhost:8080` or a timestamp
|
|
11
11
|
* - the blank line after the headers switches into the body, where JSON — the
|
|
12
|
-
* body that actually shows up in API docs — is highlighted as JSON
|
|
12
|
+
* body that actually shows up in API docs — is highlighted as JSON, and an
|
|
13
|
+
* XML body is handed to the HTML grammar when that is registered
|
|
13
14
|
*
|
|
14
15
|
* Comments are not part of HTTP. The `#` and `//` lines and the `###` separator
|
|
15
16
|
* come from the request-file format editors and REST clients use, and they are
|
|
16
17
|
* recognised outside the body only, where a `#` is far more likely to be data.
|
|
17
18
|
*
|
|
18
|
-
* What it does not model: a method has to be uppercase, a
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* What it does not model: a method has to be uppercase, a form-encoded or
|
|
20
|
+
* multipart body renders as plain text, and chunk sizes are not distinguished
|
|
21
|
+
* from the chunks around them.
|
|
21
22
|
*/
|
|
22
23
|
/**
|
|
23
24
|
* The methods RFC 9110 defines. Doubles as the anchor for "a new message starts
|
|
24
25
|
* here", which is how a body knows where it ends.
|
|
25
26
|
*/
|
|
26
27
|
const METHOD = 'GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT';
|
|
28
|
+
/** What begins the next message in a document: a separator, a status line or a request line. */
|
|
29
|
+
const MESSAGE_START = `###|HTTP/\\d|(?:${METHOD})[ \\t]`;
|
|
30
|
+
/**
|
|
31
|
+
* Where a body ends: the next message, or a comment line directly above it.
|
|
32
|
+
* The same two exits the `body` state takes, as one pattern for an embed.
|
|
33
|
+
*/
|
|
34
|
+
const NEXT_MESSAGE = `^(?:${MESSAGE_START}|[ \\t]*(?://|#)[^\\n]*\\n(?:${MESSAGE_START}))`;
|
|
27
35
|
/** `HTTP/1.1`, `HTTP/2` — scoped in three pieces so the version reads as a number. */
|
|
28
36
|
const VERSION = '(HTTP)(/)(\\d(?:\\.\\d)?)';
|
|
29
37
|
const http = {
|
|
@@ -114,9 +122,9 @@ const http = {
|
|
|
114
122
|
],
|
|
115
123
|
},
|
|
116
124
|
/**
|
|
117
|
-
* The body. JSON is highlighted as JSON
|
|
118
|
-
* fall through unscoped rather than
|
|
119
|
-
* failure rather than the loud one.
|
|
125
|
+
* The body. JSON is highlighted as JSON and XML or HTML with the HTML
|
|
126
|
+
* grammar; form-encoded and plain bodies fall through unscoped rather than
|
|
127
|
+
* being guessed at, which is the quiet failure rather than the loud one.
|
|
120
128
|
*/
|
|
121
129
|
body: {
|
|
122
130
|
rules: [
|
|
@@ -125,7 +133,7 @@ const http = {
|
|
|
125
133
|
// of the three can begin a line of JSON — a plain-text body that starts
|
|
126
134
|
// a line with `GET ` is read as a new message, which is the price of
|
|
127
135
|
// supporting multi-message documents at all.
|
|
128
|
-
{ match: `^(
|
|
136
|
+
{ match: `^(?=${MESSAGE_START})`, set: 'root' },
|
|
129
137
|
// A comment introducing the next message also ends the body, but only
|
|
130
138
|
// when the message starts on the very next line. A bare `^#` exit
|
|
131
139
|
// would be wrong far more often than right — `#` is ordinary data in a
|
|
@@ -148,9 +156,12 @@ const http = {
|
|
|
148
156
|
// exits the body to a state that cannot parse what the lookahead
|
|
149
157
|
// matched, leaving the line unscoped and reading the line after it
|
|
150
158
|
// as a header.
|
|
151
|
-
match: `^(?=[ \\t]*(?://|#)[^\\n]*\\n(
|
|
159
|
+
match: `^(?=[ \\t]*(?://|#)[^\\n]*\\n(?:${MESSAGE_START}))`,
|
|
152
160
|
set: 'root',
|
|
153
161
|
},
|
|
162
|
+
// A body that opens a line with `<` is XML or HTML, which the HTML
|
|
163
|
+
// grammar highlights up to where the next message starts.
|
|
164
|
+
{ match: '^(?=[ \\t]*<)', push: 'markup' },
|
|
154
165
|
// A string followed by `:` is a key, at any depth.
|
|
155
166
|
{
|
|
156
167
|
match: '("(?:[^"\\\\\\n]|\\\\.)*")([ \\t]*)(:)',
|
|
@@ -167,6 +178,11 @@ const http = {
|
|
|
167
178
|
{ match: '[,:]', scope: 'punctuation.delimiter' },
|
|
168
179
|
],
|
|
169
180
|
},
|
|
181
|
+
/** An XML or HTML body. Unscoped when the HTML grammar is not registered. */
|
|
182
|
+
markup: {
|
|
183
|
+
embed: { language: 'html', until: NEXT_MESSAGE },
|
|
184
|
+
rules: [],
|
|
185
|
+
},
|
|
170
186
|
string: {
|
|
171
187
|
default: 'string',
|
|
172
188
|
rules: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/langs/javascript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/langs/javascript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAkF5C,QAAA,MAAM,UAAU,EAAE,OAkSjB,CAAA;AAED,eAAe,UAAU,CAAA"}
|
package/dist/langs/javascript.js
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* is the cheapest reliable way to tell `a / b` from `/ab+/g`.
|
|
13
13
|
* - Template literals nest properly: `` `${ {a: `x`} }` `` keeps its states
|
|
14
14
|
* straight because interpolations track brace depth.
|
|
15
|
+
* - JSX children are text, not code. Once an opening tag closes, everything up
|
|
16
|
+
* to the matching closing tag is read as text with `{…}` expressions, so the
|
|
17
|
+
* apostrophe in `<p>Don't</p>` cannot open a string.
|
|
15
18
|
*/
|
|
16
19
|
/**
|
|
17
20
|
* An identifier, with its tail length-capped.
|
|
@@ -27,6 +30,41 @@
|
|
|
27
30
|
const ID = '[A-Za-z_$\\u0080-\\uFFFF][\\w$\\u0080-\\uFFFF]{0,128}';
|
|
28
31
|
/** Contexts after which a `/` begins a regex literal rather than division. */
|
|
29
32
|
const BEFORE_REGEX = '(?:[=(,:;\\[!&|?{}+\\-*%^~<>]|=>|\\breturn|\\bcase|\\btypeof|\\bin|\\bof|\\bnew|\\bdo|\\byield|\\bawait|\\belse)';
|
|
33
|
+
/**
|
|
34
|
+
* Contexts after which a `<` can open a JSX element: wherever an expression
|
|
35
|
+
* can start. Everything else — an identifier, `)` or `]` — makes `<` a
|
|
36
|
+
* comparison or a type argument list.
|
|
37
|
+
*/
|
|
38
|
+
const BEFORE_JSX = '(?:^|[=(,?:{\\[;!&|]|=>|\\breturn|\\byield|\\bdefault|\\bawait)';
|
|
39
|
+
/**
|
|
40
|
+
* TypeScript angle brackets that look like an element with no attributes: a
|
|
41
|
+
* generic arrow function `<T>(x: T) => x`, a constrained one `<T extends X>`,
|
|
42
|
+
* a defaulted one `<T = unknown>`, and the old-style assertion `<HTMLElement>el`. Reading any of them as an
|
|
43
|
+
* opening tag would turn the rest of the file into JSX text.
|
|
44
|
+
*
|
|
45
|
+
* An assertion is followed by an expression on the same line, and so is an
|
|
46
|
+
* element's text, so the line decides: an element without attributes opens
|
|
47
|
+
* only when its line ends after the `>` or holds another tag. A closing tag
|
|
48
|
+
* counts, and so does a `<` that does not follow a name, which keeps the type
|
|
49
|
+
* arguments in `get<Store>()` out. An element whose text runs on to a later
|
|
50
|
+
* closing tag reads as code instead, which costs that one element and never
|
|
51
|
+
* the rest of the file.
|
|
52
|
+
*/
|
|
53
|
+
const NOT_TS_AFTER = '(?!>[ \\t]*\\()(?!\\s+(?:extends\\b|=))(?!>(?![ \\t]*$)(?![^\\n]{0,512}(?:<\\/|(?<![\\w$)\\]])<[A-Za-z>])))';
|
|
54
|
+
/**
|
|
55
|
+
* Ends a keyword rule: the word is not followed by the `:` of an object key or
|
|
56
|
+
* a type member. Checked only after a keyword has matched, so it costs nothing
|
|
57
|
+
* on ordinary identifiers.
|
|
58
|
+
*/
|
|
59
|
+
const NOT_KEY = '(?!\\??:)';
|
|
60
|
+
/** A JSX tag name: a component, a member expression, or a lowercase element. */
|
|
61
|
+
const TAG = '[A-Z][\\w.]*|[a-z][\\w-]*(?:[.:][\\w-]+)*';
|
|
62
|
+
/**
|
|
63
|
+
* What follows a name that is assigned a function: `= () =>`, `= async x =>`,
|
|
64
|
+
* `= function`. The parameter list cannot nest parentheses, which covers real
|
|
65
|
+
* code and keeps the scan bounded.
|
|
66
|
+
*/
|
|
67
|
+
const ASSIGNS_FUNCTION = `[ \\t]*=[ \\t]*(?:async[ \\t]*)?(?:function\\b|\\([^()]{0,512}\\)[ \\t]*(?::[^=;\\n]{0,256})?=>|${ID}[ \\t]*=>)`;
|
|
30
68
|
/** Body of a regex literal: no unescaped `/`, character classes may hold one. */
|
|
31
69
|
const REGEX = '/(?![/*])(?:[^/\\\\\\n\\[]|\\\\.|\\[(?:[^\\]\\\\\\n]|\\\\.)*\\])+/[dgimsuvy]*';
|
|
32
70
|
const javascript = {
|
|
@@ -36,8 +74,10 @@ const javascript = {
|
|
|
36
74
|
root: { rules: [{ include: 'expression' }] },
|
|
37
75
|
expression: {
|
|
38
76
|
rules: [
|
|
39
|
-
|
|
40
|
-
|
|
77
|
+
// A state, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and fails
|
|
78
|
+
// once per opener, which is O(n²) on a run of unterminated `/*`.
|
|
79
|
+
{ match: '/\\*\\*(?![/*])', scope: 'comment.doc', push: 'doc-comment' },
|
|
80
|
+
{ match: '/\\*', scope: 'comment', push: 'block-comment' },
|
|
41
81
|
{ match: '//[^\\n]*', scope: 'comment' },
|
|
42
82
|
{ match: '^#!.*', scope: 'comment' },
|
|
43
83
|
{ include: 'strings' },
|
|
@@ -47,32 +87,68 @@ const javascript = {
|
|
|
47
87
|
match: `(${BEFORE_REGEX})(\\s*)(${REGEX})`,
|
|
48
88
|
scope: ['operator', null, 'regexp'],
|
|
49
89
|
},
|
|
50
|
-
|
|
90
|
+
// `if (ok) /re/.test(s)`: a `)` that closes a control condition starts
|
|
91
|
+
// an expression. The lookbehind sits after the `/` so the rule still
|
|
92
|
+
// starts with a literal character.
|
|
93
|
+
{
|
|
94
|
+
match: `/(?<=(?<![\\w$.])(?:if|while|for)[ \\t]*\\([^()\\n]{0,256}\\)[ \\t]*/)${REGEX.slice(1)}`,
|
|
95
|
+
scope: 'regexp',
|
|
96
|
+
},
|
|
97
|
+
// Blanks only: `\s*` would run across every blank line below, and
|
|
98
|
+
// retrying that at each line start is O(n²) on a run of blank lines.
|
|
99
|
+
{ match: `^([ \\t]*)(${REGEX})`, scope: [null, 'regexp'] },
|
|
51
100
|
{ include: 'numbers' },
|
|
52
101
|
{ include: 'jsx' },
|
|
53
102
|
{ match: `(@)(${ID}(?:\\.${ID})*)`, scope: ['decorator', 'decorator'] },
|
|
54
103
|
{
|
|
55
|
-
match: `(\\.)([ \\t]*)(
|
|
104
|
+
match: `(\\.)([ \\t]*)(#?${ID})(?=[ \\t]*\\()`,
|
|
56
105
|
scope: ['punctuation', null, 'function.method'],
|
|
57
106
|
},
|
|
58
107
|
{
|
|
59
|
-
match: `(\\?\\.|\\.)([ \\t]*)(
|
|
108
|
+
match: `(\\?\\.|\\.)([ \\t]*)(#?${ID})`,
|
|
60
109
|
scope: ['punctuation', null, 'variable.member'],
|
|
61
110
|
},
|
|
111
|
+
// A private field or method where it is declared, or `#x in obj`.
|
|
112
|
+
{ match: `#${ID}`, scope: 'variable.member' },
|
|
113
|
+
// `handler = function …` and `this.run = () => …` name a function as
|
|
114
|
+
// surely as a declaration does.
|
|
115
|
+
{ match: `\\b${ID}(?=${ASSIGNS_FUNCTION})`, scope: 'function' },
|
|
116
|
+
// A keyword followed by `:` is an object key or a property in a type —
|
|
117
|
+
// `{ type: 'object' }`, `{ from: start, to: end }` — so each keyword
|
|
118
|
+
// rule ends with `NOT_KEY` and the word falls through to the property
|
|
119
|
+
// rule. `default:` needs telling apart: in a `switch` it is followed by
|
|
120
|
+
// a statement or nothing, as an object key by a value. A braced block
|
|
121
|
+
// after it reads as a key, since `responses: { default: { … } }` is the
|
|
122
|
+
// commoner of the two in API code.
|
|
123
|
+
//
|
|
124
|
+
// The contextual keywords that are also common method names (`get`,
|
|
125
|
+
// `set`, `of`, `delete`, `from`, `type`) stay keywords only when no `(`
|
|
126
|
+
// follows directly, so `static of(x)` and `cache.get(key)` read as calls.
|
|
127
|
+
{
|
|
128
|
+
match: '\\bdefault\\b(?=[ \\t]*:[ \\t]*(?:$|\\/[/*]|\\b(?:return|break|continue|throw|case)\\b))|\\bdefault\\b(?!\\??:)',
|
|
129
|
+
scope: 'keyword.control',
|
|
130
|
+
},
|
|
62
131
|
{
|
|
63
|
-
match:
|
|
132
|
+
match: `\\b(?:if|else|for|while|do|switch|case|break|continue|return|throw|try|catch|finally|await|yield)\\b${NOT_KEY}`,
|
|
64
133
|
scope: 'keyword.control',
|
|
65
134
|
},
|
|
135
|
+
// A TypeScript assertion ends an expression; it does not declare the
|
|
136
|
+
// next name, even when that name begins a new line without a semicolon.
|
|
137
|
+
{ match: '\\bconst\\b(?<=\\bas\\s+const)', scope: 'keyword.declaration' },
|
|
138
|
+
// The declared name is scoped by a state of its own rather than by a
|
|
139
|
+
// rule here: a rule that has to look back at `const` runs at every
|
|
140
|
+
// identifier in the file, while the state only runs after the keyword.
|
|
141
|
+
{ match: '\\b(?:const|let|var)\\b', scope: 'keyword.declaration', push: 'declared-name' },
|
|
66
142
|
{
|
|
67
|
-
match:
|
|
143
|
+
match: `\\b(?:function|class|interface|enum|namespace|module|declare|abstract|implements|extends|constructor|static|readonly|override|public|private|protected|async|get(?!\\()|set(?!\\()|type(?!\\())\\b${NOT_KEY}`,
|
|
68
144
|
scope: 'keyword.declaration',
|
|
69
145
|
},
|
|
70
146
|
{
|
|
71
|
-
match:
|
|
147
|
+
match: `\\b(?:import|export|from(?!\\()|require)\\b${NOT_KEY}`,
|
|
72
148
|
scope: 'keyword.import',
|
|
73
149
|
},
|
|
74
150
|
{
|
|
75
|
-
match:
|
|
151
|
+
match: `\\b(?:typeof|instanceof|in|of(?!\\()|new|delete(?!\\()|void|satisfies|keyof|infer|asserts|as)\\b${NOT_KEY}`,
|
|
76
152
|
scope: 'keyword.operator',
|
|
77
153
|
},
|
|
78
154
|
{ match: '\\b(?:true|false)\\b', scope: 'boolean' },
|
|
@@ -85,20 +161,23 @@ const javascript = {
|
|
|
85
161
|
scope: 'variable.builtin',
|
|
86
162
|
},
|
|
87
163
|
{
|
|
88
|
-
match:
|
|
164
|
+
match: `\\b(?:console|window|document|process|module|exports)\\b${NOT_KEY}`,
|
|
89
165
|
scope: 'variable.builtin',
|
|
90
166
|
},
|
|
91
167
|
{
|
|
92
|
-
match:
|
|
168
|
+
match: `\\b(?:string|number|boolean|symbol|bigint|object|unknown|never|any|void|readonly)\\b(?=[^\\w$]|$)${NOT_KEY}`,
|
|
93
169
|
scope: 'type.builtin',
|
|
94
170
|
},
|
|
95
171
|
{ match: '\\b[A-Z][A-Z0-9_]+\\b(?![\\w$])', scope: 'constant' },
|
|
172
|
+
// A capitalised name followed by a call is still a call — `Error('x')`,
|
|
173
|
+
// `new Date()`, a React component invoked directly — not a type.
|
|
174
|
+
{ match: '\\b[A-Z][\\w$]{0,128}(?=[ \\t]*\\()', scope: 'function.call' },
|
|
96
175
|
{ match: '\\b[A-Z][A-Za-z0-9_$]*\\b', scope: 'type' },
|
|
97
176
|
// `key:` in an object literal, and the name half of a TS annotation.
|
|
98
177
|
// Requiring no space before the colon keeps `cond ? a : b` out.
|
|
99
178
|
{ match: `\\b${ID}(?=\\??:)`, scope: 'property' },
|
|
100
179
|
{ match: `\\b${ID}(?=\\s*=>)`, scope: 'variable.parameter' },
|
|
101
|
-
{ match: `\\b${ID}(?=[ \\t]*[(<])`, scope: 'function.call' },
|
|
180
|
+
{ match: `\\b${ID}(?=[ \\t]*[(<]|\`)`, scope: 'function.call' },
|
|
102
181
|
{
|
|
103
182
|
// Bare `=` goes last so `=>`, `==`, `===` and the compound forms all
|
|
104
183
|
// get first refusal. Without it plain assignment matched nothing.
|
|
@@ -109,6 +188,18 @@ const javascript = {
|
|
|
109
188
|
{ match: '[,;:]', scope: 'punctuation.delimiter' },
|
|
110
189
|
],
|
|
111
190
|
},
|
|
191
|
+
/**
|
|
192
|
+
* Right after `const`, `let` or `var`: the one name it declares. A
|
|
193
|
+
* destructuring pattern or anything else ends the state without a scope.
|
|
194
|
+
*/
|
|
195
|
+
'declared-name': {
|
|
196
|
+
rules: [
|
|
197
|
+
{ match: '\\benum\\b', scope: 'keyword.declaration', pop: true },
|
|
198
|
+
{ match: `${ID}(?=${ASSIGNS_FUNCTION})`, scope: 'function', pop: true },
|
|
199
|
+
{ match: ID, scope: 'variable', pop: true },
|
|
200
|
+
{ match: '(?=\\S)', pop: true },
|
|
201
|
+
],
|
|
202
|
+
},
|
|
112
203
|
numbers: {
|
|
113
204
|
rules: [
|
|
114
205
|
{ match: '\\b0[xX](?:_?[0-9a-fA-F])+n?\\b', scope: 'number' },
|
|
@@ -182,38 +273,55 @@ const javascript = {
|
|
|
182
273
|
// ---- JSX ---------------------------------------------------------------
|
|
183
274
|
jsx: {
|
|
184
275
|
rules: [
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
// extends Event>` and `Array<string>` both satisfy the lookahead, and
|
|
190
|
-
// what separates them from JSX is that a tag never follows an
|
|
191
|
-
// identifier, `)` or `]` directly.
|
|
276
|
+
// `<` is the most overloaded character in the language, so an element
|
|
277
|
+
// opens only where an expression can start. The lookbehind sits after
|
|
278
|
+
// the `<` so the rule still starts with a literal character, which
|
|
279
|
+
// keeps the engine's first-character scan.
|
|
192
280
|
{
|
|
193
|
-
match:
|
|
194
|
-
scope: ['punctuation.bracket', '
|
|
195
|
-
push: 'jsx-tag',
|
|
281
|
+
match: `(<)(?<=${BEFORE_JSX}\\s*<)(${TAG})(?=[\\s/>])${NOT_TS_AFTER}`,
|
|
282
|
+
scope: ['punctuation.bracket', 'tag'],
|
|
283
|
+
push: 'jsx-open-tag',
|
|
196
284
|
},
|
|
197
285
|
{
|
|
198
|
-
match:
|
|
199
|
-
scope:
|
|
286
|
+
match: `<(?<=${BEFORE_JSX}\\s*<)>`,
|
|
287
|
+
scope: 'punctuation.bracket',
|
|
288
|
+
push: 'jsx-children',
|
|
200
289
|
},
|
|
290
|
+
// A closing tag with no opener, as in a snippet cut out of a larger file.
|
|
201
291
|
{
|
|
202
|
-
match:
|
|
203
|
-
scope: ['punctuation.bracket', 'punctuation.bracket'],
|
|
292
|
+
match: `(</)(${TAG})?([ \\t]*)(>)`,
|
|
293
|
+
scope: ['punctuation.bracket', 'tag', null, 'punctuation.bracket'],
|
|
204
294
|
},
|
|
205
295
|
],
|
|
206
296
|
},
|
|
207
|
-
'jsx-tag': {
|
|
297
|
+
'jsx-open-tag': {
|
|
208
298
|
rules: [
|
|
209
|
-
{ match: '
|
|
299
|
+
{ match: '/>', scope: 'punctuation.bracket', pop: true },
|
|
300
|
+
{ match: '>', scope: 'punctuation.bracket', set: 'jsx-children' },
|
|
210
301
|
{ match: '\\{', scope: 'interpolation', push: 'jsx-expression' },
|
|
211
|
-
{ match:
|
|
212
|
-
{ match: `\\b${ID}(?:-${ID})*`, scope: 'tag.attribute' },
|
|
302
|
+
{ match: `\\b${ID}(?:[-:]${ID})*`, scope: 'tag.attribute' },
|
|
213
303
|
{ match: '=', scope: 'operator' },
|
|
214
304
|
{ include: 'strings' },
|
|
215
305
|
],
|
|
216
306
|
},
|
|
307
|
+
/** Between an opening tag and its closing tag: text, elements and `{…}`. */
|
|
308
|
+
'jsx-children': {
|
|
309
|
+
rules: [
|
|
310
|
+
{
|
|
311
|
+
match: `(</)(${TAG})?([ \\t]*)(>)`,
|
|
312
|
+
scope: ['punctuation.bracket', 'tag', null, 'punctuation.bracket'],
|
|
313
|
+
pop: true,
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
match: `(<)(${TAG})(?=[\\s/>])`,
|
|
317
|
+
scope: ['punctuation.bracket', 'tag'],
|
|
318
|
+
push: 'jsx-open-tag',
|
|
319
|
+
},
|
|
320
|
+
{ match: '<>', scope: 'punctuation.bracket', push: 'jsx-children' },
|
|
321
|
+
{ match: '\\{', scope: 'interpolation', push: 'jsx-expression' },
|
|
322
|
+
{ match: '&(?:#\\d{1,8}|#x[0-9a-fA-F]{1,8}|[A-Za-z][A-Za-z0-9]{1,32});', scope: 'string.escape' },
|
|
323
|
+
],
|
|
324
|
+
},
|
|
217
325
|
'jsx-expression': {
|
|
218
326
|
rules: [
|
|
219
327
|
{ match: '\\}', scope: 'interpolation', pop: true },
|
|
@@ -221,6 +329,14 @@ const javascript = {
|
|
|
221
329
|
{ include: 'expression' },
|
|
222
330
|
],
|
|
223
331
|
},
|
|
332
|
+
'block-comment': {
|
|
333
|
+
default: 'comment',
|
|
334
|
+
rules: [{ match: '\\*/', scope: 'comment', pop: true }],
|
|
335
|
+
},
|
|
336
|
+
'doc-comment': {
|
|
337
|
+
default: 'comment.doc',
|
|
338
|
+
rules: [{ match: '\\*/', scope: 'comment.doc', pop: true }],
|
|
339
|
+
},
|
|
224
340
|
},
|
|
225
341
|
};
|
|
226
342
|
export default javascript;
|
package/dist/langs/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/langs/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,QAAA,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/langs/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;GAKG;AACH,QAAA,MAAM,IAAI,EAAE,OA8CX,CAAA;AAED,eAAe,IAAI,CAAA"}
|
package/dist/langs/json.js
CHANGED
|
@@ -11,7 +11,9 @@ const json = {
|
|
|
11
11
|
root: {
|
|
12
12
|
rules: [
|
|
13
13
|
{ match: '//[^\\n]*', scope: 'comment' },
|
|
14
|
-
|
|
14
|
+
// A state, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and fails
|
|
15
|
+
// once per opener, which is O(n²) on a run of unterminated `/*`.
|
|
16
|
+
{ match: '/\\*', scope: 'comment', push: 'block-comment' },
|
|
15
17
|
// A string followed by `:` is a key, whatever nesting it sits in.
|
|
16
18
|
{
|
|
17
19
|
match: '("(?:[^"\\\\\\n]|\\\\.)*")(\\s*)(:)',
|
|
@@ -41,6 +43,10 @@ const json = {
|
|
|
41
43
|
{ match: '"', scope: 'string', pop: true },
|
|
42
44
|
],
|
|
43
45
|
},
|
|
46
|
+
'block-comment': {
|
|
47
|
+
default: 'comment',
|
|
48
|
+
rules: [{ match: '\\*/', scope: 'comment', pop: true }],
|
|
49
|
+
},
|
|
44
50
|
},
|
|
45
51
|
};
|
|
46
52
|
export default json;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"julia.d.ts","sourceRoot":"","sources":["../../src/langs/julia.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAyB5C,QAAA,MAAM,KAAK,EAAE,OA6KZ,CAAA;AAED,eAAe,KAAK,CAAA"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Julia.
|
|
3
|
+
*
|
|
4
|
+
* Things worth knowing about:
|
|
5
|
+
*
|
|
6
|
+
* - `'` is both a character literal and the transpose operator. It opens a
|
|
7
|
+
* literal only where a value cannot end — not after a name, a closing
|
|
8
|
+
* bracket, a number or another `'` — so `A'` and `x'y` stay operators.
|
|
9
|
+
* - `:` is a range, a ternary branch and the start of a symbol. A symbol needs
|
|
10
|
+
* a name straight after the colon and nothing value-like straight before it,
|
|
11
|
+
* which keeps `1:n` and `a ? b : c` out.
|
|
12
|
+
* - Interpolation is real: `"$(user.name) has $n items"` tokenizes the
|
|
13
|
+
* expressions. Prefixed string macros (`r"…"`, `raw"…"`, `b"…"`) do not
|
|
14
|
+
* interpolate, so they get a state without it.
|
|
15
|
+
* - Block comments `#= … =#` nest.
|
|
16
|
+
* - Names may end in `!` (`push!`) and carry Unicode (`α`, `∇f`).
|
|
17
|
+
*/
|
|
18
|
+
const ID = '[A-Za-z_\\u00A1-\\uFFFF][\\w!\\u00A1-\\uFFFF]{0,128}';
|
|
19
|
+
/** Something after which `'` is a transpose rather than a character literal. */
|
|
20
|
+
const VALUE_END = "[\\w)\\]}'.\\u00A1-\\uFFFF]";
|
|
21
|
+
const julia = {
|
|
22
|
+
name: 'julia',
|
|
23
|
+
aliases: ['jl'],
|
|
24
|
+
states: {
|
|
25
|
+
root: { rules: [{ include: 'expression' }] },
|
|
26
|
+
expression: {
|
|
27
|
+
rules: [
|
|
28
|
+
{ match: '#=', scope: 'comment', push: 'block-comment' },
|
|
29
|
+
{ match: '#[^\\n]*', scope: 'comment' },
|
|
30
|
+
// ---- strings -------------------------------------------------------
|
|
31
|
+
{ match: '"""', scope: 'string', push: 'string-triple' },
|
|
32
|
+
{
|
|
33
|
+
match: `(${ID})(""")`,
|
|
34
|
+
scope: ['string.special', 'string'],
|
|
35
|
+
push: 'string-raw-triple',
|
|
36
|
+
},
|
|
37
|
+
{ match: `(${ID})(")`, scope: ['string.special', 'string'], push: 'string-raw' },
|
|
38
|
+
{ match: '"', scope: 'string', push: 'string' },
|
|
39
|
+
{ match: '`', scope: 'string', push: 'command' },
|
|
40
|
+
{
|
|
41
|
+
// The lookbehind sits after the quote so the rule still starts with a
|
|
42
|
+
// literal character, which keeps the engine's first-character scan.
|
|
43
|
+
match: `'(?<!${VALUE_END}')(?:[^'\\\\\\n]|\\\\(?:x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8}|[0-7]{1,3}|[^\\n]))'`,
|
|
44
|
+
scope: 'string',
|
|
45
|
+
},
|
|
46
|
+
// ---- numbers -------------------------------------------------------
|
|
47
|
+
{ match: '\\b0x[0-9a-fA-F_]+(?:p[-+]?\\d+)?\\b', scope: 'number' },
|
|
48
|
+
{ match: '\\b0b[01_]+\\b', scope: 'number' },
|
|
49
|
+
{ match: '\\b0o[0-7_]+\\b', scope: 'number' },
|
|
50
|
+
{
|
|
51
|
+
match: '(?:\\b\\d[\\d_]*(?:\\.(?!\\.)[\\d_]*)?|\\.\\d[\\d_]*)(?:[eEf][-+]?\\d+)?(?:im\\b)?',
|
|
52
|
+
scope: 'number',
|
|
53
|
+
},
|
|
54
|
+
// ---- macros, symbols and types -------------------------------------
|
|
55
|
+
{ match: `@${ID}(?:\\.${ID})*`, scope: 'decorator' },
|
|
56
|
+
{
|
|
57
|
+
match: `(:(?<![\\w)\\]}:'".\\u00A1-\\uFFFF]:))(${ID})`,
|
|
58
|
+
scope: ['constant', 'constant'],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
match: `(::|<:|>:)([ \\t]*)(${ID}(?:\\.${ID})*)`,
|
|
62
|
+
scope: ['operator', null, 'type'],
|
|
63
|
+
},
|
|
64
|
+
// ---- definitions ---------------------------------------------------
|
|
65
|
+
{
|
|
66
|
+
match: `\\b(function|macro)([ \\t]+)(${ID}(?:\\.${ID})*)`,
|
|
67
|
+
scope: ['keyword.declaration', null, 'function'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
match: `\\b((?:mutable[ \\t]+)?struct|abstract[ \\t]+type|primitive[ \\t]+type)([ \\t]+)(${ID})`,
|
|
71
|
+
scope: ['keyword.declaration', null, 'class'],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
match: `\\b((?:bare)?module)([ \\t]+)(${ID})`,
|
|
75
|
+
scope: ['keyword.declaration', null, 'namespace'],
|
|
76
|
+
},
|
|
77
|
+
// The short form `area(r) = π * r^2` defines a function. The argument
|
|
78
|
+
// list cannot hold parentheses here, which covers the one-liners this
|
|
79
|
+
// form is used for and keeps the scan bounded.
|
|
80
|
+
{
|
|
81
|
+
match: `^([ \\t]*)(${ID})(?=\\([^()\\n]{0,256}\\)[ \\t]*(?:where[^=\\n]{0,256})?=(?!=))`,
|
|
82
|
+
scope: [null, 'function'],
|
|
83
|
+
},
|
|
84
|
+
// ---- keywords ------------------------------------------------------
|
|
85
|
+
{
|
|
86
|
+
match: '\\b(?:if|elseif|else|end|for|while|break|continue|return|try|catch|finally|do|begin|let|quote)\\b',
|
|
87
|
+
scope: 'keyword.control',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
match: '\\b(?:function|macro|struct|mutable|abstract|primitive|type|module|baremodule|const|global|local|where|outer)\\b',
|
|
91
|
+
scope: 'keyword.declaration',
|
|
92
|
+
},
|
|
93
|
+
{ match: '\\b(?:using|import|export|public|as)\\b', scope: 'keyword.import' },
|
|
94
|
+
{ match: '\\b(?:in|isa)\\b', scope: 'keyword.operator' },
|
|
95
|
+
{ match: '\\b(?:true|false)\\b', scope: 'boolean' },
|
|
96
|
+
{ match: '\\b(?:nothing|missing|NaN|Inf|NaN32|Inf32|undef|stdout|stderr|stdin)\\b', scope: 'constant.builtin' },
|
|
97
|
+
// ---- calls ---------------------------------------------------------
|
|
98
|
+
{
|
|
99
|
+
match: '\\b(?:println|print|show|display|string|length|size|push!|pop!|append!|map|filter|reduce|sum|prod|maximum|minimum|collect|typeof|isa|convert|parse|zeros|ones|rand|round|floor|ceil|abs|sqrt|exp|log|error|throw|isempty|haskey|get|keys|values|pairs|enumerate|zip|sort|sort!|occursin|replace|split|join|startswith|endswith|open|read|write|close|eachline|readline|readlines|sprint|repr|Dict|Vector|Array|Tuple)(?=\\.?\\()',
|
|
100
|
+
scope: 'function.builtin',
|
|
101
|
+
},
|
|
102
|
+
{ match: `(\\.)(${ID})(?=\\.?\\()`, scope: ['punctuation', 'function.method'] },
|
|
103
|
+
{ match: `(\\.)(${ID})`, scope: ['punctuation', 'variable.member'] },
|
|
104
|
+
// `f(x)` and the broadcast `f.(x)`.
|
|
105
|
+
{ match: `${ID}(?=\\.?\\()`, scope: 'function.call' },
|
|
106
|
+
// CapWords reads as a type, which is how Julia names them.
|
|
107
|
+
{ match: '\\b[A-Z][A-Za-z0-9_]*\\b', scope: 'type' },
|
|
108
|
+
// ---- syntax --------------------------------------------------------
|
|
109
|
+
{
|
|
110
|
+
match: "\\.?(?:===|!==|==|!=|<=|>=|=>|->|\\|\\||&&|\\|>|<\\||\\.\\.\\.|[-+*/\\\\^%÷<>=!&|~⊻∈∉≤≥≠]=?)|'",
|
|
111
|
+
scope: 'operator',
|
|
112
|
+
},
|
|
113
|
+
{ match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
|
|
114
|
+
{ match: '[,;]', scope: 'punctuation.delimiter' },
|
|
115
|
+
{ match: '[.:?]', scope: 'punctuation' },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
'block-comment': {
|
|
119
|
+
default: 'comment',
|
|
120
|
+
rules: [
|
|
121
|
+
{ match: '#=', scope: 'comment', push: 'block-comment' },
|
|
122
|
+
{ match: '=#', scope: 'comment', pop: true },
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
// ---- strings -------------------------------------------------------------
|
|
126
|
+
string: {
|
|
127
|
+
default: 'string',
|
|
128
|
+
rules: [{ include: 'escapes' }, { include: 'interpolation' }, { match: '"', scope: 'string', pop: true }],
|
|
129
|
+
},
|
|
130
|
+
'string-triple': {
|
|
131
|
+
default: 'string',
|
|
132
|
+
rules: [{ include: 'escapes' }, { include: 'interpolation' }, { match: '"""', scope: 'string', pop: true }],
|
|
133
|
+
},
|
|
134
|
+
/** Prefixed string macros: no interpolation, and `\"` is the only escape. */
|
|
135
|
+
'string-raw': {
|
|
136
|
+
default: 'string',
|
|
137
|
+
rules: [
|
|
138
|
+
{ match: '\\\\"', scope: 'string.escape' },
|
|
139
|
+
{ match: '"', scope: 'string', pop: true },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
'string-raw-triple': {
|
|
143
|
+
default: 'string',
|
|
144
|
+
rules: [{ match: '"""', scope: 'string', pop: true }],
|
|
145
|
+
},
|
|
146
|
+
command: {
|
|
147
|
+
default: 'string',
|
|
148
|
+
rules: [{ include: 'escapes' }, { include: 'interpolation' }, { match: '`', scope: 'string', pop: true }],
|
|
149
|
+
},
|
|
150
|
+
escapes: {
|
|
151
|
+
rules: [
|
|
152
|
+
{
|
|
153
|
+
match: '\\\\(?:x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8}|[0-7]{1,3}|[\\s\\S])',
|
|
154
|
+
scope: 'string.escape',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
interpolation: {
|
|
159
|
+
rules: [
|
|
160
|
+
{ match: '\\$\\(', scope: 'interpolation', push: 'interpolation-body' },
|
|
161
|
+
{ match: `(\\$)(${ID})`, scope: ['interpolation', 'variable'] },
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
/** The expression inside `$( … )`. Nested parentheses are tracked. */
|
|
165
|
+
'interpolation-body': {
|
|
166
|
+
rules: [
|
|
167
|
+
{ match: '\\)', scope: 'interpolation', pop: true },
|
|
168
|
+
{ match: '\\(', scope: 'punctuation.bracket', push: 'parens' },
|
|
169
|
+
{ include: 'expression' },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
parens: {
|
|
173
|
+
rules: [
|
|
174
|
+
{ match: '\\)', scope: 'punctuation.bracket', pop: true },
|
|
175
|
+
{ match: '\\(', scope: 'punctuation.bracket', push: 'parens' },
|
|
176
|
+
{ include: 'expression' },
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
export default julia;
|
package/dist/langs/markdown.d.ts
CHANGED
|
@@ -2,9 +2,15 @@ import type { Grammar } from '../core/types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Markdown.
|
|
4
4
|
*
|
|
5
|
-
* Prose is left alone; only the marks are styled.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Prose is left alone; only the marks are styled. Three kinds of block belong
|
|
6
|
+
* to other languages and are handed to them when they are registered:
|
|
7
|
+
*
|
|
8
|
+
* - a fenced code block that names its language
|
|
9
|
+
* - YAML front matter
|
|
10
|
+
* - HTML that starts a line, and `<script>`, `<pre>` and `<style>` blocks
|
|
11
|
+
*
|
|
12
|
+
* Any other fence becomes a literal state, so its contents are never mistaken
|
|
13
|
+
* for Markdown syntax.
|
|
8
14
|
*/
|
|
9
15
|
declare const markdown: Grammar;
|
|
10
16
|
export default markdown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/langs/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/langs/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAS,MAAM,eAAe,CAAA;AA2CnD;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,QAAQ,EAAE,OAqJf,CAAA;AAED,eAAe,QAAQ,CAAA"}
|