A tool to compile SQL to Elasticsearch queries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

token.rs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #[derive(Debug, PartialEq)]
  2. pub struct Token {
  3. token_type: TokenType,
  4. value: String,
  5. }
  6. impl Token {
  7. pub fn new(token_type: TokenType, value: &str) -> Self {
  8. Token {
  9. token_type,
  10. value: value.to_string(),
  11. }
  12. }
  13. }
  14. impl std::fmt::Display for Token {
  15. fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
  16. write!(
  17. f,
  18. r#"{{ type: {}, value: "{}" }}"#,
  19. self.token_type, self.value
  20. )
  21. }
  22. }
  23. #[derive(Clone, Copy, Debug, PartialEq)]
  24. pub enum TokenType {
  25. From,
  26. Identfiier,
  27. Number,
  28. Select,
  29. Star,
  30. String,
  31. }
  32. impl std::fmt::Display for TokenType {
  33. fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
  34. write!(
  35. f,
  36. "{}",
  37. match self {
  38. TokenType::Identfiier => "Identifier",
  39. TokenType::Number => "Number",
  40. TokenType::Star => "Star",
  41. TokenType::String => "String",
  42. TokenType::Select => "SELECT",
  43. TokenType::From => "FROM",
  44. }
  45. )
  46. }
  47. }