diff options
| author | Tolmachev Igor <me@igorek.dev> | 2026-05-11 08:34:22 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2026-05-11 08:34:22 +0300 |
| commit | abda8d00117072f7c03f57eaeca9cf44427078dc (patch) | |
| tree | a7caf8c91932ce195398dbd63758a057720366a1 /compiler/src/ast/models.rs | |
| parent | 7163aaebc993591db1cb4d7ae2be31669a0cb9a7 (diff) | |
| download | crisp-abda8d00117072f7c03f57eaeca9cf44427078dc.tar.gz crisp-abda8d00117072f7c03f57eaeca9cf44427078dc.zip | |
Replace generic list AST with typed expression tree
Each form (fn, let, for, set, do, call) now has its own variant with named fields instead of being a
plain list.
Diffstat (limited to 'compiler/src/ast/models.rs')
| -rw-r--r-- | compiler/src/ast/models.rs | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/compiler/src/ast/models.rs b/compiler/src/ast/models.rs index 2a8c5ae..64fec19 100644 --- a/compiler/src/ast/models.rs +++ b/compiler/src/ast/models.rs | |||
| @@ -2,22 +2,56 @@ use std::rc::Rc; | |||
| 2 | 2 | ||
| 3 | use crate::span::Spanned; | 3 | use crate::span::Spanned; |
| 4 | 4 | ||
| 5 | #[derive(Clone, Debug, PartialEq)] | 5 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 6 | pub struct LetVar { | ||
| 7 | pub name: Spanned<Rc<str>>, | ||
| 8 | pub expr: Spanned<Expr>, | ||
| 9 | } | ||
| 10 | |||
| 11 | #[derive(Clone, Debug, PartialEq, Eq)] | ||
| 6 | pub enum Atom { | 12 | pub enum Atom { |
| 7 | Integer(i64), | 13 | Int(i64), |
| 8 | String(Rc<str>), | 14 | Str(Rc<str>), |
| 9 | Symbol(Rc<str>), | 15 | Sym(Rc<str>), |
| 10 | Bool(bool), | 16 | Bool(bool), |
| 11 | Nil, | 17 | Nil, |
| 12 | } | 18 | } |
| 13 | 19 | ||
| 14 | #[derive(Clone, Debug, PartialEq)] | 20 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 15 | pub enum Expr { | 21 | pub enum Expr { |
| 22 | Fn { | ||
| 23 | name: Spanned<Rc<str>>, | ||
| 24 | args: Vec<Spanned<Rc<str>>>, | ||
| 25 | body: Vec<Spanned<Expr>>, | ||
| 26 | }, | ||
| 27 | Const { | ||
| 28 | vars: Vec<Spanned<LetVar>>, | ||
| 29 | }, | ||
| 30 | Let { | ||
| 31 | vars: Vec<Spanned<LetVar>>, | ||
| 32 | body: Vec<Spanned<Expr>>, | ||
| 33 | }, | ||
| 34 | For { | ||
| 35 | loop_var: Spanned<Rc<str>>, | ||
| 36 | from: Spanned<Box<Expr>>, | ||
| 37 | to: Spanned<Box<Expr>>, | ||
| 38 | body: Vec<Spanned<Expr>>, | ||
| 39 | }, | ||
| 40 | Set { | ||
| 41 | target_var: Spanned<Rc<str>>, | ||
| 42 | expr: Spanned<Box<Expr>>, | ||
| 43 | }, | ||
| 44 | Do { | ||
| 45 | body: Vec<Spanned<Expr>>, | ||
| 46 | }, | ||
| 47 | Call { | ||
| 48 | fn_name: Spanned<Rc<str>>, | ||
| 49 | args: Vec<Spanned<Expr>>, | ||
| 50 | }, | ||
| 16 | Atom(Atom), | 51 | Atom(Atom), |
| 17 | List(Vec<Spanned<Expr>>), | ||
| 18 | } | 52 | } |
| 19 | 53 | ||
| 20 | #[derive(Clone, Debug, PartialEq)] | 54 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 21 | pub struct Ast(Vec<Spanned<Expr>>); | 55 | pub struct Ast(Vec<Spanned<Expr>>); |
| 22 | 56 | ||
| 23 | impl Ast { | 57 | impl Ast { |
