Compare commits
2 commits
hoofd
...
principale
Author | SHA1 | Date | |
---|---|---|---|
67b763f20f | |||
66718968a4 |
60
README.md
60
README.md
|
@ -22,34 +22,52 @@ convenience.
|
||||||
|
|
||||||
Here's an example of what can be achieved with Rouille:
|
Here's an example of what can be achieved with Rouille:
|
||||||
|
|
||||||
|
### struct and impl (aka convention et réalisation)
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
utilisons std::collections::Dictionnaire comme Dico;
|
rouille::rouille! {
|
||||||
|
utilisons std::collections::Dictionnaire comme Dico;
|
||||||
|
|
||||||
convention CléValeur {
|
convention CléValeur {
|
||||||
fonction écrire(&soi, clé: Chaine, valeur: Chaine);
|
fonction écrire(&soi, clé: Chaine, valeur: Chaine);
|
||||||
fonction lire(&soi, clé: Chaine) -> PeutÊtre<&Chaine>;
|
fonction lire(&soi, clé: Chaine) -> PeutÊtre<&Chaine>;
|
||||||
}
|
|
||||||
|
|
||||||
statique mutable DICTIONNAIRE: PeutÊtre<Dico<Chaine, Chaine>> = Rien;
|
|
||||||
|
|
||||||
structure Concrète;
|
|
||||||
|
|
||||||
réalisation CléValeur pour Concrète {
|
|
||||||
fonction écrire(&soi, clé: Chaine, valeur: Chaine) {
|
|
||||||
soit dico = dangereux {
|
|
||||||
DICTIONNAIRE.prendre_ou_insérer_avec(Défaut::défaut)
|
|
||||||
};
|
|
||||||
dico.insérer(clé, valeur);
|
|
||||||
}
|
}
|
||||||
fonction lire(&soi, clé: Chaine) -> PeutÊtre<&Chaine> {
|
|
||||||
soit dico = dangereux {
|
statique mutable DICTIONNAIRE: PeutÊtre<Dico<Chaine, Chaine>> = Rien;
|
||||||
DICTIONNAIRE.prendre_ou_insérer_avec(Défaut::défaut)
|
|
||||||
};
|
structure Concrète;
|
||||||
dico.lire(&clé)
|
|
||||||
|
réalisation CléValeur pour Concrète {
|
||||||
|
fonction écrire(&soi, clé: Chaine, valeur: Chaine) {
|
||||||
|
soit dico = dangereux {
|
||||||
|
DICTIONNAIRE.prendre_ou_insérer_avec(Défaut::défaut)
|
||||||
|
};
|
||||||
|
dico.insérer(clé, valeur);
|
||||||
|
}
|
||||||
|
fonction lire(&soi, clé: Chaine) -> Résultat<PeutÊtre<&Chaine>, Chaine> {
|
||||||
|
si soit Quelque(dico) = dangereux { DICTIONNAIRE.en_réf() } {
|
||||||
|
Bien(dico.lire(&clé))
|
||||||
|
} sinon {
|
||||||
|
Arf("fetchez le dico".vers())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Support for regional languages
|
||||||
|
|
||||||
|
```rust
|
||||||
|
#[légal(code_inaccessible)]
|
||||||
|
fonction secondaire() {
|
||||||
|
merde!("oh non"); // for the true French experience
|
||||||
|
calisse!("tabernacle"); // for friends speaking fr-ca
|
||||||
|
oups!("fetchez la vache"); // in SFW contexts
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other examples
|
||||||
|
|
||||||
See the [examples](./examples/src/main.rs) to get a rough sense of the whole
|
See the [examples](./examples/src/main.rs) to get a rough sense of the whole
|
||||||
syntax. Voilà, that's it.
|
syntax. Voilà, that's it.
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ rouille::rouille! {
|
||||||
|
|
||||||
convention CléValeur {
|
convention CléValeur {
|
||||||
fonction écrire(&soi, clé: Chaine, valeur: Chaine);
|
fonction écrire(&soi, clé: Chaine, valeur: Chaine);
|
||||||
fonction lire(&soi, clé: Chaine) -> PeutÊtre<&Chaine>;
|
fonction lire(&soi, clé: Chaine) -> Résultat<PeutÊtre<&Chaine>, Chaine>;
|
||||||
}
|
}
|
||||||
|
|
||||||
statique mutable DICTIONNAIRE: PeutÊtre<Dico<Chaine, Chaine>> = Rien;
|
statique mutable DICTIONNAIRE: PeutÊtre<Dico<Chaine, Chaine>> = Rien;
|
||||||
|
@ -19,11 +19,12 @@ rouille::rouille! {
|
||||||
};
|
};
|
||||||
dico.insérer(clé, valeur);
|
dico.insérer(clé, valeur);
|
||||||
}
|
}
|
||||||
fonction lire(&soi, clé: Chaine) -> PeutÊtre<&Chaine> {
|
fonction lire(&soi, clé: Chaine) -> Résultat<PeutÊtre<&Chaine>, Chaine> {
|
||||||
soit dico = dangereux {
|
si soit Quelque(dico) = dangereux { DICTIONNAIRE.en_réf() } {
|
||||||
DICTIONNAIRE.prendre_ou_insérer_avec(Défaut::défaut)
|
Bien(dico.lire(&clé))
|
||||||
};
|
} sinon {
|
||||||
dico.lire(&clé)
|
Arf("fetchez le dico".vers())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ rouille::rouille! {
|
||||||
fonction principale() {
|
fonction principale() {
|
||||||
soit mutable x = 31;
|
soit mutable x = 31;
|
||||||
|
|
||||||
correspond x {
|
selon x {
|
||||||
42 => {
|
42 => {
|
||||||
affiche!("omelette du fromage")
|
affiche!("omelette du fromage")
|
||||||
}
|
}
|
||||||
|
@ -71,5 +72,14 @@ rouille::rouille! {
|
||||||
12
|
12
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secondaire();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[légal(code_inaccessible)]
|
||||||
|
fonction secondaire() {
|
||||||
|
merde!("oh non"); // for the true French experience
|
||||||
|
calisse!("tabernacle"); // for friends speaking fr-ca
|
||||||
|
oups!("fetchez la vache"); // in SFW contexts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,24 +22,26 @@ fn replace_ident(ident: Ident) -> Option<TokenTree> {
|
||||||
"boucle" => "loop",
|
"boucle" => "loop",
|
||||||
"bouge" => "move",
|
"bouge" => "move",
|
||||||
"cagette" => "crate",
|
"cagette" => "crate",
|
||||||
|
"code_inaccessible" => "unreachable_code",
|
||||||
"comme" => "as",
|
"comme" => "as",
|
||||||
"constant" => "const",
|
"constant" => "const",
|
||||||
"correspond" => "match",
|
"convention" => "trait",
|
||||||
"dangereux" => "unsafe",
|
"dangereux" => "unsafe",
|
||||||
"de" => "in",
|
"de" => "in",
|
||||||
"depuis" => "from",
|
"depuis" => "from",
|
||||||
"dynamique" => "dyn",
|
"dynamique" => "dyn",
|
||||||
"déballer" => "unwrap",
|
"déballer" => "unwrap",
|
||||||
"défaut" => "default",
|
"défaut" => "default",
|
||||||
|
"en_réf" => "as_ref",
|
||||||
"es" => "io",
|
"es" => "io",
|
||||||
"externe" => "extern",
|
"externe" => "extern",
|
||||||
"faux" => "false",
|
"faux" => "false",
|
||||||
"fonction" => "fn",
|
"fonction" => "fn",
|
||||||
"génial" => "super",
|
"génial" => "super",
|
||||||
"réalisation" => "impl",
|
|
||||||
"insérer" => "insert",
|
"insérer" => "insert",
|
||||||
"convention" => "trait",
|
|
||||||
"lire" => "get",
|
"lire" => "get",
|
||||||
|
"légal" => "allow",
|
||||||
|
"merde" | "calisse" | "oups" => "panic",
|
||||||
"module" => "mod",
|
"module" => "mod",
|
||||||
"mutable" => "mut",
|
"mutable" => "mut",
|
||||||
"nouveau" => "new",
|
"nouveau" => "new",
|
||||||
|
@ -50,6 +52,9 @@ fn replace_ident(ident: Ident) -> Option<TokenTree> {
|
||||||
"public" => "pub",
|
"public" => "pub",
|
||||||
"que" => None?,
|
"que" => None?,
|
||||||
"renvoie" => "return",
|
"renvoie" => "return",
|
||||||
|
"réalisation" => "impl",
|
||||||
|
"réf" => "ref",
|
||||||
|
"selon" => "match",
|
||||||
"si" => "if",
|
"si" => "if",
|
||||||
"sinon" => "else",
|
"sinon" => "else",
|
||||||
"soi" => "self",
|
"soi" => "self",
|
||||||
|
@ -59,6 +64,7 @@ fn replace_ident(ident: Ident) -> Option<TokenTree> {
|
||||||
"suppose" => "expect",
|
"suppose" => "expect",
|
||||||
"tant" => "while",
|
"tant" => "while",
|
||||||
"utilisons" => "use",
|
"utilisons" => "use",
|
||||||
|
"vers" => "into",
|
||||||
"vrai" => "true",
|
"vrai" => "true",
|
||||||
"énumération" => "enum",
|
"énumération" => "enum",
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue