Recommendations for generating structured text files

Hallo,

let me take the calculator example. Once I've generated Java code I'm easily able to create spring and hibernate configuration files because they are XML - so I'm using the MPS XML language.

But lets say I want to generate some other structured text file like DB creation scripts or input code for another MDSD tool. Could look like this:

------

package com.example.calculators.mysalary

calculator MySalary {

     input fields: PHP Hours, Java Hours

     formula: PHP Hours * 5 + Java Hours * 10

}

-------

or

--------

create table log_executed_calculations

(

     id                     integer NOT NULL,

     php_hours      integer,

     java_hours      integer,

     result               integer

);

--------

The bold stuff is taken from a solution, the rest is syntactic for the to-be-generated-structured-file.

Now there are several possibilities to generate these files:

  • use MPS gtext
  • create a new root template
  • the sampleXML seems to choose a different way (TextGen aspect) which I didn't understand, but there is also structured text generated
  • maybe others

Which one would an experienced developer recommend? And why?

Best regards,

jens

4 comments
Comment actions Permalink

Hello, Jens,

It depends.

If this generator is the only place where you need to use the script lanugage in your project, I would recommend gtext. If you need to use it in several times, it might be a good idea to create a dedicated language for this and text generator for it. If you want to create a text generator, I recommend using gtext since textGen is lower level language and is harder to use than gtext.

Regards,

Konstantin

0
Comment actions Permalink

Hi Konstantin,

so you recommend using gtext anyway - as simple use-as-is inside the language or in a created dedicated language.

What is the cause of gtext being not complete (at least it seems so): e.g. if I'm using the content block I have to create my own template and reduction rule to simply copy the content block content. For lines there is the the reduce_GLine which does also simply copying (and newline).

Best regards,

jens

0
Comment actions Permalink

Jens,

Could you provide more information on why gtext is incomplete? reduce_GLine template is just an implementation detail. The same thing can be expressed with a textgen for the GLine concept.

It's complete in a sense that you can describe any text file with it. We have text generator for it, so if your languages generates to gtext it can be converted to text.

Regards,

Konstantin

0
Comment actions Permalink

Hi Konstantin,

Yes, I can generate every text file. Or at least the ones I tried. But as I used content blocks a generation failure occured and I had to create a simple copy-the-content-template myself. I assumed it would work that way out of the box and I only must adopt in special cases (like "copy the node but while doing so perform some strange transformations with it")


Or is that not the right way to loop over a block of text? I can't simply mark a number of lines and surround them with a loop macro. I assume the latter does not work because macros are only applicable on single nodes, not node collections (e.g. with a virtual parent node).

Best regards

jens

0

Please sign in to leave a comment.