【发布时间】:2018-02-11 11:28:23
【问题描述】:
我是 antlr4 的新手,我正在尝试创建语法以将流利的配置文件解析为树。你能指出我在这里做错了什么吗?
fluentd 语法看起来很像 Apache 的(伪 xml、shell 样式的 cmets、标签中的 kv-pairs),例如:
# Receive events from 24224/tcp
<source>
@type forward
port 24224
</source>
# example
<match>
# file or memory
buffer_type file
<copy>
file /path
</copy>
</match>
这是我目前的语法:
grammar Fluentd;
// root element
content: (entry | comment)*;
entry: '<' name tag? '>' (entry | comment | param)* '<' '/' close_ '>';
name: NAME;
close_: NAME;
tag: TAG;
comment: '#' NL;
param: name value NL;
value: ANY;
ANY: .*?;
NL: ('\r'?'\n'|'\n') -> skip;
TAG: ('a'..'z' | 'A'..'Z' | '_' | '0'..'9'| '$' |'.' | '*' | '{' | '}')+;
NAME: ('a'..'z'| 'A..Z' | '@' | '_' | '0'..'9')+;
WS: (' '|'\t') -> skip;
...在上面的输入中它惨遭失败:
line 2:2 mismatched input 'Receive' expecting NL
line 3:1 missing NAME at 'source'
line 4:8 mismatched input 'forward' expecting ANY
line 6:2 mismatched input 'source' expecting NAME
line 8:2 mismatched input 'example' expecting NL
line 9:1 missing NAME at 'match'
line 10:6 mismatched input 'file' expecting NL
line 12:2 mismatched input 'match' expecting NAME
【问题讨论】: