2019-07-01 18:01:43 +00:00
|
|
|
const std = @import("std");
|
2019-06-05 23:29:03 +00:00
|
|
|
const tokens = @import("tokens.zig");
|
|
|
|
const Token = tokens.Token;
|
|
|
|
|
2019-07-01 18:01:43 +00:00
|
|
|
pub const NodeList = std.ArrayList(*Node);
|
2019-07-01 18:55:19 +00:00
|
|
|
pub const ParamList = std.ArrayList(*ParamDecl);
|
2019-06-05 02:44:27 +00:00
|
|
|
|
2019-07-01 18:01:43 +00:00
|
|
|
pub const NodeType = enum {
|
|
|
|
Root,
|
|
|
|
FnDecl,
|
2019-06-05 02:44:27 +00:00
|
|
|
};
|
|
|
|
|
2019-07-01 18:55:19 +00:00
|
|
|
pub const ParamDecl = struct {
|
|
|
|
param_name: Token,
|
|
|
|
|
|
|
|
// TODO types
|
|
|
|
param_type: Token,
|
|
|
|
};
|
|
|
|
|
2019-07-01 18:01:43 +00:00
|
|
|
pub const FnDecl = struct {
|
2019-07-01 18:25:07 +00:00
|
|
|
func_name: Token,
|
2019-07-01 18:55:19 +00:00
|
|
|
params: ParamList,
|
|
|
|
body: NodeList,
|
2019-06-05 02:44:27 +00:00
|
|
|
};
|
|
|
|
|
2019-07-01 18:01:43 +00:00
|
|
|
pub const Node = union(NodeType) {
|
|
|
|
Root: NodeList,
|
|
|
|
FnDecl: FnDecl,
|
2019-06-05 23:29:03 +00:00
|
|
|
};
|
|
|
|
|
2019-07-01 18:01:43 +00:00
|
|
|
pub fn mkRoot(allocator: *std.mem.Allocator) !*Node {
|
|
|
|
var node = try allocator.create(Node);
|
|
|
|
node.* = Node{ .Root = NodeList.init(allocator) };
|
|
|
|
return node;
|
2019-06-05 23:29:03 +00:00
|
|
|
}
|