forked from c3m3gyanesh/p4-syntax-highlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p4.YAML-tmLanguage
265 lines (234 loc) · 7.19 KB
/
p4.YAML-tmLanguage
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# [PackageDev] target_format: plist, ext: tmLanguage
comment: |-
https://github.com/c3m3gyanesh/p4-syntax-highlighter
Derived from various syntax definitaion files
- c.tmLanguage
- babel.tmLanguage
- p4.vim
Author - Gyanesh Patra <c3m3gyanesh@gmail.com>
Version - 1.0
Date - 15 April 2016
>> With each modification, please update the date and version.
Still it needs a lot of imporvements.
Todo:
Numericals can be improved.
Action, meter etc should be defined as function blocks.
Updated with all entities missed from the specification.
if/ifdef/endif
And much more.....
name: p4
scopeName: source.p4
fileTypes: [p4]
uuid: 1a864ad6-0f6b-485e-9b73-245db18e4852
patterns:
- include: '#p4-translation'
repository:
p4-translation:
patterns:
- include: '#p4-comments'
- include: '#p4-preprocessors'
- include: '#p4-abstractions'
- include: '#p4-literal-number'
p4-comments:
patterns:
- name: comment.block.p4
begin: \s*(/\*)
end: (\*/)
- name: comment.line.double.slash.p4
begin: \s*(//)
end: (?<=$\n)(?<!\\$\n)
p4-preprocessors:
patterns:
- include: '#define-directive'
- include: '#include-header-directive'
p4-preprocessor-lex:
patterns:
- include: '#comments'
- include: '#lex-continuation'
- include: '#lex-newline'
define-directive:
patterns:
- name: keyword.define.p4
comment: #define <name> <val> directives
begin: ^\s*(#)(define)(\s+[a-zA-Z_]\w*+)
end: (?<=$\n)(?<!\\$\n)
patterns:
- include: '#p4-literal-number'
include-header-directive:
patterns:
- name: keyword.include.p4
comment: include headers
# match: ^\s*(#)(include)\b
begin: ^\s*(#)(include)\b
# \s+[a-zA-Z_]\w*+)
beginCaptures:
'0': {name: keyword.include.start.p4}
end: (?:("[^"]*?)|(<[^>]*?))(\n)|(?<=$\n)(?<!\\$\n)
#1st Capturing group ("[^"]*?) matches the characters " literally
#2nd Capturing group (<[^>]*?) matches the characters < literally
# 3rd Capturing group (\n) matches a line-feed (newline) character
# (?<=$\n)(?<!\\$\n)
# (?<=$\n) Positive Lookbehind - Assert that the regex below can be matched
# (?<!\\$\n) Negative Lookbehind - Assert that it is impossible to match the regex below
endCaptures:
'1': {name: string.quoted.double.include.p4}
'2': {name: string.lt-gt.include.p4}
'3': {name: invalid.unexpected-end-of-line.p4}
patterns:
- include: '#include-header-directive-internals'
include-header-directive-internals:
patterns:
- include: '#p4-preprocessor-lex'
- name: string.quoted.double.include.p4
begin: '"|(?=.*?")'
beginCaptures:
'0': {name: punctuation.definition.string.begin.p4}
end: '"|(?<=^|[^\\])(?=\s*\n)'
endCaptures:
'0': {name: punctuation.definition.string.end.p4}
- name: string.quoted.other.lt-gt.include.c
begin: <(?=.*?>)
beginCaptures:
'0': {name: punctuation.definition.string.begin.p4}
end: '>|(?<=^|[^\\])(?=\s*\n)'
endCaptures:
'0': {name: punctuation.definition.string.end.p4}
- name: meta.parens.c
begin: \(
end: \)|(?<=^|[^\\])(?=\s*\n)
patterns:
- include: '#include-header-directive-internals'
p4-abstractions:
patterns:
- include: '#p4-object-keyword'
- include: '#p4-object-attribute-keyword'
- include: '#p4-match-type-keyword'
- include: '#p4-counter-type-keyword'
- include: '#p4-todo'
- include: '#p4-builtin'
- include: '#p4-primitives'
- include: '#p4-conditional'
- include: '#p4-statement'
- include: '#p4-constants'
- include: '#p4-stateful'
p4-object-keyword:
patterns:
- name: keyword.object.p4
match: |-
(?x)
\b(parser|table|action
|header_type|header|metadata
|field_list|field_list_calculation|calculated_field
|control
|parser_value_set)
\b
p4-object-attribute-keyword:
patterns:
- name: keyword.object.attribute.p4
match: |-
(?x)
# Tables / Header Types/ FieldList Calculation/ Calculated Fields
\b(reads|actions|min_size|max_size|size
|fields|length|max_length
|input|algorithm|output_width
|verify|update
|type|direct|static
|instance_count|min_width|saturating)
\b
p4-match-type-keyword:
patterns:
- name: keyword.match.type.p4
match: \b(exact|ternary|lpm|range|valid)\b
p4-counter-type-keyword:
patterns:
- name: keyword.counter.type.p4
match: \b(bytes|packets)\b
p4-todo:
patterns:
- name: keyword.todo.p4
match: \b(contained|FIXME|TODO|ToDo|todo)\b
p4-builtin:
patterns:
- name: keyword.builtin.p4
match: |-
(?x)
\b
(apply|hit|miss
|extract|set_metadata)
\b
p4-stateful:
patterns:
- name: storage.stateful.p4
match: \b(counter|meter|register)\b
p4-primitives:
patterns:
- name: keyword.primitives.p4
match: |-
(?x)
\b(add_header|copy_header|remove_header
|modify_field|add_to_field|subtract_from_field
|add|subtract
|set_field_to_hash_index
|modify_field_with_hash_based_offset
|modify_field_rng_uniform
|truncate|drop|no_op
|push|pop
|count
|execute_meter
|generate_digest
|resubmit|recirculate
|clone_ingress_pkt_to_ingress
|clone_egress_pkt_to_ingress
|clone_ingress_pkt_to_egress
|clone_egress_pkt_to_egress
|bit_and|bit_or|bit_xor
|shift_right|shift_left
|register_read
|register_write)
\b
p4-conditional:
patterns:
- name: keyword.conditional.p4
match: \b(if|else|select)\b
p4-statement:
patterns:
- name: keyword.statement.p4
match: return
p4-constants:
patterns:
- name: keyword.constants.p4
match: P4_PARSING_DONE
p4-literal-number:
patterns:
- name: invalid.illegal.numeric.hex.p4
match: (?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)
- name: invalid.illegal.numeric.octal.p4
match: (?:\B[-+]|\b)0[0-9]+\.(\B|\b[0-9]+)
- name: constant.numeric.p4
match: >-
(?xi)
(?:\B[-+])?
(?:
\b0b[0-1]*| # binary
\b0o[0-7]*| # octal
\b0x[0-9a-f]*| # hex
(
\B\.[0-9]+| # e.g. .123
\b[0-9]+(\.[0-9]*)? # e.g. 123.123, 123. or 123
)(e[-+]?[0-9]+)? # e.g. e+123, E-123
(\s|;) # e.g. To avoid 234ABC
)
lex-continuation:
patterns:
- name: punctuation.separator.continuation.c
match: (\\)$(\n?)
captures:
'1': {name: keyword.other.line-continuation.c}
'2': {name: punctuation.whitespace.newline.c}
- match: \\(\s+?)(?=\n)$
captures:
'1': {name: invalid.deprecated.space-after-continuation.c}
lex-newline:
name: punctuation.whitespace.newline.c
match: $\n
...