mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 21:55:26 +00:00
Cmpop::as_str
This commit is contained in:
parent
6bf6b29b4d
commit
209dba1eb6
2 changed files with 21 additions and 14 deletions
|
@ -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");
|
||||
|
|
|
@ -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)?;
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue