mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-09 22:25:23 +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");
|
include!("gen/generic.rs");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::ConversionFlag;
|
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;
|
use std::fmt;
|
||||||
|
|
||||||
mod precedence {
|
mod precedence {
|
||||||
|
@ -285,19 +285,9 @@ impl<'a> Unparser<'a> {
|
||||||
let new_lvl = precedence::CMP + 1;
|
let new_lvl = precedence::CMP + 1;
|
||||||
self.unparse_expr(left, new_lvl)?;
|
self.unparse_expr(left, new_lvl)?;
|
||||||
for (op, cmp) in ops.iter().zip(comparators) {
|
for (op, cmp) in ops.iter().zip(comparators) {
|
||||||
let op = match op {
|
self.p(" ")?;
|
||||||
Cmpop::Eq => " == ",
|
self.p(op.as_str())?;
|
||||||
Cmpop::NotEq => " != ",
|
self.p(" ")?;
|
||||||
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.unparse_expr(cmp, new_lvl)?;
|
self.unparse_expr(cmp, new_lvl)?;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue