The project consists of 2 main components:
- Rascal2XML: Several rascal modules for exporting Rascal grammars and programs to XML
- XML2MPS: A MPS project for importing these XML files and transforing them into MPS languages or models
For how to set up Rascal: https://www.rascal-mpl.org/start/
Setting up Jetbrains MPS: https://www.jetbrains.com/mps/
The version used by the project is 2018.2
- Copy the full Rascal2MPS repository
- Import the Rascal2XML project into Eclipse set up for Rascal
Exporting a grammar:
- Open a rascal console
- Import Rascal2MPS
- Import the to be exported Grammar module
- Call treeToXML(#StartSyntaxNonTerminal, "filename")
This will create a XML version of the grammar called "filename".xml in src\XML output folder. The #StartSymbolNonTerminal refers to the name of the starting syntax construct in the Rascal Grammar. For example, if our grammar contains "start syntax Program", we call the function using #Program. This makes sure the reified tree is created with the correct root.
Exporting a Program:
- Open a rascal console
- Import Prog2XML
- Import the to be exported Grammar module
- Create a valid parse tree for the program using the Rascal parse() function (http://docs.rascal-mpl.org/unstable/Libraries/#ParseTree-parse) and save it.
- Call the parseTree2XML(parseTree, "filename") using the previously obtainted parse tree.
This will create a XML file named "filename".xml in the src\XML output folder.
The MPS project consists of three solutions:
- plugin contains the MPS plugin and provides menu buttons
- XML2MPS contains most of the MPS functionality for creating the MPS Languages and models.
- XMLImporterJAR is a stub for a JAR containing the XML parsing logic.
- Import the full project into MPS.
- Under XMLImporterJAR -> module properties -> Java, add Rascal2MPS/XMLImporter/XMLImporter.jar as a library (select the model roots as java_source_stubs).
- Under XMLImporterJAR -> module properties -> common, create a new model root to this same jar. Make sure the jar file is selected as a source (marked blue).
- The stub should now be set up, and you should see models under XMLImporterJAR -> stubs. If so, you can build the solution.
- Build the XML2MPS module.
- Build the plugin module.
Warning: Some debug pop-ups may appear during both program and grammar importing. These are safe to ignore and click through.
Importing a grammar:
- Select Tools -> import XML from the MPS toolbar.
- Create a new language using the dialog.
- Select the XML file to import.
- A new MPS language will be created using the given name using the constructs in the XML.
Importing a program:
- Import the program's source grammar as MPS language as described above
- (optional) create a new solution using Project -> new -> solution.
- Create a new model using solution -> new -> model.
- On the model creation menu, add your program's source MPS language as used language.
- Select the created model.
- Select Tools -> Import Program from the MPS toolbar.
- Select the XML file containing the program.
- If successful, this will add a new element to the selected model using the concepts of the source MPS language.