Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom code generator #42

Open
magick93 opened this issue Jul 30, 2021 · 2 comments
Open

Custom code generator #42

magick93 opened this issue Jul 30, 2021 · 2 comments

Comments

@magick93
Copy link

Hello

Lemma looks like a really fascinating, and useful project! Really impressive!

I would be interested in new technology code generators, in particular for typescript.

Do you have any guides on how to do this?

Thanks and kind regards

@frademacher
Copy link
Collaborator

Dear @magick93,

Thank you very much for your kind words and your interest in LEMMA. In fact, we would love to have a code generator for Typescript in LEMMA :-)

Unfortunately, the description of custom code generator development is not part of LEMMA's documentation, yet. Therefore, I have prepared an example code generator that illustrates the steps to realize custom code generators for LEMMA. You can find the example generator in LEMMA's master branch at https://github.com/SeelabFhdo/lemma/tree/master/examples/model-processing. I have also added a README.md to summarize the steps for custom code generator development with LEMMA. In addition, the code of the generator has extensive comments about what is going on. Nonetheless, please feel free to ask any questions in this issue, which may occur on your way to a Typescript generator for LEMMA :-)

Below, I give a few more background information on how you may process LEMMA models, e.g., for the sake of code generation.

Model Processing Using LEMMA's Own Model Processing Framework (aka "The Preferred Way")

To facilitate model processing with LEMMA, we provide our own model processing framework that is compatible with the Eclipse Modeling Framework. Actually, the example code generator at https://github.com/SeelabFhdo/lemma/tree/master/examples/model-processing is based on this framework. In one of the upcoming LEMMA releases we will even tune the framework to be more flexible in terms of provided and processed models. For now, however, the framework is sufficient to process LEMMA models based on their intermediate representations (cf. the README.md of the example code generator for more information on this topic).

Model Processing Using Xtext

LEMMA's modeling languages are based on Xtext. Consequently, you could alternatively use Xtext's standalone parsing mechanism to parse LEMMA models and derive code from the obtained AST. You can find the Xtext-based source code of the relevant LEMMA modeling languages on GitHub:

However, a benefit of LEMMA's model processing framework is that it hides the complexity of model parsing from the user.

Model Processing Using XML Metadata Interchange (XMI)

As mentioned above, LEMMA comes with intermediate specifications for its modeling languages (cf. the README.md of the example code generator for more information on this topic). These specifications aim to facilitate model processing as they incorporate preprocessed information depending on language semantics, e.g., applying default values or resolved inheritance hierarchies (please see the links to the intermediate specifications at the end of the README.md of the example code generator). LEMMA can produce intermediate representations for its models from the Eclipse IDE (see the description at the end of the README.md of the example code generator) in the XMI format. Since XMI is an open standard, you could theoretically parse the XMI files by yourself and generate code form them. While this approach might have the charm to not require a Java environment (as LEMMA's model processing framework or the Xtext approach do), I would consider it more complex given the necessity to resolve cross-model references and/or having to deal with XML.

@frademacher
Copy link
Collaborator

Dear @magick93,

As mentioned in my last message, we now have a refactored, more flexible version of our model processing framework ready. However, compared to the code generator implementation example, which I linked in my last message (cf. https://github.com/SeelabFhdo/lemma/tree/master/examples/model-processing), the adoption of the new framework version requires some slight changes by code generator implementers (mainly related to renamed annotations and abstract methods). Therefore, I added a new code generator example to LEMMA's GitHub repository, which illustrates the usage of the refactored framework version and that you can use as a starting point for your Typescript generator :-) (cf. https://github.com/SeelabFhdo/lemma/tree/master/examples/model-processing-latest).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants