more shit
This commit is contained in:
parent
24937326f7
commit
fe50ee1f2c
4 changed files with 35 additions and 13 deletions
1
src/catgirl_nonsense.rs
Normal file
1
src/catgirl_nonsense.rs
Normal file
|
@ -0,0 +1 @@
|
|||
uwurandom_proc_macros::gen_fsm![{"choices":[{"nextNgram":0,"nextChar":"a","cumulativeProbability":2},{"nextNgram":1,"nextChar":"m","cumulativeProbability":3}],"totalProbability":3,"name":"aa"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":3},{"nextNgram":6,"nextChar":"e","cumulativeProbability":4}],"totalProbability":4,"name":"am"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"an"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"ao"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"eo"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":6},{"nextNgram":22,"nextChar":"n","cumulativeProbability":7},{"nextNgram":23,"nextChar":"p","cumulativeProbability":8}],"totalProbability":8,"name":"ew"},{"choices":[{"nextNgram":4,"nextChar":"o","cumulativeProbability":3},{"nextNgram":5,"nextChar":"w","cumulativeProbability":5}],"totalProbability":5,"name":"me"},{"choices":[{"nextNgram":16,"nextChar":"o","cumulativeProbability":15},{"nextNgram":12,"nextChar":"a","cumulativeProbability":24},{"nextNgram":18,"nextChar":"r","cumulativeProbability":28},{"nextNgram":19,"nextChar":"w","cumulativeProbability":29},{"nextNgram":13,"nextChar":"e","cumulativeProbability":30}],"totalProbability":30,"name":"mr"},{"choices":[{"nextNgram":26,"nextChar":"a","cumulativeProbability":1}],"totalProbability":1,"name":"ny"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":22},{"nextNgram":24,"nextChar":"r","cumulativeProbability":32},{"nextNgram":22,"nextChar":"n","cumulativeProbability":36},{"nextNgram":25,"nextChar":"w","cumulativeProbability":37},{"nextNgram":23,"nextChar":"p","cumulativeProbability":38}],"totalProbability":38,"name":"ow"},{"choices":[{"nextNgram":11,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"pp"},{"choices":[{"nextNgram":20,"nextChar":"r","cumulativeProbability":1}],"totalProbability":1,"name":"pu"},{"choices":[{"nextNgram":3,"nextChar":"o","cumulativeProbability":1}],"totalProbability":1,"name":"ra"},{"choices":[{"nextNgram":4,"nextChar":"o","cumulativeProbability":1}],"totalProbability":1,"name":"re"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":1},{"nextNgram":6,"nextChar":"e","cumulativeProbability":2}],"totalProbability":2,"name":"rm"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"rn"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"ro"},{"choices":[{"nextNgram":10,"nextChar":"p","cumulativeProbability":1}],"totalProbability":1,"name":"rp"},{"choices":[{"nextNgram":18,"nextChar":"r","cumulativeProbability":7},{"nextNgram":14,"nextChar":"m","cumulativeProbability":10},{"nextNgram":16,"nextChar":"o","cumulativeProbability":13},{"nextNgram":17,"nextChar":"p","cumulativeProbability":14}],"totalProbability":14,"name":"rr"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":1}],"totalProbability":1,"name":"rw"},{"choices":[{"nextNgram":18,"nextChar":"r","cumulativeProbability":1}],"totalProbability":1,"name":"ur"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":17},{"nextNgram":6,"nextChar":"e","cumulativeProbability":30}],"totalProbability":30,"name":"wm"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"wn"},{"choices":[{"nextNgram":11,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"wp"},{"choices":[{"nextNgram":14,"nextChar":"m","cumulativeProbability":7},{"nextNgram":15,"nextChar":"n","cumulativeProbability":10}],"totalProbability":10,"name":"wr"},{"choices":[{"nextNgram":25,"nextChar":"w","cumulativeProbability":3},{"nextNgram":21,"nextChar":"m","cumulativeProbability":4}],"totalProbability":4,"name":"ww"},{"choices":[{"nextNgram":0,"nextChar":"a","cumulativeProbability":4},{"nextNgram":2,"nextChar":"n","cumulativeProbability":5},{"nextNgram":1,"nextChar":"m","cumulativeProbability":6}],"totalProbability":6,"name":"ya"}];
|
1
src/keysmash.rs
Normal file
1
src/keysmash.rs
Normal file
File diff suppressed because one or more lines are too long
26
src/lib.rs
26
src/lib.rs
|
@ -5,12 +5,15 @@ pub fn add(left: usize, right: usize) -> usize {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::keysmash;
|
||||
|
||||
use super::catgirl_nonsense;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
fn catgirl_nonsense_test() {
|
||||
// Use a stable-algorithm RNG with fixed seed
|
||||
let mut rng = rand_pcg::Pcg32::new(0xcafef00dd15ea5e5, 0xa02bdbf7bb3c0a7);
|
||||
let mut state_machine = StateMachine::Ny;
|
||||
let mut state_machine = catgirl_nonsense::StateMachine::Ny;
|
||||
let mut result = String::from("ny");
|
||||
for _ in 0..100 {
|
||||
let (new_state, generated) = state_machine.generate(&mut rng);
|
||||
|
@ -19,6 +22,21 @@ mod tests {
|
|||
}
|
||||
assert_eq!(&result, "nyaaaameowmrowrmrowmrrmeowmrowmeownyanyaaaaaaaaaaaaamraowrmeowwwmeowmraowmrowmrowmeowmeowrnyamreownyaa");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keysmash_test() {
|
||||
// Use a stable-algorithm RNG with fixed seed
|
||||
let mut rng = rand_pcg::Pcg32::new(0xcafef00dd15ea5e5, 0xa02bdbf7bb3c0a7);
|
||||
let mut state_machine = keysmash::StateMachine::A;
|
||||
let mut result = String::from("a");
|
||||
for _ in 0..100 {
|
||||
let (new_state, generated) = state_machine.generate(&mut rng);
|
||||
result.push(generated);
|
||||
state_machine = new_state;
|
||||
}
|
||||
assert_eq!(&result, "ajhfhiurgjfgajhnghgadfghkfghiurgjeghnhgjalkjfhgnhrgjhnhiuradfdbahrgbafhg;djkafgjhjrajfjdfghfhdfgajgad");
|
||||
}
|
||||
}
|
||||
|
||||
uwurandom_proc_macros::gen_fsm![{"choices":[{"nextNgram":0,"nextChar":"a","cumulativeProbability":2},{"nextNgram":1,"nextChar":"m","cumulativeProbability":3}],"totalProbability":3,"name":"aa"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":3},{"nextNgram":6,"nextChar":"e","cumulativeProbability":4}],"totalProbability":4,"name":"am"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"an"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"ao"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"eo"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":6},{"nextNgram":22,"nextChar":"n","cumulativeProbability":7},{"nextNgram":23,"nextChar":"p","cumulativeProbability":8}],"totalProbability":8,"name":"ew"},{"choices":[{"nextNgram":4,"nextChar":"o","cumulativeProbability":3},{"nextNgram":5,"nextChar":"w","cumulativeProbability":5}],"totalProbability":5,"name":"me"},{"choices":[{"nextNgram":16,"nextChar":"o","cumulativeProbability":15},{"nextNgram":12,"nextChar":"a","cumulativeProbability":24},{"nextNgram":18,"nextChar":"r","cumulativeProbability":28},{"nextNgram":19,"nextChar":"w","cumulativeProbability":29},{"nextNgram":13,"nextChar":"e","cumulativeProbability":30}],"totalProbability":30,"name":"mr"},{"choices":[{"nextNgram":26,"nextChar":"a","cumulativeProbability":1}],"totalProbability":1,"name":"ny"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":22},{"nextNgram":24,"nextChar":"r","cumulativeProbability":32},{"nextNgram":22,"nextChar":"n","cumulativeProbability":36},{"nextNgram":25,"nextChar":"w","cumulativeProbability":37},{"nextNgram":23,"nextChar":"p","cumulativeProbability":38}],"totalProbability":38,"name":"ow"},{"choices":[{"nextNgram":11,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"pp"},{"choices":[{"nextNgram":20,"nextChar":"r","cumulativeProbability":1}],"totalProbability":1,"name":"pu"},{"choices":[{"nextNgram":3,"nextChar":"o","cumulativeProbability":1}],"totalProbability":1,"name":"ra"},{"choices":[{"nextNgram":4,"nextChar":"o","cumulativeProbability":1}],"totalProbability":1,"name":"re"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":1},{"nextNgram":6,"nextChar":"e","cumulativeProbability":2}],"totalProbability":2,"name":"rm"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"rn"},{"choices":[{"nextNgram":9,"nextChar":"w","cumulativeProbability":1}],"totalProbability":1,"name":"ro"},{"choices":[{"nextNgram":10,"nextChar":"p","cumulativeProbability":1}],"totalProbability":1,"name":"rp"},{"choices":[{"nextNgram":18,"nextChar":"r","cumulativeProbability":7},{"nextNgram":14,"nextChar":"m","cumulativeProbability":10},{"nextNgram":16,"nextChar":"o","cumulativeProbability":13},{"nextNgram":17,"nextChar":"p","cumulativeProbability":14}],"totalProbability":14,"name":"rr"},{"choices":[{"nextNgram":21,"nextChar":"m","cumulativeProbability":1}],"totalProbability":1,"name":"rw"},{"choices":[{"nextNgram":18,"nextChar":"r","cumulativeProbability":1}],"totalProbability":1,"name":"ur"},{"choices":[{"nextNgram":7,"nextChar":"r","cumulativeProbability":17},{"nextNgram":6,"nextChar":"e","cumulativeProbability":30}],"totalProbability":30,"name":"wm"},{"choices":[{"nextNgram":8,"nextChar":"y","cumulativeProbability":1}],"totalProbability":1,"name":"wn"},{"choices":[{"nextNgram":11,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"wp"},{"choices":[{"nextNgram":14,"nextChar":"m","cumulativeProbability":7},{"nextNgram":15,"nextChar":"n","cumulativeProbability":10}],"totalProbability":10,"name":"wr"},{"choices":[{"nextNgram":25,"nextChar":"w","cumulativeProbability":3},{"nextNgram":21,"nextChar":"m","cumulativeProbability":4}],"totalProbability":4,"name":"ww"},{"choices":[{"nextNgram":0,"nextChar":"a","cumulativeProbability":4},{"nextNgram":2,"nextChar":"n","cumulativeProbability":5},{"nextNgram":1,"nextChar":"m","cumulativeProbability":6}],"totalProbability":6,"name":"ya"}];
|
||||
mod catgirl_nonsense;
|
||||
mod keysmash;
|
||||
|
|
|
@ -13,8 +13,7 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
|
|||
let mut match_arms = quote!();
|
||||
let mut variants = quote!();
|
||||
for state in input.iter() {
|
||||
let name = state.name.to_case(Case::Pascal);
|
||||
let name = Ident::new(&name, Span::call_site().into());
|
||||
let name = to_ident(&state.name);
|
||||
variants = quote!(
|
||||
#variants
|
||||
#name,
|
||||
|
@ -22,8 +21,7 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
|
|||
let mut inner_match_arms = quote!();
|
||||
if state.total_probability == 1 {
|
||||
let choice = &state.choices[0];
|
||||
let next_state = input[choice.next_ngram].name.to_case(Case::Pascal);
|
||||
let next_state = Ident::new(&next_state, Span::call_site().into());
|
||||
let next_state = to_ident(&input[choice.next_ngram].name);
|
||||
let next_char = LitChar::new(choice.next_char, Span::call_site().into());
|
||||
match_arms = quote!(
|
||||
#match_arms
|
||||
|
@ -32,8 +30,7 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
|
|||
continue;
|
||||
}
|
||||
for choice in &state.choices {
|
||||
let next_state = input[choice.next_ngram].name.to_case(Case::Pascal);
|
||||
let next_state = Ident::new(&next_state, Span::call_site().into());
|
||||
let next_state = to_ident(&input[choice.next_ngram].name);
|
||||
let cumulative_probability = choice.cumulative_probability - 1;
|
||||
let next_char = LitChar::new(choice.next_char, Span::call_site().into());
|
||||
inner_match_arms = quote!(
|
||||
|
@ -52,15 +49,20 @@ pub fn gen_fsm(item: TokenStream) -> TokenStream {
|
|||
}
|
||||
quote!(
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum StateMachine {
|
||||
pub enum StateMachine {
|
||||
#variants
|
||||
}
|
||||
impl StateMachine {
|
||||
fn generate(self, mut rng: impl ::rand_core::RngCore) -> (Self, char) {
|
||||
pub fn generate(self, mut rng: impl ::rand_core::RngCore) -> (Self, char) {
|
||||
match self {
|
||||
#match_arms
|
||||
}
|
||||
}
|
||||
}
|
||||
).into()
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn to_ident(name: &str) -> Ident {
|
||||
Ident::new(&name.replace(';', " semicolon").to_case(Case::Pascal), Span::call_site().into())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue