@@ -121,6 +121,29 @@ variables:
121
121
| filemd1
122
122
)
123
123
124
+ # IPs and CIDR
125
+ # # IPv6 pattern stolen lovingly from https://github.com/tijn/hosts.tmLanguage,
126
+ # # where Michael Lyons adapted them from David M. Szydek https://stackoverflow.com/a/17871737.
127
+ zero_to_32 : (?:3[0-2]|[12][0-9]|[0-9])
128
+ zero_to_128 : (?:12[0-8]|1[01][0-9]|[1-9][0-9]|[0-9])
129
+ zero_to_255 : (?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9][0-9])|(?:[1-9][0-9])|[0-9])
130
+ ipv4 : (?:(?:{{zero_to_255}}\.){3}{{zero_to_255}})
131
+ ipv6 : |-
132
+ (?xi:
133
+ (?:::(?:ffff(?::0{1,4}){0,1}:){0,1}{{ipv4}}) # ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses)
134
+ |(?:(?:[0-9a-f]{1,4}:){1,4}:{{ipv4}}) # 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 (IPv4-Embedded IPv6 Address)
135
+ |(?:fe80:(?::[0-9a-f]{1,4}){0,4}%[0-9a-z]{1,}) # fe80::7:8%eth0 fe80::7:8%1 (link-local IPv6 addresses with zone index)
136
+ |(?:(?:[0-9a-f]{1,4}:){7,7} [0-9a-f]{1,4}) # 1:2:3:4:5:6:7:8
137
+ | (?:[0-9a-f]{1,4}: (?::[0-9a-f]{1,4}){1,6}) # 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8
138
+ |(?:(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}) # 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8
139
+ |(?:(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}) # 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8
140
+ |(?:(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}) # 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8
141
+ |(?:(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}) # 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8
142
+ |(?:(?:[0-9a-f]{1,4}:){1,6} :[0-9a-f]{1,4}) # 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8
143
+ |(?:(?:[0-9a-f]{1,4}:){1,7} :) # 1:: 1:2:3:4:5:6:7::
144
+ |(?::(?:(?::[0-9a-f]{1,4}){1,7}|:)) # ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::
145
+ )
146
+
124
147
contexts :
125
148
main :
126
149
- include : comments
@@ -294,6 +317,8 @@ contexts:
294
317
scope : constant.character.escape.terraform
295
318
- include : string-interpolation
296
319
- include : aws-acl
320
+ - include : ip-addresses-with-cidr-at-start
321
+ - include : ipv6-square-bracket-at-start
297
322
298
323
aws-acl :
299
324
- match : (?=\barn:aws:)
@@ -319,6 +344,43 @@ contexts:
319
344
- meta_content_scope : source.terraform
320
345
- include : string-interpolation-body
321
346
347
+ ipv4-at-start :
348
+ - match : \G{{ipv4}}\b
349
+ scope : meta.number.integer.other.terraform constant.numeric.ip-address.v4.terraform
350
+
351
+ ipv6-at-start :
352
+ - match : \G{{ipv6}}
353
+ scope : meta.number.integer.other.terraform constant.numeric.ip-address.v6.terraform
354
+
355
+ ipv6-square-bracket-at-start :
356
+ - match : \G(\[){{ipv6}}(\])
357
+ scope : meta.number.integer.other.terraform constant.numeric.ip-address.v6.terraform
358
+ captures :
359
+ 1 : punctuation.definition.constant.begin.terraform
360
+ 2 : punctuation.definition.constant.end.terraform
361
+
362
+ ip-addresses-at-start :
363
+ - include : ipv6-at-start
364
+ - include : ipv4-at-start
365
+
366
+ ipv4-with-cidr-at-start :
367
+ - match : \G({{ipv4}})(?:(/)({{zero_to_32}}))?\b
368
+ captures :
369
+ 1 : meta.number.integer.other.terraform constant.numeric.ip-address.v4.terraform
370
+ 2 : punctuation.separator.sequence.terraform
371
+ 3 : constant.other.range.terraform
372
+
373
+ ipv6-with-cidr-at-start :
374
+ - match : \G({{ipv6}})(?:(/)({{zero_to_128}})\b)?
375
+ captures :
376
+ 1 : meta.number.integer.other.terraform constant.numeric.ip-address.v6.terraform
377
+ 2 : punctuation.separator.sequence.terraform
378
+ 3 : constant.other.range.terraform
379
+
380
+ ip-addresses-with-cidr-at-start :
381
+ - include : ipv6-with-cidr-at-start
382
+ - include : ipv4-with-cidr-at-start
383
+
322
384
# String Interpolation: ("${" | "${~") Expression ("}" | "~}"
323
385
#
324
386
# https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#templates
0 commit comments