Skip to content

Commit ef53f02

Browse files
authoredOct 11, 2021
Added support for Web IDL (#3107)
1 parent 3b2238f commit ef53f02

20 files changed

+811
-3
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+5
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,11 @@
14241424
"title": "WebAssembly",
14251425
"owner": "Golmote"
14261426
},
1427+
"web-idl": {
1428+
"title": "Web IDL",
1429+
"alias": "webidl",
1430+
"owner": "RunDevelopment"
1431+
},
14271432
"wiki": {
14281433
"title": "Wiki markup",
14291434
"require": "markup",

‎components/prism-web-idl.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
(function (Prism) {
2+
3+
var id = /(?:\B-|\b_|\b)[A-Za-z][\w-]*(?![\w-])/.source;
4+
var type =
5+
'(?:' +
6+
/\b(?:unsigned\s+)?long\s+long(?![\w-])/.source +
7+
'|' +
8+
/\b(?:unrestricted|unsigned)\s+[a-z]+(?![\w-])/.source +
9+
'|' +
10+
/(?!(?:unrestricted|unsigned)\b)/.source + id + /(?:\s*<(?:[^<>]|<[^<>]*>)*>)?/.source +
11+
')' + /(?:\s*\?)?/.source;
12+
13+
var typeInside = {};
14+
15+
Prism.languages['web-idl'] = {
16+
'comment': {
17+
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
18+
greedy: true
19+
},
20+
'string': {
21+
pattern: /"[^"]*"/,
22+
greedy: true
23+
},
24+
25+
'namespace': {
26+
pattern: RegExp(/(\bnamespace\s+)/.source + id),
27+
lookbehind: true,
28+
},
29+
'class-name': [
30+
{
31+
pattern: /(^|[^\w-])(?:iterable|maplike|setlike)\s*<(?:[^<>]|<[^<>]*>)*>/,
32+
lookbehind: true,
33+
inside: typeInside
34+
},
35+
{
36+
pattern: RegExp(/(\b(?:attribute|const|deleter|getter|optional|setter)\s+)/.source + type),
37+
lookbehind: true,
38+
inside: typeInside
39+
},
40+
{
41+
// callback return type
42+
pattern: RegExp('(' + /\bcallback\s+/.source + id + /\s*=\s*/.source + ')' + type),
43+
lookbehind: true,
44+
inside: typeInside
45+
},
46+
{
47+
// typedef
48+
pattern: RegExp(/(\btypedef\b\s*)/.source + type),
49+
lookbehind: true,
50+
inside: typeInside
51+
},
52+
53+
{
54+
pattern: RegExp(/(\b(?:callback|dictionary|enum|interface(?:\s+mixin)?)\s+)(?!(?:interface|mixin)\b)/.source + id),
55+
lookbehind: true,
56+
},
57+
{
58+
// inheritance
59+
pattern: RegExp(/(:\s*)/.source + id),
60+
lookbehind: true,
61+
},
62+
63+
// includes and implements
64+
RegExp(id + /(?=\s+(?:implements|includes)\b)/.source),
65+
{
66+
pattern: RegExp(/(\b(?:implements|includes)\s+)/.source + id),
67+
lookbehind: true,
68+
},
69+
70+
{
71+
// function return type, parameter types, and dictionary members
72+
pattern: RegExp(type + '(?=' + /\s*(?:\.{3}\s*)?/.source + id + /\s*[(),;=]/.source + ')'),
73+
inside: typeInside
74+
},
75+
],
76+
77+
'builtin': /\b(?:ArrayBuffer|BigInt64Array|BigUint64Array|ByteString|DOMString|DataView|Float32Array|Float64Array|FrozenArray|Int16Array|Int32Array|Int8Array|ObservableArray|Promise|USVString|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray)\b/,
78+
'keyword': [
79+
/\b(?:async|attribute|callback|const|constructor|deleter|dictionary|enum|getter|implements|includes|inherit|interface|mixin|namespace|null|optional|or|partial|readonly|required|setter|static|stringifier|typedef|unrestricted)\b/,
80+
// type keywords
81+
/\b(?:any|bigint|boolean|byte|double|float|iterable|long|maplike|object|octet|record|sequence|setlike|short|symbol|undefined|unsigned|void)\b/
82+
],
83+
'boolean': /\b(?:false|true)\b/,
84+
85+
'number': {
86+
pattern: /(^|[^\w-])-?(?:0x[0-9a-f]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|NaN|Infinity)(?![\w-])/i,
87+
lookbehind: true
88+
},
89+
'operator': /\.{3}|[=:?<>-]/,
90+
'punctuation': /[(){}[\].,;]/
91+
};
92+
93+
for (var key in Prism.languages['web-idl']) {
94+
if (key !== 'class-name') {
95+
typeInside[key] = Prism.languages['web-idl'][key];
96+
}
97+
}
98+
99+
Prism.languages['webidl'] = Prism.languages['web-idl'];
100+
101+
}(Prism));

