Skip to main content

coda_runtime/runtime/
ast.rs

1use crate::frontend::token::TokenKind;
2
3#[derive(Debug, Clone)]
4pub enum Expr {
5    Literal(ValueLiteral),
6    Variable(String),
7    Binary { left: Box<Expr>, operator: TokenKind, right: Box<Expr> },
8    Call { callee: Box<Expr>, args: Vec<Expr> },
9    Assign { name: String, value: Box<Expr> },
10    Array(Vec<Expr>),
11
12    Function { name: String, params: Vec<String>, body: Vec<Stmt> },
13}
14
15#[derive(Debug, Clone)]
16pub enum Stmt {
17    Let {
18        name: String,
19        value: Expr,
20        is_const: bool,
21        is_exported: bool,
22    },
23    Function {
24        name: String,
25        params: Vec<String>,
26        body: Vec<Stmt>,
27        is_exported: bool,
28    },
29    Return(Option<Expr>),
30    If {
31        condition: Expr,
32        then_branch: Vec<Stmt>,
33        else_branch: Option<Vec<Stmt>>,
34    },
35    While {
36        condition: Expr,
37        body: Vec<Stmt>,
38    },
39    Block(Vec<Stmt>),
40    Import(String),
41    Expr(Expr),
42}
43
44#[derive(Debug, Clone)]
45pub enum ValueLiteral {
46    Number(f64),
47    String(String),
48    Bool(bool),
49    Null,
50}