<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Antoine Gagnon</title>
    <description>The latest articles on DEV Community by Antoine Gagnon (@antoine).</description>
    <link>https://dev.to/antoine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F5090%2F5faf1215-951a-4c1b-bd62-b11e384bf259.jpeg</url>
      <title>DEV Community: Antoine Gagnon</title>
      <link>https://dev.to/antoine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/antoine"/>
    <language>en</language>
    <item>
      <title>Create Code screenshots straight from your IDE</title>
      <dc:creator>Antoine Gagnon</dc:creator>
      <pubDate>Wed, 03 Mar 2021 03:11:03 +0000</pubDate>
      <link>https://dev.to/antoine/create-code-screenshots-straight-from-your-ide-38ke</link>
      <guid>https://dev.to/antoine/create-code-screenshots-straight-from-your-ide-38ke</guid>
      <description>&lt;h1&gt;
  
  
  What are you talking about?
&lt;/h1&gt;

&lt;p&gt;You've seen them, sometimes on Twitter, sometimes on Medium post. They look something like this:&lt;/p&gt;

&lt;p&gt;
   &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf4snms5h4iz5hywfy16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf4snms5h4iz5hywfy16.png"&gt;&lt;/a&gt;
&lt;/p&gt; 
 

&lt;p&gt;They're usually made with a website called &lt;a href="https://carbon.now.sh/" rel="noopener noreferrer"&gt;Carbon&lt;/a&gt; which is really good looking, with a ton of design options, but it forces you to go to a different website, save, open the image again in your browser... what if you want to do things fast without going back and forth between Carbon, then your article, then your IDE every time? &lt;/p&gt;

&lt;p&gt;Well, you can generate them in your IDE directly with Silicon!&lt;/p&gt;

&lt;h1&gt;
  
  
  How to install Silicon
&lt;/h1&gt;

&lt;p&gt;Silicon is a command-line tool to generate images from files, clipboard content, stdin input.&lt;/p&gt;

&lt;p&gt;You can follow directions &lt;a href="https://github.com/Aloxaf/silicon#install" rel="noopener noreferrer"&gt;here&lt;/a&gt; on how to install it on your system.&lt;/p&gt;

&lt;p&gt;You can look at all the different configuration options for theming, to change the font, remove line numbers, controls, there's quite a lot of customization possible. &lt;/p&gt;

&lt;p&gt;For now, we'll use the bare minimum and use a command that takes input from &lt;strong&gt;stdin&lt;/strong&gt; and pushes the final image to the clipboard. &lt;br&gt;
In my case, I am using Kotlin as my language, but of course, you'll have to change that to the language you want to use.&lt;/p&gt;

&lt;p&gt;In my case the command will look like this: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nba75stwyks0z1y1411.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nba75stwyks0z1y1411.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will &lt;code&gt;echo&lt;/code&gt; the code I want inside of my image, then pipe it to the &lt;code&gt;silicon&lt;/code&gt; command to be formatted in Kotlin and put inside the clipboard.&lt;/p&gt;
&lt;h1&gt;
  
  
  Set it up in your IDE
&lt;/h1&gt;

&lt;p&gt;Now that we're able to create an image from code written straight inside the command line, let's integrate that with our IDE&lt;/p&gt;
&lt;h2&gt;
  
  
  Jetbrains IDE
&lt;/h2&gt;

&lt;p&gt;I am mostly using this tool inside of Android Studio, but it will be able to work in pretty much any of Jetbrain's tools.&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting up the external tools
&lt;/h3&gt;

&lt;p&gt;Let's get started by going to &lt;code&gt;Preferences → Tools → External Tools&lt;/code&gt; then let's add a new external tool to our setup.&lt;/p&gt;

&lt;p&gt;Adding the command directly won't work with Android Studio as there are some issues with using the &lt;code&gt;|&lt;/code&gt; pipe in external tools directly. To bypass it we'll configure our tool using &lt;code&gt;bash -c&lt;/code&gt; to read a bash command from a string. &lt;/p&gt;

