2017-12-17 12 views
0

현재 help op Xtext로 새 DSL을 만드는 중입니다. 문법에서 규칙을 정의 할 수 있기를 원합니다. 특정 값을 조작 할 수 있고 this을 사용하여 현재 객체를 참조 할 수 있습니다. 그러나, 나는 그것이 작동하도록 문법 권리를 얻을 수 없습니다.이 키워드를 사용하는 Xtext 상호 참조

나는 Xtext Expressions example에서 약간의 코드를 가져 와서 카드 값에 대한 상호 참조를 넣을 수 있도록 수정했습니다. 이 키워드를 어떻게 사용할 수 있습니까? 나는 다른 스코어 질문에서이 점에 대해 나 자신의 스코핑 제공자를 사용할 수 있다는 것을 알았지 만 어디서부터 시작해야할지 모른다.

일부 코드를 참조하십시오

// MyDSL.xtext

Game returns Game: 
    'Game' 
    name=STRING 
    ... 
    ('Cardpropertytypes' '{' cardpropertytypes+=CardPropertyType ("," cardpropertytypes+=CardPropertyType)* '}')? 
    cards += Card* 
; 

Card returns Card: 
    'Card' 
    name=ID 
    '{' 
     'type' type=[CardType] 
     ('cost' '{' cost+=Cost ("," cost+=Cost)* '}')? 
     ('properties' '{' properties+=CardProperty ("," properties+=CardProperty)* '}')? 
     ('rules' '{' rules+=CardRule ("," rules+=CardRule)* '}')? 
     ('actions' '{' actions+=CardAction ("," actions+=CardAction)* '}')? 
    '}'; 

CardRule returns CardRule: 
    {CardRule} 
    '{' 
     ('description' description=STRING)? 
     ('requirements' requirements=Addition)? 
     ('action' action=Addition)? 
     ('duration' duration=Duration)? 
    '}'; 

CardProperty returns CardProperty: 
    type=[CardPropertyType] (':' value=INT)?; 

Addition returns Expression: 
    Multiplication ({Addition.left=current} '+' right=Multiplication)*; 

Multiplication returns Expression: 
    Primary ({Multiplication.left=current} '*' right=Primary)*; 

Primary returns Expression: 
    Literal | 
    '(' Addition ')'; 

Literal returns Expression: 
    {Expression} 
    QualifiedName | 
    NumberLiteral; 

QualifiedName: 
    ID ('.' ID)*; 

NumberLiteral: 
    value=INT; 

// Card.mydsl

Cardpropertytypes { 
    Toughness, 
    Power, 
    Flying, 
    Indestructible 
} 
Card AdantoVanguard { 
    ... 
    properties { 
     Toughness: 1, 
     Power: 1, 
     Flying 
    } 
    rules { 
     { 
      //action this.properties.Toughness + 2 
      action ???? 
     } 
    } 
} 

명확한 설명 : 나는 같은 속성을 가진 카드 모델이있는 경우 위의 코드 샘플에서 규칙 섹션에서 말할 수 있기를 바랍니다.

this.properties.propertyName + 2 

어떻게하면됩니까? xtext 상호 참조에

+0

어떤 상호 참조입니까? 귀하의 문법은 그 점에서 불완전한 것 같습니다 –

답변

0

때문에 예컨대 다른 규칙 ID 대체하여 IDSomeType 참조 파싱한다는 뜻

ref=[SomeType|ID] 

대한 짧은

ref=[SomeType] 

처럼

ref=[SomeType|IDORTHIS] 
... 
IDORTHIS: ID | "this"; 

당신이 범위를 제공

  • 재정 getScope
  • 사용 컨텍스트 내부의 범위를 제공

    을 구현하는 데 필요한 범위 지정 측의 분석 측면

    을 달성 할 수 있으며, 어떤 참조가 범위인지를 결정하기위한 참조 매개 변수

  • 범위에 넣으려는 요소를 수집하기 위해 컨텍스트를 사용했습니다.
  • 새 스코프 만들기 Scopes 클래스의 메소드를 사용하거나 SimpleScope를 수동으로/EObjectDescription.create 또는 intantiating (요구 사항은 매우 모호합니다.)
+0

나는 내 질문 하단에 설명을 추가했습니다. 기본적으로 말하고자하는 것은'this.attribute.linkedattribute + 2' – Victor

+0

입니다. 간단히이 이름의 범위를 –

+0

으로 지정하면 결국 xbase를 사용하여 저장했습니다. 시각! – Victor