From 075d2f22a52eebdd08c3c8507659fd2f43c3bffb Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 20 Sep 2019 13:24:52 -0300 Subject: [PATCH] add error contexts to other top levels --- src/parsers.zig | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/parsers.zig b/src/parsers.zig index bb8e873..4d2c0b4 100644 --- a/src/parsers.zig +++ b/src/parsers.zig @@ -518,11 +518,15 @@ pub const Parser = struct { var consts = ast.ConstList.init(self.allocator); errdefer consts.deinit(); + self.setErrContext("const"); + _ = try self.consumeSingle(.Const); _ = try self.consumeSingle(.LeftParen); while (self.peek().typ != .RightParen) { const const_name = try self.consumeSingle(.Identifier); + self.setErrContext("const {}", const_name); + _ = try self.consumeSingle(.Equal); // const declarations dont have type, a future type system must @@ -537,18 +541,19 @@ pub const Parser = struct { } _ = try self.consumeSingle(.RightParen); - return self.mkConstDecl(consts); } fn parseStructDecl(self: *@This()) !*Node { var fields = ast.FieldList.init(self.allocator); errdefer fields.deinit(); + self.setErrContext("struct", name); _ = try self.consumeSingle(.Struct); - var name = try self.consumeSingle(.Identifier); + self.setErrContext("struct {}", name); + _ = try self.consumeSingle(.LeftBrace); var field_state = FieldState{}; @@ -557,6 +562,8 @@ pub const Parser = struct { try self.parseFieldModifiers(&field_state); const field_name = try self.consumeSingle(.Identifier); + self.setErrContext("struct {} field {}", name, field_name); + const field_type = try self.consumeSingle(.Identifier); // we could create a FieldState on the heap and copy our current @@ -624,13 +631,16 @@ pub const Parser = struct { } fn parseEnumDecl(self: *@This()) !*Node { - _ = try self.consumeSingle(.Enum); - var fields = ast.TokenList.init(self.allocator); errdefer fields.deinit(); + self.setErrContext("enum"); + + _ = try self.consumeSingle(.Enum); const name = try self.consumeSingle(.Identifier); + self.setErrContext("enum {}", name); + _ = try self.consumeSingle(.LeftBrace); while (!self.check(.RightBrace)) {