Expressions - Minecraftian14/JShortyOutlet GitHub Wiki

Getting into deeper concepts xD

Target

This time let's introduce yet another feature of JShorty, ie, Expressions.

These serve the purpose of adding some additional boiler codes which should be placed given a specific condition.

One important difference against Element is - an Expression can either exist or does not exist, but never repeat.

As always, let's boot up a simple example.

Let's say there are some components called List and ArrayList. And we would like JShorty to sutomatically add their import lines if we are using them.

Basic setup

We can start by a simple JShort Template like:

{
  "name": "Expressions Demo",
  "identities": [
    {  
      "name": "Import Statement",  
      "regex": "[\\w\\W]+(\\npublic class) (?:[\\w]+ )+\\{[\\w\\W]+$",  
      "template": {  
      "type": "word",  
      "content": "\n<<VAR_AL>>\n\n public class"  }  
    }
  ]

}

Here we are looking for the area between the import statements and the public class declaration, finally replacing it with VAR_AL and public class (we need to put public class again because we captured it in the group, ie, it got replaced).

Creating an Expression

Next we can proceed to declare an expression as:

{
  "name": "Template Demo"
  "identities": [...]
  "expressions": [  
  {  
    "name": "Import statement",  
    "regex": "ArrayList",  
    "tag": "VAR_AL",  
    "expression": "import java.util.ArrayList;"  
   }  
 ]
}

Here we define yet another array expressions to contain all the expression we may define.

Inside an Expression, regex refers to the condition which the code must match and expression is the code which we add in.

Once again, boom we added in an Expression!

⚠️ **GitHub.com Fallback** ⚠️