mirror of
https://github.com/joshuadavidthomas/django-template-ast.git
synced 2025-09-26 18:19:09 +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)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
enum TokenType {
|
enum TokenType {
|
||||||
// Single-character
|
LeftParen, // (
|
||||||
LeftParen,
|
RightParen, // )
|
||||||
RightParen,
|
LeftBrace, // {
|
||||||
LeftBrace,
|
RightBrace, // }
|
||||||
RightBrace,
|
LeftBracket, // [
|
||||||
LeftBracket,
|
RightBracket, // ]
|
||||||
RightBracket,
|
LeftAngle, // <
|
||||||
LeftAngle,
|
RightAngle, // >
|
||||||
RightAngle,
|
Comma, // ,
|
||||||
Comma,
|
Dot, // .
|
||||||
Dot,
|
Minus, // -
|
||||||
Minus,
|
Plus, // +
|
||||||
Plus,
|
Colon, // :
|
||||||
Colon,
|
Semicolon, // ;
|
||||||
Semicolon,
|
Slash, // /
|
||||||
Slash,
|
Star, // *
|
||||||
Star,
|
Bang, // !
|
||||||
Bang,
|
Equal, // =
|
||||||
Equal,
|
Pipe, // |
|
||||||
Pipe,
|
Percent, // %
|
||||||
Percent,
|
Hash, // #
|
||||||
Hash,
|
SingleQuote, // '
|
||||||
SingleQuote,
|
DoubleQuote, // "
|
||||||
DoubleQuote,
|
DoubleLeftBrace, // {{
|
||||||
|
DoubleRightBrace, // }}
|
||||||
// Multi-character
|
LeftBracePercent, // {%
|
||||||
DoubleLeftBrace,
|
PercentRightBrace, // %}
|
||||||
DoubleRightBrace,
|
LeftBraceHash, // {#
|
||||||
LeftBracePercent,
|
HashRightBrace, // #}
|
||||||
PercentRightBrace,
|
BangEqual, // !=
|
||||||
LeftBraceHash,
|
DoubleEqual, // ==
|
||||||
HashRightBrace,
|
LeftAngleEqual, // <=
|
||||||
BangEqual,
|
RightAngleEqual, // =>
|
||||||
DoubleEqual,
|
|
||||||
LeftAngleEqual,
|
|
||||||
RightAngleEqual,
|
|
||||||
|
|
||||||
// Literals
|
|
||||||
Text,
|
Text,
|
||||||
|
|
||||||
Eof,
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
struct Token {
|
struct Token {
|
||||||
token_type: TokenType,
|
token_type: TokenType,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue