forked from PrismJS/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prism-abnf.js
54 lines (51 loc) · 1.17 KB
/
prism-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
(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);