mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Curley tokens
This commit is contained in:
parent
1c5d859195
commit
460c8bbdec
6 changed files with 47 additions and 131 deletions
|
@ -1366,94 +1366,6 @@ impl AstToken for RDollar {
|
|||
fn syntax(&self) -> &SyntaxToken { &self.syntax }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum LeftDelimiter {
|
||||
LParen(LParen),
|
||||
LBrack(LBrack),
|
||||
LCurly(LCurly),
|
||||
}
|
||||
impl From<LParen> for LeftDelimiter {
|
||||
fn from(node: LParen) -> LeftDelimiter { LeftDelimiter::LParen(node) }
|
||||
}
|
||||
impl From<LBrack> for LeftDelimiter {
|
||||
fn from(node: LBrack) -> LeftDelimiter { LeftDelimiter::LBrack(node) }
|
||||
}
|
||||
impl From<LCurly> for LeftDelimiter {
|
||||
fn from(node: LCurly) -> LeftDelimiter { LeftDelimiter::LCurly(node) }
|
||||
}
|
||||
impl std::fmt::Display for LeftDelimiter {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl AstToken for LeftDelimiter {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
L_PAREN | L_BRACK | L_CURLY => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxToken) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
L_PAREN => LeftDelimiter::LParen(LParen { syntax }),
|
||||
L_BRACK => LeftDelimiter::LBrack(LBrack { syntax }),
|
||||
L_CURLY => LeftDelimiter::LCurly(LCurly { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxToken {
|
||||
match self {
|
||||
LeftDelimiter::LParen(it) => &it.syntax,
|
||||
LeftDelimiter::LBrack(it) => &it.syntax,
|
||||
LeftDelimiter::LCurly(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum RightDelimiter {
|
||||
RParen(RParen),
|
||||
RBrack(RBrack),
|
||||
RCurly(RCurly),
|
||||
}
|
||||
impl From<RParen> for RightDelimiter {
|
||||
fn from(node: RParen) -> RightDelimiter { RightDelimiter::RParen(node) }
|
||||
}
|
||||
impl From<RBrack> for RightDelimiter {
|
||||
fn from(node: RBrack) -> RightDelimiter { RightDelimiter::RBrack(node) }
|
||||
}
|
||||
impl From<RCurly> for RightDelimiter {
|
||||
fn from(node: RCurly) -> RightDelimiter { RightDelimiter::RCurly(node) }
|
||||
}
|
||||
impl std::fmt::Display for RightDelimiter {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl AstToken for RightDelimiter {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
R_PAREN | R_BRACK | R_CURLY => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxToken) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
R_PAREN => RightDelimiter::RParen(RParen { syntax }),
|
||||
R_BRACK => RightDelimiter::RBrack(RBrack { syntax }),
|
||||
R_CURLY => RightDelimiter::RCurly(RCurly { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxToken {
|
||||
match self {
|
||||
RightDelimiter::RParen(it) => &it.syntax,
|
||||
RightDelimiter::RBrack(it) => &it.syntax,
|
||||
RightDelimiter::RCurly(it) => &it.syntax,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum RangeSeparator {
|
||||
Dotdot(Dotdot),
|
||||
Dotdotdot(Dotdotdot),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue