How to load a text file as a model inside a solution by using PlainText Sample?

I was reading some examples and I saw PlainText. It seems to me that the idea of the Model Manager is to load in a solution a new Model from a file. In the case of PlainText, I can load a txt file. I read the source code and I can understand how it works, however I cannot test such a feature because I don't know how to load the file. For instance:

I created a file:

echo "The content of my file" > /home/myuser/Desktop/lala.txt

What I want to have is a model inside the solution which conforms to the language PlainText. The content of such a model must be "The content of my file". I am want to SEE the loaded model in the GUI.

I added the directory /home/myuser/Desktop/ in the dialog "Solution Properties -> External code -> Libraries" and I picked PlainText as Manager, but MPS doesn't load the file, or I least I cannot see it in the GUI under the solution in the Logical View.

This is a veeery dumb question, but the GUI is not natural to me. Or maybe I am understanding everything in the wrong way. Am I?

BTW, I want to do something similar with a different DSL, but it is impossible to develop without testing.

Hi guest,
one important thing about MPS is this: everything has to be a valid AST (abstract syntax tree). So are the solutions. If you want to load a plain text file as solution, you have to transform the plain text into an AST. This step is known as 'parsing' or a combination of 'lexing' and 'parsing'. This is what all compilers as first step do. To write your own parser is often surprisingly simple as a DSL should be focused and simple. In your case it should be enough to read the file line by line and create an AST node for every line, adding it to the model. You may use swing to create a file chooser. If I find my plain text file parsing sample tomorrow I'll push it to github.

Best regards,

Please sign in to leave a comment.