Skip to content

Commit

Permalink
feat: Merged spans
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Dec 7, 2023
1 parent 364206f commit 66d1889
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 74 deletions.
60 changes: 32 additions & 28 deletions src/lang/ast/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,44 @@ use crate::lang::token::Token;

use super::expr::ExprId;

// Enums

#[derive(Debug, Eq, PartialEq)]
pub enum SqlDistinct {
All,
Distinct,
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlJoinType {
Left,
LeftOuter,
Right,
Inner,
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlCompoundOperator {
Union,
UnionAll,
Intersect,
Except,
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlOrdering {
Asc,
Desc,
}

//

#[derive(Debug, Eq, PartialEq)]
pub enum SqlFrom {
TableSubquery(Vec<SqlTableSubquery>),
JoinClause(Box<SqlJoinClause>),
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlProjection {
All,
Expand All @@ -33,40 +65,12 @@ pub enum SqlTableSubquery {
},
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlJoinType {
Left,
LeftOuter,
Right,
Inner,
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlJoinClause {
None(SqlTableSubquery),
Join(Vec<(SqlJoinType, SqlTableSubquery, SqlExpr)>),
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlCompoundOperator {
Union,
UnionAll,
Intersect,
Except,
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlOrdering {
Asc,
Desc,
}

#[derive(Debug, Eq, PartialEq)]
pub enum SqlFrom {
TableSubquery(Vec<SqlTableSubquery>),
JoinClause(Box<SqlJoinClause>),
}

#[derive(Debug, Eq, PartialEq)]
pub struct SelectCore {
pub distinct: SqlDistinct,
Expand Down
18 changes: 17 additions & 1 deletion src/lang/ast/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::lang::token::{Span, Token};
use crate::lang::token::{Span, Spanned, Token};

use super::expr::ExprId;

Expand Down Expand Up @@ -45,6 +45,22 @@ pub enum Stmt {
},
}

impl Spanned for Stmt {
fn get_span(&self) -> Span {
match self {
Stmt::Program { span, .. } => *span,
Stmt::Expression { span, .. } => *span,
Stmt::Break { span, .. } => *span,
Stmt::Continue { span, .. } => *span,
Stmt::Block { span, .. } => *span,
Stmt::Declaration { span, .. } => *span,
Stmt::If { span, .. } => *span,
Stmt::Loop { span, .. } => *span,
Stmt::Return { span, .. } => *span,
}
}
}

#[repr(transparent)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct StmtId(pub usize);
Loading

0 comments on commit 66d1889

Please sign in to comment.