mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Convert more tokens
This commit is contained in:
parent
548f562dda
commit
779f06ed77
5 changed files with 34 additions and 268 deletions
|
@ -1410,208 +1410,6 @@ impl AstToken for RangeSeparator {
|
|||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum BinOp {
|
||||
Pipepipe(Pipepipe),
|
||||
Ampamp(Ampamp),
|
||||
Eqeq(Eqeq),
|
||||
Neq(Neq),
|
||||
Lteq(Lteq),
|
||||
Gteq(Gteq),
|
||||
LAngle(LAngle),
|
||||
RAngle(RAngle),
|
||||
Plus(Plus),
|
||||
Star(Star),
|
||||
Minus(Minus),
|
||||
Slash(Slash),
|
||||
Percent(Percent),
|
||||
Shl(Shl),
|
||||
Shr(Shr),
|
||||
Caret(Caret),
|
||||
Pipe(Pipe),
|
||||
Amp(Amp),
|
||||
Eq(Eq),
|
||||
Pluseq(Pluseq),
|
||||
Slasheq(Slasheq),
|
||||
Stareq(Stareq),
|
||||
Percenteq(Percenteq),
|
||||
Shreq(Shreq),
|
||||
Shleq(Shleq),
|
||||
Minuseq(Minuseq),
|
||||
Pipeeq(Pipeeq),
|
||||
Ampeq(Ampeq),
|
||||
Careteq(Careteq),
|
||||
}
|
||||
impl From<Pipepipe> for BinOp {
|
||||
fn from(node: Pipepipe) -> BinOp { BinOp::Pipepipe(node) }
|
||||
}
|
||||
impl From<Ampamp> for BinOp {
|
||||
fn from(node: Ampamp) -> BinOp { BinOp::Ampamp(node) }
|
||||
}
|
||||
impl From<Eqeq> for BinOp {
|
||||
fn from(node: Eqeq) -> BinOp { BinOp::Eqeq(node) }
|
||||
}
|
||||
impl From<Neq> for BinOp {
|
||||
fn from(node: Neq) -> BinOp { BinOp::Neq(node) }
|
||||
}
|
||||
impl From<Lteq> for BinOp {
|
||||
fn from(node: Lteq) -> BinOp { BinOp::Lteq(node) }
|
||||
}
|
||||
impl From<Gteq> for BinOp {
|
||||
fn from(node: Gteq) -> BinOp { BinOp::Gteq(node) }
|
||||
}
|
||||
impl From<LAngle> for BinOp {
|
||||
fn from(node: LAngle) -> BinOp { BinOp::LAngle(node) }
|
||||
}
|
||||
impl From<RAngle> for BinOp {
|
||||
fn from(node: RAngle) -> BinOp { BinOp::RAngle(node) }
|
||||
}
|
||||
impl From<Plus> for BinOp {
|
||||
fn from(node: Plus) -> BinOp { BinOp::Plus(node) }
|
||||
}
|
||||
impl From<Star> for BinOp {
|
||||
fn from(node: Star) -> BinOp { BinOp::Star(node) }
|
||||
}
|
||||
impl From<Minus> for BinOp {
|
||||
fn from(node: Minus) -> BinOp { BinOp::Minus(node) }
|
||||
}
|
||||
impl From<Slash> for BinOp {
|
||||
fn from(node: Slash) -> BinOp { BinOp::Slash(node) }
|
||||
}
|
||||
impl From<Percent> for BinOp {
|
||||
fn from(node: Percent) -> BinOp { BinOp::Percent(node) }
|
||||
}
|
||||
impl From<Shl> for BinOp {
|
||||
fn from(node: Shl) -> BinOp { BinOp::Shl(node) }
|
||||
}
|
||||
impl From<Shr> for BinOp {
|
||||
fn from(node: Shr) -> BinOp { BinOp::Shr(node) }
|
||||
}
|
||||
impl From<Caret> for BinOp {
|
||||
fn from(node: Caret) -> BinOp { BinOp::Caret(node) }
|
||||
}
|
||||
impl From<Pipe> for BinOp {
|
||||
fn from(node: Pipe) -> BinOp { BinOp::Pipe(node) }
|
||||
}
|
||||
impl From<Amp> for BinOp {
|
||||
fn from(node: Amp) -> BinOp { BinOp::Amp(node) }
|
||||
}
|
||||
impl From<Eq> for BinOp {
|
||||
fn from(node: Eq) -> BinOp { BinOp::Eq(node) }
|
||||
}
|
||||
impl From<Pluseq> for BinOp {
|
||||
fn from(node: Pluseq) -> BinOp { BinOp::Pluseq(node) }
|
||||
}
|
||||
impl From<Slasheq> for BinOp {
|
||||
fn from(node: Slasheq) -> BinOp { BinOp::Slasheq(node) }
|
||||
}
|
||||
impl From<Stareq> for BinOp {
|
||||
fn from(node: Stareq) -> BinOp { BinOp::Stareq(node) }
|
||||
}
|
||||
impl From<Percenteq> for BinOp {
|
||||
fn from(node: Percenteq) -> BinOp { BinOp::Percenteq(node) }
|
||||
}
|
||||
impl From<Shreq> for BinOp {
|
||||
fn from(node: Shreq) -> BinOp { BinOp::Shreq(node) }
|
||||
}
|
||||
impl From<Shleq> for BinOp {
|
||||
fn from(node: Shleq) -> BinOp { BinOp::Shleq(node) }
|
||||
}
|
||||
impl From<Minuseq> for BinOp {
|
||||
fn from(node: Minuseq) -> BinOp { BinOp::Minuseq(node) }
|
||||
}
|
||||
impl From<Pipeeq> for BinOp {
|
||||
fn from(node: Pipeeq) -> BinOp { BinOp::Pipeeq(node) }
|
||||
}
|
||||
impl From<Ampeq> for BinOp {
|
||||
fn from(node: Ampeq) -> BinOp { BinOp::Ampeq(node) }
|
||||
}
|
||||
impl From<Careteq> for BinOp {
|
||||
fn from(node: Careteq) -> BinOp { BinOp::Careteq(node) }
|
||||
}
|
||||
impl std::fmt::Display for BinOp {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl AstToken for BinOp {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
PIPEPIPE | AMPAMP | EQEQ | NEQ | LTEQ | GTEQ | L_ANGLE | R_ANGLE | PLUS | STAR
|
||||
| MINUS | SLASH | PERCENT | SHL | SHR | CARET | PIPE | AMP | EQ | PLUSEQ | SLASHEQ
|
||||
| STAREQ | PERCENTEQ | SHREQ | SHLEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxToken) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
PIPEPIPE => BinOp::Pipepipe(Pipepipe { syntax }),
|
||||
AMPAMP => BinOp::Ampamp(Ampamp { syntax }),
|
||||
EQEQ => BinOp::Eqeq(Eqeq { syntax }),
|
||||
NEQ => BinOp::Neq(Neq { syntax }),
|
||||
LTEQ => BinOp::Lteq(Lteq { syntax }),
|
||||
GTEQ => BinOp::Gteq(Gteq { syntax }),
|
||||
L_ANGLE => BinOp::LAngle(LAngle { syntax }),
|
||||
R_ANGLE => BinOp::RAngle(RAngle { syntax }),
|
||||
PLUS => BinOp::Plus(Plus { syntax }),
|
||||
STAR => BinOp::Star(Star { syntax }),
|
||||
MINUS => BinOp::Minus(Minus { syntax }),
|
||||
SLASH => BinOp::Slash(Slash { syntax }),
|
||||
PERCENT => BinOp::Percent(Percent { syntax }),
|
||||
SHL => BinOp::Shl(Shl { syntax }),
|
||||
SHR => BinOp::Shr(Shr { syntax }),
|
||||
CARET => BinOp::Caret(Caret { syntax }),
|
||||
PIPE => BinOp::Pipe(Pipe { syntax }),
|
||||
AMP => BinOp::Amp(Amp { syntax }),
|
||||
EQ => BinOp::Eq(Eq { syntax }),
|
||||
PLUSEQ => BinOp::Pluseq(Pluseq { syntax }),
|
||||
SLASHEQ => BinOp::Slasheq(Slasheq { syntax }),
|
||||
STAREQ => BinOp::Stareq(Stareq { syntax }),
|
||||
PERCENTEQ => BinOp::Percenteq(Percenteq { syntax }),
|
||||
SHREQ => BinOp::Shreq(Shreq { syntax }),
|
||||
SHLEQ => BinOp::Shleq(Shleq { syntax }),
|
||||
MINUSEQ => BinOp::Minuseq(Minuseq { syntax }),
|
||||
PIPEEQ => BinOp::Pipeeq(Pipeeq { syntax }),
|
||||
AMPEQ => BinOp::Ampeq(Ampeq { syntax }),
|
||||
CARETEQ => BinOp::Careteq(Careteq { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxToken {
|
||||
match self {
|
||||
BinOp::Pipepipe(it) => &it.syntax,
|
||||
BinOp::Ampamp(it) => &it.syntax,
|
||||
BinOp::Eqeq(it) => &it.syntax,
|
||||
BinOp::Neq(it) => &it.syntax,
|
||||
BinOp::Lteq(it) => &it.syntax,
|
||||
BinOp::Gteq(it) => &it.syntax,
|
||||
BinOp::LAngle(it) => &it.syntax,
|
||||
BinOp::RAngle(it) => &it.syntax,
|
||||
BinOp::Plus(it) => &it.syntax,
|
||||
BinOp::Star(it) => &it.syntax,
|
||||
BinOp::Minus(it) => &it.syntax,
|
||||
BinOp::Slash(it) => &it.syntax,
|
||||
BinOp::Percent(it) => &it.syntax,
|
||||
BinOp::Shl(it) => &it.syntax,
|
||||
BinOp::Shr(it) => &it.syntax,
|
||||
BinOp::Caret(it) => &it.syntax,
|
||||
BinOp::Pipe(it) => &it.syntax,
|
||||
BinOp::Amp(it) => &it.syntax,
|
||||
BinOp::Eq(it) => &it.syntax,
|
||||
BinOp::Pluseq(it) => &it.syntax,
|
||||
BinOp::Slasheq(it) => &it.syntax,
|
||||
BinOp::Stareq(it) => &it.syntax,
|
||||
BinOp::Percenteq(it) => &it.syntax,
|
||||
BinOp::Shreq(it) => &it.syntax,
|
||||
BinOp::Shleq(it) => &it.syntax,
|
||||
BinOp::Minuseq(it) => &it.syntax,
|
||||
BinOp::Pipeeq(it) => &it.syntax,
|
||||
BinOp::Ampeq(it) => &it.syntax,
|
||||
BinOp::Careteq(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum PrefixOp {
|
||||
Minus(Minus),
|
||||
Excl(Excl),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue