[d24f17c] | 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));
|
---|