Skip to content

Commit 0b528ba

Browse files
committed
Finish parser impl
1 parent aed5abb commit 0b528ba

File tree

7 files changed

+517
-3
lines changed

7 files changed

+517
-3
lines changed

Cargo.lock

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ authors = ["John <[email protected]>"]
66
descriptions = "A tiny sql server"
77
readme = "README.md"
88
repository = "https://github.com/gotorion/db1969"
9-
[dependencies]
9+
[dependencies]
10+
serde = { version = "1.0",features = ["derive"] }

src/error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@ pub enum Error {
66
Internal(String),
77
WriteConflict,
88
}
9+
10+
impl From<std::num::ParseIntError> for Error {
11+
fn from(value: std::num::ParseIntError) -> Self {
12+
Error::Parse(value.to_string())
13+
}
14+
}
15+
16+
impl From<std::num::ParseFloatError> for Error {
17+
fn from(value: std::num::ParseFloatError) -> Self {
18+
Error::Parse(value.to_string())
19+
}
20+
}

src/sql/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
mod parser;
1+
mod parser;
2+
mod types;

src/sql/parser/ast.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::sql::types::*;
2+
3+
#[derive(Debug, PartialEq)]
4+
pub enum Statement {
5+
CreateTable {
6+
name: String,
7+
columns: Vec<Column>,
8+
},
9+
Insert {
10+
table_name: String,
11+
columns: Option<Vec<String>>,
12+
values: Vec<Vec<Expression>>,
13+
},
14+
Select {
15+
table_name: String,
16+
},
17+
}
18+
19+
#[derive(Debug, PartialEq)]
20+
pub struct Column {
21+
pub name: String,
22+
pub data_type: DataType,
23+
pub nullable: Option<bool>,
24+
pub default: Option<Expression>,
25+
}
26+
27+
#[derive(Debug, PartialEq)]
28+
pub enum Expression {
29+
Consts(Consts),
30+
}
31+
32+
impl From<Consts> for Expression {
33+
fn from(consts: Consts) -> Self {
34+
Self::Consts(consts)
35+
}
36+
}
37+
38+
#[derive(Debug, PartialEq)]
39+
pub enum Consts {
40+
Null,
41+
Boolean(bool),
42+
Integer(i64),
43+
Float(f64),
44+
String(String),
45+
}

0 commit comments

Comments
 (0)