Cmpop::as_str

This commit is contained in:
Jeong YunWon 2023-05-29 01:20:13 +09:00
parent 6bf6b29b4d
commit 209dba1eb6
2 changed files with 21 additions and 14 deletions

View file

@ -45,4 +45,21 @@ impl<R> Default for EmptyRange<R> {
}
}
impl Cmpop {
pub fn as_str(&self) -> &'static str {
match self {
Cmpop::Eq => "==",
Cmpop::NotEq => "!=",
Cmpop::Lt => "<",
Cmpop::LtE => "<=",
Cmpop::Gt => ">",
Cmpop::GtE => ">=",
Cmpop::Is => "is",
Cmpop::IsNot => "is not",
Cmpop::In => "in",
Cmpop::NotIn => "not in",
}
}
}
include!("gen/generic.rs");

View file

@ -1,5 +1,5 @@
use crate::ConversionFlag;
use crate::{Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, Expr, Identifier, Operator};
use crate::{Arg, Arguments, Boolop, Comprehension, Constant, Expr, Identifier, Operator};
use std::fmt;
mod precedence {
@ -285,19 +285,9 @@ impl<'a> Unparser<'a> {
let new_lvl = precedence::CMP + 1;
self.unparse_expr(left, new_lvl)?;
for (op, cmp) in ops.iter().zip(comparators) {
let op = match op {
Cmpop::Eq => " == ",
Cmpop::NotEq => " != ",
Cmpop::Lt => " < ",
Cmpop::LtE => " <= ",
Cmpop::Gt => " > ",
Cmpop::GtE => " >= ",
Cmpop::Is => " is ",
Cmpop::IsNot => " is not ",
Cmpop::In => " in ",
Cmpop::NotIn => " not in ",
};
self.p(op)?;
self.p(" ")?;
self.p(op.as_str())?;
self.p(" ")?;
self.unparse_expr(cmp, new_lvl)?;
}
})