Вопрос

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