Skip to content

Commit

Permalink
fix: Revised AST
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Dec 5, 2023
1 parent d795c73 commit 1f281a8
Show file tree
Hide file tree
Showing 12 changed files with 786 additions and 400 deletions.
41 changes: 31 additions & 10 deletions src/lang/ast/expr.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,63 @@
use std::rc::Rc;

use crate::{lang::token::Token, runtime::types::RV};
use crate::{
lang::token::{Span, Token, TokenType},
runtime::types::RV,
};

use super::{sql::SqlSelect, stmt::StmtId};

#[derive(Debug, Eq, PartialEq)]
pub enum Expr {
Select(SqlSelect),
Variable(Token),
Grouping(ExprId),
Literal(RV),
Select {
query: SqlSelect,
span: Span,
},
Variable {
name: Token,
span: Span,
},
Grouping {
expr: ExprId,
span: Span,
},
Literal {
value: RV,
raw: String,
span: Span,
},
Function {
name: Option<Token>,
parameters: Vec<Token>,
body: Rc<Vec<StmtId>>,
span: Span,
},
Binary {
left: ExprId,
token: Token,
symbol: TokenType,
right: ExprId,
span: Span,
},
Unary {
token: Token,
symbol: TokenType,
expr: ExprId,
span: Span,
},
Assignment {
var_tok: Token,
dst: Token,
expr: ExprId,
span: Span,
},
Logical {
left: ExprId,
token: Token,
symbol: TokenType,
right: ExprId,
span: Span,
},
Call {
callee: ExprId,
paren: Token,
args: Vec<ExprId>,
span: Span,
},
}

Expand Down
31 changes: 24 additions & 7 deletions src/lang/ast/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
use crate::lang::token::Token;
use crate::lang::token::{Span, Token};

use super::expr::ExprId;

#[derive(Debug, Eq, PartialEq)]
pub enum Stmt {
Expression(ExprId),
Break(Token),
Continue(Token),
Block(Vec<StmtId>),
Program {
stmts: Vec<StmtId>,
span: Span,
},
Expression {
expr: ExprId,
span: Span,
},
Break {
span: Span,
},
Continue {
span: Span,
},
Block {
stmts: Vec<StmtId>,
span: Span,
},
Declaration {
token: Token,
dst: Token,
expr: ExprId,
span: Span,
},
If {
condition: ExprId,
body: StmtId,
r#else: Option<StmtId>,
span: Span,
},
Loop {
condition: Option<ExprId>,
body: StmtId,
post: Option<StmtId>,
span: Span,
},
Return {
token: Token,
expr: Option<ExprId>,
span: Span,
},
}

Expand Down
Loading

0 comments on commit 1f281a8

Please sign in to comment.