|
Onetastic Macro Documentation >
>
Code Structure
Code Structure
In Onetastic Macro Language, a program is a sequence of . Each statement normally occupies one line. The number of tab characters at the start of a statement (its indentation level) determines which block the statement belongs to.
Blocks and Indentation
Control flow statements such as for, foreach, if, while, and switch introduce a block of child statements. Statements belonging to a block must be indented exactly one tab deeper than their block header. Statements at the same indentation level as the header are outside the block.
Copied!
$sum = 0
for ($i = 1, $i <= 5, ++$i)
$sum += $i
ShowMessage($sum)
User-defined follow the same rule. The statements inside a function body must be indented one tab deeper than the function signature. This applies to all functions including Main.
Copied!
function Add($a, $b)
return $a + $b
function Main($arg, $context)
$result = Add(3, 4)
ShowMessage($result)
Nested Blocks
Blocks can be nested inside each other. Each additional level of nesting requires one more tab of indentation.
Copied!
for ($i = 1, $i <= 3, ++$i)
if ($i > 1)
ShowMessage($i)
Multi-Line Statements
A statement can be split across multiple physical lines by ending a line with a backslash \. The next line is treated as a continuation of the same statement. This is useful when a statement is long and would be difficult to read on a single line.
Copied!
$result = String_Replace( \
"the original text", \
"original", \
"replaced")
The indentation on continuation lines is purely cosmetic (it does not affect which block the statement belongs to). Only the indentation of the first line of a statement determines its block membership. Multi-line statements work inside blocks as well:
Copied!
for ($i = 1, $i <= 5, ++$i)
$message = "Item " + \
String($i)
ShowMessage($message)
Comments can also appear on continuation lines:
Copied!
$result = String_Replace($text, \
"original", \
"replaced")
|