-
Notifications
You must be signed in to change notification settings - Fork 0
/
hosts.ebnf
43 lines (39 loc) · 1.7 KB
/
hosts.ebnf
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
hosts = (host? <SPACE*><comment?><EOL>)*
host = <SPACE*> address <SPACE+> name (<SPACE+> aliases)? <SPACE*>
aliases = hostname (<SPACE+> hostname)*
comment = '#' STRING?
name = hostname
address = ipv4 | ipv6
hostname = hostname_segment ('.' hostname_segment)*
hostname_segment = #'[a-zA-Z0-9][a-zA-Z0-9-]*'
(* IP parsing from https://github.com/lunatic-cat/iproute/blob/master/resources/route.ebnf *)
(* https://stackoverflow.com/a/14639569/423551 *)
ipv6 = h16-colon-6 ls32 |
"::" h16-colon-5 ls32 |
h16? "::" h16-colon-4 ls32 |
h16-colon-upto-1? "::" h16-colon-3 ls32 |
h16-colon-upto-2? "::" h16-colon-2 ls32 |
h16-colon-upto-3? "::" h16 ":" ls32 |
h16-colon-upto-4? "::" ls32 |
h16-colon-upto-5? "::" h16 |
h16-colon-upto-6? "::"
(* https://github.com/Engelberg/instaparse/issues/187 *)
<h16-colon-6> = #"([0-9a-fA-F]{1,4}:){6}"
<h16-colon-5> = #"([0-9a-fA-F]{1,4}:){5}"
<h16-colon-4> = #"([0-9a-fA-F]{1,4}:){4}"
<h16-colon-3> = #"([0-9a-fA-F]{1,4}:){3}"
<h16-colon-2> = #"([0-9a-fA-F]{1,4}:){2}"
<h16-colon-upto-6> = #"([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}"
<h16-colon-upto-5> = #"([0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}"
<h16-colon-upto-4> = #"([0-9a-fA-F]{1,4}:){0,4}[0-9a-fA-F]{1,4}"
<h16-colon-upto-3> = #"([0-9a-fA-F]{1,4}:){0,3}[0-9a-fA-F]{1,4}"
<h16-colon-upto-2> = #"([0-9a-fA-F]{1,4}:){0,2}[0-9a-fA-F]{1,4}"
<h16-colon-upto-1> = #"([0-9a-fA-F]{1,4}:){0,1}[0-9a-fA-F]{1,4}"
<ls32> = h16 ":" h16 | ipv4
<h16> = #"[0-9a-fA-F]{1,4}"
ipv4 = dec-octet "." dec-octet "." dec-octet "." dec-octet
<dec-octet> = digit | (#"[0-9]" digit) | ("1" digit digit) | ("2" #"[0-4]" digit) | ("25" #"[0-5]")
<digit> = #"[0-9]"
SPACE = #'[ \t]'
STRING = #'[^\r\n]+'
EOL = #'(?:\r\n|\r|\n)'