# Rustastic Automaton
This [Rust](http://www.rust-lang.org/) package allows you to ease the creation of a language lexer based on finite state machines.
You can build the documentation with `cargo doc` or [view it online](https://conradk.com/docs/rustastic-am/).
The source code is released under the MIT license.
I'd appreciate feedback if you use this library :-)
## Usage
Add `ram` as a dependency in Cargo.toml:
```toml
[dependencies]
ram = "5.0.0"
```
Import the `ram` crate and use the `Automaton` struct to create a language lexer. In this example, we are lexing a language that has no tokens other than the "End of source" token:
```rust
extern crate ram;
use ram::Automaton;
enum TokenType {
End,
}
// Create the FSM (2 states, 0 or 1) that will parse the source code
let mut am = Automaton::new(0, 1);
// When the FSM hits the end of the source, go to state 1, the final state
am.find_end(TokenType::End as i32, 0, 1);
// Run the FSM with an empty string as the source code
let source_code = format!("");
let runner = am.run(source_code);
// Print the parsed tokens to the console
println!("{:?}", runner.tokens);
```
There are multiple `find_*` methods to your disposal, like `find_regex` or `find_whitespace` or
even `find_automaton`, which allows you to combine various finite state machines together
to create more powerful tokenizers.