/toy-rsql-parser

toy SQL parser written in Rust. (ongoing)

Primary LanguageRustMIT LicenseMIT

toy-rsql-parser

Rust

toy SQL parser written in Rust. (ongoing)

Lexer

// input query
SELECT * FROM user WHERE id = 1;

// output tokens
[
  Annot { value: Select },
  Annot { value: Ast },
  Annot { value: FromTable },
  Annot { value: Ident("user") },
  Annot { value: Where },
  Annot { value: Ident("id") },
  Annot { value: EqOp },
  Annot { value: Number(1) },
  Annot { value: SemiColon }
]

Parser

// input query
SELECT 1+1+2, id, name FROM user WHERE id = 1;

// output AST
Select { 
  columns: [
    Column { 
      value: Infix { 
        op: Plus, 
        left: Infix { 
          op: Plus, 
          left: Number(1), 
          right: Number(1) 
        }, 
        right: Number(2)
      }, alias: ""
    }, 
    Column {
      value: Identifier("id"), 
      alias: ""
    }, 
    Column { 
      value: Identifier("name"), 
      alias: ""
    }
  ], 
  table: TableExpression { 
    from: "user", 
    where_cond: Some(
      Infix { 
        op: Eq,
        left: Identifier("id"),
        right: Number(1)
      }
    ), 
    group_by: None 
  } 
}

Features

  • Minimum Lexer
  • Minimum Parser
  • Lexer
  • DML Parse
    • SELECT
    • INSERT
    • UPDATE
    • DELETE
  • DDL Parse
  • DCL Parse