12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #[derive(Debug, PartialEq)]
- pub struct Token {
- pub token_type: TokenType,
- pub value: String,
- }
-
- impl Token {
- pub fn new(token_type: TokenType, value: &str) -> Self {
- Token {
- token_type,
- value: value.to_string(),
- }
- }
- }
-
- impl std::fmt::Display for Token {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(
- f,
- r#"{{ type: {}, value: "{}" }}"#,
- self.token_type, self.value
- )
- }
- }
-
- #[derive(Clone, Copy, Debug, PartialEq)]
- pub enum TokenType {
- Comma,
- From,
- Equals,
- Identfiier,
- Number,
- Select,
- Star,
- String,
- Where,
- }
-
- impl std::fmt::Display for TokenType {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(
- f,
- "{}",
- match self {
- TokenType::Comma => "Comma",
- TokenType::Equals => "Equals",
- TokenType::Identfiier => "Identifier",
- TokenType::Number => "Number",
- TokenType::Star => "Star",
- TokenType::String => "String",
-
- TokenType::Select => "SELECT",
- TokenType::From => "FROM",
- TokenType::Where => "WHERE",
- }
- )
- }
- }
|