Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » TortoiseShell - is there simple way to run the interpreter to run a program ?
TortoiseShell - is there simple way to run the interpreter to run a program ? [message #1807243] Sat, 25 May 2019 17:22 Go to next message
Andrea Bigi is currently offline Andrea BigiFriend
Messages: 2
Registered: May 2019
Junior Member
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 17:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13071
Registered: July 2009
Senior Member
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");
	}

}



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 25 May 2019 18:44]

Report message to a moderator

Previous Topic:Deployed xText IDE does not work
Next Topic:Xtext - how to extend XtextDocument class
Goto Forum:
  


Current Time: Thu Aug 22 19:47:45 GMT 2019

Powered by FUDForum. Page generated in 0.01796 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top