Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Web IDL #3107

Merged
merged 5 commits into from Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -1424,6 +1424,11 @@
"title": "WebAssembly",
"owner": "Golmote"
},
"web-idl": {
"title": "Web IDL",
"alias": "webidl",
"owner": "RunDevelopment"
},
"wiki": {
"title": "Wiki markup",
"require": "markup",
Expand Down
101 changes: 101 additions & 0 deletions components/prism-web-idl.js
@@ -0,0 +1,101 @@
(function (Prism) {

var id = /(?:\B-|\b_|\b)[A-Za-z][\w-]*(?![\w-])/.source;
var type =
'(?:' +
/\b(?:unsigned\s+)?long\s+long(?![\w-])/.source +
'|' +
/\b(?:unrestricted|unsigned)\s+[a-z]+(?![\w-])/.source +
'|' +
/(?!(?:unrestricted|unsigned)\b)/.source + id + /(?:\s*<(?:[^<>]|<[^<>]*>)*>)?/.source +
')' + /(?:\s*\?)?/.source;

var typeInside = {};

Prism.languages['web-idl'] = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
greedy: true
},
'string': {
pattern: /"[^"]*"/,
greedy: true
},

'namespace': {
pattern: RegExp(/(\bnamespace\s+)/.source + id),
lookbehind: true,
},
'class-name': [
{
pattern: /(^|[^\w-])(?:iterable|maplike|setlike)\s*<(?:[^<>]|<[^<>]*>)*>/,
lookbehind: true,
inside: typeInside
},
{
pattern: RegExp(/(\b(?:attribute|const|deleter|getter|optional|setter)\s+)/.source + type),
lookbehind: true,
inside: typeInside
},
{
// callback return type
pattern: RegExp('(' + /\bcallback\s+/.source + id + /\s*=\s*/.source + ')' + type),
lookbehind: true,
inside: typeInside
},
{
// typedef
pattern: RegExp(/(\btypedef\b\s*)/.source + type),
lookbehind: true,
inside: typeInside
},

{
pattern: RegExp(/(\b(?:callback|dictionary|enum|interface(?:\s+mixin)?)\s+)(?!(?:interface|mixin)\b)/.source + id),
lookbehind: true,
},
{
// inheritance
pattern: RegExp(/(:\s*)/.source + id),
lookbehind: true,
},

// includes and implements
RegExp(id + /(?=\s+(?:implements|includes)\b)/.source),
{
pattern: RegExp(/(\b(?:implements|includes)\s+)/.source + id),
lookbehind: true,
},

{
// function return type, parameter types, and dictionary members
pattern: RegExp(type + '(?=' + /\s*(?:\.{3}\s*)?/.source + id + /\s*[(),;=]/.source + ')'),
inside: typeInside
},
],

'builtin': /\b(?:ArrayBuffer|BigInt64Array|BigUint64Array|ByteString|DOMString|DataView|Float32Array|Float64Array|FrozenArray|Int16Array|Int32Array|Int8Array|ObservableArray|Promise|USVString|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray)\b/,
'keyword': [
/\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/,
// type keywords
/\b(?:any|bigint|boolean|byte|double|float|iterable|long|maplike|object|octet|record|sequence|setlike|short|symbol|undefined|unsigned|void)\b/
],
'boolean': /\b(?:false|true)\b/,

'number': {
pattern: /(^|[^\w-])-?(?:0x[0-9a-f]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|NaN|Infinity)(?![\w-])/i,
lookbehind: true
},
'operator': /\.{3}|[=:?<>-]/,
'punctuation': /[(){}[\].,;]/
};

for (var key in Prism.languages['web-idl']) {
if (key !== 'class-name') {
typeInside[key] = Prism.languages['web-idl'][key];
}
}

Prism.languages['webidl'] = Prism.languages['web-idl'];

}(Prism));
1 change: 1 addition & 0 deletions components/prism-web-idl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions examples/prism-web-idl.html
@@ -0,0 +1,28 @@
<h2>Full example</h2>
<pre><code>[Exposed=Window]
interface Paint { };

[Exposed=Window]
interface SolidColor : Paint {
attribute double red;
attribute double green;
attribute double blue;
};

[Exposed=Window]
interface Pattern : Paint {
attribute DOMString imageURL;
};

[Exposed=Window]
interface GraphicalWindow {
constructor();
readonly attribute unsigned long width;
readonly attribute unsigned long height;

attribute Paint currentPaint;

undefined drawRectangle(double x, double y, double width, double height);

undefined drawText(double x, double y, DOMString text);
};</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -250,6 +250,7 @@
"url": "uri",
"vb": "visual-basic",
"vba": "visual-basic",
"webidl": "web-idl",
"mathematica": "wolfram",
"nb": "wolfram",
"wl": "wolfram",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -246,6 +246,8 @@
"vba": "VBA",
"vb": "Visual Basic",
"wasm": "WebAssembly",
"web-idl": "Web IDL",
"webidl": "Web IDL",
"wiki": "Wiki markup",
"wolfram": "Wolfram language",
"nb": "Mathematica Notebook",
Expand Down