【发布时间】:2015-03-17 07:55:53
【问题描述】:
我是 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
我收到此错误 3 次:
不匹配的输入“0”需要 RULE_INT 不匹配的输入 '1' 期望 RULE_INT 不匹配的输入“5”需要 RULE_INT
我看不出这些错误来自哪里,我能做些什么来修复它们。有什么想法吗?
【问题讨论】:
-
您确定您发布了语法的所有相关部分吗?确定没有与 INT 终端规则重叠的关键字或终端规则?
-
我有这个终端规则,但我还没有使用它:终端 FLOAT:'-'? INT ('.' INT)?;