Refine op-assignment.

This commit is contained in:
Stephen Chung
2021-04-24 11:55:40 +08:00
parent e58b57b6e7
commit 61b559a58f
5 changed files with 64 additions and 21 deletions

View File

@@ -578,6 +578,25 @@ impl Token {
}
}
/// Is this token an op-assignment operator?
#[inline]
pub fn is_op_assignment(&self) -> bool {
match self {
Self::PlusAssign
| Self::MinusAssign
| Self::MultiplyAssign
| Self::DivideAssign
| Self::LeftShiftAssign
| Self::RightShiftAssign
| Self::ModuloAssign
| Self::PowerOfAssign
| Self::AndAssign
| Self::OrAssign
| Self::XOrAssign => true,
_ => false,
}
}
/// Get the corresponding operator of the token if it is an op-assignment operator.
pub fn map_op_assignment(&self) -> Option<Self> {
Some(match self {
@@ -596,6 +615,25 @@ impl Token {
})
}
/// Has this token a corresponding op-assignment operator?
#[inline]
pub fn has_op_assignment(&self) -> bool {
match self {
Self::Plus
| Self::Minus
| Self::Multiply
| Self::Divide
| Self::LeftShift
| Self::RightShift
| Self::Modulo
| Self::PowerOf
| Self::Ampersand
| Self::Pipe
| Self::XOr => true,
_ => false,
}
}
/// Get the corresponding op-assignment operator of the token.
pub fn make_op_assignment(&self) -> Option<Self> {
Some(match self {