0

In my current work, I have written code generator using String Template without thinking about Parser ( I am instantiating Template files using direct Java Object). and code generator generator generates nice Java code.

Now, I have started to write Parser. B'coz of some nice editor features of xText, I am thinking to write parser in Xtext.

My question is "Is it possible to use code generator ( written using StringTemplate ) and Parse (written in Xtext) in same project?

user-517752
  • 1,188
  • 5
  • 21
  • 54

1 Answers1

2

Yes that's possible. Xtext offers a typed AST for the parsed files and you could easily pass them to your code generator (directly, iff they fulfil the same contract / interfaces, or indirectly by transforming them to the expected structure). Xtext does not impose any constraints on how you want to use the parsed information.

Sebastian Zarnekow
  • 6,609
  • 20
  • 23
  • Thanks Sebastian. "Xtext will offer" ---- does it mean that this features is not a part of current version of xText? – user-517752 Jun 05 '12 at 08:56
  • 1
    I improved the wording. The strongly typed AST is an Xtext feature from the very beginning and naturally part of the current version of the framework. – Sebastian Zarnekow Jun 05 '12 at 09:04
  • Thanks lot Sebastian for answer. could you pls provide a link, which talks about "Strongly Type AST"? your quick help would be appreciated. – user-517752 Jun 05 '12 at 10:00
  • 1
    Hi Pankesh, Xtext will read your input file and instantiate an in-memory-representation from that. This AST is not generic as in Antlr (where it's basically a tree of Nodes) but a rich semantic model (in the sense of Fowler's description in his book about Domain specific languages). You may want to read the reference documentation (http://www.eclipse.org/Xtext/documentation/2_1_0/020-grammar-language.php#metamodelInference) and learn some basics about the Eclipse modeling framework (EMF). – Sebastian Zarnekow Jun 05 '12 at 13:22