TortoiseShell - is there simple way to run the interpreter to run a program ? [message #1807243] |
Sat, 25 May 2019 13:22  |
Eclipse User |
|
|
|
sorry,
can someone please help me ??
is there a simple way to run the interpreter and have a look at commands execution ?
what I have to do to have the following code running ?
(now I'm getting a a null pointer exception at the line indicated below, inside the method)
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.text.ParseException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parser.IParser;
import org.xtext.tortoiseshell.TortoiseShellStandaloneSetup;
import org.xtext.tortoiseshell.interpreter.TortoiseShellInterpeter;
import org.xtext.tortoiseshell.lib.Tortoise;
import com.google.inject.Inject;
import com.google.inject.Injector;
public class XtextParser {
@Inject
private IParser parser;
public XtextParser() {
setupParser();
}
private void setupParser() {
Injector injector = new TortoiseShellStandaloneSetup().createInjectorAndDoEMFRegistration();
injector.injectMembers(this);
}
/**
* Parses data provided by an input reader using Xtext and returns the root node of the resulting object tree.
* @param reader Input reader
* @return root object node
* @throws IOException when errors occur during the parsing process
*/
public EObject parse(Reader reader) throws IOException, ParseException
{
IParseResult result = parser.parse(reader);
if(result.hasSyntaxErrors())
{
throw new ParseException("Provided input contains syntax errors.", 0);
}
return result.getRootASTElement();
}
public static void main(String[] args) throws IOException, ParseException {
XtextParser xtp=new XtextParser();
xtp.setupParser();
FileReader reader=new FileReader("c:\\\Nikolaus.tortoiseshell");
EObject program = xtp.parse(reader);
TortoiseShellInterpeter tsi = new TortoiseShellInterpeter();
Tortoise tortoise= new Tortoise();
tsi.run(tortoise, program, 1000); <<<<<NPE INSIDE THIS METHOD>>>>
}
}
Thanks in advance
Andrea
|
|
|
Re: TortoiseShell - is there simple way to run the interpreter to run a program ? [message #1807244 is a reply to message #1807243] |
Sat, 25 May 2019 13:24  |
Eclipse User |
|
|
|
The usual way to load a model I showed here
https://www.eclipse.org/forums/index.php/t/1098976/
With no specifics about the npe?
i cannot help!
Maybe there are injects in the interpreter and you should create it with the injector
you also may have a look at the prjects unit tests
/*******************************************************************************
* Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.xtext.tortoiseshell;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.util.StringInputStream;
import org.xtext.tortoiseshell.interpreter.TortoiseShellInterpeter;
import org.xtext.tortoiseshell.lib.Tortoise;
import com.google.inject.Injector;
/**
* @author dietrich - Initial contribution and API
*/
public class Main {
public static void main(String[] args) throws IOException {
Injector i = new TortoiseShellStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = i.getInstance(ResourceSet.class);
Resource r = rs.getResource(URI.createURI("file:/home/dietrich/Downloads/2019-03-RC1/wswm22/org.xtext.tortoiseshell.examples/src/org/xtext/tortoiseshell/example/Pentgram.tortoiseshell"), true);
r.load(null);
TortoiseShellInterpeter interpreter = i.getInstance(TortoiseShellInterpeter.class);
Tortoise tortoise = new Tortoise();
tortoise.addListener((e)->{
System.out.println(e);
});
EcoreUtil.resolveAll(r);
EObject program = r.getContents().get(0);
System.out.println(program);
interpreter.run(tortoise, program, -100);
System.out.println("done");
}
}
[Updated on: Sat, 25 May 2019 14:44] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03185 seconds