Getting Started - Minecraftian14/JShortyOutlet GitHub Wiki
Let's start with a simple syntax to allow us to import classes using the C++ and C# style.
#include<java.util.List.h>
will be converted to import java.util.List;
and using java.util.ArrayList;
will be converted to import java.util.ArrayList;
In the project create a file with the name TestTemplate.jstmp
:
{
"name": "Template Demo"
}
To recognize the part where library is imported, we need to define an Identity
{
"name": "Template Demo"
"identities": [
{
"name": "Import Statement",
"regex": "((?:#include[ ]?<|using )([\\w.$*]*)(?:\\.h>|;))",
"template": {
"type": "word",
"content": "import <<PATH:NAME>>;"
}
}
]
}
Here, we created an array called identities
and added an object representing our first identity.
It has a name, a regex
expression to identify the syntax and a template block.
A template contains a block of String where we define entries for the final conversion, elements and expressions.
There are two types of template block, either is defined using a type
entry in the block. Here we create a Word Template
.
If the template contains references to Elements or Expressions, they must be enclosed within <<
and >>
.
To extract useful information from a syntax used in JShorty file, we define a corresponding Element
.
An Element definition consists of a Tag and a list of References.
{
"name": "Template Demo"
"identities": [...]
"elements": [
{
"name": "Library Path",
"tag": "PATH",
"references": {
"NAME from PARENT": 2
}
}
]
}
Here we defined a name for the Element, and tagged it as PATH
. This element has a Reference
called NAME. The value inside the Reference
is the group number which the regex matches.
In this Reference
, "from PARENT" means that the regex to be referred comes from the Identity
matched.
An Element
is referred in a Template
as tag:reference name
, in this case, PATH:NAME
Boom the syntax is ready!