# Rustastic Automaton
[](https://travis-ci.org/conradkleinespel/ram)
[](https://ci.appveyor.com/project/conradkleinespel/ram)
[](https://discord.gg/9zXtYqQ)
`ram` allows you to ease the creation of a language lexer based on finite state machines.
## Supporting `ram`
`ram` is currently being maintained as a side-project, during nights and weekends, next to my full-time job. I am looking for a way to sustain my work on open source. If you find value in what I do and you would like to contribute, please consider:
- [Becoming a backer on Patreon](https://www.patreon.com/conradkleinespel)
- [Making a recurring donation on Liberapay](https://liberapay.com/conradkleinespel/)
## Usage
Add `ram` as a dependency in Cargo.toml:
```toml
[dependencies]
ram = "7.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.
The full API documentation is available at [https://docs.rs/ram](https://docs.rs/ram).
## License
The source code is released under the Apache 2.0 license.