What do you do if you have some data that you want to import into MPS? There is no built-in importer in MPS, nor is there a ready-to-use framework, so it can be overwhelming for a beginning MPS language developer to piece together all the required knowledge of MPS subsystems.
That’s why I want to start a series of beginner-level posts to cover the process of writing an importer. I will assume you have experience programming in Java but are just starting with MPS.
Our domain is going to be text-based adventure games, also known as interactive fiction. We will use a very simple language for describing a very simple adventure game, and import game data from a JSON file into MPS. I am not going to cover the development of the language itself in this series and will only focus on the importing process.
I will be using the latest currently released version of MPS, 2021.2.3, and I will publish my code on GitHub as we go, so you can follow along. The linked repository already contains our simple language, a sandbox where I have manually created a few game locations, and a sample JSON input file with the map data. I will talk more about the language in the next post.
In the upcoming posts I am going to cover these topics:
- The basics. Using Google Gson from MPS to read a JSON file and using the MPS SModel API to create MPS nodes from the data.
- Invoking the importer. Various ways in which you can launch the import from within MPS.
- Supporting subsequent reimports. How to update the model when the input data changes.
- Error handling. Letting the user know if there was a problem with the input data.
The list of topics isn’t set in stone and I may come up with additional topics as we go. But if there’s an interesting aspect related to importers that you want me to cover, let me know. You can hit Reply if you are reading this as an email or email me directly at sergej@specificlanguages.com).