2017-04-13 1 views
0

Xtext에서 문법을 만들었습니다. plugin.xml에서 이클립스 응용 프로그램을 시작하고 내 문법을 테스트 할 수 있습니다. 이제 내 DSL 코드를 시작할 수 있도록 통역사를 만들어야합니다.Xtext 문법에 대한 독자적인 인터프리터 만들기

클래스 인터프리터를 사용하여 패키지를 만들었지 만 Eclipse 에디터에서 열어 본 파일에 액세스하는 방법을 모른다. 다른 한편, 나는 인터프리터가 편집자의 파일을 줄 단위로 읽고 문장을 실행한다고 생각하는데, 그렇지?

마지막 질문은 Xtext 문법에 대한 인터프리터를 구현하는 데 필요한 자습서 나 더 나은 방법을 알고 있고 모두 함께 작동하는 것입니다. 나는 거북이 예를 이해하려고 노력하지만 나는 아무것도 이해하지 못한다.

감사합니다 !!!

답변

1

그럼 일반적인 질문에 답하기 란 거의 불가능합니다. 귀하의 통역사가하는 일과 의견을 제공하는 방식에 크게 좌우됩니다. 줄 단위로 작업하는 것조차도 모델 컨텐트를 단순히 반복하는 대신 전혀 이해가되지 않을 수도 있습니다. 사용자가 파일에 입력 할 때 "autoedit"에서이 작업을 수행 할 수 있습니다. 이것은 xtext와 함께 제공되는 산술 예제입니다. 또는 에디터로 뷰를 토글 할 수 있습니다 - 거북이 예제가 수행하는 것입니다 (https://github.com/xtext/seven-languages-xtext/blob/c04e8d56e362bfb8d6163f4b001b22ab878686ca/languages/org.xtext.tortoiseshell.lib/src/org/xtext/tortoiseshell/lib/view/TortoiseView.xtend). 또는 컨텍스트 메뉴 (및 바로 가기)에서 rightclick을 통해 호출하는 eclipse 명령을 사용할 수도 있습니다. 다음은 열린 파일에서 작동하는 Eclipse Command Handler를 빌드하는 작은 스 니펫입니다. 당신이 xtext 리소스에 액세스하고 작업 할 수 있습니다 XtextEditor.getDocument(). readOnly 인() 전화를 아래로

public class InterpretCodeHandler extends AbstractHandler implements IHandler { 

    @Override 
    public Object execute(ExecutionEvent event) throws ExecutionException { 

     IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); 
     IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class); 
     if (file != null) { 
      IProject project = file.getProject(); 



      if (activeEditor instanceof XtextEditor) { 
       ((XtextEditor)activeEditor).getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() { 

        @Override 
        public Boolean exec(XtextResource state) 
          throws Exception { 
         // TODO your code here 
         return Boolean.TRUE; 
        } 
       }); 

      } 
     } 
     return null; 
    } 

    @Override 
    public boolean isEnabled() { 
     return true; 
    } 

} 

그것은 기본적으로 손톱을 (https://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/에서 촬영). 여기

하고 등록 (들)

<extension point="org.eclipse.ui.menus"> 
    <menuContribution locationURI="popup:#TextEditorContext?after=additions"> 
     <command commandId="org.xtext.example.mydsl.ui.handler.InterpreterCommand" style="push"> 
      <visibleWhen checkEnabled="false"> 
        <reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened"></reference> 
      </visibleWhen> 
     </command> 
    </menuContribution> 
</extension> 
<extension point="org.eclipse.ui.handlers"> 
    <handler class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.xtext.example.mydsl.ui.handler.InterpretCodeHandler" commandId="org.xtext.example.mydsl.ui.handler.InterpreterCommand"> 
    </handler> 
</extension> 
<extension point="org.eclipse.ui.commands"> 
     <command name="Interpret Code" id="org.xtext.example.mydsl.ui.handler.InterpreterCommand"> 
     </command> 
</extension>