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