We've encountered an issue exporting this macro. Please try exporting this page again later.
To use SIL like any other scripting language follow a few simple syntax rules.
General rules
All instructions Info |
---|
This topic provides an overview of the basic elements of the Simple Issue Language (SIL) scripting syntax. |
Complex data types
Arrays
Arrays are created by adding []
after any basic type. The following list represents valid arrays:
string[]
boolean[]
number[][]
integer[]
date[][][]
interval[]
You can also create arrays for a user-defined structure:
- where Person is a user-defined structureValue Arrays (Maps) are actually maps where values are keyed by their position in SIL where positions in the list
, and so keyact as keys. Key-value arrays (or maps) are declared
the same as like regular arrays.
Learn more about
maps and using the indexing operator to create key-value maps and retrieve values from them.
Structures
The general Structures are user-defined data types. A structure in SIL is like a container that can hold different types of data together. The syntax for defining a structure is:
<name> <type> <fieldName>;
}Structures are defined by their name and pairs of field type and field name. A structure can have any number of fields. type1 field1;
type2 field2;
// ... more fields
} |
The type of each field can be a
simple basic data type, a user-defined structure
(including the structure being defined) , a self-referential structure, or arrays of these types.
ExampleThe following examples show how to define a structure with each type:
struct Person {
struct Address {
string street;
string city;
string zipCode; //Basic data types in structure
}
struct Employee {
string id;
|
string name;
Address workAddress; // Structure inside structure
Address homeAddress; |
date birthDate;
Person manager;
Person [] subordinates;
} // Can use same type multiple times
}
struct Department {
string name;
Department parent; // A Department can reference itself
Department[] subDepartments; // Can have array of same type
} |
Panel |
---|
panelIconId | 2699 |
---|
panelIcon | :gear: |
---|
panelIconText | ⚙️ |
---|
bgColor | #FFFAE6 |
---|
|
Best practices when creating structures: Use meaningful field names. Group related fields together. Consider the logical hierarchy of your data.
|
To access the value of a field from a variable in a structure, use the syntax
will look likeExample 1:
Code Block |
---|
<varName>.<fieldName> |
Initializing Structures:
You can initialize structures field-by-field:
//considering structure Person defined above
Person p;
pemp;
emp.id = "E123";
emp.name = "John Doe";
|
pid1234567string hisManager = p.manager.name;
string employee = p.subordinates[0].name;Example 2emp.workAddress.city = "Work City"; |
Alternatively, you can do a one-line initialization, including nested initialization:
Pintintint z;
}{10, 20}; // Initialize all fields at once
struct |
Sab
datec;Ppoint;Ss-text-3.14, "1974-03-15"01, 2//oneline init
youdo not have to expand the creation of the struct anymore
//you do not need to quote them as stringsLiterals
Info |
This topic is about constant values, NOT about the read-only
Literals
Literals are fixed values that appear directly in the code. In SIL, literals are used to represent constant values of different data types.
Note |
---|
Literals refer to the constant values used in scripts, NOT the use of a constant which is the readonly attribute of variables. |
Single Value Literals
For numbers, integers and boolean values, constants are represented without any additional alterations.
Example
Code Block |
integer n = 1;
Type | |
---|
Basic type literals | Code Block |
---|
// Integer literals
integer a = 42;
integer b = -17;
// Number (floating point) literals
number pi = 3.14;
number temperature = -40.5;
// Boolean literals
boolean |
|
iLikeSILisTrue = true;
boolean isFalse = false;
// |
|
bytesneedcasts.sincetheliteralis an integer
b20;Literals for string, date and interval are provided between 255; // maximum byte value |
|
String, Date, and Interval literals | These types require double quotes (" "). |
The full format for date is Code Block |
---|
// String literals
string name = "John Doe";
string empty = ""; // empty string
// Date literals
// Full format: "yyyy-MM-ddTHH:mm:ss.SSSZ |
|
", and may include the time-zone information at the end. The short format "yyyy-MM-dd" is acceptedas well.The intervals should be provided in the JIRA standard format: 1w 2d 3h 4m".Example
Code Block |
// valid dates
"2010-12-31"
date fullDate = "2010-12-31T24:59:59.999Z"; |
|
(thedefaultconfiguredtimezoneistaken)
"2010-12-31T24:59:59Z" (Zulu time = UTC = GMT)
UTC
date withZone = "2010-12-31T22:59:59+0200"; // with timezone (UTC+2)
date simpleDate = "2010-12- |
|
31T24:59:59.999Z" (Zulu time = UTC = GMT)
"2010-12-31T22:59:59.999+0200" (UTC+2)
// interval
31"; // just date
// Interval literals
// Format: combines w(weeks) d(days) h(hours) m(minutes)
interval oneDay = "1d";
interval complex = "1w 2d 3h 4m" |
|
Array Literals
Array literals are created using the following syntax; // 1 week, 2 days, 3 hours, 4 minutes
interval justHours = "8h"; |
|
Array literals | Arrays use curly braces and commas: Code Block |
---|
{<value1>, <value2>, ..., <value3>} |
|
Example Code Block |
---|
// One-dimensional arrays
string[] names = {"this", "is", "a", "string", "array"} |
|
// string array
{{0,1}, {2,3}, {4,5}} // number matrix
{true, false, false} // boolean array
{"1d", "2d", "3d"} // interval array
{ variable1, variable2, variable3 } // array of the type of variable#, where variable# can also be an array Note |
---|
Note
We currently do not support constant representation of key-value arrays. You will need to ;
number[] scores = {95.5, 87.0, 91.5};
boolean[] flags = {true, false, true};
// Multi-dimensional arrays
number[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Array of intervals
interval[] durations = {"1d", "2h", "30m"}; |
Note |
---|
Constant representation of key-value arrays is not supported. You can build one using the indexing operator. |
|
NULL (and NIL)
Null values have been |
Special literals | You can use null or nil to unset variables. Info |
---|
The null and nil values were introduced in SIL |
|
in , Motivation is very simple Consider the following code, when you are required to nullify (unset) a variable Code Block |
---|
number n = 0;
.....
n = uninitialized; // not |
|
modified, you hope, by anyone
number recommended
n = null; // or:
n = |
|
0nil; // alternative syntax |
|
Variables
Variables are named containers that use the data types.
....
n = uninitialized; //it was the only way to unset itWe considered this way unhealthy, therefore we introduced null (or nil)
Code Block |
---|
number n = 0;
.....
n = null; // or:
n = nil; //nil is fine, too. Use whatever convention you like |
Variable Declaration
The general syntax for declaring a variable is:
Code Block |
---|
<type> varname; // declaration without initialization
// or
<type> varname = <expression>; // declaration with initialization |
Example
Code Block |
string name = "John Doe";They are like labeled boxes that can hold specific values.
Code Block |
---|
// Variable format: <data type> <variable name>
// Variable declaration:
string name; // A container that can hold text
number pi; // A container that can hold decimal numbers
//You can also have an array of the type of variable#
{ variable1, variable2, variable3 }. // where variable# can also be an array |
You can create an array from variables as illustrated in the following example:
Code Block |
---|
// First, declare some variables
string name1 = "John";
string name2 = "Jane";
string name3 = "Bob";
// Create an array from these variables
string[] names = {name1, name2, name3};
// Result: names = {"John", "Jane", "Bob"} |
You can also create array variables:
Code Block |
---|
// First, declare some array variables
string[] teamA = {"John", "Jane"};
string[] teamB = {"Bob", "Alice"};
string[] teamC = {"Charlie", "David"};
// Create an array of arrays from these variables
string[][] allTeams = {teamA, teamB, teamC};
// Result: allTeams = {
// {"John", "Jane"},
// {"Bob", "Alice"},
// {"Charlie", "David"}
// } |
Variable declaration and initialization
To give value to your variables, you initialize them either when you declare them or later.
Code Block |
---|
string employeeName; // Just declaring
employeeName = "John"; // Initializing after declaration
string employeeAge = 25; // Declare and initialize at once
// More examples of variable declaration
integer random = 2;
number pi = 3.14;
boolean valid;
date today = currentDate();
interval spent = "1h 30m";
interval estimate = "2d" - spent;
number [][] matrix = {{0,1}, {2,3}, {4,5}}; |
Constants
Variables can be made
read-only readonly by adding the keyword
"" before the data type when the variable is first defined.
Code Block |
---|
const string COMMA = ",";
const number PI = 3.14; |
If set to an array or structure, the
read-only readonly attribute will be applied to all the elements of the array or all fields of the structure.
Routine Declaration
In addition to the routines provided out-of-the-box by SIL, you can define your local routines (user-defined routines or UDRs in short) that use the following syntax:
Code Block |
---|
function <name>(<type> param1, <type> param2, ...) {
Instruction1;
...
InstructionN;
return <value>;
} |
Learn more about UDRs.
Explicit Type Casts
Most of the time, SIL™ will attempt to do the type-casting for you automatically, however this cannot be always performed like this. These type casts allow you explicitly to convert a variable to a specific type.The general syntax for casting is
Explicit type casting
When types are compatible, SIL automatically converts one type to another. Automatic conversion can lead to ambiguous results. If you want to tell SIL how to convert a type, use explicit type casting with the following syntax:
Code Block |
---|
(<target_type>)varname |
Example The following example illustrates how explicit type casting returns accurate results:
Code Block |
---|
integer n = 1;
number x = 3.14;
string s = "2";
//Ambiguous - could mean different things:
return n + s; // |
whatwillthisreturn?3or? or 3
//Explicit - clearn intentions:
return (string)n + s; // |
now we know that adding 2 strings will result inForces n to be treated as string "1" - clearly wants a string "12"
return n + (number)s; // |
adding Forces s to be treated as number 2 |
numberswilldefinitely return: Not all type casts are valid. |
For example it makes no sense to convert Contents
Table of Contents |
---|
minLevel | 1 |
---|
maxLevel | 2Converting an interval to a date or a date to a string is an example of invalid type casting. |
See also
User-defined functions
SIL comes with many out-of-the-box functions by SIL, but allows you to define local functions, referred to as user-defined routines (UDRs). To define and declare a function, use this general syntax:
Code Block |
---|
function <name>(<type> param1, <type> param2, ...) {
Instruction1;
...
InstructionN;
return <value>;
} |
For additional details, check the User-defined routines (UDRs) topic.