Files
StateMachineParser/spec.md
T
Reece Dunham 3d2c19a349 Handle pushunique as a condition.
This needs tests to be written for it!
2022-07-12 02:07:23 -04:00

2.7 KiB

Unofficial State Machine Specification

This is a list of the possible nodes that can appear in a state machine, and what they do, from the research we have done so far.

Generic Nodes

These nodes all return boolean values, which represent if the checks inside these nodes pass or fail.

$eq

This node checks if the child elements are equal to each other.

This node accepts an array of 2 items, which will be checked for equality.

This node returns true if the 2 items are equal to each other.

Implementation Note: Arrays will not equal each other (starting in v4.1.0).

Example:

{
    $eq: [true, true], // -> true
}
{
    $eq: [5, 6], // -> false, 5 is not 6
}

$and

This node checks if the child elements are all true.

This node accepts an array of 2 or more items, which will all be evaluated for their truthiness.

This node returns true if all child elements evaluate to true.

Example:

{
    $and: [
        {
            $eq: [40, 40],
        }, // -> true
        {
            $eq: ["hello world", "hello world"],
        }, // -> true
    ], // -> true
}
{
    $and: [
        {
            $eq: [40, 50],
        }, // -> false
        {
            $eq: ["hello world", "hello world"],
        }, // -> true
    ], // -> false
}

$or

This node is a version of the $and node that only checks if one of the children evaluates to true.

Example:

{
    $or: [true, false], // -> true
}
{
    $or: [
        {
            $eq: ["chicken", "steak"],
        }, // -> false
        false,
    ], // -> false
}

$not

This node returns true if the child element is false.

It accepts the child object as its value.

Example:

{
    $not: {
        $eq: ["lettuce", "tomato"], // -> false
    }, // -> true
}

$after

This node is indented for delaying a state machine's evaluation by a number of seconds.

Implementation Note: This node is very loosely implemented, and will be rewritten in the near future.

$inarray

Documentation not yet done here. Feel free to open a PR!

Side Effect Nodes

Side effect nodes are nodes that are only supposed to be used inside Actions definitions, as they have side effects (e.g. modifying the globals).

$inc, $dec

Documentation not yet done here. Feel free to open a PR!

$mul, $div

Documentation not yet done here. Feel free to open a PR!

$set

Documentation not yet done here. Feel free to open a PR!

$push

Documentation not yet done here. Feel free to open a PR!

$pushunique

Warning

: This node is the only one that is both a condition and an action.

Documentation not yet done here. Feel free to open a PR!