2012-08-08 5 views
1

XText의 도움으로 jape language from gate에 대한 도구 지원을 만들고 싶습니다. Jape은 기본적으로 주석에 대한 패턴 언어입니다. 해당 주석을 만났을 때 취할 조치를 선언하십시오. 문제는 그 동작이 자바로 작성 될 수 있다는 것이다. 잠시 jdt로 어려움을 겪은 후, 나는 파싱 된 내용의 일부분에 대해 작동하도록 만들지 못했습니다. 그래서 나는 XBlockExpression을 사용하여 xbase 지원을 사용하기로 결정했습니다.XText 전역 변수 등록

문제는 동작에 사용할 수있는 몇 가지 변수가 있다는 것입니다. 예를 들어, 변수 bindings을 바인딩하여 패턴에서 주석을 얻을 수 있습니다. 그래서 내 질문은 xblock 범위에서 이러한 변수를 등록하는 방법입니다. 3 시간 동안 문서를 읽은 후에도 나는 아무 곳에도 여전히 가까이 있지 않습니다. 여기

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase 

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl" 

Model: 
    greetings=Greeting; 


Greeting: 
    block=XBlockExpression; 

는이 같은 내용으로 파일을 구문 분석 할 내 문제에 대한 최소한의 문법이다 : 나는 내 자신의 범위 제공자를 연결하여 시작

{ 
    val testAS = bindings.get("test") as AnnotationSet 
} 

하지만하지 않았다 나를 많이 도와 줘. 여기 공급자에 대한 구현 : 어떤 도움을 이해할 수있을 것이다

package org.xtext.example.mydsl; 

import java.util.List; 

public class MyScopeProvider extends XbaseScopeProvider { 

    XbaseFactory factory = new XbaseFactoryImpl(); 

    @Override 
    public IScope getScope(EObject context, EReference reference) { 
     //System.err.println(context); 
     //System.err.println(reference); 
     List<IValidatedEObjectDescription> descriptions = Lists.newArrayList(); 
     XVariableDeclaration variableDeclaration = factory 
       .createXVariableDeclaration(); 
     variableDeclaration.setName("bindings"); 
     IValidatedEObjectDescription variableDescription = createLocalVarDescription(variableDeclaration); 

     System.err.println(variableDescription); 

     IScope scope = super.getScope(context, reference); 
     System.err.println(variableDeclaration); 
     return new JvmFeatureScope(scope, "test", descriptions); 
    } 
} 

답변

2

당신이 중 하나를 유추 필드 또는 동작 인수로 암시 적으로 사용 가능한 변수를 추가 할 경우 해당 언어에 대한 JvmModelInferrer을 구현하기 위해 시도해야 유형. 그것은 트릭을 할 것입니다. 이 접근법은 7 언어 예제에서 잘 설명되어 있습니다. xtext.org