&lt;p&gt;This is a simple workaround that will fix this issue.&lt;br&gt;
So we put &lt;code&gt;bash&lt;/code&gt; as our program, and the arguments will contain&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-c "echo '$SelectedText$ ' | silicon -l kt -c "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we're using the macro &lt;code&gt;$SelectedText$&lt;/code&gt; to fetch the text selected inside Android Studio and use it as part of our command.&lt;/p&gt;

&lt;p&gt;In the end, the command window should look something like that: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswd5ybrru0lnoj1q1k9l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fswd5ybrru0lnoj1q1k9l.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, whenever you have text selected inside Android Studio you can go to &lt;code&gt;Tools → External Tools → Code to Image&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But that's slow! Way too slow! So let's create a shortcut for it&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup the shortcut
&lt;/h3&gt;

&lt;p&gt;Let's open our preferences again by going to &lt;code&gt;Preferences → Keymap&lt;/code&gt; then we can expand the External Tools section to find our custom tool.&lt;/p&gt;

&lt;p&gt;Now we can right-click, &lt;code&gt;Add keyboard shortcut&lt;/code&gt; and assign the one we want. In my case I chose ⌘ + I for "Image" (but mostly because that's the first letter that available)&lt;/p&gt;

&lt;p&gt;Now you can simply select your code, press your shortcut and your image is ready to be pasted anywhere you want! &lt;/p&gt;

&lt;p&gt;I hope you enjoyed this! If you find ways to add it in your favorite IDE, feel free to send them my way and I'll add them to the article.&lt;/p&gt;

</description>
      <category>android</category>
      <category>jetbrains</category>
      <category>carbon</category>
      <category>ide</category>
    </item>
    <item>
      <title>Creating a simple language using JetBrains MPS</title>
      <dc:creator>Antoine Gagnon</dc:creator>
      <pubDate>Fri, 15 Dec 2017 18:21:23 +0000</pubDate>
      <link>https://dev.to/antoine/creating-a-simple-language-using-jetbrains-mps-c7d</link>
      <guid>https://dev.to/antoine/creating-a-simple-language-using-jetbrains-mps-c7d</guid>
      <description>&lt;h1&gt;
  
  
  Presentation of the project
&lt;/h1&gt;

&lt;p&gt;The objective of this project is to construct a language to define mindmaps. These mindmaps have multiple levels of topics and also include a potential marker for each topic. The mindmap file will be able to generate a LaTeXfile that will have section and subsections defined according to the mindmap’s topics. The UML diagram we will follow is this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7swic009jrwmghnxs6ua.png" class="article-body-image-wrapper"&gt;&lt;img alt="UML Diagram" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7swic009jrwmghnxs6ua.png"&gt;&lt;/a&gt;&lt;br&gt;
This tutorial is geared toward programmers with some experience using object-oriented languages and more specifically Java-like languages.&lt;/p&gt;

&lt;p&gt;The tutorial can be used in conjunction with this &lt;a href="https://github.com/AntoineGagnon/MindMapMPS" rel="noopener noreferrer"&gt;git repository&lt;/a&gt; to follow each step with each commit.&lt;/p&gt;

&lt;h1&gt;
  
  
  Initial setup
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;To install the program, the best way to make sure we have the latest stable version is to head on to the official &lt;a href="https://www.jetbrains.com/mps/download" rel="noopener noreferrer"&gt;download page&lt;/a&gt; and download the version for our operating system. MPS is available on Windows, Mac and most flavors of Linux.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the project
&lt;/h2&gt;

&lt;p&gt;After launching MPS choose the theme and shortcuts we want to use for our editor and click “Create new project”. In this article, we used the default IntelliJ theme and default shortcuts.&lt;/p&gt;

&lt;p&gt;As we can see on the left side of the project creation window, we can either create a new language with the &lt;strong&gt;Language project&lt;/strong&gt;, create a solution to use a DSL created with MPS with &lt;strong&gt;Solution project&lt;/strong&gt; or create an empty project and build everything from scratch.&lt;/p&gt;

&lt;p&gt;We will be creating a new language so click on &lt;strong&gt;Language project&lt;/strong&gt;, chose a name for our project and a name for our language and make sure we click the &lt;strong&gt;Create Sandbox Solution&lt;/strong&gt; check-box to be able to test our language along the way. Our menu should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg7474lkdmozsnbwkbhj4.png" class="article-body-image-wrapper"&gt;&lt;img alt="Project creation menu" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg7474lkdmozsnbwkbhj4.png"&gt;&lt;/a&gt;&lt;br&gt;
Now we simply have to click OK to create our project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Navigating the logical view
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxdamt8aigpc6e6yz1ih3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxdamt8aigpc6e6yz1ih3.png" alt="Logical view"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see the logical view splits the sandbox where the language testing is done and the language module, here simply called &lt;strong&gt;Mindmap&lt;/strong&gt; and identified by the L icon before its name. We will mostly focus on the language part, pay attention to the different aspects that are defined like &lt;strong&gt;structure, editor, constraints…etc&lt;/strong&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Language creation
&lt;/h1&gt;

&lt;p&gt;We will now focus on language creation. We will edit the language module, and test the effects on the language using the sandbox provided by MPS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sandbox use
&lt;/h2&gt;

&lt;p&gt;To be able to use the language in the sandbox, we need to make sure we rebuild the language after changes by right-clicking the language module and clicking &lt;strong&gt;Rebuild Language MindMap&lt;/strong&gt;. After our first concept is created we will be able to create a new mindmap file by right-clicking on the &lt;strong&gt;sandbox&lt;/strong&gt; model inside the &lt;strong&gt;MindMap.sandbox&lt;/strong&gt; module and choosing &lt;strong&gt;Newmindmap&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structure
&lt;/h2&gt;

&lt;p&gt;The structure of our language is the definition of properties and relations between concepts of our language. We will first start by creating a new concept by right-clicking on the &lt;strong&gt;structure&lt;/strong&gt; aspect and selecting &lt;strong&gt;NewConcept&lt;/strong&gt; thus creating an empty concept.&lt;/p&gt;

&lt;p&gt;We will first create our root concept of a mindmap. As we can see if we open the concept file, the editing process is very different, this is because MPS is a projectional editor that directly edits the abstract syntax tree (AST) of our program. The main difference is that MPS won’t let us write anywhere we want and will guide us to fill the blanks in our file with elements that comply with its syntax.&lt;/p&gt;

&lt;p&gt;Let’s change the name of our concept to &lt;em&gt;Mindmap&lt;/em&gt; by editing the empty field, then change the &lt;strong&gt;instance can be root&lt;/strong&gt; property to &lt;em&gt;true&lt;/em&gt;. Our mindmap concept is now at the top of our abstract syntax tree and we can build elements from there.&lt;/p&gt;

&lt;p&gt;Let’s add a name property to our mindmap by implem enting the &lt;em&gt;INamedConcept&lt;/em&gt; interface, we can also use the Ctrl + Space shortcut to autocomplete the name and get a suggestion of different concept we can use. This interface that we can navigate to using Ctrl + B has a &lt;strong&gt;name : string&lt;/strong&gt; property that will be implemented and also adds some functions and refactoring options to the property.&lt;/p&gt;

&lt;p&gt;We can add an alias that will be used by default in the editor to define our concept and also a short description that will be shown in the tooltip when using the auto-completion and in other menus when trying to use the &lt;strong&gt;Mindmap&lt;/strong&gt; concept.&lt;/p&gt;

&lt;p&gt;Now we need to add topics to our mindmap, we will create a new &lt;strong&gt;Topic&lt;/strong&gt; concept that all other types of topics will derive from. Once our concept is created, we give it its name and also use the Alt + Enter shortcut in the same field to access the class actions where we click the &lt;strong&gt;Make abstract&lt;/strong&gt; option. Let’s also have this Topic implement the &lt;strong&gt;INamedConcept&lt;/strong&gt; interface since we also need a name for our topics.&lt;/p&gt;

&lt;p&gt;We also planned on being able to add a marker to our topics, so let’s create a new concept called &lt;strong&gt;Marker&lt;/strong&gt; that simply implements the &lt;strong&gt;INamedConcept&lt;/strong&gt; interface and has an alias and a description.&lt;br&gt;
Now we can come back to our &lt;strong&gt;Topic&lt;/strong&gt; concept and add a marker reference. To do so we start by typing the name of the property, here &lt;em&gt;marker&lt;/em&gt;, then press to get to the next field and add the &lt;em&gt;Marker&lt;/em&gt; class. We will leave the multiplicity at &lt;em&gt;[0..1]&lt;/em&gt; since our topics can only have zero or one marker. We will also add a &lt;em&gt;markers&lt;/em&gt; child to the &lt;strong&gt;Mindmap&lt;/strong&gt; concept with a &lt;em&gt;[0..n]&lt;/em&gt; multiplicity as we can define&lt;br&gt;
multiple markers that will be referenced by our topics later on.&lt;/p&gt;

&lt;p&gt;Now we are able to create topics that aren’t abstract and will be used in the mindmap. By following the UML diagram, we create a new concept called &lt;em&gt;CentralTopic&lt;/em&gt; that will extends the &lt;em&gt;Topic&lt;/em&gt; class instead of &lt;em&gt;BaseConcept&lt;/em&gt;, we give it an alias and a short description.&lt;br&gt;
We can then come back to our mindmap and add a child of the &lt;strong&gt;CentralTopic&lt;/strong&gt; class that we will simply call &lt;em&gt;centralTopic&lt;/em&gt; and that will have a &lt;em&gt;[0..1]&lt;/em&gt; multiplicity.&lt;br&gt;
By following the same pattern as for &lt;strong&gt;CentralTopic&lt;/strong&gt; we will create a &lt;em&gt;MainTopic&lt;/em&gt; concept and add it as a child of &lt;strong&gt;CentralTopic&lt;/strong&gt; with a &lt;em&gt;[0..n]&lt;/em&gt; multiplicity, as a central topic can have multiple main topics. We will also do the same with a &lt;em&gt;SubTopic&lt;/em&gt; concept that is a child with &lt;em&gt;[0..n]&lt;/em&gt; multiplicity of &lt;strong&gt;MainTopic&lt;/strong&gt; but with a twist on its children as they are also of the &lt;strong&gt;SubTopic&lt;/strong&gt; type and are called &lt;em&gt;subSubTopics&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We now have a functional mindmap language that we can test in the sandbox. Although the syntax is rough and sometimes confusing, it lets us create topics at different levels, assign them markers created in the mindmap and give them names. We can also use the node explorer function by pressing Alt + X to watch the different elements composing our mindmap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Behavior
&lt;/h2&gt;

&lt;p&gt;Behavior in MPS are mostly similar to methods and define functions for a concept. They also offer the possibility to modify the constructor, although the constructor function isn’t able to access the model as it is called before the node is linked to the tree.&lt;/p&gt;

&lt;p&gt;In our project we will add an &lt;strong&gt;equals&lt;/strong&gt; function to our &lt;strong&gt;Marker&lt;/strong&gt; concept and a function to analyze the names of the marker in a mindmap and pick the highest one out of the markers using numbers as their names. This will be used to gradually increment the marker’s names when they are created.&lt;/p&gt;

&lt;p&gt;To create a new behavior for our &lt;strong&gt;Marker&lt;/strong&gt; concept, we go to its editor page and access the &lt;strong&gt;Behavior&lt;/strong&gt; tab at the bottom of the editor, then we click &lt;strong&gt;Click to create new aspect&lt;/strong&gt; and chose &lt;strong&gt;Concept Behavior&lt;/strong&gt;. In the new aspect we just created, we can see we have access to the constructor, but here we will create a new method by clicking on &lt;strong&gt;concept methods&lt;/strong&gt; and pressing . Our function will have a &lt;em&gt;boolean&lt;/em&gt; type and will be called &lt;em&gt;equals&lt;/em&gt;, it will also take a &lt;em&gt;node&amp;lt;Marker&amp;gt; otherMarker&lt;/em&gt; as parameters. The body of the function will simply test if the two marker’s names are the same as shown here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88lcg6twruhrfq72jwjn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88lcg6twruhrfq72jwjn.png" alt="Marker's behavior"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will now do the same behavior creation process for the &lt;strong&gt;Mindmap&lt;/strong&gt; concept where we will create a function that will return an &lt;em&gt;integer&lt;/em&gt; and will be called &lt;em&gt;getHighestMarkerNumber&lt;/em&gt; but won’t have any parameter as it will analyze the calling node itself.&lt;/p&gt;

&lt;p&gt;This method will go through all the children markers and try to parse their name as integers, if the name isn’t a number, the exception is caught and discarded while printing on the error pipe that it wasn’t parsed. If it is indeed a number, we compare the value with our max value variable created at the beginning and update our base value with the new one if it is bigger. We finally return the maximum value at the end of the function juste like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0t5ldgndacxwpp4fa71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0t5ldgndacxwpp4fa71.png" alt="Mindmap behavior"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Constraints
&lt;/h2&gt;

&lt;p&gt;Constraints are rules that define the way our nodes interact with each other and the properties they can have.&lt;/p&gt;

&lt;p&gt;In our project, we will implement a constraint that says that two markers defined in the mindmap can’t have the same name. To do so we go in the &lt;strong&gt;Marker&lt;/strong&gt; concept and access the &lt;strong&gt;Constraints&lt;/strong&gt; tab at the bottom of the editor, we can then click &lt;strong&gt;Click to create new aspect&lt;/strong&gt; and choose &lt;strong&gt;Concept Constraints&lt;/strong&gt;. We will edit the &lt;strong&gt;can be child&lt;/strong&gt; function, this function returns either true or false according to the rules defined inside. We can access the model from this function, and we have access to specific functions to help us in this regard. We will access all the marker’s &lt;em&gt;siblings&lt;/em&gt; and loop over them with a &lt;em&gt;for loop&lt;/em&gt; checking if the current node &lt;em&gt;node&lt;/em&gt; and the sibling node &lt;em&gt;n&lt;/em&gt; are the same using the &lt;strong&gt;equals&lt;/strong&gt; behavior defined earlier and returning the value. The end code should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjqdfki6f08h1znh2dqb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjqdfki6f08h1znh2dqb.png" alt="Marker constraints function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we now try to create two markers with the same name, we will get an error saying these markers can’t be children of the mindmap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Editor and actions
&lt;/h2&gt;

&lt;p&gt;The editor is here to define the projection of the AST, it can be textual, visual, include a lot of different layouts and rules on what concrete syntax to use. In our case, we will focus on a simplistic indented textual syntax that is similar to the default one.&lt;/p&gt;

&lt;p&gt;Similarly to the previous concepts we’re going to add a &lt;strong&gt;Concept Editor&lt;/strong&gt; aspect to our &lt;strong&gt;Mindmap&lt;/strong&gt; concept. For the cell layout we are going to use a &lt;strong&gt;collection (indent)&lt;/strong&gt; layout that is triggered by the &lt;strong&gt;[-&lt;/strong&gt; keyword, or can be found using the Ctrl + Space shortcut. This layout allows us to add new lines for children nodes while increasing indentation.&lt;/p&gt;

&lt;p&gt;Inside of our layout we can add the &lt;em&gt;mindmap&lt;/em&gt; keyword followed by the &lt;em&gt;{name}&lt;/em&gt; property that can be found using the Ctrl + Space shortcut again. We’ll now add the &lt;em&gt;with&lt;/em&gt; keyword followed by the &lt;em&gt;%markers%&lt;/em&gt; children and finally we can add the &lt;em&gt;about&lt;/em&gt; keyword and the child &lt;em&gt;%centralTopic%&lt;/em&gt; getting this line:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdxxusxyyoqs0od0e76i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdxxusxyyoqs0od0e76i.png" alt="Mindmap concrete syntax"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;CentralTopic&lt;/strong&gt; concept editor and the other topics are built in the following fashion while the marker editor isn’t modified. This concept editor will also use the indented layout, starting on the first line with the &lt;em&gt;{name}&lt;/em&gt; property of the topic, with the &lt;em&gt;with&lt;/em&gt; keyword and the &lt;em&gt;%marker%&lt;/em&gt; reference, where the editor is asking us for a cell model, this is the way the markers will be displayed and we will choose to use the &lt;em&gt;{name}&lt;/em&gt; property. This whole line will be followed by a left bracket before using the Alt + Enter shortcut to add a new line, then pressing to get on the new line before reusing the shortcut to add an indent. Now that we are on a new indented line, we can add the &lt;em&gt;%mainTopics%&lt;/em&gt; children, add a new line again, press and finally add a right bracket and a new line to end our &lt;strong&gt;CentralTopic&lt;/strong&gt; concrete syntax. The other topics are built the exact same way, only with different children, for instance, the &lt;strong&gt;SubTopic&lt;/strong&gt; concept editor is built just like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8qxxcxl0fg8raiwjyae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8qxxcxl0fg8raiwjyae.png" alt="SubTopic editor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also use the Alt + 2 command on part of the editor to modify an elements properties, such as its background color by editing the &lt;strong&gt;no base style&lt;/strong&gt; part and adding a &lt;em&gt;text-background-color&lt;/em&gt; property. We did it on the name element of our &lt;strong&gt;MainTopic&lt;/strong&gt; using the &lt;em&gt;# B3FFCF&lt;/em&gt; color and also on our &lt;strong&gt;SubTopic&lt;/strong&gt; by using a small function that checks if the parent node is also a &lt;strong&gt;SubTopic&lt;/strong&gt; or not to get an insight on how deep the topic, this function should end up looking something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc1ukwt6wrl9fml5zwso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc1ukwt6wrl9fml5zwso.png" alt="Function to pick a color in the editor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another aspect that can be added is actions, they are functions that are used in the editor. They usually take the form of copy/paste functions wrapper, adding new functionalities to them, or simply make sure the copy/paste functions are working correctly since using a projectional editor can sometimes lead to some trouble using it. In our case we will be using the node factory action that regulates how nodes are created, by assigning them properties and such while being able to access the&lt;br&gt;
model, compared to the &lt;strong&gt;Behavior&lt;/strong&gt; aspect’s constructor that couldn’t.&lt;/p&gt;

&lt;p&gt;We can go ahead and access the &lt;strong&gt;Marker&lt;/strong&gt; concept and create a new &lt;strong&gt;Node Factories&lt;/strong&gt; action aspect for it. This action will increment the marker’s name using the behavior function we defined in the mindmap, we will set its name to &lt;em&gt;IncrementMarker&lt;/em&gt;. We will create a new &lt;strong&gt;set-up&lt;/strong&gt; and set the &lt;em&gt;newNode’s name&lt;/em&gt; that is the marker’s name to the string value of the &lt;em&gt;enclosing&lt;/em&gt; mindmap node’s &lt;em&gt;getHighestMarkerNumber&lt;/em&gt; function plus one. This will increase the name of the marker everytime we create a new one. The final line of code should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9a8yu9e6i7278u1u8mao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9a8yu9e6i7278u1u8mao.png" alt="Marker incrementation function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a fully functional mindmap editor, with colors, a nice layout, some added features and constraints to the editor. Although it is nice to have a way to create good mindmap file, the end goal is to be able to create a LaTeXfile to write about each topic.&lt;/p&gt;

&lt;h1&gt;
  
  
  Text generation
&lt;/h1&gt;

&lt;p&gt;Text generation in MPS allows us to use layouts, functions, a complete language to create the perfect text files combined with specific functions dedicated to text generation to append and indent our text. &lt;/p&gt;

&lt;p&gt;For our mindmap, we will focus on a relatively simple text generation in LaTeXand will simply use the append function and some conditions for the subtopics. If you don’t know anything about LaTeX, you can check out &lt;a href="https://www.sharelatex.com/learn/Learn_LaTeX_in_30_minutes" rel="noopener noreferrer"&gt;this tutorial&lt;/a&gt; to get started and be able to follow the fields we’ll be using.&lt;/p&gt;

&lt;p&gt;To do so, go into the &lt;strong&gt;MindMap&lt;/strong&gt; concept and create a new &lt;strong&gt;TextGen&lt;/strong&gt; aspect with a &lt;strong&gt;Concept TextGenDeclaration&lt;/strong&gt;. All of the fields of our textgen can be filled by pressing to create the function it will use. We will set the file name to &lt;em&gt;node.name&lt;/em&gt; and the extension to &lt;em&gt;“tex”&lt;/em&gt;, we won’t change the encoding but feel free to do so if you use a special language that requires it. We don’t need context objects and we will directly edit the &lt;strong&gt;use textgen of ancestor&lt;/strong&gt; field to edit it. We will use the append function to create the default lines of our latex document followed by new lines for each tag and we will set the title to be the &lt;em&gt;node.centralTopic.name&lt;/em&gt; property, the content of our document will simply be an append of our &lt;em&gt;\${node.topic}&lt;/em&gt;, with the end result looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzoentkn2o0mrv6uxcmrd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzoentkn2o0mrv6uxcmrd.png" alt="Mindmap base template for text generation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can go on to our &lt;strong&gt;CentralTopic&lt;/strong&gt; concept and create a textgen. Since this concept isn’t a root concept, we have a lot fewer elements we can modify, so we will simply edit the statement and since we’re already using the topic’s title in our mindmap textgen, here we will simply append the children main topics and a new line using &lt;em&gt;append \$list{node.mainTopics} \n&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We can now add a text gen to our &lt;strong&gt;MainTopics&lt;/strong&gt; concept and edit the statement to append the text &lt;em&gt;\\section{&lt;/em&gt; followed by the &lt;em&gt;\${node.name}&lt;/em&gt; and finally the closing bracket &lt;em&gt;}&lt;/em&gt; and a newline. On the next line, we can append the subTopics list.&lt;/p&gt;

&lt;p&gt;Finally we can create a textgen for our &lt;strong&gt;SubTopics&lt;/strong&gt; concept and add a condition that checks if the &lt;em&gt;parent node&lt;/em&gt; is a SubTopic, creates a new &lt;em&gt;subsection&lt;/em&gt; if it isn’t, and a new &lt;em&gt;paragraph&lt;/em&gt; if it is. This condition is also followed by an append for the &lt;em&gt;subSubTopics&lt;/em&gt; children as we can see here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxq4fbgtr76q3e4fbser.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxq4fbgtr76q3e4fbser.png" alt="Text generation of a SubTopic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can now create a mindmap file, edit it, create your new topic and press Ctrl + Shift + F9 or right-click and use &lt;strong&gt;Preview generated text&lt;/strong&gt; to get access to your structured LaTeXfile !&lt;/p&gt;

&lt;p&gt;We now have our fully functional language with a text generation that creates LaTeXfiles according to the elements we created.&lt;/p&gt;

&lt;h1&gt;
  
  
  What now ?
&lt;/h1&gt;

&lt;p&gt;If you want to get more information on how to create more complex languages, use code generation instead of the simple text generation or simply to get ideas on the capabilities of MPS, you can head on to the &lt;a href="https://dev.tolearn%20page%20of%20MPS"&gt;https://www.jetbrains.com/mps/learn/&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>mps</category>
      <category>languageengineering</category>
      <category>tutorial</category>
      <category>introduction</category>
    </item>
    <item>
      <title>Hi, I'm Antoine Gagnon</title>
      <dc:creator>Antoine Gagnon</dc:creator>
      <pubDate>Sun, 05 Mar 2017 13:23:50 +0000</pubDate>
      <link>https://dev.to/antoine/hi-im-antoine-gagnon</link>
      <guid>https://dev.to/antoine/hi-im-antoine-gagnon</guid>
      <description>&lt;p&gt;I have been coding for 5 years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/AntoineGagnon" rel="noopener noreferrer"&gt;AntoineGagnon&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Bordeaux, France.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Java, PHP.&lt;/p&gt;

&lt;p&gt;I am currently learning more about whatever I saw in a random article.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
