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'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local comment
= token(l
.COMMENT
, l
.starts_line(S(';#')) * l
.nonnewline^
0)
17 local sq_str
= l
.delimited_range("'")
18 local dq_str
= l
.delimited_range('"')
19 local section_word
= word_match
{
41 local string = token(l
.STRING
, sq_str
+ dq_str
+ '[' * section_word
* ']')
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
))
50 local keyword
= token(l
.KEYWORD
, word_match
{
61 local option_word
= word_match
{
62 -- match section options
74 -- link section options
86 -- network section options
90 'LinkLocalAddressing',
96 'DNSSECNegativeTrustAnchors',
106 'IPv6PrivacyExtensions',
107 'IPv6AcceptRouterAdvertisements',
108 'IPv6DuplicateAddressDetection',
117 -- address section options
123 -- route section options
131 -- dhcp section options
141 'CriticalConnection',
143 'VendorClassIdentifier',
147 -- dhcpserver section options
150 'DefaultLeaseTimeSec',
159 -- bridge section options
167 -- bridgefdb section options
171 -- netdev section options
178 -- bridge (netdev) section options
183 -- vlan section options
186 -- macvlan, macvtap and ipvlan section options
189 -- vxlan section options
198 'L2MissNotification',
199 'L3MissNotification',
202 'UDP6ZeroChecksumTx',
203 'UDP6ZeroCheckSumRx',
204 'GroupPolicyExtension',
208 -- tunnel section options
216 'EncapsulationLimit',
219 -- peer section options
223 -- tun and tap section options
231 -- bond section options
233 'TransmitHashPolicy',
238 'LearnPacketIntervalSec',
245 'PrimaryReselectPolicy',
252 local preproc
= token(l
.PREPROCESSOR
, option_word
)
255 local word
= (l
.alpha
+ '_') * (l
.alnum
+ S('_.'))^
0
256 local identifier
= token(l
.IDENTIFIER
, word
)
259 local operator
= token(l
.OPERATOR
, '=')
263 {'keyword', keyword
},
265 {'preproc', preproc
},
266 {'identifier', identifier
},
267 {'comment', comment
},
269 {'operator', operator
},