/
source.abnf.js
181 lines (180 loc) · 5.88 KB
/
source.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// This is a TextMate grammar distributed by `starry-night`.
// This grammar is developed at
// <https://github.com/Alhadis/language-grammars>
// and licensed `isc`.
// See <https://github.com/wooorm/starry-night> for more info.
/** @type {import('../lib/index.js').Grammar} */
const grammar = {
extensions: ['.abnf'],
names: ['abnf'],
patterns: [{include: '#main'}],
repository: {
assignment: {
patterns: [
{match: '=/', name: 'keyword.operator.assignment.increment.abnf'},
{
match: ':+=',
name: 'keyword.operator.assignment.colon.non-standard.abnf'
},
{match: '=', name: 'keyword.operator.assignment.abnf'}
]
},
comment: {
begin: ';',
beginCaptures: {0: {name: 'punctuation.definition.comment.abnf'}},
end: '$',
name: 'comment.line.semicolon.abnf'
},
'core-rules': {
match:
'(?x)\n\\b (?<!-)\n(ALPHA|BIT|CHAR|CRLF|CR|CTL|DIGIT|DQUOTE\n|HEXDIG|HTAB|LF|LWSP|OCTET|SP|VCHAR|WSP)\n\\b (?!-)',
name: 'support.constant.reference.core-rule.abnf'
},
group: {
begin: '\\(',
beginCaptures: {
0: {name: 'punctuation.definition.round.bracket.begin.abnf'}
},
end: '\\)',
endCaptures: {0: {name: 'punctuation.definition.round.bracket.end.abnf'}},
name: 'meta.group.abnf',
patterns: [{include: '#rhs'}]
},
main: {patterns: [{include: '#comment'}, {include: '#rule'}]},
optional: {
begin: '\\[',
beginCaptures: {
0: {name: 'punctuation.definition.square.bracket.begin.abnf'}
},
end: '\\]',
endCaptures: {
0: {name: 'punctuation.definition.square.bracket.end.abnf'}
},
name: 'meta.optional.abnf',
patterns: [{include: '#rhs'}]
},
prose: {
begin: '<',
beginCaptures: {0: {name: 'punctuation.definition.string.begin.abnf'}},
end: '>',
endCaptures: {0: {name: 'punctuation.definition.string.end.abnf'}},
name: 'string.other.prose.abnf'
},
quantifier: {
captures: {
1: {name: 'constant.numeric.decimal.integer.int.abnf'},
2: {name: 'keyword.operator.logical.repetition.asterisk.star.abnf'}
},
match: '([0-9]*)(\\*)',
name: 'meta.quantifier.abnf'
},
reference: {
match: '[A-Za-z][-A-Za-z0-9]*',
name: 'variable.parameter.argument.identifier.reference.abnf'
},
rhs: {
patterns: [
{include: '#assignment'},
{include: '#string'},
{include: '#terminal'},
{include: '#comment'},
{include: '#quantifier'},
{include: '#group'},
{include: '#optional'},
{include: '#core-rules'},
{include: '#reference'},
{include: '#prose'},
{match: '/', name: 'keyword.operator.logical.or.alternation.pipe.abnf'}
]
},
rule: {
begin: '(?:^|\\G)(\\s*)([A-Za-z][-A-Za-z0-9]*)',
beginCaptures: {
0: {name: 'meta.lhs.abnf'},
1: {name: 'punctuation.whitespace.leading.abnf'},
2: {name: 'entity.name.rule.identifier.abnf'}
},
contentName: 'meta.rhs.abnf',
end: '^(?!\\1\\s+\\S)|^(?=\\S)',
name: 'meta.ruleset.$2.abnf',
patterns: [{include: '#rhs'}]
},
string: {
begin: '"',
beginCaptures: {0: {name: 'punctuation.definition.string.begin.abnf'}},
end: '"',
endCaptures: {0: {name: 'punctuation.definition.string.end.abnf'}},
name: 'string.quoted.double.abnf'
},
terminal: {
patterns: [
{
begin: '(%)(d|D)',
beginCaptures: {
1: {name: 'punctuation.definition.terminal.percentage-sign.abnf'},
2: {name: 'storage.type.modifier.radix.abnf'}
},
end: '(?=$|[;()\\[\\]{}\\s])',
name: 'meta.terminal.numeric.decimal.abnf',
patterns: [
{
match: '[0-9A-Fa-f]*[^-\\s0-9.;()\\[\\]{}][^-.;()\\[\\]{}]*',
name: 'invalid.illegal.syntax.abnf'
},
{
match: '[0-9]+',
name: 'constant.numeric.integer.int.decimal.abnf'
},
{match: '-', name: 'punctuation.separator.range.dash.hyphen.abnf'},
{match: '\\.', name: 'keyword.operator.concatenation.abnf'}
]
},
{
begin: '(%)(x|X)',
beginCaptures: {
1: {name: 'punctuation.definition.terminal.percentage-sign.abnf'},
2: {name: 'storage.type.modifier.radix.abnf'}
},
end: '(?=$|[;()\\[\\]{}\\s])',
name: 'meta.terminal.numeric.hexadecimal.hex.abnf',
patterns: [
{
match:
'[0-9A-Fa-f]*[^-\\s0-9A-Fa-f.;()\\[\\]{}][^-.;()\\[\\]{}]*',
name: 'invalid.illegal.syntax.abnf'
},
{
match: '[0-9A-Fa-f]+',
name: 'constant.numeric.integer.int.hexadecimal.hex.abnf'
},
{match: '-', name: 'punctuation.separator.range.dash.hyphen.abnf'},
{match: '\\.', name: 'keyword.operator.concatenation.abnf'}
]
},
{
begin: '(%)(b|B)',
beginCaptures: {
1: {name: 'punctuation.definition.terminal.percentage-sign.abnf'},
2: {name: 'storage.type.modifier.radix.abnf'}
},
end: '(?=$|[;()\\[\\]{}\\s])',
name: 'meta.terminal.numeric.binary.bin.abnf',
patterns: [
{
match: '[0-1]*[^-\\s0-1.;()\\[\\]{}][^-.;()\\[\\]{}]*',
name: 'invalid.illegal.syntax.abnf'
},
{
match: '[0-1]+',
name: 'constant.numeric.integer.int.binary.bin.abnf'
},
{match: '-', name: 'punctuation.separator.range.dash.hyphen.abnf'},
{match: '\\.', name: 'keyword.operator.concatenation.abnf'}
]
}
]
}
},
scopeName: 'source.abnf'
}
export default grammar