MPSGrammar... API or templates?

Hi,
I could not resist to experiment with grammar to MPS concept translation.
So I wrote a trivial grammar (an ANTLR one very similar to ANTLR itself), I made some test with Actions and Tools, I created some concepts through "new node<ConceptDeclaration>" and enum declaration into an existing empty language.
It's a trivial one but I want first to focus on the overall engine.

Then I imagine another strategy: write a language to allocate the import of the grammar file, than from this model generate ConceptDeclaration, editors ecc of another language using generator/templates.
I think this way is more powerfull and it will result in a clearer implementation.
The drawback will be that one could not "refresh" an existing language using an updated grammar.
Whereas, in theory, I can update an existing language through API during import apply only differences with respect to the existing concepts.

Can this second way possibly works?
If yes, how can be persisted (into a real language) the transient objects (ConceptDeclaration, ConceptEditorDeclaratio, ecc) created by the generator? Thx, Mar
11 comments
Update: the generator/templates way probably it's not feasible for other reasons: I created a Concept template than I create a MACRO into the template concept inspector and... where is the inspector of the inspector's MACRO? :-)

Maybe a mix of API + quotations/antiquotation is the best solution.
0
You can access the inspector using the keystroke associated with it. Place the cursor on the macro in the inspector and invoke cmd/ctrl-I. This should navigate the inspector to the content of the macro.
0
I like the second strategy. I think importing ANTRL directly into an MPS ANTRL language would make sense because there are many languages defined in this format already (e.g., you can find a C# ANTLR grammar here, somebody was recently asking for an MPS C# language: https://antlrcsharp.codeplex.com/).

You could use the ANTRL parser with custom persistence. Then I would try to build a language that refers to parts of the ANTRL AST, and customizes how that ANTRL grammar maps to the target MPS language. If you keep the two parts separate, i.e., the original ANTLR grammar and the customizations to map to a language, then I think it will be possible to evolve the grammar, and or the mapping, and regenerate the language periodically. I am not sure exactly how to handle modifications to the mapping, but I would think it should be possible to reuse the refactoring support built into MPS. For instance, if you could preserve the concept IDs when you regenerate, renaming of target concepts would be handled by the platform, I think.

This may need input from the MPS team, but I think support for something like this could really open up the MPS platform to a large number of people. I know my group would immediately start using such a tool to build an R language in MPS for our MetaR project. I see people looking for C# support, etc.
0
We've experimented with this approach as well, to help with the development of an R language for MetaR. You can find the result here: https://github.com/campagnelaboratory/ANTRL_MPS (also submitted as a plugin to the Jetbrains repo).
Unfortunately, there is no documentation at this stage, but it works sufficiently well to be useful. An example of application can be found in the MetaR project, in version 1.4, which should be pushed to GitHub tomorrow.

There are two parts to it: one is an MPS ANTLR language that represents a subset of ANTLR 1.4. You can paste a grammar into the MPS root node and the rules will be imported, similar to pasting Java class content into a BaseLanguage class root node.
The second part is a converter root node, which you can use to develop a visitor. The converter knows about the grammar and can be used to develop concepts in the new language to represent the output of the grammar. The visitor will convert an ANTLR parse tree, produced from an ANTLR parser compiled from the grammar to nodes of the output language. There is also support for generating editors and TextGen for the language (skeleton are generated which will need manual review and corrections, but it is a start and better than nothing), but unfortunately we did not spend much time developing tools to also generate actions and substitution rules (perhaps this is something you could contribute given your experience with your project and if you thought it made sense to combine forces).
0
That's super interesting! I can't wait until to try it out.
On the same subject I spent quite a lot of time... without great results.

What does it means "great results"? Well I also wrote a languge to write grammars than experiment how to create concept using the MPS API. Than I feel I need something like EMOF inside MPS.
But here I get 2 stops: the first is that the MOF/EMOF specification from OMG are not the kind of documents one expects to read after dinner, the second my company asked for some hours more of work due to staff turn over.

And I did not publish anything just because it's not a whole work it's instead a lot a small works.
0
Hi Fabien,very interesting I will spare some time to test it.You are a master!Hope to write to you some feedback soon.Mar



 



     On Thursday, June 11, 2015 4:40 AM, Fabien Campagne - Meta Programming System <jetforum@jetbrains.com> wrote:
   

Meta Programming System>MPSGrammar... API or templates?[API+generator+grammar]4:39Fabien CampagneWe've experimented with this approach as well, to help with the development of an R language for MetaR. You can find the result here: https://github.com/campagnelaboratory/ANTRL_MPS (also submitted as a plugin to the Jetbrains repo).
Unfortunately, there is no documentation at this stage, but it works sufficiently well to be useful. An example of application can be found in the MetaR project, in version 1.4, which should be pushed to GitHub tomorrow.

There are two parts to it: one is an MPS ANTLR language that represents a subset of ANTLR 1.4. You can paste a grammar into the MPS root node and the rules will be imported, similar to pasting Java class content into a BaseLanguage class root node.
The second part is a converter root node, which you can use to develop a visitor. The converter knows about the grammar and can be used to develop concepts in the new language to represent the output of the grammar. The visitor will convert an ANTLR parse tree, produced from an ANTLR parser compiled from the grammar to nodes of the output language. There is also support for generating editors and TextGen for the language (skeleton are generated which will need manual review and corrections, but it is a start and better than nothing), but unfortunately we did not spend much time developing tools to also generate actions and substitution rules (perhaps this is something you could contribute given your experience with your project and if you thought it made sense to combine forces).
Fabien Campagne@20 MarI like the second strategy. I think importing ANTRL directly into an MPS ANTRL language would make sense because there are many languages defined in this format already (e.g., you can find a C# ANTLR grammar here, somebody was recently asking for an MPS C# language: https://antlrcsharp.codeplex.com/).

You could use the ANTRL parser with custom persistence. Then I would try to build a language that refers to parts of the ANTRL AST, and customizes how that ANTRL grammar maps to the target MPS language. If you keep the two parts separate, i.e., the original ANTLR grammar and the customizations to map to a language, then I think it will be possible to evolve the grammar, and or the mapping, and regenerate the language periodically. I am not sure exactly how to handle modifications to the mapping, but I would think it should be possible to reuse the refactoring support built into MPS. For instance, if you could preserve the concept IDs when you regenerate, renaming of target concepts would be handled by the platform, I think.

This may need input from the MPS team, but I think support for something like this could really open up the MPS platform to a large number of people. I know my group would immediately start using such a tool to build an R language in MPS for our MetaR project. I see people looking for C# support, etc.
JetBrains Forum|Build #182(Apr/23/2015 5:01PM)|Feedback
0
Let me know if you need some pointers. I don't have time to write some detailed doc (a lot to write for our MetaR project), but if there is interest I could sketch some suggested steps for using it for new language.

If you're interested in the design steps, take a look at the commit log. I try to address one goal at a time, starting with something small as long as it will take me closer to what I am trying to build. I don't mind refactoring sub-optimal designs later (and very frequently do). If the previous step helped me understand the problem domain better, that design was useful and I don't have any problem reorganizing it when needed to take the next step.

It would be great if you were interested in contributing pieces for generation of  actions and side-transforms.
0
Hi Fabien,
I downloaded and try to understannd your project.
Can you shortly describe the languages and solutions that the project contains?
I'm trying to figure out the order in which they are used and responsabilities of each language/solution.

Together with the git log I will try to understand the project.

Mar
0
It seems the document has a restricted access.
0

Please sign in to leave a comment.