Update TODO.md

This commit is contained in:
Zihan Chen
2017-03-10 16:18:53 -08:00
committed by GitHub
parent efa926e5f0
commit eee50a3fdf
+49 -42
View File
@@ -121,7 +121,7 @@ namespace system
/* If raiseException == true, the function will raise the exception after storing to the Failure property */ /* If raiseException == true, the function will raise the exception after storing to the Failure property */
func Resume(raiseException : bool) : void; func Resume(raiseException : bool) : void;
/* Stored the $raise result */ /* Stored the $raise/$retry result */
prop Failure : Exception^ {const} prop Failure : Exception^ {const}
prop Status : StateMachineStatus {const} prop Status : StateMachineStatus {const}
event OnStatusChanged(); event OnStatusChanged();
@@ -131,16 +131,19 @@ namespace system
### Core Syntax ### Core Syntax
* `$coroutine {...}` **expression** * `$state_machine {...}` **expression**
* Building a StateMachine^ * Building a StateMachine^
* `$pause {}` **statement** * `$pause {}` **statement**
* `$pause`, `return`, `break`, `continue` are not allowed inside `$pause` * `$pause`, `return`, `break`, `continue` are not allowed inside `$pause`
* `return` **statement** * `return` **statement**
* No expression * No expression
* Stop the state machine
* `raise <EXPRESSION>` **statement**
* Stop the state machine with a failure
``` ```
/* Status == Waiting */ /* Status == Waiting */
$coroutine $state_machine
{ {
/* Resume(): Status == Executing */ /* Resume(): Status == Executing */
for (i in range [1, 10]) for (i in range [1, 10])
@@ -164,21 +167,33 @@ $coroutine
* `$input Name(a:Ta, b:Tb);` **declaration** * `$input Name(a:Ta, b:Tb);` **declaration**
* `func Name(a:Ta, b:Tb) : bool` * `func Name(a:Ta, b:Tb) : bool`
* Returns false if a failed input causes a retry * Returns false if a failed input causes a retry
* No overloading
* `prop NameEnabled : bool {const}` * `prop NameEnabled : bool {const}`
* `var <prop>NameEnabled : bool = false;` * `var <prop>NameEnabled : bool = false;`
* `func GetNameEnabled() : bool { ... }` * `func GetNameEnabled() : bool { ... }`
* `func SetNameEnabled(<value> : bool) : void { ... }` * `func SetNameEnabled(<value> : bool) : void { ... }`
* `$switch { $case <$INPUT-DECL>: { ... } ... [$default [ = continue]: { ... }] }` **statement** * `$retry [<EXPRESSION>]` **statement**
* If there is `$default = continue` * Pause a state machine with a failure
* Failed input will not cause a retry * Can only appear inside `$input`
* Continue to execute until the next `$switch`, and use the current input as the input * Cause the current input fail
* In this case we don't call it **failed input**, until the next `$switch` failed * `[$watch { ... }] ($input | $input_optional) if <INPUT-DECL>(arguments...) { ... } else if ... else ...` **statement**
* `$watch { ... } $switch { ... }` **statement** * If there is `$watch`
* Failed input will fall into `$switch` directly * Cannot be followed by $input_optional
* If there is no **appropriate** `$watch` to catch failed input, the failed input cause a retry immediately * Failed input will go through the following $input
* If there is no `$watch`
* Pause the state machine with no failure
* If there is `$input_optional`
* If an input doesn't match the list, it is not considered failed, the state machine continue to run, and the input will be consumed by the next `$input` statement
* If there is `$input`
* If an input doesn't match the list, it is considered failed.
* Failed input will cause a retry
* Inside the original input
* `$input_optional` doesn't produce failed input, so it is not an original input
* `$input` inside a `$watch` is not an original input
* Original input is the last `$input` statement that receives the failed input
* If a retry is not initiated by `$retry` with an expression, then a default exceptions string is used
* `$join <STATE>;` **statement** * `$join <STATE>;` **statement**
* Cannot be directly or indirectly recursive * Only accept states that are declared **before** $join
* Which means `$join` and `$state` should not exceed type 3 grammar
* `$state [<NAME> ( ... )] { ... }` **declaration** * `$state [<NAME> ( ... )] { ... }` **declaration**
* If there is a name with parameters (optional), than it can be `$join` * If there is a name with parameters (optional), than it can be `$join`
* If there is no name, than this is the state machine for implementating the current interface * If there is no name, than this is the state machine for implementating the current interface
@@ -212,7 +227,7 @@ var calculator = new ICalculator^
{ {
if (valueFirst == "") if (valueFirst == "")
{ {
Update(value); valueFirst = value;
} }
else if (op == "+") else if (op == "+")
{ {
@@ -224,67 +239,60 @@ var calculator = new ICalculator^
} }
else else
{ {
throw $"Unrecognized operator: $(op)"; raise $"Unrecognized operator: $(op)";
} }
} }
$state Digits() $state Digits()
{ {
while (true) // this is wrong, it conflict with $default = continue while (true)
{ {
$switch $input_optional if Digit(i)
{ {
$case Digit(i : int): { Value = Value & i; } Value = Value & i;
$default = continue: {} }
else
{
break;
} }
} }
} }
$state Integer() $state Integer()
{ {
$switch $input_optional if Digit(i)
{ {
$case Digit(i : int): { Value = i; } Value = i;
$default = continue: {}
}
$join Digits(); $join Digits();
} }
}
$state Number() $state Number()
{ {
$join Integer(); $join Integer();
$switch $input_optional if Dot()
{
$case Dot()
{ {
Value = Value & "."; Value = Value & ".";
$switch $input Digit(i)
{ {
$case Digit(i : int): { Value = Value & i; } Value = Value & i;
}
$join Digits(); $join Digits();
} }
} }
$join Integer();
} }
$state $state
{ {
while (true) while (true)
{ {
$watch $monitor
{ {
$join Number(); $join Number();
$switch $input if Add() {Calculate(); op = "+";}
{ else if Mul() {Calculate(); op = "-";}
$case Add(): { Calculate(); op = "+"; } else if Equal() {Calculate(); op = "=";}
$case Mul(): { Calculate(); op = "-"; }
$case Equal(): { Calculate(); op = "="; }
} }
} $input if Clear()
$switch
{
$case Clear():
{ {
valueFirst = ""; valueFirst = "";
op = ""; op = "";
@@ -292,7 +300,6 @@ var calculator = new ICalculator^
} }
} }
} }
}
}; };
``` ```
@@ -376,7 +383,7 @@ EnumerableStateMachine.Create
( (
func (impl : EnumerableStateMachine.IImpl*) : StateMachine^ func (impl : EnumerableStateMachine.IImpl*) : StateMachine^
{ {
return $coroutine return $state_machine
{ {
for (i in range [1, 10]) for (i in range [1, 10])
{ {