diff options
author | JJ | 2023-11-06 01:54:53 +0000 |
---|---|---|
committer | JJ | 2023-11-06 01:54:53 +0000 |
commit | dc1640fd403649f6e54146754b30dbfa3145fba9 (patch) | |
tree | 1039640a797d369dee3acb6f2b47ec1b7e575031 /src/frontend/ast.rs | |
parent | bfe0a6fa21f1124c60dd4cc4fd60cdd9c2ec6d4f (diff) |
compiler: progress on parser
Diffstat (limited to 'src/frontend/ast.rs')
-rw-r--r-- | src/frontend/ast.rs | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/frontend/ast.rs b/src/frontend/ast.rs index 6c7963e..ed7a01a 100644 --- a/src/frontend/ast.rs +++ b/src/frontend/ast.rs @@ -5,9 +5,12 @@ pub type Id = String; pub enum Type { Void, Never, Integer, Float, String, // char et al are defined later - Func{from: Box<Type>, to: Box<Type>}, // todo: multiple params, effects + Func { // todo: multiple params, effects + from: Box<Type>, + to: Box<Type> + }, Struct(Vec<(Id, Box<Type>)>), - Tuple(Vec<(Option<String>, Box<Type>)>), + Tuple(Vec<(Option<Id>, Box<Type>)>), Union(Vec<(Id, Box<Type>)>), Interface { funcs: Vec<Sig>, @@ -17,9 +20,14 @@ pub enum Type { List(Box<Type>), Slice(Box<Type>), // todo: plus ownership Reference(Box<Type>), + Pointer(Box<Type>), + Distinct(Box<Type>), // todo: not sure Mutable(Box<Type>), // parameters only Static(Box<Type>), // parameters only - Alias{ id: Id, params: Vec<Type> }, // todo: this is wrong + Alias { // todo: this is wrong + id: Id, + generics: Vec<Type> + } } /// Function signatures. @@ -38,14 +46,11 @@ pub enum Pattern { Ident(Id), // type aliases, union variants, calls... Number(i64), Float(f64), Char(char), String(String), - Struct(Vec<StructPattern>), - Tuple(Vec<TuplePattern>), + Struct(Vec<(Id, Expr)>), // field, value + Tuple(Vec<(Option<Id>, Expr)>), // field, value List(Vec<Expr>), // arrays, slices, lists } -pub struct StructPattern { field: Id, value: Expr } -pub struct TuplePattern { field: Option<Id>, value: Expr } - /// Expressions introduce a new binding or bindings, in some regard. pub enum Binding { Let { @@ -68,8 +73,8 @@ pub enum Binding { public: bool, effect: Option<Id>, id: Id, - generics: Vec<GenericDecl>, - params: Vec<ParamDecl>, + generics: Vec<(Id, Option<Type>)>, // id, kind + params: Vec<(Id, Type)>, // id, kind kind: Type, body: Vec<Expr> }, @@ -78,9 +83,6 @@ pub enum Binding { Module { id: Id, body: Vec<Expr> }, } -pub struct GenericDecl { id: Id, kind: Option<Type> } -pub struct ParamDecl { id: Id, kind: Type } - /// Expressions related to control flow. pub enum Control { Call { id: Id, params: Vec<Expr> }, // function calls, macro invocations, field access... @@ -104,9 +106,9 @@ pub enum Control { Loop { body: Vec<Expr> }, } -pub struct CondBranch { cond: Expr, body: Vec<Expr> } -pub struct CatchBranch { exceptions: Vec<Id>, binding: Option<Id>, body: Vec<Expr> } -pub struct MatchBranch { pattern: Pattern, guard: Option<Expr>, body: Vec<Expr> } +pub struct CondBranch { pub cond: Expr, pub body: Vec<Expr> } +pub struct CatchBranch { pub exceptions: Vec<Id>, pub binding: Option<Id>, pub body: Vec<Expr> } +pub struct MatchBranch { pub pattern: Pattern, pub guard: Option<Expr>, pub body: Vec<Expr> } /// Expressions are either Patterns, Bindings, or Control flow constructs. pub enum Expr { |