aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/ast.rs
diff options
context:
space:
mode:
authorJJ2023-11-08 21:18:08 +0000
committerJJ2023-11-08 21:18:08 +0000
commit3851012eeb1420bef0db7cd3e9a76affdb6145b9 (patch)
treeab2fbf7b80ea76ac971f85271bbc5a05337c4550 /src/frontend/ast.rs
parentb7b2f41976eb0315130e002e0a40631b30f28add (diff)
compiler: progress. parse most of the hard things.
Diffstat (limited to 'src/frontend/ast.rs')
-rw-r--r--src/frontend/ast.rs35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/frontend/ast.rs b/src/frontend/ast.rs
index ed7a01a..ed44712 100644
--- a/src/frontend/ast.rs
+++ b/src/frontend/ast.rs
@@ -2,6 +2,7 @@
pub type Id = String;
/// Puck's fundamental types.
+#[derive(Clone, PartialEq)]
pub enum Type {
Void, Never,
Integer, Float, String, // char et al are defined later
@@ -12,10 +13,7 @@ pub enum Type {
Struct(Vec<(Id, Box<Type>)>),
Tuple(Vec<(Option<Id>, Box<Type>)>),
Union(Vec<(Id, Box<Type>)>),
- Interface {
- funcs: Vec<Sig>,
- for_type: Option<Box<Type>>,
- },
+ Interface(Vec<Sig>),
Array{size: usize, kind: Box<Type>},
List(Box<Type>),
Slice(Box<Type>), // todo: plus ownership
@@ -31,12 +29,13 @@ pub enum Type {
}
/// Function signatures.
+#[derive(Clone, PartialEq)]
pub struct Sig {
- effect: Option<Id>,
- id: Id,
- generics: Vec<(Id, Option<Type>)>,
- params: Vec<Type>,
- result: Option<Type>
+ pub effect: Option<Id>,
+ pub id: Id,
+ pub generics: Vec<(Id, Option<Type>)>,
+ pub parameters: Vec<Type>,
+ pub kind: Option<Type>
}
/// Patterns are recognizable given zero context.
@@ -69,16 +68,24 @@ pub enum Binding {
kind: Option<Type>,
value: Box<Expr>
},
- FuncDecl {
+ Func {
public: bool,
effect: Option<Id>,
id: Id,
generics: Vec<(Id, Option<Type>)>, // id, kind
- params: Vec<(Id, Type)>, // id, kind
+ parameters: Vec<(Id, Type)>, // id, kind
kind: Type,
body: Vec<Expr>
},
- TypeDecl { id: Id, generics: Vec<Id>, alias: Type },
+ Macro {
+ public: bool,
+ id: Id,
+ generics: Vec<(Id, Option<Type>)>, // id, kind
+ parameters: Vec<(Id, Option<Type>)>, // id, kind
+ kind: Option<Type>,
+ body: Vec<Expr>
+ },
+ TypeDecl { id: Id, generics: Vec<(Id, Option<Type>)>, alias: Type },
Import { from: Option<Id>, imports: Vec<Id>, alias: Option<Id> },
Module { id: Id, body: Vec<Expr> },
}
@@ -107,8 +114,8 @@ pub enum Control {
}
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> }
+pub struct CatchBranch { pub exceptions: Vec<(Id, Option<Id>)>, pub body: Vec<Expr> }
+pub struct MatchBranch { pub patterns: Vec<Pattern>, pub guard: Option<Expr>, pub body: Vec<Expr> }
/// Expressions are either Patterns, Bindings, or Control flow constructs.
pub enum Expr {