Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext DSL to Binary conversion(Xtext DSL to Binary conversion)
Xtext DSL to Binary conversion [message #1730488] Tue, 26 April 2016 09:46 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

Can anyone tell me is any way convert dsl to binary in the work flow of xtext project?
Re: Xtext DSL to Binary conversion [message #1730574 is a reply to message #1730488] Tue, 26 April 2016 18:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Sachin Samaram <forums-noreply@xxxxxxxx> wrote:
> Hi,
>
> Can anyone tell me is any way convert dsl to binary in the work flow of xtext project?
>

Hi can you be a bit more specific about your binary format. You can write
binary files in your IGenerator(2) trough the implementations of
filesystemaccess. Or is this about invoking a proprietary compiler, or ...


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext DSL to Binary conversion [message #1730806 is a reply to message #1730574] Thu, 28 April 2016 15:26 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I created xtext example project and able to write .mydsl files. I want to convert this .mydsl file to binary format file something like sample.bin using my own .exe file and place it some other folder of active mydsl editor project.

How can I do it?
Re: Xtext DSL to Binary conversion [message #1730811 is a reply to message #1730806] Thu, 28 April 2016 16:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
do you want to call this automatically (use the Generated MyDslGenerator or Register a own IXtextBuilderParticipant through the Extension Point org.eclipse.xtext.builder.participant xtext offeres) or manually then do it with std. means e.g. like https://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/

is both cases you have to care about invoking etc manually. the resources give you a uri which give you Access to where the file that is built is


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext DSL to Binary conversion [message #1730821 is a reply to message #1730811] Thu, 28 April 2016 17:51 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Wow!!! Great tutorial..

I got path of my editor as "platform:/resource/FirEditor/sample.fir" but how to use it with run with system commands as in Java applications as

String s = null;

try {
Process p = Runtime.getRuntime().exec("con2bin -b Sample.fir"); //This is a command I general use in cmd prompt to convert my .fir file to .bin
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}

System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}

Any idea? Can I write java type code in xtext because I am familiar with java coding.
Re: Xtext DSL to Binary conversion [message #1730825 is a reply to message #1730821] Thu, 28 April 2016 18:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
having org.eclipse.core.resources as dependency in manifest.mf (dirctly or indirectly)

IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resource.getURI().toPlatformString(true)));
System.err.println(file.getRawLocation())


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext DSL to Binary conversion [message #1730828 is a reply to message #1730821] Thu, 28 April 2016 18:56 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
platform:/resource refers to the root of your Eclipse workspace. The workspace is an abstraction over the file system. Not every file in the workspace must be backed by a real file. So there is no general way to turn a URI into a file path.

Nevertheless, for the usual case there is, and you can. See
https://www.eclipse.org/forums/index.php/t/127675/
how to convert a platform resource URI into an IFile, and then use IFile.getLocation to get the path to the file in the filesystem.



---
Get professional support from the Xtext committers at www.typefox.io
Re: Xtext DSL to Binary conversion [message #1730840 is a reply to message #1730828] Fri, 29 April 2016 06:41 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I got Null Pointer Exception when I use

val EclipseResourceFileSystemAccess2 ERFS2 = fileAccessProvider.get();

After some research I got a snippet as

val EclipseResourceFileSystemAccess2 ERFS2 = fileAccessProvider.get();
ERFS2 .monitor = new NullProgressMonitor
then the problem is solved.

I read this http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcore%2Fruntime%2FNullProgressMonitor.html

But I don't understand What is NullProgressMonitor? What it does in my case?
Re: Xtext DSL to Binary conversion [message #1730841 is a reply to message #1730825] Fri, 29 April 2016 07:03 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi Christian,

I am beginner of xtext recently I started learning. My simple question is

I have command prompt command

c:\>con2bin -b filename.fir

Here con2bin is a con2bin.exe file

If I run the above command filename.fir will be converted as required bin file.

So in my case I have written code in eclipse runtime editor with file name test.fir

Now I want to execute command as shown above to convert .fir file to .bin file and save in src-gen folder using xtext.

I am succeed in implementing https://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/

Here in this example we are putting .mydsl in src-gen folder as .txt file. Likewise I want to execute the command as like above and place the .bin file in src-gen folder
example: test.fir after executing it should be test.bin in src-gen folder.

Helping is appreciated.

Thanks in advance!!!
Re: Xtext DSL to Binary conversion [message #1730842 is a reply to message #1730841] Fri, 29 April 2016 07:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Sry you have to digg

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext DSL to Binary conversion [message #1730861 is a reply to message #1730842] Fri, 29 April 2016 11:19 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi Christian,

Could you please tell me how can I read .mydsl file line by line from resource?
Re: Xtext DSL to Binary conversion [message #1730862 is a reply to message #1730861] Fri, 29 April 2016 11:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Sachin Samaram <forums-noreply@xxxxxxxx> wrote:
> Hi Christian,
>
> Could you please tell me how can I read .mydsl file line by line from resource?
>

Hi this question is not xtext related

You can downcast resource to xtext resource and the call
getarseresult().getrootnode().getText to access the xtext but I do not
understand why one would want to read it line by line


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext DSL to Binary conversion [message #1730880 is a reply to message #1730862] Fri, 29 April 2016 13:12 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi Christian,

I am getting
My DSL file is : test.mydsl
Resource URI : platform:/resource/JPLEditor/sample.jpl
Resource URI Class : class org.eclipse.emf.common.util.URI$Hierarchical

My command is on cmd : con2bin -c test.mydsl

In java we can do this my locating the file by giving it's path but how can I use test.mydsl as above from runtime editor?
Re: Xtext DSL to Binary conversion [message #1730881 is a reply to message #1730880] Fri, 29 April 2016 13:19 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Jan and me both answered this question before

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:DSL editor without launching new Eclipse instance
Next Topic: Problem by reference in Xtext
Goto Forum:
  


Current Time: Tue Apr 16 21:55:07 GMT 2024

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

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

Back to the top