문제

I am trying -->> VL:'this is test dsl in xtext' IS ABC

TestLabelBase returns ResultExpressionRhs:
   'VL:' path=stringRule;

The Rule I tried was:

TestLabel returns ResultExpressionRhs:
   TestLabelBase ('IS' modifier=alphabateModifier)?;

alphabateModifier:
   (abc?='ABC' | def?='DEF' | ghi?='GHI');

It would recognize the IS but not the ABC.

도움이 되었습니까?

해결책

The following xtext grammar will parse your example

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')
  ;

It parses the following test file just fine:

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

Cheers, Steve

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top