-
Notifications
You must be signed in to change notification settings - Fork 195
Category
Category is a way to limit the place of calling a specified block or sentence.
###Category on Sentences
Some sentences are only make sense to call in some blocks, like break
and repeat
. Multiple blocks can share a same category, and a sentence is allowed to be configured to be appear inside multiple categories of blocks.
For example, if we want to limit that break
can only be used inside repeat
:
category
start REPEAT
closable
block repeat ...
category
inside REPEAT
sentence break ...
A block can only have one start
, but a sentence can have multiple inside
. closable
means that this block can be ended by end
.
Because of the category configuration, the following statements are correct:
repeat
break
end
repeat
if true
break
end
end
Although if
is not in category REPEAT
, but repeat
is. So break
can be used in the if
in repeat
.
And this is not correct because break
does not appear inside repeat
or any other blocks that in caregory REPEAT
:
try
break
finally
end
inside
is not allowed on blocks, it is the only allowed configuration for sentences.
###Category on Blocks and Block Chains
You can specify follow
on blocks the build a block chain!
For example, you can use block to build the if
statement:
block (sentence body) if (condition)
select condition
case true
body
end
end
``
But what about `else if` and `else`?
To enable that, Tinymoe provide a feature called **block chain**. If you declare `if`, `else if` and `else` in the following way:
category start IFELSE if closable block (sentence body) if (condition) ...
category (signal) follow IFELSE if start IFELSE if closable block (sentence body) else if (expression condition) ...
category (signal) follow IFELSE if closable block (sentence body) else ...
Then `else if` and `else` can be used right after `if` because of the `follow` configuration. `else if` and `else` cannot be used without `if` also because of the `follow` configuration. `if`, `else if` and `else` can be the last block in a block chain because of the `closable` configuration.
The `follow` configuration require a block should be appear right after other blocks in the specified category. Multiple `follow` are allowed on a block.
If a block has a `follow` configuration, than `category (signal)` is required because a block should receive the return value from the previous block. For example:
if condition one A else if condition two B else if condition three C else D end
All four blocks, `if`, two `else if` and `else`, **are executed sequencially**. When `condition one` success, `if` should pass the imformation to the next `else if` to tell it to skip, and `else if` will tell the second `else if` to skip, and it will tell the last `else` to skip.
A block can pass information to the next block by writing `the result` variable. A block can receive information from the previous block by `signal` variable specified in `category (signal)`.
If one of the previous block succeed, then the current `else if` should not evaluate both the condition and the variable. This is why else if uses `(expression condition)`.
More explanation for `if` series blocks can be found in [Standard Library: If Else](https://github.com/vczh/tinymoe/wiki/Standard-Library-If-Else).