From fe50ee1f2cb76253a947f9561758ad0483b68a41 Mon Sep 17 00:00:00 2001 From: Skye Date: Wed, 21 Sep 2022 18:22:14 +0900 Subject: [PATCH] more shit --- src/catgirl_nonsense.rs | 1 + src/keysmash.rs | 1 + src/lib.rs | 26 ++++++++++++++++++++++---- uwurandom-proc-macros/src/lib.rs | 20 +++++++++++--------- 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 src/catgirl_nonsense.rs create mode 100644 src/keysmash.rs diff --git a/src/catgirl_nonsense.rs b/src/catgirl_nonsense.rs new file mode 100644 index 0000000..add369f --- /dev/null +++ b/src/catgirl_nonsense.rs @@ -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"}]; diff --git a/src/keysmash.rs b/src/keysmash.rs new file mode 100644 index 0000000..5309f29 --- /dev/null +++ b/src/keysmash.rs @@ -0,0 +1 @@ +uwurandom_proc_macros::gen_fsm![{"choices":[{"nextNgram":1,"nextChar":"a","cumulativeProbability":4},{"nextNgram":10,"nextChar":"k","cumulativeProbability":5},{"nextNgram":3,"nextChar":"d","cumulativeProbability":6},{"nextNgram":11,"nextChar":"l","cumulativeProbability":7},{"nextNgram":7,"nextChar":"h","cumulativeProbability":8}],"totalProbability":8,"name":";"},{"choices":[{"nextNgram":7,"nextChar":"h","cumulativeProbability":7},{"nextNgram":9,"nextChar":"j","cumulativeProbability":13},{"nextNgram":5,"nextChar":"f","cumulativeProbability":18},{"nextNgram":11,"nextChar":"l","cumulativeProbability":21},{"nextNgram":16,"nextChar":"u","cumulativeProbability":24},{"nextNgram":6,"nextChar":"g","cumulativeProbability":26},{"nextNgram":3,"nextChar":"d","cumulativeProbability":28},{"nextNgram":0,"nextChar":";","cumulativeProbability":29},{"nextNgram":14,"nextChar":"r","cumulativeProbability":30}],"totalProbability":30,"name":"a"},{"choices":[{"nextNgram":10,"nextChar":"k","cumulativeProbability":1},{"nextNgram":1,"nextChar":"a","cumulativeProbability":2},{"nextNgram":7,"nextChar":"h","cumulativeProbability":3}],"totalProbability":3,"name":"b"},{"choices":[{"nextNgram":5,"nextChar":"f","cumulativeProbability":7},{"nextNgram":7,"nextChar":"h","cumulativeProbability":12},{"nextNgram":15,"nextChar":"s","cumulativeProbability":13},{"nextNgram":6,"nextChar":"g","cumulativeProbability":14},{"nextNgram":10,"nextChar":"k","cumulativeProbability":15},{"nextNgram":9,"nextChar":"j","cumulativeProbability":16},{"nextNgram":2,"nextChar":"b","cumulativeProbability":17}],"totalProbability":17,"name":"d"},{"choices":[{"nextNgram":6,"nextChar":"g","cumulativeProbability":1}],"totalProbability":1,"name":"e"},{"choices":[{"nextNgram":6,"nextChar":"g","cumulativeProbability":12},{"nextNgram":10,"nextChar":"k","cumulativeProbability":16},{"nextNgram":9,"nextChar":"j","cumulativeProbability":19},{"nextNgram":11,"nextChar":"l","cumulativeProbability":21},{"nextNgram":7,"nextChar":"h","cumulativeProbability":23},{"nextNgram":3,"nextChar":"d","cumulativeProbability":25},{"nextNgram":1,"nextChar":"a","cumulativeProbability":26}],"totalProbability":26,"name":"f"},{"choices":[{"nextNgram":1,"nextChar":"a","cumulativeProbability":8},{"nextNgram":7,"nextChar":"h","cumulativeProbability":14},{"nextNgram":0,"nextChar":";","cumulativeProbability":18},{"nextNgram":9,"nextChar":"j","cumulativeProbability":22},{"nextNgram":11,"nextChar":"l","cumulativeProbability":25},{"nextNgram":2,"nextChar":"b","cumulativeProbability":27},{"nextNgram":5,"nextChar":"f","cumulativeProbability":29},{"nextNgram":3,"nextChar":"d","cumulativeProbability":30},{"nextNgram":15,"nextChar":"s","cumulativeProbability":31},{"nextNgram":10,"nextChar":"k","cumulativeProbability":32},{"nextNgram":16,"nextChar":"u","cumulativeProbability":33},{"nextNgram":12,"nextChar":"n","cumulativeProbability":34}],"totalProbability":34,"name":"g"},{"choices":[{"nextNgram":6,"nextChar":"g","cumulativeProbability":7},{"nextNgram":9,"nextChar":"j","cumulativeProbability":11},{"nextNgram":5,"nextChar":"f","cumulativeProbability":14},{"nextNgram":10,"nextChar":"k","cumulativeProbability":17},{"nextNgram":1,"nextChar":"a","cumulativeProbability":20},{"nextNgram":3,"nextChar":"d","cumulativeProbability":23},{"nextNgram":8,"nextChar":"i","cumulativeProbability":25},{"nextNgram":14,"nextChar":"r","cumulativeProbability":27},{"nextNgram":0,"nextChar":";","cumulativeProbability":28},{"nextNgram":12,"nextChar":"n","cumulativeProbability":29},{"nextNgram":7,"nextChar":"h","cumulativeProbability":30},{"nextNgram":16,"nextChar":"u","cumulativeProbability":31}],"totalProbability":31,"name":"h"},{"choices":[{"nextNgram":16,"nextChar":"u","cumulativeProbability":1}],"totalProbability":1,"name":"i"},{"choices":[{"nextNgram":7,"nextChar":"h","cumulativeProbability":5},{"nextNgram":3,"nextChar":"d","cumulativeProbability":9},{"nextNgram":10,"nextChar":"k","cumulativeProbability":12},{"nextNgram":5,"nextChar":"f","cumulativeProbability":15},{"nextNgram":1,"nextChar":"a","cumulativeProbability":17},{"nextNgram":14,"nextChar":"r","cumulativeProbability":18},{"nextNgram":4,"nextChar":"e","cumulativeProbability":19},{"nextNgram":13,"nextChar":"o","cumulativeProbability":20},{"nextNgram":11,"nextChar":"l","cumulativeProbability":21},{"nextNgram":6,"nextChar":"g","cumulativeProbability":22}],"totalProbability":22,"name":"j"},{"choices":[{"nextNgram":1,"nextChar":"a","cumulativeProbability":6},{"nextNgram":5,"nextChar":"f","cumulativeProbability":10},{"nextNgram":6,"nextChar":"g","cumulativeProbability":13},{"nextNgram":9,"nextChar":"j","cumulativeProbability":16},{"nextNgram":15,"nextChar":"s","cumulativeProbability":17},{"nextNgram":3,"nextChar":"d","cumulativeProbability":18},{"nextNgram":11,"nextChar":"l","cumulativeProbability":19},{"nextNgram":7,"nextChar":"h","cumulativeProbability":20}],"totalProbability":20,"name":"k"},{"choices":[{"nextNgram":10,"nextChar":"k","cumulativeProbability":4},{"nextNgram":0,"nextChar":";","cumulativeProbability":6},{"nextNgram":15,"nextChar":"s","cumulativeProbability":7},{"nextNgram":6,"nextChar":"g","cumulativeProbability":8},{"nextNgram":5,"nextChar":"f","cumulativeProbability":9},{"nextNgram":3,"nextChar":"d","cumulativeProbability":10},{"nextNgram":1,"nextChar":"a","cumulativeProbability":11}],"totalProbability":11,"name":"l"},{"choices":[{"nextNgram":6,"nextChar":"g","cumulativeProbability":1},{"nextNgram":7,"nextChar":"h","cumulativeProbability":2}],"totalProbability":2,"name":"n"},{"choices":[{"nextNgram":6,"nextChar":"g","cumulativeProbability":1}],"totalProbability":1,"name":"o"},{"choices":[{"nextNgram":6,"nextChar":"g","cumulativeProbability":4},{"nextNgram":1,"nextChar":"a","cumulativeProbability":6},{"nextNgram":7,"nextChar":"h","cumulativeProbability":7}],"totalProbability":7,"name":"r"},{"choices":[{"nextNgram":3,"nextChar":"d","cumulativeProbability":1},{"nextNgram":10,"nextChar":"k","cumulativeProbability":2}],"totalProbability":2,"name":"s"},{"choices":[{"nextNgram":14,"nextChar":"r","cumulativeProbability":3},{"nextNgram":1,"nextChar":"a","cumulativeProbability":4},{"nextNgram":5,"nextChar":"f","cumulativeProbability":5},{"nextNgram":9,"nextChar":"j","cumulativeProbability":6},{"nextNgram":4,"nextChar":"e","cumulativeProbability":7}],"totalProbability":7,"name":"u"}]; \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1b1a06d..fb484e6 100644 --- a/src/lib.rs +++ b/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; diff --git a/uwurandom-proc-macros/src/lib.rs b/uwurandom-proc-macros/src/lib.rs index ca6bac8..d02e1eb 100644 --- a/uwurandom-proc-macros/src/lib.rs +++ b/uwurandom-proc-macros/src/lib.rs @@ -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()) }