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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #[derive(Debug, PartialEq)]
  2. pub struct Token {
  3. pub token_type: TokenType,
  4. pub 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. Comma,
  26. From,
  27. Equals,
  28. Identfiier,
  29. Number,
  30. Select,
  31. Star,
  32. String,
  33. Where,
  34. }
  35. impl std::fmt::Display for TokenType {
  36. fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
  37. write!(
  38. f,
  39. "{}",
  40. match self {
  41. TokenType::Comma => "Comma",
  42. TokenType::Equals => "Equals",
  43. TokenType::Identfiier => "Identifier",
  44. TokenType::Number => "Number",
  45. TokenType::Star => "Star",
  46. TokenType::String => "String",
  47. TokenType::Select => "SELECT",
  48. TokenType::From => "FROM",
  49. TokenType::Where => "WHERE",
  50. }
  51. )
  52. }
  53. }