Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Need simple parser and text generator (based on EMF) - Xtext?
Need simple parser and text generator (based on EMF) - Xtext? [message #1069652] Tue, 16 July 2013 10:03 Go to next message
Kirsten M. Z. is currently offline Kirsten M. Z.Friend
Messages: 132
Registered: July 2010
Senior Member
Hi @all,

I don't know yet, if Xtext is really what I need. I worked with some examples and browsed generated code, but I doubt that the complexity and output of Xtext is what I need. So please let me ask, if I can/should use Xtext or another tool within the eclipse world.

In several projects I have the following problem:

I have data based on EMF objects. Lists of such objects must be converted to (complex) strings. And, the strings must be converted back again. So basically I need some kind of string serialization/deserialization. However, the strings are tied to specified formats (far away from XML).

For example:

class EMF_class
{
a: String;
b: String;
c: String;
}

I have a list of three such objects (1,2,3), so the string should look like:

1.a[1.b] = "1.c", 2.a[2.b] = "2.c", 3.a[3.b] = "3.c"

However, this is just an example. Some rules of our string specifications are really complex. In past, I worked with JavaCC for specifying a parser. However, integrating with EMF and serialization is always additional work (overhead). Therefore, I thought working with "modern" tools like Xtext would be meaningful. However, I am not happy with the (default) output of Xtext. I expected to get a (simple) "parse" Method which generates my EMF ojects and another method vice versa. In addition, I don't want to get any further dependencies (Xtext libraries, Xtend, UI generation etc). Just simple methods like parser generators generated in the past decades.

Is this possible with Xtext? Can you recommend another way?

Thanks in advance!

[Updated on: Tue, 16 July 2013 10:03]

Report message to a moderator

Re: Need simple parser and text generator (based on EMF) - Xtext? [message #1070132 is a reply to message #1069652] Wed, 17 July 2013 09:41 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
Registered: December 2012
Location: Belfast
Member
I used to work with JavaCC and now use Xtext, and would say that JavaCC is good when you want to run a stand alone compiler that will do a single pass parse and trigger actions as you go, a bit like the SAX approach to XML. Whereas Xtext is best when you want an editor and need a model/AST so you can refer back to earlier lines, which is like the DOM approach to XML. It also separates validation from compilation which is very useful.

If it's the complexity of the language that is the main issue then I would say that if you can't do it in Xtext I wouldn't hold out much hope that JavaCC would do it either (although I'm not an expert on the finer points of left-recursion etc).

As for the output you have full control over it and can generate any output of your choice (text, csv, html) in the same way as JavaCC. It doesn't have to be Java unless you code it to be Java.
Re: Need simple parser and text generator (based on EMF) - Xtext? [message #1070174 is a reply to message #1070132] Wed, 17 July 2013 11:44 Go to previous messageGo to next message
Kirsten M. Z. is currently offline Kirsten M. Z.Friend
Messages: 132
Registered: July 2010
Senior Member
Thanks for sharing your experience.

No, it is not the complexity of the language. I think Xtext is designed very carefully and has a great syntax. I am thinking about the overhead when using Xtext: library dependencies, creation of additional projects, MWE, bunch of generated/non generated files etc.

In my world it should be as simple as this:

specification file ---- generate ----> one or multiple Java files

Inside the generated file(s) there should be two public methods:
- From EMF objects to language string
- From language string to EMF objects

BTW: By using JJTree (JavaCC) you can generate an AST easily. But this is not EMF, JJTree is even harder to learn (compared to modern stuff like Xtext) and still the other way around must be coded by hand.

I'm wondering if there is no project which makes such tasks feasible.

[Updated on: Wed, 17 July 2013 11:46]

Report message to a moderator

Re: Need simple parser and text generator (based on EMF) - Xtext? [message #1070281 is a reply to message #1070174] Wed, 17 July 2013 16:13 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-17-07 13:44, Kirsten M. Z. wrote:
> Thanks for sharing your experience.
>
> No, it is not the complexity of the language. I think Xtext is designed
> very carefully and has a great syntax. I am thinking about the overhead
> when using Xtext: library dependencies, creating of additional projects,
> MWE, bunch of generated/non generated files etc.
>
> In my world it should be as simple as this:
>
> specification file ---- generate ----> one or multiple Java files
>
> Inside the generated file(s) there should be two public methods:
> - From EMF objects to language string
> - From language string to EMF objects
>
> BTW: By using JJTree (JavaCC) you can generate an AST easily. But this
> is not EMF, JJTree is still hard (compared to modern stuff like Xtext)
> and still the other way around must be coded by hand.
>
> I'm wondering if there is no project which makes such tasks feasible.

Xtext is the closest thing there is (that I know of) to do what you are
asking for. Although you do not get the two methods you would like to
see, you can easily create those two; at some point you do have to tell
the framework how you want it to work anyway.

I have been using a combination of Racc and RGen (EMF for Ruby) for some
time; don't know if that qualifies as having "lower overhead". In any
case, this setup requires a lot more manual work compared to Xtext.

Regards
- henrik
Previous Topic:Xtext: Referencing by the "Fully Qualified Name"
Next Topic:Content assist for Identifier
Goto Forum:
  


Current Time: Thu Apr 25 03:35:11 GMT 2024

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

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

Back to the top