我是Xtext的新手,正在尝试为铁路系统创建简单的DSL,这是我的语法:
grammar org.xtext.railway.RailWay with org.eclipse.xtext.common.Terminals
generate railWay "http://www.xtext.org/railway/RailWay"
Model:
(trains+=Train)*
| (paths+=Path)*
| (sections+=Section)*
;
Train:
'Train' name=ID ':'
'Path' path=[Path]
'Speed' speed=INT
'end'
;
Path:
'Path' name=ID ':'
'Sections' ('{' sections+=[Section] (',' sections+=[Section] )+ '}' ) | sections+=[Section]
'end'
;
Section:
'Section' name=ID ':'
'Start' start=INT
'End' end=INT
('SpeedMax' speedMax=INT)?
'end'
;
但是,当我将这段代码放在Eclipse实例中时:
Section brestStBrieux :
Start 0
End 5
end
Section StBrieuxLeMan :
Start 5
End 10
end
Section leManParis :
Start 1
End 12
end
Path brestParis :
Sections { brestStBrieux, StBrieuxLeMan, leManParis}
end
Train tgv :
Path brestParis
Speed 23
end
我三次遇到此错误:
输入'0'不匹配,期望RULE_INT输入不匹配,输入'1',期望RULE_INT输入不匹配,输入'5',期望匹配RULE_INT
我看不到这些错误来自何处,该如何解决。任何的想法?
Christian是正确的,因为不再定义FLOAT终端,所以原来的问题就解决了。无论如何,剩下的问题就是规则
Path:
'Path' name=ID ':'
'Sections' ('{' sections+=[Section] (',' sections+=[Section] )+ '}' ) | sections+=[Section]
'end'
;
当前具有以下优先级:
Path:
(
'Path' name=ID ':' 'Sections'
('{' sections+=[Section] (',' sections+=[Section] )+ '}' )
)
|
(sections+=[Section] 'end')
;
您可能需要将其重写为
Path:
'Path' name=ID ':'
'Sections'
(
('{' sections+=[Section] (',' sections+=[Section] )+ '}' )
| sections+=[Section]
) 'end'
;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句