想用来处理 Windows 的 hosts 文件,但是只能正确处理注释部分。
grammar hosts;
hostfile: line* EOF;
line : item
| comment
;
item: IPADDRESS HOSTNAME ;
comment: COMMENT;
HOSTNAME: [A-z0-9.]+;
NUM: [0-9] +;
IPADDRESS: NUM ;
COMMENT: '#' .*? '\r'? '\n';
NL: ('\r\n'|'\n\r'|'\r'|'\n') ->skip;
BLANK: (' '|'\t') ->skip;