remove optional from parseTopDecl
This commit is contained in:
parent
90543d1d56
commit
a3127c76e7
2 changed files with 16 additions and 6 deletions
|
@ -34,4 +34,15 @@ fn main(a int) int {
|
|||
cock_and_ball_torture('cbt', 1, 2, 3)
|
||||
|
||||
return 23
|
||||
|
||||
//p := Point{
|
||||
// x: 10
|
||||
// y: 20
|
||||
//}
|
||||
//println(p.x)
|
||||
}
|
||||
|
||||
//struct Point {
|
||||
// x int
|
||||
// y int
|
||||
//}
|
||||
|
|
|
@ -325,8 +325,7 @@ pub const Parser = struct {
|
|||
if (token.ttype == .EOF) break;
|
||||
|
||||
var node = try self.parseTopDecl();
|
||||
if (node == null) continue;
|
||||
try root.Root.append(node.?);
|
||||
try root.Root.append(node);
|
||||
}
|
||||
|
||||
if (self.hadError) {
|
||||
|
@ -336,7 +335,7 @@ pub const Parser = struct {
|
|||
return root;
|
||||
}
|
||||
|
||||
fn parseFnDecl(self: *@This()) !?*Node {
|
||||
fn parseFnDecl(self: *@This()) !*Node {
|
||||
var param_list = ast.ParamList.init(self.allocator);
|
||||
errdefer param_list.deinit();
|
||||
|
||||
|
@ -365,7 +364,7 @@ pub const Parser = struct {
|
|||
return try self.mkFnDecl(name, param_list, return_type, block_node.Block);
|
||||
}
|
||||
|
||||
fn parseConstDecl(self: *@This()) !?*Node {
|
||||
fn parseConstDecl(self: *@This()) !*Node {
|
||||
var consts = ast.ConstList.init(self.allocator);
|
||||
errdefer consts.deinit();
|
||||
|
||||
|
@ -389,14 +388,14 @@ pub const Parser = struct {
|
|||
return self.mkConstDecl(consts);
|
||||
}
|
||||
|
||||
fn parseTopDecl(self: *@This()) !?*Node {
|
||||
fn parseTopDecl(self: *@This()) !*Node {
|
||||
return switch (self.peek().ttype) {
|
||||
.Fn => try self.parseFnDecl(),
|
||||
.Const => try self.parseConstDecl(),
|
||||
|
||||
else => |ttype| blk: {
|
||||
self.doError("(basic) expected fn/const, got {}\n", ttype);
|
||||
break :blk null;
|
||||
return Result.CompileError;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue