我正在尝试 - >> VL:'this is test dsl in xtext' IS ABC
TestLabelBase returns ResultExpressionRhs:
'VL:' path=stringRule;
我试过的规则是:
TestLabel returns ResultExpressionRhs:
TestLabelBase ('IS' modifier=alphabateModifier)?;
alphabateModifier:
(abc?='ABC' | def?='DEF' | ghi?='GHI');
它会识别IS
,但不识别ABC
。
答案 0 :(得分:1)
以下xtext语法将解析您的示例
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model
: lables+=TestLabel+
;
TestLabel returns ResultExpressionRhs
: TestLabelBase ('IS' modifier=AlphabateModifier)?
;
TestLabelBase returns ResultExpressionRhs
: 'VL:' path=STRING
;
AlphabateModifier
: (abc?='ABC' | def?='DEF' | ghi?='GHI')
;
它解析了以下测试文件:
VL:'this is test dsl in xtext' IS ABC
VL:'this is test dsl in xtext' IS DEF
VL:'this is test dsl in xtext' IS GHI
干杯,史蒂夫