6

I am thinking to move to Jetbrains MPS, so i can edit my files with custom defined language more easily.

I have started to create the files a while ago and there are a lot of files already. Is there any way to convert those files automatically to my language in MPS, than just copy pasting parts of code?

1 Answers1

2

Sure: there are several ways. The first one is to define a custom persistence mechanism for MPS. It means that you will be able to open, edit and save the files in MPS keeping the current format. However if you do this you will lose some of the flexibility of MPS because when you will extend the language or combine your language with others you will have to revise the persistence mechanism. I suggest instead to simply parse your files, build an Abstract Syntax Tree and create corresponding nodes in MPS. Here there is a tutorial showing how to use an ANTLR parser to import files in MPS: http://tomassetti.me/antlr-and-jetbrains-mps-parsing-files-and-display-the-ast-usign-the-tree-notation/

Federico Tomassetti
  • 2,100
  • 1
  • 19
  • 26
  • I have another question, Is it possible to open a hyper link from MPS default text/html/xml editor – Sanjit Kumar Mishra May 22 '16 at 08:33
  • well, inside MPS you can basically write any Java code you want so, yes, if Java has a function to do that – Federico Tomassetti May 22 '16 at 08:35
  • I think i didn't put the question properly, for example I have a xml file(abc.xml) which contains Hyper Links and i open that xml file inside MPS, currently MPS editor for xml/html/txt doesn't handle displaying hyper link, so my question is, is it possible to enrich the mps text editor? – Sanjit Kumar Mishra May 22 '16 at 08:38
  • Yes, it is: you can define custom cell in MPS and write any sort of swing widget. You could also add keymaps or whatever you want to react to all sort of events. – Federico Tomassetti May 22 '16 at 08:39
  • Ok, but how i can link that to an file that is present externally in my hard drive? Example: I can create a java class and paste java code as class content or method content, but i can't just open a external java file in mps and start working with it. – Sanjit Kumar Mishra May 22 '16 at 08:44
  • I think this is another question :) – Federico Tomassetti May 22 '16 at 08:44