forked from tijn/hosts.tmLanguage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hosts.sublime-syntax
158 lines (149 loc) · 6.33 KB
/
hosts.sublime-syntax
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
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: Hosts File
file_extensions:
- hosts
scope: text.hosts
variables:
zero_to_255: (?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9][0-9])|(?:[1-9][0-9])|[0-9])
sixteen_to_31: (?:1[6-9]|2[0-9]|3[0-1])
ipv4: (?:(?:{{zero_to_255}}\.){3}{{zero_to_255}})
ipv4_private: |-
(?x:
10(?:\.{{zero_to_255}}){3} # 10.x.x.x
|172\.{{sixteen_to_31}}(?:\.{{zero_to_255}}){2} # 172.16.0.0 - 172.31.255.255
|192\.168(?:\.{{zero_to_255}}){2} # 192.168.x.x
)
ipv4_loopback: 127(?:\.{{zero_to_255}}){3} # 127.x.x.x
ipv6: |-
(?xi:
::(?: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)
|(?:[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)
|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)
|(?:[0-9a-f]{1,4}:){7,7} [0-9a-f]{1,4} # 1:2:3:4:5:6:7:8
| [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
|(?:[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
|(?:[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
|(?:[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
|(?:[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
|(?:[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
|(?:[0-9a-f]{1,4}:){1,7} : # 1:: 1:2:3:4:5:6:7::
|:(?:(?::[0-9a-f]{1,4}){1,7}|:) # ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::
)
ipv6_private: |-
(?xi:f[cd]\h\h:(?:
(?:[0-9a-f]{1,4}:){6} [0-9a-f]{1,4}
|(?:[0-9a-f]{1,4}:)? (?::[0-9a-f]{1,4}){1,5}
|(?:[0-9a-f]{1,4}:){0,2}(?::[0-9a-f]{1,4}){1,4}
|(?:[0-9a-f]{1,4}:){0,3}(?::[0-9a-f]{1,4}){1,3}
|(?:[0-9a-f]{1,4}:){0,4}(?::[0-9a-f]{1,4}){1,2}
|(?:[0-9a-f]{1,4}:){0,5} :[0-9a-f]{1,4}
|(?:[0-9a-f]{1,4}:){0,6} :
))
hostname_char: '[\w-]'
hostname_segment: (?:\w{{hostname_char}}{1,61}\w|\w\w?)
hostname_break: (?=[ \t#]|$)
contexts:
# The prototype context is prepended to all contexts but those setting
# meta_include_prototype: false.
prototype:
- include: comments
main:
- match: ^
push:
- meta_scope: meta.line.ip-mapping.hosts
- match: (?=\n|\s*#)
pop: true
- include: loopback
- include: private
- include: public
- match: \S+
# Consume non-IP lines to prevent highlighting.
# Less destructive than invalid.illegal, especially while typing
loopback:
- match: \B::1(?=\s|$)
scope: meta.ip-address.v6.hosts constant.language.hosts
push: expect-hostnames
- match: \b{{ipv4_loopback}}(?=\s|$)
scope: meta.ip-address.v4.hosts constant.language.hosts
push: expect-hostnames
private:
- match: \b{{ipv4_private}}(?=\s|$)
scope: meta.ip-address.v4.hosts support.constant.built-in.hosts
push: expect-hostnames
- match: \b{{ipv6_private}}(?=\s|$)
scope: meta.ip-address.v6.hosts support.constant.built-in.hosts
push: expect-hostnames
public:
- match: \b{{ipv4}}(?=\s|$)
scope: meta.ip-address.v4.hosts constant.numeric.integer.decimal.hosts
push: expect-hostnames
- match: (?i:fe80:(?::[0-9a-f]{1,4}){0,4}(%)([0-9a-z]+))(?=\s|$)
scope: meta.ip-address.v6.hosts constant.numeric.integer.hexadecimal.hosts
captures:
1: punctuation.separator.mapping.hosts
2: meta.link-local.hosts entity.name.label.hosts
push: expect-hostnames
- match: '{{ipv6}}(?=\s|$)'
scope: meta.ip-address.v6.hosts constant.numeric.integer.hexadecimal.hosts
push: expect-hostnames
expect-hostnames:
- match: (?=\n|\s*#)
pop: true
- match: '[ \t]([.-])'
captures:
1: invalid.illegal.hostname.leading-character.hosts
- match: ([\w.-]{254,})(\.)?{{hostname_break}}
captures:
1: invalid.illegal.hostname.too-long.hosts
2: punctuation.terminator.hosts
- match: (?=\w)
push: in-hostname
in-hostname:
- meta_content_scope: meta.hostname.hosts string.unquoted.hosts
- match: '-(?=\n|$)'
scope: invalid.illegal.hostname.trailing-character.hosts
pop: true
- match: '-(?=[ \t#])'
scope: invalid.illegal.hostname.trailing-character.hosts
- match: (?:\.{2,}|\.-|-\.)
scope: invalid.illegal.hostname.sequence.hosts
- match: '{{hostname_char}}{64,}'
scope: invalid.illegal.hostname.too-long.hosts
# Punycode segments
- match: \b(xn--)(?:{{hostname_char}}+(-))?(\w+)\b(?!\.?{{hostname_break}})
scope: meta.punycode.hosts
captures:
1: punctuation.definition.string.begin.punycode.hosts
2: punctuation.separator.mapping.hosts
3: constant.character.injection.hosts
- match: \b(xn--)(?:{{hostname_char}}+(-))?(\w+)\b(\.)?{{hostname_break}}
scope: meta.hostname.hosts string.unquoted.hosts meta.punycode.hosts
captures:
1: punctuation.definition.string.begin.punycode.hosts
2: punctuation.separator.mapping.hosts
3: constant.character.injection.hosts
4: punctuation.terminator.hosts
pop: true
# Normal segments
- match: '{{hostname_segment}}\b(?!\.?{{hostname_break}})'
scope: meta.string.subdomain.hosts
- match: '{{hostname_segment}}(\.)?{{hostname_break}}'
scope: meta.hostname.hosts string.unquoted.hosts
captures:
1: punctuation.terminator.hosts
pop: true
# Segment separators
- match: \.
scope: punctuation.separator.sequence.hosts
# Invalid hostname characters
- match: '[^\w.-]'
scope: invalid.illegal.hostname.character.hosts
comments:
- match: '#'
scope: punctuation.definition.comment.hosts
push:
- meta_scope: comment.line.number-sign.hosts
- match: $\n?
pop: true