Search code examples
eclipseinterpreterdslxtext

xtext writing and interpreter


currently I am writing an interpreter for my DSL which is launched from a menu in a eclipse application . The interpreter read the active file with:

IXtextDocument document = ((XtextEditor) activeEditor).getDocument().get(); (return a String)

Then I read line by line with a scanner the active file , but is really hard , reading all lines and make switches and ifs for every possibility for their execution .

is there a way to use my grammar information(know what is the line: declaration , function , ...) while I read the active file in the eclipse application ? , or is there a better way to implement this without reading the file like a normal string?


Solution

  • IXtextDocument implements IReadAccess<XtextResource> interface, so you should be able to call editor.document.readOnly(...), like here: https://github.com/eclipse/xtext-eclipse/blob/01ffa30f58160e4c13cb193da3d1e21a40e0d508/org.eclipse.xtext.ui.tests/tests/org/eclipse/xtext/ui/tests/editor/SimpleEditorTest.java#L64