added some display
This commit is contained in:
parent
4edede94cb
commit
9032e00b72
|
@ -1 +1 @@
|
|||
{"categories":[{"name":"todo","content":[{"name":"erreur calcul bool/nombre","description":"affiche element precedent lorsque mauvais enchainement","id":1},{"name":"display element","description":"for better print","id":6},{"name":"if","description":"implémente if avec des guillemets de délimitation","id":1},{"name":"scope variable","description":"// Hello there","id":6},{"name":"while","description":"implémente un while","id":2},{"name":"else","description":"// Hello there","id":7},{"name":"break","description":"// Hello there","id":8},{"name":"continue","description":"// Hello there","id":9},{"name":"compilation","description":"// Hello there","id":3},{"name":"puis à la ligne, alinéa","description":"// Hello there","id":1}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"comparaison","description":"// Hello there","id":2},{"name":"booleen type","description":"// Hello there","id":4},{"name":"soixante-dix","description":"// Hello there","id":1},{"name":"parenthese comparaison","description":"// Hello there","id":1},{"name":"test comparaison","description":"// Hello there","id":4},{"name":"error ligne compilation","description":"// Hello there","id":2},{"name":"commentaires","description":"// Hello there","id":3},{"name":"compile time verification","description":"odre des termes rpn","id":1},{"name":"test multiple space in texte","description":"// Hello there","id":3},{"name":"test puis in texte","description":"// Hello there","id":2},{"name":"enchainement puis","description":"// Hello there","id":5},{"name":"guillemet mal ferme","description":"// Hello there","id":4}]},{"name":"bug","content":[]},{"name":"to test","content":[{"name":"tests mod","description":"// Hello there","id":3}]},{"name":"bonus","content":[{"name":"stop cheating with \"-\"","description":"// Hello there","id":5},{"name":"affiche ligne et position erreur","description":"// Hello there","id":1}]},{"name":"+","content":[]}]}
|
||||
{"categories":[{"name":"todo","content":[{"name":"erreur calcul bool/nombre","description":"affiche element precedent lorsque mauvais enchainement","id":1},{"name":"display element","description":"for better print","id":6},{"name":"if","description":"implémente if avec des guillemets de délimitation","id":1},{"name":"scope variable","description":"// Hello there","id":6},{"name":"while","description":"implémente un while","id":2},{"name":"else","description":"// Hello there","id":7},{"name":"break","description":"// Hello there","id":8},{"name":"continue","description":"// Hello there","id":9},{"name":"compilation","description":"// Hello there","id":3},{"name":"puis à la ligne, alinéa","description":"// Hello there","id":1}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"comparaison","description":"// Hello there","id":2},{"name":"booleen type","description":"// Hello there","id":4},{"name":"soixante-dix","description":"// Hello there","id":1},{"name":"parenthese comparaison","description":"// Hello there","id":1},{"name":"test comparaison","description":"// Hello there","id":4},{"name":"error ligne compilation","description":"// Hello there","id":2},{"name":"commentaires","description":"// Hello there","id":3},{"name":"compile time verification","description":"odre des termes rpn","id":1},{"name":"test multiple space in texte","description":"// Hello there","id":3},{"name":"test puis in texte","description":"// Hello there","id":2},{"name":"enchainement puis","description":"// Hello there","id":5},{"name":"guillemet mal ferme","description":"// Hello there","id":4}]},{"name":"bug","content":[]},{"name":"to test","content":[{"name":"tests mod","description":"// Hello there","id":3},{"name":"test variable","description":"// Hello there","id":2}]},{"name":"bonus","content":[{"name":"stop cheating with \"-\"","description":"// Hello there","id":5},{"name":"affiche ligne et position erreur","description":"// Hello there","id":1}]},{"name":"+","content":[]}]}
|
|
@ -105,7 +105,7 @@ impl Pendragon {
|
|||
}
|
||||
} else if let Ok(type_comparaison) = texte_comme_comparaison(autre) {
|
||||
if let Some(comparaison) = possible_comparaison {
|
||||
return Err(ErreurPendragon::BooleenInvalide(format!("besoin d'un operateur booleen entre {:?} et {:?}", comparaison, type_comparaison)))
|
||||
return Err(ErreurPendragon::BooleenInvalide(format!("besoin d'un operateur booleen entre {} et {}", comparaison, type_comparaison)))
|
||||
}
|
||||
let mut comparaison = Comparaison::nouvelle();
|
||||
let nombre_parenthese = compare_parentheses(&pile_inconnu);
|
||||
|
@ -134,7 +134,7 @@ impl Pendragon {
|
|||
}
|
||||
if !pile_inconnu.is_empty() {
|
||||
let Some(mut comparaison) = possible_comparaison else {
|
||||
return Err(ErreurPendragon::BooleenInvalide(format!("{:?}", pile_inconnu)))
|
||||
return Err(ErreurPendragon::BooleenInvalide(format!("[{}]", pile_inconnu.join(","))))
|
||||
};
|
||||
self.ajoute_comparaison_membre(&mut comparaison, &pile_inconnu.join(" "))?;
|
||||
expression.push(Element::Comparaison(comparaison.clone()));
|
||||
|
@ -156,7 +156,7 @@ impl Pendragon {
|
|||
return Ok(());
|
||||
}
|
||||
let Some(ancienne_comparaison) = possible_comparaison else {
|
||||
return Err(ErreurPendragon::BooleenInvalide(format!("{:?}", pile_inconnu)))
|
||||
return Err(ErreurPendragon::BooleenInvalide(format!("[{}]", pile_inconnu.join(","))))
|
||||
};
|
||||
let mut comparaison = ancienne_comparaison.clone();
|
||||
self.ajoute_comparaison_membre(&mut comparaison, &pile_inconnu.join(" "))?;
|
||||
|
@ -188,7 +188,7 @@ impl Pendragon {
|
|||
};
|
||||
if element_de_comparaison.type_element() != element.type_element() {
|
||||
return Err(ErreurPendragon::MauvaisType(
|
||||
format!("{:?}", element), element.type_element().nom(),
|
||||
format!("{}", element), element.type_element().nom(),
|
||||
element_de_comparaison.type_element().nom()))
|
||||
}
|
||||
comparaison.membre_b = membre;
|
||||
|
@ -232,7 +232,7 @@ pub fn calcule_booleen(expression: Vec<Element>, variables: &HashMap<String, Ele
|
|||
continue
|
||||
}
|
||||
let Element::Operateur(ref operateur) = element else {
|
||||
return Err(ErreurPendragon::MauvaisArgument(format!("{:?}, attendais un opérateur", element)))
|
||||
return Err(ErreurPendragon::MauvaisArgument(format!("{}, attendais un opérateur", element)))
|
||||
};
|
||||
let Some(booleen_a) = pile.pop() else {
|
||||
return Err(ErreurPendragon::CalculBooleen("la pile est vide".into()))
|
||||
|
@ -253,7 +253,7 @@ pub fn calcule_booleen(expression: Vec<Element>, variables: &HashMap<String, Ele
|
|||
};
|
||||
pile.push(booleen_a || booleen_b);
|
||||
}
|
||||
_ => return Err(ErreurPendragon::MauvaisArgument(format!("{:?}, attendais un opérateur booléen", element)))
|
||||
_ => return Err(ErreurPendragon::MauvaisArgument(format!("{}, attendais un opérateur booléen", element)))
|
||||
}
|
||||
}
|
||||
if pile.len() > 1 {
|
||||
|
|
|
@ -69,6 +69,67 @@ impl fmt::Display for Commande {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Element {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//'
|
||||
match self {
|
||||
Self::Entier(nombre) => write!(f, "{}", nombre),
|
||||
Self::Texte(texte) => write!(f, "\"{}\"", texte),
|
||||
Self::Booleen(booleen) => write!(f, "{}", booleen),
|
||||
Self::Variable(nom, type_variable) => write!(f, "{}:{}", nom, type_variable.nom()),
|
||||
Self::Operateur(operateur) => write!(f, "{}", operateur),
|
||||
Self::Comparaison(comparaison) => write!(f, "{}.", comparaison),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Comparaison {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//'
|
||||
let mut texte_membre_a: String = String::new();
|
||||
for element in &self.membre_a {
|
||||
texte_membre_a += &format!("{} ", element);
|
||||
}
|
||||
let mut texte_membre_b: String = String::new();
|
||||
for element in &self.membre_b {
|
||||
texte_membre_b += &format!(" {}", element);
|
||||
}
|
||||
write!(f, "({}{:?}{})",
|
||||
texte_membre_a,
|
||||
self.type_comparaison,
|
||||
texte_membre_b,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for TypeComparaison {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//'
|
||||
match self {
|
||||
Self::Egal => write!(f, "=="),
|
||||
Self::Different => write!(f, "!="),
|
||||
Self::SuperieurEgal => write!(f, ">="),
|
||||
Self::InferieurEgal => write!(f, "<="),
|
||||
Self::Superieur => write!(f, ">"),
|
||||
Self::Inferieur => write!(f, "<"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Operateur {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//'
|
||||
match self {
|
||||
Self::Ou => write!(f, "ou"),
|
||||
Self::Et => write!(f, "et"),
|
||||
Self::Non => write!(f, "non"),
|
||||
Self::ParentheseBooleen => write!(f, "["),
|
||||
Self::Puis => write!(f, ";"),
|
||||
Self::Plus => write!(f, "+"),
|
||||
Self::Moins => write!(f, "-"),
|
||||
Self::Fois => write!(f, "*"),
|
||||
Self::Divise => write!(f, "/"),
|
||||
Self::ParentheseEntier => write!(f, "("),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Programme {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//'
|
||||
let mut texte: String = format!("variables : {:?}", self.variables);
|
||||
|
|
|
@ -131,7 +131,7 @@ pub fn calcule_nombre(expression: Vec<Element>, variables: &HashMap<String, Elem
|
|||
}
|
||||
}
|
||||
let Element::Operateur(ref operateur) = element else {
|
||||
return Err(ErreurPendragon::MauvaisArgument(format!("{:?}, attendais un opérateur", element)))
|
||||
return Err(ErreurPendragon::MauvaisArgument(format!("{}, attendais un opérateur", element)))
|
||||
};
|
||||
let Some(nombre_a) = pile.pop() else {
|
||||
return Err(ErreurPendragon::CalculEntier("la pile est vide".into()))
|
||||
|
@ -145,7 +145,7 @@ pub fn calcule_nombre(expression: Vec<Element>, variables: &HashMap<String, Elem
|
|||
}
|
||||
Operateur::Moins => {
|
||||
if nombre_b < nombre_a {
|
||||
return Err(ErreurPendragon::CalculEntier(format!("a essayé de soustraire {} à {}", nombre_a, nombre_b)))
|
||||
return Err(ErreurPendragon::CalculEntier(format!("a essayé de soustraire '{}' à '{}'", nombre::nombre_comme_texte(nombre_a), nombre::nombre_comme_texte(nombre_b))))
|
||||
}
|
||||
pile.push(nombre_b - nombre_a);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ pub fn calcule_nombre(expression: Vec<Element>, variables: &HashMap<String, Elem
|
|||
Operateur::Divise => {
|
||||
pile.push(nombre_b / nombre_a);
|
||||
}
|
||||
_ => return Err(ErreurPendragon::MauvaisArgument(format!("{:?}, attendais un opérateur d'entiers", element)))
|
||||
_ => return Err(ErreurPendragon::MauvaisArgument(format!("'{}', attendais un opérateur d'entiers", element)))
|
||||
}
|
||||
}
|
||||
if pile.len() > 1 {
|
||||
|
|
|
@ -174,10 +174,10 @@ impl Element {
|
|||
return Ok(*self != element)
|
||||
}
|
||||
let Self::Entier(nombre_a) = self else {
|
||||
return Err(ErreurPendragon::ComparaisonInvalide(format!("comparaison numérique avec {:?}", self)))
|
||||
return Err(ErreurPendragon::ComparaisonInvalide(format!("comparaison numérique avec {}", self)))
|
||||
};
|
||||
let Self::Entier(nombre_b) = element else {
|
||||
return Err(ErreurPendragon::ComparaisonInvalide(format!("comparaison numérique avec {:?}", element)))
|
||||
return Err(ErreurPendragon::ComparaisonInvalide(format!("comparaison numérique avec {}", element)))
|
||||
};
|
||||
match comparaison {
|
||||
TypeComparaison::SuperieurEgal => Ok(*nombre_a >= nombre_b),
|
||||
|
@ -245,7 +245,7 @@ impl Comparaison {
|
|||
self.type_comparaison = Some(type_comparaison);
|
||||
return Ok(());
|
||||
}
|
||||
return Err(ErreurPendragon::ComparaisonInvalide(format!("voulait comparer {} avec {:?}", element.type_element().nom(), type_comparaison)))
|
||||
return Err(ErreurPendragon::ComparaisonInvalide(format!("voulait comparer {} avec {}", element.type_element().nom(), type_comparaison)))
|
||||
}
|
||||
|
||||
pub fn calcule(&self, variables: &HashMap<String, Element>) -> Result<bool, ErreurPendragon> {
|
||||
|
|
|
@ -16,7 +16,7 @@ impl Pendragon {
|
|||
let element_texte = pile_texte[1..pile_texte.len()].join(" ");
|
||||
if let Some(dernier_element) = expression.last() {
|
||||
if *dernier_element != Element::Operateur(Operateur::Puis) {
|
||||
return Err(ErreurPendragon::TexteInvalide(format!("attends un 'puis' entre '{:?}' et '{}'", dernier_element, element)))
|
||||
return Err(ErreurPendragon::TexteInvalide(format!("attends un 'puis' entre '{}' et '{}'", dernier_element, element)))
|
||||
}
|
||||
}
|
||||
expression.push(Element::Texte(element_texte));
|
||||
|
@ -110,7 +110,7 @@ pub fn calcule_texte(expression: Vec<Element>, variables: &HashMap<String, Eleme
|
|||
texte += &contenu;
|
||||
}
|
||||
autre => {
|
||||
return Err(ErreurPendragon::MauvaisArgument(format!("{:?}", autre)))
|
||||
return Err(ErreurPendragon::MauvaisArgument(format!("{}", autre)))
|
||||
}
|
||||
}
|
||||
pile = Vec::new();
|
||||
|
|
Loading…
Reference in a new issue