Skip to content

Commit ddf52e1

Browse files
authored
Merge pull request #42 from Tcode-Motion/refactor-tokenkind-display-3962382208496788572
🧹 [code health improvement description] Refactor Display formatters in `token_kind.rs`
2 parents d408bb4 + 9eb1f7e commit ddf52e1

1 file changed

Lines changed: 3 additions & 27 deletions

File tree

compiler/syntax/src/token_kind.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ pub enum LiteralKind {
2121

2222
impl fmt::Display for LiteralKind {
2323
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24-
let label = match self {
25-
LiteralKind::Int => "Int",
26-
LiteralKind::Float => "Float",
27-
LiteralKind::Str => "Str",
28-
LiteralKind::Bool => "Bool",
29-
LiteralKind::Null => "Null",
30-
};
31-
write!(f, "{}", label)
24+
fmt::Debug::fmt(self, f)
3225
}
3326
}
3427

@@ -47,13 +40,7 @@ pub enum NumericLiteralKind {
4740

4841
impl fmt::Display for NumericLiteralKind {
4942
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50-
let label = match self {
51-
NumericLiteralKind::Decimal => "Decimal",
52-
NumericLiteralKind::Hex => "Hex",
53-
NumericLiteralKind::Binary => "Binary",
54-
NumericLiteralKind::Octal => "Octal",
55-
};
56-
write!(f, "{}", label)
43+
fmt::Debug::fmt(self, f)
5744
}
5845
}
5946

@@ -791,18 +778,7 @@ impl fmt::Display for TokenKind {
791778
if let Some(lexeme) = self.static_lexeme() {
792779
write!(f, "'{}'", lexeme)
793780
} else {
794-
let label = match self {
795-
TokenKind::Identifier => "Identifier",
796-
TokenKind::IntLiteral => "Integer Literal",
797-
TokenKind::FloatLiteral => "Float Literal",
798-
TokenKind::StringLiteral => "String Literal",
799-
TokenKind::FStringText => "f-string segment",
800-
TokenKind::Newline => "Newline",
801-
TokenKind::Eof => "EOF",
802-
TokenKind::Error => "Error",
803-
_ => "Unknown Token",
804-
};
805-
write!(f, "{}", label)
781+
fmt::Debug::fmt(self, f)
806782
}
807783
}
808784
}

0 commit comments

Comments
 (0)