‎components/prism-web-idl.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-web-idl.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<h2>Full example</h2>
2+
<pre><code>[Exposed=Window]
3+
interface Paint { };
4+
5+
[Exposed=Window]
6+
interface SolidColor : Paint {
7+
attribute double red;
8+
attribute double green;
9+
attribute double blue;
10+
};
11+
12+
[Exposed=Window]
13+
interface Pattern : Paint {
14+
attribute DOMString imageURL;
15+
};
16+
17+
[Exposed=Window]
18+
interface GraphicalWindow {
19+
constructor();
20+
readonly attribute unsigned long width;
21+
readonly attribute unsigned long height;
22+
23+
attribute Paint currentPaint;
24+
25+
undefined drawRectangle(double x, double y, double width, double height);
26+
27+
undefined drawText(double x, double y, DOMString text);
28+
};</code></pre>

‎plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
"url": "uri",
251251
"vb": "visual-basic",
252252
"vba": "visual-basic",
253+
"webidl": "web-idl",
253254
"mathematica": "wolfram",
254255
"nb": "wolfram",
255256
"wl": "wolfram",

‎plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
"vba": "VBA",
247247
"vb": "Visual Basic",
248248
"wasm": "WebAssembly",
249+
"web-idl": "Web IDL",
250+
"webidl": "Web IDL",
249251
"wiki": "Wiki markup",
250252
"wolfram": "Wolfram language",
251253
"nb": "Mathematica Notebook",

‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ArrayBuffer
2+
BigInt64Array
3+
BigUint64Array
4+
ByteString
5+
DOMString
6+
DataView
7+
Float32Array
8+
Float64Array
9+
FrozenArray
10+
Int16Array
11+
Int32Array
12+
Int8Array
13+
ObservableArray
14+
Promise
15+
USVString
16+
Uint16Array
17+
Uint32Array
18+
Uint8Array
19+
Uint8ClampedArray
20+
21+
----------------------------------------------------
22+
23+
[
24+
["builtin", "ArrayBuffer"],
25+
["builtin", "BigInt64Array"],
26+
["builtin", "BigUint64Array"],
27+
["builtin", "ByteString"],
28+
["builtin", "DOMString"],
29+
["builtin", "DataView"],
30+
["builtin", "Float32Array"],
31+
["builtin", "Float64Array"],
32+
["builtin", "FrozenArray"],
33+
["builtin", "Int16Array"],
34+
["builtin", "Int32Array"],
35+
["builtin", "Int8Array"],
36+
["builtin", "ObservableArray"],
37+
["builtin", "Promise"],
38+
["builtin", "USVString"],
39+
["builtin", "Uint16Array"],
40+
["builtin", "Uint32Array"],
41+
["builtin", "Uint8Array"],
42+
["builtin", "Uint8ClampedArray"]
43+
]

‎tests/languages/web-idl/class-name_feature.test

+410
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// comment
2+
/* comment */
3+
4+
----------------------------------------------------
5+
6+
[
7+
["comment", "// comment"],
8+
["comment", "/* comment */"]
9+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
async;
2+
attribute;
3+
callback;
4+
const;
5+
constructor;
6+
deleter;
7+
dictionary;
8+
enum;
9+
getter;
10+
includes;
11+
inherit;
12+
interface;
13+
mixin;
14+
namespace;
15+
null;
16+
optional;
17+
or;
18+
partial;
19+
readonly;
20+
required;
21+
setter;
22+
static;
23+
stringifier;
24+
typedef;
25+
unrestricted;
26+
27+
----------------------------------------------------
28+
29+
[
30+
["keyword", "async"], ["punctuation", ";"],
31+
["keyword", "attribute"], ["punctuation", ";"],
32+
["keyword", "callback"], ["punctuation", ";"],
33+
["keyword", "const"], ["punctuation", ";"],
34+
["keyword", "constructor"], ["punctuation", ";"],
35+
["keyword", "deleter"], ["punctuation", ";"],
36+
["keyword", "dictionary"], ["punctuation", ";"],
37+
["keyword", "enum"], ["punctuation", ";"],
38+
["keyword", "getter"], ["punctuation", ";"],
39+
["keyword", "includes"], ["punctuation", ";"],
40+
["keyword", "inherit"], ["punctuation", ";"],
41+
["keyword", "interface"], ["punctuation", ";"],
42+
["keyword", "mixin"], ["punctuation", ";"],
43+
["keyword", "namespace"], ["punctuation", ";"],
44+
["keyword", "null"], ["punctuation", ";"],
45+
["keyword", "optional"], ["punctuation", ";"],
46+
["keyword", "or"], ["punctuation", ";"],
47+
["keyword", "partial"], ["punctuation", ";"],
48+
["keyword", "readonly"], ["punctuation", ";"],
49+
["keyword", "required"], ["punctuation", ";"],
50+
["keyword", "setter"], ["punctuation", ";"],
51+
["keyword", "static"], ["punctuation", ";"],
52+
["keyword", "stringifier"], ["punctuation", ";"],
53+
["keyword", "typedef"], ["punctuation", ";"],
54+
["keyword", "unrestricted"], ["punctuation", ";"]
55+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace SomeNamespace {
2+
/* namespace_members... */
3+
};
4+
5+
partial namespace SomeNamespace {
6+
/* namespace_members... */
7+
};
8+
9+
----------------------------------------------------
10+
11+
[
12+
["keyword", "namespace"],
13+
["namespace", "SomeNamespace"],
14+
["punctuation", "{"],
15+
16+
["comment", "/* namespace_members... */"],
17+
18+
["punctuation", "}"],
19+
["punctuation", ";"],
20+
21+
["keyword", "partial"],
22+
["keyword", "namespace"],
23+
["namespace", "SomeNamespace"],
24+
["punctuation", "{"],
25+
26+
["comment", "/* namespace_members... */"],
27+
28+
["punctuation", "}"],
29+
["punctuation", ";"]
30+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
0xfff
2+
123423
3+
-123423
4+
5+
123.456
6+
123.e64
7+
123.324e-4
8+
.324e+4
9+
10+
NaN
11+
Infinity
12+
-Infinity
13+
14+
----------------------------------------------------
15+
16+
[
17+
["number", "0xfff"],
18+
["number", "123423"],
19+
["number", "-123423"],
20+
21+
["number", "123.456"],
22+
["number", "123.e64"],
23+
["number", "123.324e-4"],
24+
["number", ".324e+4"],
25+
26+
["number", "NaN"],
27+
["number", "Infinity"],
28+
["number", "-Infinity"]
29+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
...
2+
= : ? < >
3+
4+
----------------------------------------------------
5+
6+
[
7+
["operator", "..."],
8+
9+
["operator", "="],
10+
["operator", ":"],
11+
["operator", "?"],
12+
["operator", "<"],
13+
["operator", ">"]
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
any
2+
bigint
3+
boolean
4+
byte
5+
double
6+
float
7+
iterable
8+
long
9+
maplike
10+
object
11+
octet
12+
record
13+
sequence
14+
setlike
15+
short
16+
symbol
17+
undefined
18+
unsigned
19+
void
20+
21+
----------------------------------------------------
22+
23+
[
24+
["keyword", "any"],
25+
["keyword", "bigint"],
26+
["keyword", "boolean"],
27+
["keyword", "byte"],
28+
["keyword", "double"],
29+
["keyword", "float"],
30+
["keyword", "iterable"],
31+
["keyword", "long"],
32+
["keyword", "maplike"],
33+
["keyword", "object"],
34+
["keyword", "octet"],
35+
["keyword", "record"],
36+
["keyword", "sequence"],
37+
["keyword", "setlike"],
38+
["keyword", "short"],
39+
["keyword", "symbol"],
40+
["keyword", "undefined"],
41+
["keyword", "unsigned"],
42+
["keyword", "void"]
43+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
( ) [ ] { }
2+
. , ;
3+
4+
----------------------------------------------------
5+
6+
[
7+
["punctuation", "("],
8+
["punctuation", ")"],
9+
["punctuation", "["],
10+
["punctuation", "]"],
11+
["punctuation", "{"],
12+
["punctuation", "}"],
13+
14+
["punctuation", "."],
15+
["punctuation", ","],
16+
["punctuation", ";"]
17+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
""
2+
"foo"
3+
"\"
4+
5+
----------------------------------------------------
6+
7+
[
8+
["string", "\"\""],
9+
["string", "\"foo\""],
10+
["string", "\"\\\""]
11+
]

0 commit comments

Comments
 (0)
Please sign in to comment.