A toy automaton engine for DFA and a subset of NFA
Find a file
2021-05-06 20:00:15 +08:00
rustomaton compile-time transfer function construction simplified 2021-05-06 20:00:15 +08:00
rustomaton_macro compile-time transfer function construction simplified 2021-05-06 20:00:15 +08:00
.gitignore version 1 finished 2021-05-02 23:28:00 +08:00
Cargo.toml module renamed 2021-05-06 12:55:29 +08:00
README.md readme updated 2021-05-06 12:56:12 +08:00

A toy automaton engine for Rust

Now you can use a macro like this:

rustomaton! {
    #[init(initial_state)]
    /// an automaton can have multiple final states 
    #[ends(final_state1, final_state2, ...)]
    
    /// an automaton edge has the form: 
    start -> end: "some string";
    
    /// a transfer function function can be empty:
    start -> end: _;
    
    /// or a bool expression
    start -> end: "str1" | "str2"

    /// note that there cannot be two rules with the same edge, use a OR instead
    /// be aware that there is no extra semicolon after the last rule
}

this macro will generate an Automaton struct which implements a new method for the input type.

just new a instance and call the run method.

for example:

mod initial {
    pub use rustomaton::{AutomatonContext, Automaton};
    use rustomaton_macro::rustomaton;

    rustomaton!{
        #[init(0)]
        #[ends(3)]

        0 -> 1: "a";
        0 -> 2: "b";
        1 -> 2: "b";
        2 -> 1: "a";
        1 -> 3: "a";
        2 -> 3: "b";
        3 -> 3: "a" | "b"
    }
}

#[test]
fn test_tmp() {
    use initial::NewAutomaton;
    let automaton = initial::Automaton::new();

    println!("{:?}", automaton.run(&mut initial::AutomatonContext {
        src: String::from("baaaaaaaaa"),
        cur: 0
    }));
}