简体   繁体   中英

Xtext enum value setting

I have an ecore metamodel like this

Pattern
  direction:Direction
  patternDetail:Details

Direction
  BOTH=0
  LEFT=1
  RIGHT=2

This is a simplification but it is a representation of a graph query language that use patterns. A pattern as a direction and some details (name, whatever)

In my grammar I want to parse some input where the direction information is on 2 places, for example

<-[patterndetails]-> (direction = BOTH)
-[patterndetails]->  (direction = RIGHT)
<-[patterndetails]-  (direction = LEFT)

So I have created this rule

Pattern returns Pattern:
    '<-'patternDetails=PatternDetails'->'
    |'<-'patternDetails=PatternDetails'-'
    |'-'patternDetails=PatternDetails'->'
    ;

But I can't figure out how I can set the direction associated. I try to add direction=Direction.BOTH at the end of the first line but it is not possible. This seems strange because it is possible to affect a value for an EString attribute for example, but not for enums.

Am I missing something on enum access or am I doing this wrong ?

You can have multiple Rules for the same Enum

Pattern returns Pattern:
    '<-' patternDetails=PatternDetails direction=Both
    | '<-' patternDetails=PatternDetails direction=Left
    | '-' patternDetails=PatternDetails direction=Right;

enum Direction:
    BOTH |
    LEFT |
    RIGHT;

enum Both returns Direction:
    BOTH='->';

enum Right returns Direction:
    RIGHT='->';

enum Left returns Direction:
    LEFT='-';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM