How to extend language with custom text gen

Here again. I want to have root language with my concepts and some languages extending root one.

Each sub-language has textGen aspect, but MPS throws exception "%concept_name% cannot be resolved or is not  a field"

4 comments
Comment actions Permalink

Imagine there's a root language with a concept, and two other languages that extend it, and provide textgen components for the same concept. If there's a model that utilize both these extending languages, how would you pick proper textgen component then?

The mechanism MPS uses to find a relevant component (here, textgen) for a concept is to take concepts language and to look for components in the language implementation. Therefore, it's not possible to define a textgen component for a concept that comes from a different language (even if the language you define component in extends the one with the concept).

0
Comment actions Permalink

So what should I do to implement system with 1 core languages and some languages that generate source code of (JS / Java / Other language )?

0
Comment actions Permalink

I'd go with a core-language without any textgen, and JS/Java/Other language modules with own set of concepts and respective textgen, and use generators to transform concepts of core-language into JS/Java/Other's as appropriate.

Anyway, it's unlikely that core-language could get easily translated into text of different languages. Usually, your core-language would address specific problem/domain and is not a general-purpose language as JS/Java. You'll need to reduce high-level abstractions of your core language into low-level concepts of a general-purpose language first, and only then produce text for them. Consider structure language in MPS, which is high-level language that captures notion of a Concept, Reference, Property. These get translated to Java classes, fields and methods to get executed. Indeed, one could imagine a text template that produces necessary Java files from e.g. ConceptDeclaration. There would be a huge gap between abstraction of ConceptDeclaration and the text, though. Besides, this approach doesn't scale up, and therefore TextGen aspect in MPS is quite limited (you can't write complex logic in there), and all the transformation complexity is in generators (in MOF terms, M2M is feature-rich, while M2T is almost straightforward serialization of an AST/model).

Once you have say JS with textgen, you can reduce (with generators/M2M transformations) more than just single core-language. You may come up with another core-language-2, translate it to JS-language without need to care about textual generation again and again.

2
Comment actions Permalink

Yep, I got the point about m2m, I'm just practicing and trying to understand concepts of mps. Anyway, thanks a lot!

0

Please sign in to leave a comment.