Last active
October 11, 2022 02:17
-
-
Save ErnWong/789fd98b4dfcaeb6054be7cea3c865f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error[E0599]: no function or associated item named `generatee_random` found for struct `ConsCell` in the current scope | |
--> src/main.rs:803:36 | |
| | |
66 | struct ConsCell<ElementType, TypeListType: TypeList>(ElementType, TypeListType); | |
| ---------------------------------------------------- function or associated item `generatee_random` not found for this struct | |
... | |
803 | println!("{}", EnglishGrammar::generatee_random::<Sentence>()); | |
| ^^^^^^^^^^^^^^^^ function or associated item not found in `ConsCell<(Sentence, ConsCell<ConsCell<NounPhrase, ConsCell<VerbPhrase, ConsCell<Terminal<".">, Empty>>>, ConsCell<ConsCell<VerbPhrase, ConsCell<Terminal<".">, Empty>>, ConsCell<ConsCell<AuxiliaryVerb, ConsCell<NounPhrase, ConsCell<VerbPhrase, ConsCell<Terminal<"?">, Empty>>>>, Empty>>>), ConsCell<(ComplementizerPhrase, ConsCell<ConsCell<Complementizer, ConsCell<Sentence, Empty>>, Empty>), ConsCell<(PrepositionalPhrase, ConsCell<ConsCell<Preposition, ConsCell<NounPhrase, Empty>>, Empty>), ConsCell<(NounPhrase, ConsCell<ConsCell<Pronoun, Empty>, ConsCell<ConsCell<ProperNoun, Empty>, ConsCell<ConsCell<Determiner, ConsCell<Nominal, Empty>>, ConsCell<ConsCell<Itself, ConsCell<Conjunction, ConsCell<Itself, Empty>>>, Empty>>>>), ConsCell<(Nominal, ConsCell<ConsCell<Noun, Empty>, ConsCell<ConsCell<Adjective, ConsCell<Itself, Empty>>, Empty>>), ConsCell<(VerbPhrase, ConsCell<ConsCell<Verb, Empty>, ConsCell<ConsCell<Verb, ConsCell<NounPhrase, Empty>>, ConsCell<ConsCell<Verb, ConsCell<NounPhrase, ConsCell<PrepositionalPhrase, Empty>>>, ConsCell<ConsCell<Verb, ConsCell<PrepositionalPhrase, Empty>>, Empty>>>>), ConsCell<(Conjunction, ConsCell<ConsCell<Terminal<"and">, Empty>, ConsCell<ConsCell<Terminal<"or">, Empty>, ConsCell<ConsCell<Terminal<"nor">, Empty>, ConsCell<ConsCell<Terminal<"for">, Empty>, ConsCell<ConsCell<Terminal<"but">, Empty>, ConsCell<ConsCell<Terminal<"yet">, Empty>, ConsCell<ConsCell<Terminal<"so">, Empty>, Empty>>>>>>>), ConsCell<(Preposition, ConsCell<ConsCell<Terminal<"to">, Empty>, ConsCell<ConsCell<Terminal<"in">, Empty>, ConsCell<ConsCell<Terminal<"on">, Empty>, ConsCell<ConsCell<Terminal<"at">, Empty>, ConsCell<ConsCell<Terminal<"near">, Empty>, ConsCell<ConsCell<Terminal<"by">, Empty>, Empty>>>>>>), ConsCell<(Complementizer, ConsCell<ConsCell<Terminal<"that">, Empty>, ConsCell<ConsCell<Terminal<"while">, Empty>, ConsCell<ConsCell<Terminal<"since">, Empty>, ConsCell<ConsCell<Terminal<"because">, Empty>, ConsCell<ConsCell<Terminal<"although">, Empty>, ConsCell<ConsCell<Terminal<"if">, Empty>, ConsCell<ConsCell<Terminal<"when">, Empty>, ConsCell<ConsCell<Terminal<"whether">, Empty>, ConsCell<ConsCell<Terminal<"so that">, Empty>, ConsCell<ConsCell<Terminal<"as such">, Empty>, ConsCell<ConsCell<Terminal<"before">, Empty>, ConsCell<ConsCell<Terminal<"after">, Empty>, ConsCell<ConsCell<Terminal<"until">, Empty>, ConsCell<ConsCell<Terminal<"as long as">, Empty>, ConsCell<ConsCell<Terminal<"by the time that">, Empty>, ConsCell<ConsCell<Terminal<"once">, Empty>, ConsCell<ConsCell<Terminal<"inasmuch as">, Empty>, Empty>>>>>>>>>>>>>>>>>), ConsCell<(Determiner, ConsCell<ConsCell<Terminal<"the">, Empty>, ConsCell<ConsCell<Terminal<"a">, Empty>, ConsCell<ConsCell<Terminal<"an">, Empty>, ConsCell<ConsCell<Terminal<"this">, Empty>, ConsCell<ConsCell<Terminal<"that">, Empty>, ConsCell<ConsCell<Terminal<"these">, Empty>, ConsCell<ConsCell<Terminal<"those">, Empty>, ConsCell<ConsCell<Terminal<"my">, Empty>, ConsCell<ConsCell<Terminal<"your">, Empty>, ConsCell<ConsCell<Terminal<"his">, Empty>, ConsCell<ConsCell<Terminal<"her">, Empty>, ConsCell<ConsCell<Terminal<"its">, Empty>, ConsCell<ConsCell<Terminal<"our">, Empty>, ConsCell<ConsCell<Terminal<"their">, Empty>, ConsCell<ConsCell<Terminal<"1">, Empty>, ConsCell<ConsCell<Terminal<"2">, Empty>, ConsCell<ConsCell<Terminal<"3">, Empty>, ConsCell<ConsCell<Terminal<"4">, Empty>, ConsCell<ConsCell<Terminal<"5">, Empty>, ConsCell<ConsCell<Terminal<"6">, Empty>, ConsCell<ConsCell<Terminal<"7">, Empty>, ConsCell<ConsCell<Terminal<"8">, Empty>, ConsCell<ConsCell<Terminal<"9">, Empty>, ConsCell<ConsCell<Terminal<"10">, Empty>, ConsCell<ConsCell<Terminal<"100">, Empty>, ConsCell<ConsCell<Terminal<"1000">, Empty>, ConsCell<ConsCell<Terminal<"a few">, Empty>, ConsCell<ConsCell<Terminal<"a little">, Empty>, ConsCell<ConsCell<Terminal<"much">, Empty>, ConsCell<ConsCell<Terminal<"many">, Empty>, ConsCell<ConsCell<Terminal<"a lot of">, Empty>, ConsCell<ConsCell<Terminal<"most">, Empty>, ConsCell<ConsCell<Terminal<"some">, Empty>, ConsCell<ConsCell<Terminal<"any">, Empty>, ConsCell<ConsCell<Terminal<"enough">, Empty>, Empty>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>), ConsCell<(AuxiliaryVerb, ConsCell<ConsCell<Terminal<"will">, Empty>, ConsCell<ConsCell<Terminal<"can">, Empty>, ConsCell<ConsCell<Terminal<"must">, Empty>, ConsCell<ConsCell<Terminal<"should">, Empty>, ConsCell<ConsCell<Terminal<"could">, Empty>, ConsCell<ConsCell<Terminal<"have">, Empty>, ConsCell<ConsCell<Terminal<"be">, Empty>, Empty>>>>>>>), ConsCell<(Adjective, ConsCell<ConsCell<Terminal<"able">, Empty>, ConsCell<ConsCell<Terminal<"bad">, Empty>, ConsCell<ConsCell<Terminal<"best">, Empty>, ConsCell<ConsCell<Terminal<"better">, Empty>, ConsCell<ConsCell<Terminal<"big">, Empty>, ConsCell<ConsCell<Terminal<"black">, Empty>, ConsCell<ConsCell<Terminal<"certain">, Empty>, ConsCell<ConsCell<Terminal<"clear">, Empty>, ConsCell<ConsCell<Terminal<"different">, Empty>, ConsCell<ConsCell<Terminal<"early">, Empty>, ConsCell<ConsCell<Terminal<"easy">, Empty>, ConsCell<ConsCell<Terminal<"economic">, Empty>, ConsCell<ConsCell<Terminal<"federal">, Empty>, ConsCell<ConsCell<Terminal<"free">, Empty>, ConsCell<ConsCell<Terminal<"full">, Empty>, ConsCell<ConsCell<Terminal<"good">, Empty>, ConsCell<ConsCell<Terminal<"great">, Empty>, ConsCell<ConsCell<Terminal<"hard">, Empty>, ConsCell<ConsCell<Terminal<"high">, Empty>, ConsCell<ConsCell<Terminal<"human">, Empty>, ConsCell<ConsCell<Terminal<"important">, Empty>, ConsCell<ConsCell<Terminal<"international">, Empty>, ConsCell<ConsCell<Terminal<"large">, Empty>, ConsCell<ConsCell<Terminal<"late">, Empty>, ConsCell<ConsCell<Terminal<"little">, Empty>, ConsCell<ConsCell<Terminal<"local">, Empty>, ConsCell<ConsCell<Terminal<"long">, Empty>, ConsCell<ConsCell<Terminal<"low">, Empty>, ConsCell<ConsCell<Terminal<"major">, Empty>, ConsCell<ConsCell<Terminal<"military">, Empty>, ConsCell<ConsCell<Terminal<"national">, Empty>, ConsCell<ConsCell<Terminal<"new">, Empty>, ConsCell<ConsCell<Terminal<"old">, Empty>, ConsCell<ConsCell<Terminal<"only">, Empty>, ConsCell<ConsCell<Terminal<"other">, Empty>, ConsCell<ConsCell<Terminal<"political">, Empty>, ConsCell<ConsCell<Terminal<"possible">, Empty>, ConsCell<ConsCell<Terminal<"public">, Empty>, ConsCell<ConsCell<Terminal<"real">, Empty>, ConsCell<ConsCell<Terminal<"recent">, Empty>, ConsCell<ConsCell<Terminal<"right">, Empty>, ConsCell<ConsCell<Terminal<"small">, Empty>, ConsCell<ConsCell<Terminal<"social">, Empty>, ConsCell<ConsCell<Terminal<"special">, Empty>, ConsCell<ConsCell<Terminal<"strong">, Empty>, ConsCell<ConsCell<Terminal<"sure">, Empty>, ConsCell<ConsCell<Terminal<"true">, Empty>, ConsCell<ConsCell<Terminal<"white">, Empty>, ConsCell<ConsCell<Terminal<"whole">, Empty>, ConsCell<ConsCell<Terminal<"young">, Empty>, Empty>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>), ConsCell<(Pronoun, ConsCell<ConsCell<Terminal<"it">, Empty>, ConsCell<ConsCell<Terminal<"I">, Empty>, ConsCell<ConsCell<Terminal<"you">, Empty>, ConsCell<ConsCell<Terminal<"he">, Empty>, ConsCell<ConsCell<Terminal<"they">, Empty>, ConsCell<ConsCell<Terminal<"we">, Empty>, ConsCell<ConsCell<Terminal<"she">, Empty>, ConsCell<ConsCell<Terminal<"who">, Empty>, ConsCell<ConsCell<Terminal<"them">, Empty>, ConsCell<ConsCell<Terminal<"me">, Empty>, ConsCell<ConsCell<Terminal<"him">, Empty>, ConsCell<ConsCell<Terminal<"one">, Empty>, ConsCell<ConsCell<Terminal<"her">, Empty>, ConsCell<ConsCell<Terminal<"us">, Empty>, ConsCell<ConsCell<Terminal<"something">, Empty>, ConsCell<ConsCell<Terminal<"nothing">, Empty>, ConsCell<ConsCell<Terminal<"anything">, Empty>, ConsCell<ConsCell<Terminal<"himself">, Empty>, ConsCell<ConsCell<Terminal<"everything">, Empty>, ConsCell<ConsCell<Terminal<"someone">, Empty>, ConsCell<ConsCell<Terminal<"themselves">, Empty>, ConsCell<ConsCell<Terminal<"everyone">, Empty>, ConsCell<ConsCell<Terminal<"itself">, Empty>, ConsCell<ConsCell<Terminal<"anyone">, Empty>, ConsCell<ConsCell<Terminal<"myself">, Empty>, Empty>>>>>>>>>>>>>>>>>>>>>>>>>), ConsCell<(ProperNoun, ConsCell<ConsCell<Terminal<"Alice">, Empty>, ConsCell<ConsCell<Terminal<"Bob">, Empty>, ConsCell<ConsCell<Terminal<"Charlie">, Empty>, ConsCell<ConsCell<Terminal<"David">, Empty>, Empty>>>>), ConsCell<(Noun, ConsCell<ConsCell<Terminal<"time">, Empty>, ConsCell<ConsCell<Terminal<"year">, Empty>, ConsCell<ConsCell<Terminal<"people">, Empty>, ConsCell<ConsCell<Terminal<"way">, Empty>, ConsCell<ConsCell<Terminal<"day">, Empty>, ConsCell<ConsCell<Terminal<"man">, Empty>, ConsCell<ConsCell<Terminal<"thing">, Empty>, ConsCell<ConsCell<Terminal<"woman">, Empty>, ConsCell<ConsCell<Terminal<"life">, Empty>, ConsCell<ConsCell<Terminal<"child">, Empty>, ConsCell<ConsCell<Terminal<"world">, Empty>, ConsCell<ConsCell<Terminal<"school">, Empty>, ConsCell<ConsCell<Terminal<"state">, Empty>, ConsCell<ConsCell<Terminal<"family">, Empty>, ConsCell<ConsCell<Terminal<"student">, Empty>, ConsCell<ConsCell<Terminal<"group">, Empty>, ConsCell<ConsCell<Terminal<"country">, Empty>, ConsCell<ConsCell<Terminal<"problem">, Empty>, ConsCell<ConsCell<Terminal<"hand">, Empty>, ConsCell<ConsCell<Terminal<"part">, Empty>, ConsCell<ConsCell<Terminal<"place">, Empty>, ConsCell<ConsCell<Terminal<"case">, Empty>, ConsCell<ConsCell<Terminal<"week">, Empty>, ConsCell<ConsCell<Terminal<"company">, Empty>, ConsCell<ConsCell<Terminal<"system">, Empty>, ConsCell<ConsCell<Terminal<"program">, Empty>, ConsCell<ConsCell<Terminal<"question">, Empty>, ConsCell<ConsCell<Terminal<"work">, Empty>, ConsCell<ConsCell<Terminal<"government">, Empty>, ConsCell<ConsCell<Terminal<"number">, Empty>, ConsCell<ConsCell<Terminal<"night">, Empty>, ConsCell<ConsCell<Terminal<"point">, Empty>, ConsCell<ConsCell<Terminal<"home">, Empty>, ConsCell<ConsCell<Terminal<"water">, Empty>, ConsCell<ConsCell<Terminal<"room">, Empty>, ConsCell<ConsCell<Terminal<"mother">, Empty>, ConsCell<ConsCell<Terminal<"area">, Empty>, ConsCell<ConsCell<Terminal<"money">, Empty>, ConsCell<ConsCell<Terminal<"story">, Empty>, ConsCell<ConsCell<Terminal<"fact">, Empty>, ConsCell<ConsCell<Terminal<"month">, Empty>, ConsCell<ConsCell<Terminal<"lot">, Empty>, ConsCell<ConsCell<Terminal<"right">, Empty>, ConsCell<ConsCell<Terminal<"study">, Empty>, ConsCell<ConsCell<Terminal<"book">, Empty>, ConsCell<ConsCell<Terminal<"eye">, Empty>, ConsCell<ConsCell<Terminal<"job">, Empty>, ConsCell<ConsCell<Terminal<"word">, Empty>, ConsCell<ConsCell<Terminal<"business">, Empty>, ConsCell<ConsCell<Terminal<"issue">, Empty>, ConsCell<ConsCell<Terminal<"side">, Empty>, ConsCell<ConsCell<Terminal<"kind">, Empty>, ConsCell<ConsCell<Terminal<"head">, Empty>, ConsCell<ConsCell<Terminal<"house">, Empty>, ConsCell<ConsCell<Terminal<"service">, Empty>, ConsCell<ConsCell<Terminal<"friend">, Empty>, ConsCell<ConsCell<Terminal<"father">, Empty>, ConsCell<ConsCell<Terminal<"power">, Empty>, ConsCell<ConsCell<Terminal<"hour">, Empty>, ConsCell<ConsCell<Terminal<"game">, Empty>, ConsCell<ConsCell<Terminal<"line">, Empty>, ConsCell<ConsCell<Terminal<"end">, Empty>, ConsCell<ConsCell<Terminal<"member">, Empty>, ConsCell<ConsCell<Terminal<"law">, Empty>, ConsCell<ConsCell<Terminal<"car">, Empty>, ConsCell<ConsCell<Terminal<"city">, Empty>, ConsCell<ConsCell<Terminal<"community">, Empty>, ConsCell<ConsCell<Terminal<"name">, Empty>, ConsCell<ConsCell<Terminal<"president">, Empty>, ConsCell<ConsCell<Terminal<"team">, Empty>, ConsCell<ConsCell<Terminal<"minute">, Empty>, ConsCell<ConsCell<Terminal<"idea">, Empty>, ConsCell<ConsCell<Terminal<"kid">, Empty>, ConsCell<ConsCell<Terminal<"body">, Empty>, ConsCell<ConsCell<Terminal<"information">, Empty>, ConsCell<ConsCell<Terminal<"back">, Empty>, ConsCell<ConsCell<Terminal<"parent">, Empty>, ConsCell<ConsCell<Terminal<"face">, Empty>, ConsCell<ConsCell<Terminal<"others">, Empty>, ConsCell<ConsCell<Terminal<"level">, Empty>, ConsCell<ConsCell<Terminal<"office">, Empty>, ConsCell<ConsCell<Terminal<"door">, Empty>, ConsCell<ConsCell<Terminal<"health">, Empty>, ConsCell<ConsCell<Terminal<"person">, Empty>, ConsCell<ConsCell<Terminal<"art">, Empty>, ConsCell<ConsCell<Terminal<"war">, Empty>, ConsCell<ConsCell<Terminal<"history">, Empty>, ConsCell<ConsCell<Terminal<"party">, Empty>, ConsCell<ConsCell<Terminal<"result">, Empty>, ConsCell<ConsCell<Terminal<"change">, Empty>, ConsCell<ConsCell<Terminal<"morning">, Empty>, ConsCell<ConsCell<Terminal<"reason">, Empty>, ConsCell<ConsCell<Terminal<"research">, Empty>, ConsCell<ConsCell<Terminal<"girl">, Empty>, ConsCell<ConsCell<Terminal<"guy">, Empty>, ConsCell<ConsCell<Terminal<"moment">, Empty>, ConsCell<ConsCell<Terminal<"air">, Empty>, ConsCell<ConsCell<Terminal<"teacher">, Empty>, ConsCell<ConsCell<Terminal<"force">, Empty>, ConsCell<ConsCell<Terminal<"education">, Empty>, Empty>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>), ConsCell<(Verb, ConsCell<ConsCell<Terminal<"ask">, Empty>, ConsCell<ConsCell<Terminal<"be">, Empty>, ConsCell<ConsCell<Terminal<"become">, Empty>, ConsCell<ConsCell<Terminal<"begin">, Empty>, ConsCell<ConsCell<Terminal<"call">, Empty>, ConsCell<ConsCell<Terminal<"can">, Empty>, ConsCell<ConsCell<Terminal<"come">, Empty>, ConsCell<ConsCell<Terminal<"could">, Empty>, ConsCell<ConsCell<Terminal<"do">, Empty>, ConsCell<ConsCell<Terminal<"feel">, Empty>, ConsCell<ConsCell<Terminal<"find">, Empty>, ConsCell<ConsCell<Terminal<"get">, Empty>, ConsCell<ConsCell<Terminal<"give">, Empty>, ConsCell<ConsCell<Terminal<"go">, Empty>, ConsCell<ConsCell<Terminal<"have">, Empty>, ConsCell<ConsCell<Terminal<"hear">, Empty>, ConsCell<ConsCell<Terminal<"help">, Empty>, ConsCell<ConsCell<Terminal<"keep">, Empty>, ConsCell<ConsCell<Terminal<"know">, Empty>, ConsCell<ConsCell<Terminal<"leave">, Empty>, ConsCell<ConsCell<Terminal<"let">, Empty>, ConsCell<ConsCell<Terminal<"like">, Empty>, ConsCell<ConsCell<Terminal<"live">, Empty>, ConsCell<ConsCell<Terminal<"look">, Empty>, ConsCell<ConsCell<Terminal<"make">, Empty>, ConsCell<ConsCell<Terminal<"may">, Empty>, ConsCell<ConsCell<Terminal<"mean">, Empty>, ConsCell<ConsCell<Terminal<"might">, Empty>, ConsCell<ConsCell<Terminal<"move">, Empty>, ConsCell<ConsCell<Terminal<"need">, Empty>, ConsCell<ConsCell<Terminal<"play">, Empty>, ConsCell<ConsCell<Terminal<"put">, Empty>, ConsCell<ConsCell<Terminal<"run">, Empty>, ConsCell<ConsCell<Terminal<"say">, Empty>, ConsCell<ConsCell<Terminal<"see">, Empty>, ConsCell<ConsCell<Terminal<"seem">, Empty>, ConsCell<ConsCell<Terminal<"should">, Empty>, ConsCell<ConsCell<Terminal<"show">, Empty>, ConsCell<ConsCell<Terminal<"start">, Empty>, ConsCell<ConsCell<Terminal<"take">, Empty>, ConsCell<ConsCell<Terminal<"talk">, Empty>, ConsCell<ConsCell<Terminal<"tell">, Empty>, ConsCell<ConsCell<Terminal<"think">, Empty>, ConsCell<ConsCell<Terminal<"try">, Empty>, ConsCell<ConsCell<Terminal<"turn">, Empty>, ConsCell<ConsCell<Terminal<"use">, Empty>, ConsCell<ConsCell<Terminal<"want">, Empty>, ConsCell<ConsCell<Terminal<"will">, Empty>, ConsCell<ConsCell<Terminal<"work">, Empty>, ConsCell<ConsCell<Terminal<"would">, Empty>, Empty>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>), Empty>>>>>>>>>>>>>>>>` | |
For more information about this error, try `rustc --explain E0599`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rand = "0.8.3" | |
// regex = "1.5.4" | |
//! README | |
//! ====== | |
//! | |
//! 1. Install rust if not already installed: | |
//! | |
//! ```sh | |
//! curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh | |
//! ``` | |
//! | |
//! 2. Switch to nightly rust: | |
//! | |
//! ```sh | |
//! rustup default nightly | |
//! ``` | |
//! | |
//! 3. Install cargo-single: | |
//! | |
//! ```sh | |
//! cargo install cargo-single | |
//! ``` | |
//! | |
//! 4. Run the program. The first time you run it may take a while, as it needs to install the | |
//! program dependencies and compile the program. | |
//! | |
//! ```sh | |
//! cargo single run random_message.rs | |
//! ``` | |
//! | |
//! 5. Run again for a different message. | |
//! | |
//! ```sh | |
//! cargo single run random_message.rs | |
//! ``` | |
#![feature(negative_impls)] | |
#![feature(auto_traits)] | |
#![feature(min_specialization)] | |
#![feature(trace_macros)] | |
#![feature(adt_const_params)] | |
#![feature(generic_const_exprs)] | |
#![recursion_limit = "256"] | |
trace_macros!(false); | |
use rand::Rng; | |
use regex::{Captures, Regex}; | |
trait TypeList { | |
const LENGTH: usize; | |
fn len(&self) -> usize { | |
Self::LENGTH | |
} | |
} | |
#[derive(Default)] | |
struct Empty; | |
impl TypeList for Empty { | |
const LENGTH: usize = 0; | |
} | |
#[derive(Default)] | |
struct ConsCell<ElementType, TypeListType: TypeList>(ElementType, TypeListType); | |
impl<ElementType, TypeListType: TypeList> TypeList for ConsCell<ElementType, TypeListType> { | |
const LENGTH: usize = TypeListType::LENGTH + 1; | |
} | |
auto trait IsTypeNotEqual {} | |
impl<T> !IsTypeNotEqual for (T, T) {} | |
trait Append<ElementType> { | |
type Appended: TypeList; | |
fn append(self, element: ElementType) -> Self::Appended; | |
} | |
impl<ElementType> Append<ElementType> for Empty { | |
type Appended = ConsCell<ElementType, Empty>; | |
fn append(self, element: ElementType) -> Self::Appended { | |
ConsCell(element, Empty) | |
} | |
} | |
impl<ElementType, ExistingType, TypeListType> Append<ElementType> | |
for ConsCell<ExistingType, TypeListType> | |
where | |
TypeListType: TypeList + Append<ElementType>, | |
{ | |
type Appended = ConsCell<ExistingType, TypeListType::Appended>; | |
fn append(self, element: ElementType) -> Self::Appended { | |
ConsCell(self.0, self.1.append(element)) | |
} | |
} | |
trait Reverse { | |
type Reversed: TypeList; | |
fn reverse(self) -> Self::Reversed; | |
} | |
impl Reverse for Empty { | |
type Reversed = Empty; | |
fn reverse(self) -> Self::Reversed { | |
Empty | |
} | |
} | |
impl<ElementType, TypeListType> Reverse for ConsCell<ElementType, TypeListType> | |
where | |
TypeListType: TypeList + Reverse, | |
TypeListType::Reversed: Append<ElementType>, | |
{ | |
type Reversed = <TypeListType::Reversed as Append<ElementType>>::Appended; | |
fn reverse(self) -> Self::Reversed { | |
self.1.reverse().append(self.0) | |
} | |
} | |
trait KeyValueList {} | |
impl KeyValueList for Empty {} | |
impl<K, V, TypeListType> KeyValueList for ConsCell<(K, V), TypeListType> where | |
TypeListType: TypeList + KeyValueList | |
{ | |
} | |
trait HasKey<K> {} | |
impl<K, V, TypeListType> HasKey<K> for ConsCell<(K, V), TypeListType> where | |
TypeListType: TypeList + KeyValueList | |
{ | |
} | |
impl<Desired, K, V, TypeListType> HasKey<Desired> for ConsCell<(K, V), TypeListType> | |
where | |
TypeListType: TypeList + KeyValueList + HasKey<Desired>, | |
(K, Desired): IsTypeNotEqual, | |
{ | |
} | |
trait NotHasKey<K> {} | |
impl<K> NotHasKey<K> for Empty {} | |
impl<Desired, K, V, TypeListType> NotHasKey<Desired> for ConsCell<(K, V), TypeListType> | |
where | |
TypeListType: TypeList + KeyValueList + NotHasKey<Desired>, | |
(K, Desired): IsTypeNotEqual, | |
{ | |
} | |
trait TypeDictionary {} | |
impl TypeDictionary for Empty {} | |
impl<K, V, TypeListType> TypeDictionary for ConsCell<(K, V), TypeListType> where | |
TypeListType: TypeList + TypeDictionary + NotHasKey<K> | |
{ | |
} | |
trait GetValue<K> { | |
type Value; | |
fn get_value(self) -> Self::Value; | |
} | |
impl<K, V, TypeListType> GetValue<K> for ConsCell<(K, V), TypeListType> | |
where | |
TypeListType: TypeList, | |
{ | |
type Value = V; | |
fn get_value(self) -> V { | |
self.0 .1 | |
} | |
} | |
impl<K, V, Desired, TypeListType> GetValue<Desired> for ConsCell<(K, V), TypeListType> | |
where | |
(K, Desired): IsTypeNotEqual, | |
TypeListType: TypeList + GetValue<Desired>, | |
{ | |
type Value = <TypeListType as GetValue<Desired>>::Value; | |
fn get_value(self) -> Self::Value { | |
self.1.get_value() | |
} | |
} | |
struct Itself; | |
auto trait NonSelfReferential {} | |
impl !NonSelfReferential for Itself {} | |
struct Terminal<const S: &'static str>; | |
auto trait NonTerminal {} | |
impl<const S: &'static str> !NonTerminal for Terminal<S> {} | |
enum GeneratedSymbol { | |
Terminal(&'static str), | |
NonTerminal, | |
} | |
trait GrammarRule<GrammarType: Grammar> { | |
fn generate_random_reversed() -> Vec<GeneratedSymbol>; | |
} | |
impl<GrammarType: Grammar> GrammarRule<GrammarType> for Empty { | |
fn generate_random_reversed() -> Vec<GeneratedSymbol> { | |
Vec::new() | |
} | |
} | |
impl<GrammarType, TypeListType, const S: &'static str> GrammarRule<GrammarType> | |
for ConsCell<Terminal<S>, TypeListType> | |
where | |
GrammarType: Grammar, | |
TypeListType: TypeList + GrammarRule<GrammarType>, | |
{ | |
fn generate_random_reversed() -> Vec<GeneratedSymbol> { | |
let mut s = TypeListType::generate_random_reversed(); | |
s.push(GeneratedSymbol::Terminal(S)); | |
s | |
} | |
} | |
impl<GrammarType, TypeListType> GrammarRule<GrammarType> for ConsCell<Itself, TypeListType> | |
where | |
GrammarType: Grammar, | |
TypeListType: TypeList + GrammarRule<GrammarType>, | |
{ | |
fn generate_random_reversed() -> Vec<GeneratedSymbol> { | |
let mut s = TypeListType::generate_random_reversed(); | |
s.push(GeneratedSymbol::NonTerminal); | |
s | |
} | |
} | |
impl<GrammarType, Symbol, TypeListType> GrammarRule<GrammarType> for ConsCell<Symbol, TypeListType> | |
where | |
GrammarType: Grammar + GetValue<Symbol>, | |
<GrammarType as GetValue<Symbol>>::Value: SymbolDefinition<GrammarType>, | |
Symbol: NonTerminal + NonSelfReferential, | |
TypeListType: TypeList + GrammarRule<GrammarType>, | |
{ | |
fn generate_random_reversed() -> Vec<GeneratedSymbol> { | |
let mut s = TypeListType::generate_random_reversed(); | |
s.extend( | |
<GrammarType as GetValue<Symbol>>::Value::generate_random() | |
.iter() | |
.map(|s| GeneratedSymbol::Terminal(s)), | |
); | |
s | |
} | |
} | |
trait GenerateFromNthRule<GrammarType: Grammar> { | |
fn generate_from_nth_rule(n: usize) -> Vec<GeneratedSymbol>; | |
} | |
impl<GrammarType: Grammar> GenerateFromNthRule<GrammarType> for Empty { | |
fn generate_from_nth_rule(_n: usize) -> Vec<GeneratedSymbol> { | |
panic!(); | |
} | |
} | |
impl<GrammarType, RuleType, TypeListType> GenerateFromNthRule<GrammarType> | |
for ConsCell<RuleType, TypeListType> | |
where | |
GrammarType: Grammar, | |
RuleType: Reverse, | |
RuleType::Reversed: GrammarRule<GrammarType>, | |
TypeListType: TypeList + GenerateFromNthRule<GrammarType>, | |
{ | |
fn generate_from_nth_rule(n: usize) -> Vec<GeneratedSymbol> { | |
if n > 0 { | |
TypeListType::generate_from_nth_rule(n - 1) | |
} else { | |
RuleType::Reversed::generate_random_reversed() | |
} | |
} | |
} | |
trait SymbolDefinition<GrammarType: Grammar + ?Sized> { | |
fn generate_random() -> Vec<&'static str>; | |
} | |
impl<GrammarType, RuleListType> SymbolDefinition<GrammarType> for RuleListType | |
where | |
GrammarType: Grammar, | |
RuleListType: TypeList + GenerateFromNthRule<GrammarType>, | |
{ | |
fn generate_random() -> Vec<&'static str> { | |
let i = rand::thread_rng().gen_range(0..RuleListType::LENGTH); | |
let with_holes = RuleListType::generate_from_nth_rule(i); | |
let mut filled = Vec::new(); | |
for symbol in with_holes { | |
match symbol { | |
GeneratedSymbol::Terminal(s) => filled.push(s), | |
GeneratedSymbol::NonTerminal => filled.extend(Self::generate_random()), | |
} | |
} | |
filled | |
} | |
} | |
trait Grammar { | |
fn generate_random<Symbol>() -> String | |
where | |
Self: GetValue<Symbol>, | |
<Self as GetValue<Symbol>>::Value: SymbolDefinition<Self>; | |
} | |
impl<GrammarType: TypeDictionary> Grammar for GrammarType { | |
fn generate_random<Symbol>() -> String | |
where | |
Self: GetValue<Symbol>, | |
<Self as GetValue<Symbol>>::Value: SymbolDefinition<Self>, | |
{ | |
let symbols = <Self as GetValue<Symbol>>::Value::generate_random(); | |
let string = symbols.join(" "); | |
let punctuation_space_fixed = Regex::new(r"\s(?P<punctuation>[,.?])") | |
.unwrap() | |
.replace_all(&string, "$punctuation"); | |
let sentence_case_fixed = Regex::new(r"(^|[.?])([[:alpha:]])") | |
.unwrap() | |
.replace_all(&punctuation_space_fixed, |caps: &Captures| { | |
format!("{}{}", &caps[1], &caps[2].to_uppercase()) | |
}) | |
.into(); | |
sentence_case_fixed | |
} | |
} | |
macro_rules! grammar_rules { | |
() => { | |
Empty | |
}; | |
($symbol:ty { $($alternatives:tt)* } $($tail:tt)*) => { | |
ConsCell< | |
($symbol, grammar_rules!(@alternatives $($alternatives)*)), | |
grammar_rules!($($tail)*) | |
> | |
}; | |
(@alternatives $($rule:tt),* ; $($($tail:tt),*;)*) => { | |
ConsCell< | |
grammar_rules!(@rule $($rule),*), | |
grammar_rules!(@alternatives $($($tail),*;)*) | |
> | |
}; | |
(@alternatives) => { | |
Empty | |
}; | |
(@rule $symbol:ty $(,$tail:tt)*) => { | |
ConsCell< | |
$symbol, | |
grammar_rules!(@rule $($tail),*) | |
> | |
}; | |
(@rule $symbol:literal $(,$tail:tt)*) => { | |
ConsCell< | |
Terminal<$symbol>, | |
grammar_rules!(@rule $($tail),*) | |
> | |
}; | |
(@rule) => { | |
Empty | |
}; | |
} | |
struct Sentence; | |
struct ComplementizerPhrase; | |
struct PrepositionalPhrase; | |
struct NounPhrase; | |
struct VerbPhrase; | |
struct Preposition; | |
struct Complementizer; | |
struct Nominal; | |
struct Noun; | |
struct Pronoun; | |
struct ProperNoun; | |
struct Determiner; | |
struct Conjunction; | |
struct Adjective; | |
struct Verb; | |
struct AuxiliaryVerb; | |
macro_rules! with_big_vocabulary { | |
($callback:ident { $($args:tt)* }) => { | |
$callback! { | |
$($args)* | |
Conjunction { | |
"and"; | |
"or"; | |
"nor"; | |
"for"; | |
"but"; | |
"yet"; | |
"so"; | |
} | |
Preposition { | |
"to"; | |
"in"; | |
"on"; | |
"at"; | |
"near"; | |
"by"; | |
} | |
Complementizer { | |
"that"; | |
"while"; | |
"since"; | |
"because"; | |
"although"; | |
"if"; | |
"when"; | |
"whether"; | |
"so that"; | |
"as such"; | |
"before"; | |
"after"; | |
"until"; | |
"as long as"; | |
"by the time that"; | |
"once"; | |
"inasmuch as"; | |
} | |
Determiner { | |
"the"; | |
"a"; | |
"an"; | |
"this"; | |
"that"; | |
"these"; | |
"those"; | |
"my"; | |
"your"; | |
"his"; | |
"her"; | |
"its"; | |
"our"; | |
"their"; | |
"1"; | |
"2"; | |
"3"; | |
"4"; | |
"5"; | |
"6"; | |
"7"; | |
"8"; | |
"9"; | |
"10"; | |
"100"; | |
"1000"; | |
"a few"; | |
"a little"; | |
"much"; | |
"many"; | |
"a lot of"; | |
"most"; | |
"some"; | |
"any"; | |
"enough"; | |
} | |
AuxiliaryVerb { | |
"will"; | |
"can"; | |
"must"; | |
"should"; | |
"could"; | |
"have"; | |
"be"; | |
} | |
Adjective { | |
"able"; | |
"bad"; | |
"best"; | |
"better"; | |
"big"; | |
"black"; | |
"certain"; | |
"clear"; | |
"different"; | |
"early"; | |
"easy"; | |
"economic"; | |
"federal"; | |
"free"; | |
"full"; | |
"good"; | |
"great"; | |
"hard"; | |
"high"; | |
"human"; | |
"important"; | |
"international"; | |
"large"; | |
"late"; | |
"little"; | |
"local"; | |
"long"; | |
"low"; | |
"major"; | |
"military"; | |
"national"; | |
"new"; | |
"old"; | |
"only"; | |
"other"; | |
"political"; | |
"possible"; | |
"public"; | |
"real"; | |
"recent"; | |
"right"; | |
"small"; | |
"social"; | |
"special"; | |
"strong"; | |
"sure"; | |
"true"; | |
"white"; | |
"whole"; | |
"young"; | |
} | |
Pronoun { | |
"it"; | |
"I"; | |
"you"; | |
"he"; | |
"they"; | |
"we"; | |
"she"; | |
"who"; | |
"them"; | |
"me"; | |
"him"; | |
"one"; | |
"her"; | |
"us"; | |
"something"; | |
"nothing"; | |
"anything"; | |
"himself"; | |
"everything"; | |
"someone"; | |
"themselves"; | |
"everyone"; | |
"itself"; | |
"anyone"; | |
"myself"; | |
} | |
ProperNoun { | |
"Alice"; | |
"Bob"; | |
"Charlie"; | |
"David"; | |
} | |
Noun { | |
"time"; | |
"year"; | |
"people"; | |
"way"; | |
"day"; | |
"man"; | |
"thing"; | |
"woman"; | |
"life"; | |
"child"; | |
"world"; | |
"school"; | |
"state"; | |
"family"; | |
"student"; | |
"group"; | |
"country"; | |
"problem"; | |
"hand"; | |
"part"; | |
"place"; | |
"case"; | |
"week"; | |
"company"; | |
"system"; | |
"program"; | |
"question"; | |
"work"; | |
"government"; | |
"number"; | |
"night"; | |
"point"; | |
"home"; | |
"water"; | |
"room"; | |
"mother"; | |
"area"; | |
"money"; | |
"story"; | |
"fact"; | |
"month"; | |
"lot"; | |
"right"; | |
"study"; | |
"book"; | |
"eye"; | |
"job"; | |
"word"; | |
"business"; | |
"issue"; | |
"side"; | |
"kind"; | |
"head"; | |
"house"; | |
"service"; | |
"friend"; | |
"father"; | |
"power"; | |
"hour"; | |
"game"; | |
"line"; | |
"end"; | |
"member"; | |
"law"; | |
"car"; | |
"city"; | |
"community"; | |
"name"; | |
"president"; | |
"team"; | |
"minute"; | |
"idea"; | |
"kid"; | |
"body"; | |
"information"; | |
"back"; | |
"parent"; | |
"face"; | |
"others"; | |
"level"; | |
"office"; | |
"door"; | |
"health"; | |
"person"; | |
"art"; | |
"war"; | |
"history"; | |
"party"; | |
"result"; | |
"change"; | |
"morning"; | |
"reason"; | |
"research"; | |
"girl"; | |
"guy"; | |
"moment"; | |
"air"; | |
"teacher"; | |
"force"; | |
"education"; | |
} | |
Verb { | |
"ask"; | |
"be"; | |
"become"; | |
"begin"; | |
"call"; | |
"can"; | |
"come"; | |
"could"; | |
"do"; | |
"feel"; | |
"find"; | |
"get"; | |
"give"; | |
"go"; | |
"have"; | |
"hear"; | |
"help"; | |
"keep"; | |
"know"; | |
"leave"; | |
"let"; | |
"like"; | |
"live"; | |
"look"; | |
"make"; | |
"may"; | |
"mean"; | |
"might"; | |
"move"; | |
"need"; | |
"play"; | |
"put"; | |
"run"; | |
"say"; | |
"see"; | |
"seem"; | |
"should"; | |
"show"; | |
"start"; | |
"take"; | |
"talk"; | |
"tell"; | |
"think"; | |
"try"; | |
"turn"; | |
"use"; | |
"want"; | |
"will"; | |
"work"; | |
"would"; | |
} | |
} | |
}; | |
} | |
#[macro_export] | |
macro_rules! with_test_vocabulary { | |
($callback:ident { $($args:tt)* } ) => { | |
$callback! { | |
$($args)* | |
Conjunction { | |
"and"; | |
} | |
Preposition { | |
"to"; | |
} | |
Complementizer { | |
"that"; | |
} | |
Determiner { | |
"the"; | |
} | |
AuxiliaryVerb { | |
"should"; | |
} | |
Adjective { | |
"best"; | |
} | |
Pronoun { | |
"it"; | |
} | |
ProperNoun { | |
"Bob"; | |
} | |
Noun { | |
"thing"; | |
} | |
Verb { | |
"do"; | |
} | |
} | |
}; | |
} | |
type EnglishGrammar = with_big_vocabulary! { | |
grammar_rules { | |
Sentence { | |
NounPhrase, VerbPhrase, "."; // Declarative. | |
VerbPhrase, "."; // Imperative. | |
AuxiliaryVerb, NounPhrase, VerbPhrase, "?"; // Yes-no question. | |
//ComplementizerPhrase, VerbPhrase, "."; | |
} | |
ComplementizerPhrase { | |
Complementizer, Sentence; | |
} | |
PrepositionalPhrase { | |
Preposition, NounPhrase; | |
} | |
NounPhrase { | |
Pronoun; | |
ProperNoun; | |
Determiner, Nominal; | |
Itself, Conjunction, Itself; | |
} | |
Nominal { | |
Noun; | |
Adjective, Itself; | |
//Itself, PrepositionalPhrase; | |
//Itself, ComplementizerPhrase; | |
// Itself, Conjunction, Itself; | |
} | |
VerbPhrase { | |
Verb; | |
Verb, NounPhrase; | |
Verb, NounPhrase, PrepositionalPhrase; | |
Verb, PrepositionalPhrase; | |
//AuxiliaryVerb, Verb; | |
//AuxiliaryVerb, Verb, NounPhrase; | |
//AuxiliaryVerb, Verb, NounPhrase, PrepositionalPhrase; | |
//AuxiliaryVerb, Verb, PrepositionalPhrase; | |
//Itself, ComplementizerPhrase; | |
// Itself, Conjunction, Itself; | |
} | |
} | |
}; | |
fn main() { | |
println!("{}", EnglishGrammar::generatee_random::<Sentence>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment