[−][src]Crate ogma
Ogma (named after the this guy) is a library to create Natural Language DSLs. Specifically, the library provides convenience macros for wrapping a function with implementations to parse parameters from English.
Examples
#[given(Add, "the addition of q`input` and d`constant` henceforth q`out`")] fn add<'a>( ctx: &mut Context, input: &Vec<Query<'a>>, constant: i32, out: &Vec<Query<'a>>, ) -> Result<(), Trap> { // get global variable from `ctx` using `input`, add `constant` to it // and save to `ctx` via `out` Ok(()) }
which you can then use in a Script
let mut ctx = bdd::Step::new(); let script = Module::compile( &mut ctx, r#" Given the addition of the input and 2 henceforth the left And the product of the input and 2 henceforth the right When the left is equal to the right Then do nothing "#, ) .unwrap(); let mut instance = script.instance(); instance.ctx_mut().set_global::<_, i32>("input", 2); assert!(instance.exec().is_ok());
Re-exports
pub extern crate object_query; |
Modules
bdd | BDD utilities |
clause | Clause parsing utilities |
matcher | Function matching utilities |
module | Script parsing utilities |
vm | Virtual machine for running functions |
Macros
clause | Parse a clause into a static list of tokens |
mod_list | Creates a Module from a list of types |
mod_type | Creates a ModuleType from a list of Types |
Attribute Macros
given | Derive a function structure which matches during the BDD "Given" state |
ogma_fn | Derive a callable and matchable function structure from a function |
then | Derive a function structure which matches during the BDD "Then" state |
when | Derive a function structure which matches during the BDD "When" state |