diff options
| author | Vexu <git@vexu.eu> | 2020-05-13 16:51:23 +0300 |
|---|---|---|
| committer | Vexu <git@vexu.eu> | 2020-05-13 16:51:23 +0300 |
| commit | 91358f3092fb2004bb46572d44a0e377ed400565 (patch) | |
| tree | ff310c3d77389b7b11544b2d550804acd57029b6 /lib/std | |
| parent | df22c7dfef7312474865c868a633c8e9bbaa63fa (diff) | |
| download | zig-91358f3092fb2004bb46572d44a0e377ed400565.tar.gz zig-91358f3092fb2004bb46572d44a0e377ed400565.zip | |
continue parsing on extra qualifier errors
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/parse.zig | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index eec1765002..586af02194 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -226,6 +226,10 @@ fn findEndOfBlock(it: *TokenIterator) void { count -= 1; if (count == 0) return; }, + .Eof => { + _ = it.prev(); + return; + }, else => {}, }; } @@ -242,8 +246,12 @@ fn findToken(it: *TokenIterator, wanted: Token.Id) void { } count -= 1; }, + .Eof => { + _ = it.prev(); + return; + }, else => { - if (tok.id == wanted and count == 0) return; + if (tok.id == wanted and count == 0) return; }, }; } @@ -2324,7 +2332,7 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node const node = try arena.create(Node.AnyFrameType); node.* = .{ .anyframe_token = token, - .result = Node.AnyFrameType.Result{ + .result = .{ .arrow_token = arrow, .return_type = undefined, // set by caller }, @@ -2365,6 +2373,13 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node } else null; _ = try expectToken(it, tree, .RParen); + if (ptr_info.align_info != null) { + try tree.errors.push(.{ + .ExtraAlignQualifier = .{ .token = it.index - 1 }, + }); + continue; + } + ptr_info.align_info = Node.PrefixOp.PtrInfo.Align{ .node = expr_node, .bit_range = bit_range, @@ -2373,14 +2388,32 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node continue; } if (eatToken(it, .Keyword_const)) |const_token| { + if (ptr_info.const_token != null) { + try tree.errors.push(.{ + .ExtraConstQualifier = .{ .token = it.index - 1 }, + }); + continue; + } ptr_info.const_token = const_token; continue; } if (eatToken(it, .Keyword_volatile)) |volatile_token| { + if (ptr_info.volatile_token != null) { + try tree.errors.push(.{ + .ExtraVolatileQualifier = .{ .token = it.index - 1 }, + }); + continue; + } ptr_info.volatile_token = volatile_token; continue; } if (eatToken(it, .Keyword_allowzero)) |allowzero_token| { + if (ptr_info.allowzero_token != null) { + try tree.errors.push(.{ + .ExtraAllowZeroQualifier = .{ .token = it.index - 1 }, + }); + continue; + } ptr_info.allowzero_token = allowzero_token; continue; } @@ -2399,9 +2432,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node if (try parseByteAlign(arena, it, tree)) |align_expr| { if (slice_type.align_info != null) { try tree.errors.push(.{ - .ExtraAlignQualifier = .{ .token = it.index }, + .ExtraAlignQualifier = .{ .token = it.index - 1 }, }); - return error.ParseError; + continue; } slice_type.align_info = Node.PrefixOp.PtrInfo.Align{ .node = align_expr, @@ -2412,9 +2445,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node if (eatToken(it, .Keyword_const)) |const_token| { if (slice_type.const_token != null) { try tree.errors.push(.{ - .ExtraConstQualifier = .{ .token = it.index }, + .ExtraConstQualifier = .{ .token = it.index - 1 }, }); - return error.ParseError; + continue; } slice_type.const_token = const_token; continue; @@ -2422,9 +2455,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node if (eatToken(it, .Keyword_volatile)) |volatile_token| { if (slice_type.volatile_token != null) { try tree.errors.push(.{ - .ExtraVolatileQualifier = .{ .token = it.index }, + .ExtraVolatileQualifier = .{ .token = it.index - 1 }, }); - return error.ParseError; + continue; } slice_type.volatile_token = volatile_token; continue; @@ -2432,9 +2465,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node if (eatToken(it, .Keyword_allowzero)) |allowzero_token| { if (slice_type.allowzero_token != null) { try tree.errors.push(.{ - .ExtraAllowZeroQualifier = .{ .token = it.index }, + .ExtraAllowZeroQualifier = .{ .token = it.index - 1 }, }); - return error.ParseError; + continue; } slice_type.allowzero_token = allowzero_token; continue; |
