-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
abnf.js
63 lines (62 loc) · 1.55 KB
/
abnf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// @ts-nocheck
abnf.displayName = 'abnf'
abnf.aliases = []
/** @type {import('../core.js').Syntax} */
export default function abnf(Prism) {
;(function (Prism) {
var coreRules =
'(?:ALPHA|BIT|CHAR|CR|CRLF|CTL|DIGIT|DQUOTE|HEXDIG|HTAB|LF|LWSP|OCTET|SP|VCHAR|WSP)'
Prism.languages.abnf = {
comment: /;.*/,
string: {
pattern: /(?:%[is])?"[^"\n\r]*"/,
greedy: true,
inside: {
punctuation: /^%[is]/
}
},
range: {
pattern: /%(?:b[01]+-[01]+|d\d+-\d+|x[A-F\d]+-[A-F\d]+)/i,
alias: 'number'
},
terminal: {
pattern:
/%(?:b[01]+(?:\.[01]+)*|d\d+(?:\.\d+)*|x[A-F\d]+(?:\.[A-F\d]+)*)/i,
alias: 'number'
},
repetition: {
pattern: /(^|[^\w-])(?:\d*\*\d*|\d+)/,
lookbehind: true,
alias: 'operator'
},
definition: {
pattern: /(^[ \t]*)(?:[a-z][\w-]*|<[^<>\r\n]*>)(?=\s*=)/m,
lookbehind: true,
alias: 'keyword',
inside: {
punctuation: /<|>/
}
},
'core-rule': {
pattern: RegExp(
'(?:(^|[^<\\w-])' + coreRules + '|<' + coreRules + '>)(?![\\w-])',
'i'
),
lookbehind: true,
alias: ['rule', 'constant'],
inside: {
punctuation: /<|>/
}
},
rule: {
pattern: /(^|[^<\w-])[a-z][\w-]*|<[^<>\r\n]*>/i,
lookbehind: true,
inside: {
punctuation: /<|>/
}
},
operator: /=\/?|\//,
punctuation: /[()\[\]]/
}
})(Prism)
}