vig/src/ast.zig

36 lines
689 B
Zig
Raw Normal View History

const std = @import("std");
2019-06-05 23:29:03 +00:00
const tokens = @import("tokens.zig");
const Token = tokens.Token;
pub const NodeList = std.ArrayList(*Node);
2019-07-01 18:55:19 +00:00
pub const ParamList = std.ArrayList(*ParamDecl);
pub const NodeType = enum {
Root,
FnDecl,
};
2019-07-01 18:55:19 +00:00
pub const ParamDecl = struct {
param_name: Token,
// TODO types
param_type: Token,
};
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,
};
pub const Node = union(NodeType) {
Root: NodeList,
FnDecl: FnDecl,
2019-06-05 23:29:03 +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
}