add error contexts to other top levels

This commit is contained in:
Luna 2019-09-20 13:24:52 -03:00
parent 3ad0859bc9
commit 075d2f22a5
1 changed files with 14 additions and 4 deletions

View File

@ -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)) {