HSL language syntax
As with almost any other programming language there are rules on how to use the languages features, It can be how to set a variable, how to compare a value or how to call a function. HSL has a syntax that might remind you of languages like PHP, Perl or C.
Contents |
Trivial code example
// Define Variables
$number = 5;
$string = "Hello";
$array = array("Hello", "World");
// Function Call
$random = rand(1,10);
Syntax notes
The Syntax of HSL are quite like PHP and C. Here follows some of the things to be aware of when using HSL.
1. It does not care about white space, that is newlines, spaces or tabs; except those splitting an keyword, variable, function or value.
| Best Practice | Works | Error |
|---|---|---|
$variable = 5; |
$variable = 5; |
$vari able = 5; |
2. Each statement must be terminated with a ;. This style is just like in PHP and C.
$variable = rand(1,10);
rand(1,1);
if (true) {
echo "Hello World";
}
3. Comments are of C-style
Its always a good idea to comment the code heavily.
/*
This is a multi-line comment
*/
// This is also a comment
If applicable the first comment may specify an icon from custom scripting blocks using --webui-icon=http://url.
// My first block --webui-icon=http://example.org/images/internet-mail.png
echo "Hello World";
4. Keywords, Variables and Function are case sensitive
$test = "a";
$TEST = "A";
echo $test; // Prints "a"
echo $TEST; // Prints "A"
5. There is no such thing as scoping
$test = 1;
if (true) {
$test = 2;
}
echo $test;
Script errors
Its very important that you write scripts that works, or else it will fall back to default actions. Which for IP Policy flows are Allow() and Mail Content flows Deliver().
Syntax error
Syntax error are errors in the syntax, these are very easy to avoid by simply writing the correct syntax.
Error Example
$variable = 1
In this example you have missed a ; at the end.
Runtime error
A runtime error appears in runtime, that is when the script executes. Eg. when you receive a mail or accepts a connection. They are hard to foresee but, when they occurs they do get reported to the system log and the script falls back to the the default action for each flow.
Error Example
if (false) {
$test = 2;
}
echo $test;
It will result is a runtime error, since it will only be defined if false is true.
if (rand(0,1)) {
$test = 2;
}
echo $test;
Since the execution can choose different code paths each time, its very important to always define variables.