mirror of
https://github.com/joshuadavidthomas/django-template-ast.git
synced 2025-08-04 08:58:17 +00:00
Remove unnecessary display from TokenType enum (#1)
This commit is contained in:
parent
b1bb62c086
commit
51e00e7a5d
1 changed files with 33 additions and 83 deletions
116
src/lexer.rs
116
src/lexer.rs
|
@ -2,93 +2,43 @@ use std::fmt;
|
|||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum TokenType {
|
||||
// Single-character
|
||||
LeftParen,
|
||||
RightParen,
|
||||
LeftBrace,
|
||||
RightBrace,
|
||||
LeftBracket,
|
||||
RightBracket,
|
||||
LeftAngle,
|
||||
RightAngle,
|
||||
Comma,
|
||||
Dot,
|
||||
Minus,
|
||||
Plus,
|
||||
Colon,
|
||||
Semicolon,
|
||||
Slash,
|
||||
Star,
|
||||
Bang,
|
||||
Equal,
|
||||
Pipe,
|
||||
Percent,
|
||||
Hash,
|
||||
SingleQuote,
|
||||
DoubleQuote,
|
||||
|
||||
// Multi-character
|
||||
DoubleLeftBrace,
|
||||
DoubleRightBrace,
|
||||
LeftBracePercent,
|
||||
PercentRightBrace,
|
||||
LeftBraceHash,
|
||||
HashRightBrace,
|
||||
BangEqual,
|
||||
DoubleEqual,
|
||||
LeftAngleEqual,
|
||||
RightAngleEqual,
|
||||
|
||||
// Literals
|
||||
LeftParen, // (
|
||||
RightParen, // )
|
||||
LeftBrace, // {
|
||||
RightBrace, // }
|
||||
LeftBracket, // [
|
||||
RightBracket, // ]
|
||||
LeftAngle, // <
|
||||
RightAngle, // >
|
||||
Comma, // ,
|
||||
Dot, // .
|
||||
Minus, // -
|
||||
Plus, // +
|
||||
Colon, // :
|
||||
Semicolon, // ;
|
||||
Slash, // /
|
||||
Star, // *
|
||||
Bang, // !
|
||||
Equal, // =
|
||||
Pipe, // |
|
||||
Percent, // %
|
||||
Hash, // #
|
||||
SingleQuote, // '
|
||||
DoubleQuote, // "
|
||||
DoubleLeftBrace, // {{
|
||||
DoubleRightBrace, // }}
|
||||
LeftBracePercent, // {%
|
||||
PercentRightBrace, // %}
|
||||
LeftBraceHash, // {#
|
||||
HashRightBrace, // #}
|
||||
BangEqual, // !=
|
||||
DoubleEqual, // ==
|
||||
LeftAngleEqual, // <=
|
||||
RightAngleEqual, // =>
|
||||
Text,
|
||||
|
||||
Eof,
|
||||
}
|
||||
|
||||
impl fmt::Display for TokenType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use TokenType::*;
|
||||
let s = match self {
|
||||
LeftParen => "(",
|
||||
RightParen => ")",
|
||||
LeftBrace => "{",
|
||||
RightBrace => "}",
|
||||
LeftBracket => "[",
|
||||
RightBracket => "]",
|
||||
LeftAngle => "<",
|
||||
RightAngle => ">",
|
||||
Comma => ",",
|
||||
Dot => ".",
|
||||
Minus => "-",
|
||||
Plus => "+",
|
||||
Colon => ":",
|
||||
Semicolon => ";",
|
||||
Slash => "/",
|
||||
Star => "*",
|
||||
Bang => "!",
|
||||
Equal => "=",
|
||||
Pipe => "|",
|
||||
Percent => "%",
|
||||
Hash => "#",
|
||||
SingleQuote => "'",
|
||||
DoubleQuote => "\"",
|
||||
DoubleLeftBrace => "{{",
|
||||
DoubleRightBrace => "}}",
|
||||
LeftBracePercent => "{%",
|
||||
PercentRightBrace => "%}",
|
||||
LeftBraceHash => "{#",
|
||||
HashRightBrace => "#}",
|
||||
BangEqual => "!=",
|
||||
DoubleEqual => "==",
|
||||
LeftAngleEqual => "<=",
|
||||
RightAngleEqual => ">=",
|
||||
Text => "text",
|
||||
Eof => "EOF",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Token {
|
||||
token_type: TokenType,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue