aboutsummaryrefslogtreecommitdiff
path: root/std/ast.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/ast.pk')
-rw-r--r--std/ast.pk31
1 files changed, 18 insertions, 13 deletions
diff --git a/std/ast.pk b/std/ast.pk
index 4b8a783..21a5569 100644
--- a/std/ast.pk
+++ b/std/ast.pk
@@ -1,13 +1,14 @@
## std.ast: Exposes the AST for building and operating on with macros.
## The `Expr` type represents the abstract syntax tree of Puck itself.
-## It notably lacks type information.
-## It is, however, syntactically correct-by-construction.
+## It notably lacks type information. It is also not necessarily syntactically
+## correct-by-construction: Cond, Try, and Match expressions must have at least
+## one branch in their branches (yet this is not expressible here).
pub type Expr = union
Ident(string)
Number(int)
Float(float)
- Char(chr)
+ Char(char)
String(str)
Struct(list[(field: str, value: Expr)])
Tuple(list[(field: str?, value: Expr)])
@@ -29,17 +30,25 @@ pub type Expr = union
params: list[(id: Pattern, kind: Type?)],
kind: Type?,
body: list[Expr])
- TypeDecl(public: bool, id: str, generics: list[str], alias: Type)
- Module(public: bool, id: str, body: list[Expr])
+ TypeDecl(
+ public: bool,
+ id: str,
+ generics: list[str],
+ body: Type)
+ Module(
+ public: bool,
+ id: str,
+ generics: list[str],
+ body: list[Expr])
Use(path: str)
Call(id: str, params: list[Expr])
Cond(
branches: list[(cond: Expr, body: list[Expr])],
- else_body: list[Expr]?)
+ else_body: list[Expr])
Try(
try_body: list[Expr],
catches: list[(exceptions: list[str], body: list[Expr])],
- finally_body: list[Expr]?)
+ finally_body: list[Expr])
Match(
item: ref Expr,
branches: list[(pattern: Pattern, guard: Expr?, body: list[Expr])])
@@ -54,15 +63,11 @@ pub type Type = ref union
Int(size: uint)
Dec(size: uint)
Float(size: uint)
- String
Func(from: list[Type], to: Type)
Struct(list[(id: str, kind: Type)])
Tuple(list[(id: str?, kind: Type)])
Union(list[(id: str, kind: Type)])
- Class( # todo: generics
- funcs: list[(id: str, from: list[Type], to: Type?)]
- for_type: Type?
- )
+ Class(list[(id: str, from: list[Type], to: Type?)])
Array(size: uint, kind: Type)
List(Type)
Slice(Type) # todo: plus ownership
@@ -76,7 +81,7 @@ pub type Type = ref union
pub type Pattern = union
Ident(str)
- Number(int), Float(float), Char(chr), String(str)
+ Number(int), Float(float), Char(char), String(str)
Struct(name: str, params: list[Pattern])
Tuple(list[Pattern])
List(list[Pattern])