build: set version to 0.5
[vis.git] / lua / lexers / networkd.lua
blob3f27bae10e9b132af0edd7aac68e2892c938a6e9
1 -- Copyright 2016 Christian Hesse
2 -- systemd networkd file LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'networkd'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, l.starts_line(S(';#')) * l.nonnewline^0)
16 -- Strings.
17 local sq_str = l.delimited_range("'")
18 local dq_str = l.delimited_range('"')
19 local section_word = word_match{
20 'Address',
21 'Link',
22 'Match',
23 'Network',
24 'Route',
25 'DHCP',
26 'DHCPServer',
27 'Bridge',
28 'BridgeFDB',
29 'NetDev',
30 'VLAN',
31 'MACVLAN',
32 'MACVTAP',
33 'IPVLAN',
34 'VXLAN',
35 'Tunnel',
36 'Peer',
37 'Tun',
38 'Tap',
39 'Bond'
41 local string = token(l.STRING, sq_str + dq_str + '[' * section_word * ']')
43 -- Numbers.
44 local dec = l.digit^1 * ('_' * l.digit^1)^0
45 local oct_num = '0' * S('01234567_')^1
46 local integer = S('+-')^-1 * (l.hex_num + oct_num + dec)
47 local number = token(l.NUMBER, (l.float + integer))
49 -- Keywords.
50 local keyword = token(l.KEYWORD, word_match{
51 -- boolean values
52 'true',
53 'false',
54 'on',
55 'off',
56 'yes',
57 'no',
60 -- Options.
61 local option_word = word_match{
62 -- match section options
63 'MACAddress',
64 'OriginalName',
65 'Path',
66 'Driver',
67 'Type',
68 'Host',
69 'Name',
70 'Virtualization',
71 'KernelCommandLine',
72 'Architecture',
74 -- link section options
75 'Description',
76 'Alias',
77 'MACAddressPolicy',
78 'MACAddress',
79 'NamePolicy',
80 'Name',
81 'MTUBytes',
82 'BitsPerSecond',
83 'Duplex',
84 'WakeOnLan',
86 -- network section options
87 'Description',
88 'DHCP',
89 'DHCPServer',
90 'LinkLocalAddressing',
91 'IPv4LLRoute',
92 'IPv6Token',
93 'LLMNR',
94 'MulticastDNS',
95 'DNSSEC',
96 'DNSSECNegativeTrustAnchors',
97 'LLDP',
98 'BindCarrier',
99 'Address',
100 'Gateway',
101 'DNS',
102 'Domains',
103 'NTP',
104 'IPForward',
105 'IPMasquerade',
106 'IPv6PrivacyExtensions',
107 'IPv6AcceptRouterAdvertisements',
108 'IPv6DuplicateAddressDetection',
109 'IPv6HopLimit',
110 'Bridge',
111 'Bond',
112 'VLAN',
113 'MACVLAN',
114 'VXLAN',
115 'Tunnel',
117 -- address section options
118 'Address',
119 'Peer',
120 'Broadcast',
121 'Label',
123 -- route section options
124 'Gateway',
125 'Destination',
126 'Source',
127 'Metric',
128 'Scope',
129 'PreferredSource',
131 -- dhcp section options
132 'UseDNS',
133 'UseNTP',
134 'UseMTU',
135 'SendHostname',
136 'UseHostname',
137 'Hostname',
138 'UseDomains',
139 'UseRoutes',
140 'UseTimezone',
141 'CriticalConnection',
142 'ClientIdentifier',
143 'VendorClassIdentifier',
144 'RequestBroadcast',
145 'RouteMetric',
147 -- dhcpserver section options
148 'PoolOffset',
149 'PoolSize',
150 'DefaultLeaseTimeSec',
151 'MaxLeaseTimeSec',
152 'EmitDNS',
153 'DNS',
154 'EmitNTP',
155 'NTP',
156 'EmitTimezone',
157 'Timezone',
159 -- bridge section options
160 'UnicastFlood',
161 'HairPin',
162 'UseBPDU',
163 'FastLeave',
164 'AllowPortToBeRoot',
165 'Cost',
167 -- bridgefdb section options
168 'MACAddress',
169 'VLANId',
171 -- netdev section options
172 'Description',
173 'Name',
174 'Kind',
175 'MTUBytes',
176 'MACAddress',
178 -- bridge (netdev) section options
179 'HelloTimeSec',
180 'MaxAgeSec',
181 'ForwardDelaySec',
183 -- vlan section options
184 'Id',
186 -- macvlan, macvtap and ipvlan section options
187 'Mode',
189 -- vxlan section options
190 'Id',
191 'Group',
192 'TOS',
193 'TTL',
194 'MacLearning',
195 'FDBAgeingSec',
196 'MaximumFDBEntries',
197 'ARPProxy',
198 'L2MissNotification',
199 'L3MissNotification',
200 'RouteShortCircuit',
201 'UDPCheckSum',
202 'UDP6ZeroChecksumTx',
203 'UDP6ZeroCheckSumRx',
204 'GroupPolicyExtension',
205 'DestinationPort',
206 'PortRange',
208 -- tunnel section options
209 'Local',
210 'Remote',
211 'TOS',
212 'TTL',
213 'DiscoverPathMTU',
214 'IPv6FlowLabel',
215 'CopyDSCP',
216 'EncapsulationLimit',
217 'Mode',
219 -- peer section options
220 'Name',
221 'MACAddress',
223 -- tun and tap section options
224 'OneQueue',
225 'MultiQueue',
226 'PacketInfo',
227 'VNetHeader',
228 'User',
229 'Group',
231 -- bond section options
232 'Mode',
233 'TransmitHashPolicy',
234 'LACPTransmitRate',
235 'MIIMonitorSec',
236 'UpDelaySec',
237 'DownDelaySec',
238 'LearnPacketIntervalSec',
239 'AdSelect',
240 'FailOverMACPolicy',
241 'ARPValidate',
242 'ARPIntervalSec',
243 'ARPIPTargets',
244 'ARPAllTargets',
245 'PrimaryReselectPolicy',
246 'ResendIGMP',
247 'PacketsPerSlave',
248 'GratuitousARP',
249 'AllSlavesActive',
250 'MinLinks',
252 local preproc = token(l.PREPROCESSOR, option_word)
254 -- Identifiers.
255 local word = (l.alpha + '_') * (l.alnum + S('_.'))^0
256 local identifier = token(l.IDENTIFIER, word)
258 -- Operators.
259 local operator = token(l.OPERATOR, '=')
261 M._rules = {
262 {'whitespace', ws},
263 {'keyword', keyword},
264 {'string', string},
265 {'preproc', preproc},
266 {'identifier', identifier},
267 {'comment', comment},
268 {'number', number},
269 {'operator', operator},
272 M._LEXBYLINE = true
274 return M