Skip to main content

banish/
lib.rs

1//! # Banish
2//! An easy to use declarative DSL for creating state machines and rules-base logic. 
3//! It allows you to define "States" and "Rules" that execute until they reach a fixed point or transition.
4//!
5//! ## Syntax
6//! - **@state** : Defines a state that loops until no rules trigger or a state transition. States execute from top to bottom.
7//! - **rule ? condition {}** : Defines a rule. Executes if its condition is true. Rules execute from top to bottom.
8//! - **!? {}** : Defines an else clause after the closing brace of a rule with a condition.
9//! - **rule ? {}** : A rule without a condition. Executes exactly once per state entry. Cannot have an else clause.
10//! - **=> @state;** : Transitions immediately to another state, but is a rule top-level statement only.
11//! - **return value;** : Immediately exit banish and return a value if passed.
12//!
13//! ## Example
14//!
15//! ```rust
16//! use banish::banish;
17//!
18//! fn main() {
19//!     let mut ticks: i32 = 0;
20//!     let mut loop_count: i32 = 0;
21//!     banish! {
22//!         @red
23//!             announce ? {
24//!                 ticks = 0;
25//!                 println!("Red light");
26//!                 loop_count += 1;
27//!              }
28//!
29//!             timer ? ticks < 3 {
30//!                 ticks += 1;
31//!             }
32//!
33//!         @green
34//!             announce ? {
35//!                 println!("Green light");
36//!             }
37//!
38//!             timer ? ticks < 6 {
39//!                 ticks += 1;
40//!             }
41//!
42//!         @yellow
43//!             announce ? {
44//!                 println!("Yellow light");
45//!             }
46//!
47//!             timer ? ticks < 10 {
48//!                 ticks += 1;
49//!             }
50//!
51//!             reset ? ticks == 10 && loop_count < 2 {
52//!                 => @red;
53//!             }
54//! 
55//!             stop ? loop_count == 2 { return; }
56//!     }
57//! }
58//! ```
59
60pub use banish_derive::banish;