authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-13 16:51:23+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-13 16:51:23+03:00
log91358f3092fb2004bb46572d44a0e377ed400565
treeff310c3d77389b7b11544b2d550804acd57029b6
parentdf22c7dfef7312474865c868a633c8e9bbaa63fa
signature Commit is signed but in an unrecognized format.

continue parsing on extra qualifier errors


1 files changed, 43 insertions(+), 10 deletions(-)

lib/std/zig/parse.zig+43-10
...@@ -226,6 +226,10 @@ fn findEndOfBlock(it: *TokenIterator) void {...@@ -226,6 +226,10 @@ fn findEndOfBlock(it: *TokenIterator) void {
226 count -= 1;226 count -= 1;
227 if (count == 0) return;227 if (count == 0) return;
228 },228 },
229 .Eof => {
230 _ = it.prev();
231 return;
232 },
229 else => {},233 else => {},
230 };234 };
231}235}
...@@ -242,8 +246,12 @@ fn findToken(it: *TokenIterator, wanted: Token.Id) void {...@@ -242,8 +246,12 @@ fn findToken(it: *TokenIterator, wanted: Token.Id) void {
242 }246 }
243 count -= 1;247 count -= 1;
244 },248 },
249 .Eof => {
250 _ = it.prev();
251 return;
252 },
245 else => {253 else => {
246 if (tok.id == wanted and count == 0) return; 254 if (tok.id == wanted and count == 0) return;
247 },255 },
248 };256 };
249}257}
...@@ -2324,7 +2332,7 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2324,7 +2332,7 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2324 const node = try arena.create(Node.AnyFrameType);2332 const node = try arena.create(Node.AnyFrameType);
2325 node.* = .{2333 node.* = .{
2326 .anyframe_token = token,2334 .anyframe_token = token,
2327 .result = Node.AnyFrameType.Result{2335 .result = .{
2328 .arrow_token = arrow,2336 .arrow_token = arrow,
2329 .return_type = undefined, // set by caller2337 .return_type = undefined, // set by caller
2330 },2338 },
...@@ -2365,6 +2373,13 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2365,6 +2373,13 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2365 } else null;2373 } else null;
2366 _ = try expectToken(it, tree, .RParen);2374 _ = try expectToken(it, tree, .RParen);
23672375
2376 if (ptr_info.align_info != null) {
2377 try tree.errors.push(.{
2378 .ExtraAlignQualifier = .{ .token = it.index - 1 },
2379 });
2380 continue;
2381 }
2382
2368 ptr_info.align_info = Node.PrefixOp.PtrInfo.Align{2383 ptr_info.align_info = Node.PrefixOp.PtrInfo.Align{
2369 .node = expr_node,2384 .node = expr_node,
2370 .bit_range = bit_range,2385 .bit_range = bit_range,
...@@ -2373,14 +2388,32 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2373,14 +2388,32 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2373 continue;2388 continue;
2374 }2389 }
2375 if (eatToken(it, .Keyword_const)) |const_token| {2390 if (eatToken(it, .Keyword_const)) |const_token| {
2391 if (ptr_info.const_token != null) {
2392 try tree.errors.push(.{
2393 .ExtraConstQualifier = .{ .token = it.index - 1 },
2394 });
2395 continue;
2396 }
2376 ptr_info.const_token = const_token;2397 ptr_info.const_token = const_token;
2377 continue;2398 continue;
2378 }2399 }
2379 if (eatToken(it, .Keyword_volatile)) |volatile_token| {2400 if (eatToken(it, .Keyword_volatile)) |volatile_token| {
2401 if (ptr_info.volatile_token != null) {
2402 try tree.errors.push(.{
2403 .ExtraVolatileQualifier = .{ .token = it.index - 1 },
2404 });
2405 continue;
2406 }
2380 ptr_info.volatile_token = volatile_token;2407 ptr_info.volatile_token = volatile_token;
2381 continue;2408 continue;
2382 }2409 }
2383 if (eatToken(it, .Keyword_allowzero)) |allowzero_token| {2410 if (eatToken(it, .Keyword_allowzero)) |allowzero_token| {
2411 if (ptr_info.allowzero_token != null) {
2412 try tree.errors.push(.{
2413 .ExtraAllowZeroQualifier = .{ .token = it.index - 1 },
2414 });
2415 continue;
2416 }
2384 ptr_info.allowzero_token = allowzero_token;2417 ptr_info.allowzero_token = allowzero_token;
2385 continue;2418 continue;
2386 }2419 }
...@@ -2399,9 +2432,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2399,9 +2432,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2399 if (try parseByteAlign(arena, it, tree)) |align_expr| {2432 if (try parseByteAlign(arena, it, tree)) |align_expr| {
2400 if (slice_type.align_info != null) {2433 if (slice_type.align_info != null) {
2401 try tree.errors.push(.{2434 try tree.errors.push(.{
2402 .ExtraAlignQualifier = .{ .token = it.index },2435 .ExtraAlignQualifier = .{ .token = it.index - 1 },
2403 });2436 });
2404 return error.ParseError;2437 continue;
2405 }2438 }
2406 slice_type.align_info = Node.PrefixOp.PtrInfo.Align{2439 slice_type.align_info = Node.PrefixOp.PtrInfo.Align{
2407 .node = align_expr,2440 .node = align_expr,
...@@ -2412,9 +2445,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2412,9 +2445,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2412 if (eatToken(it, .Keyword_const)) |const_token| {2445 if (eatToken(it, .Keyword_const)) |const_token| {
2413 if (slice_type.const_token != null) {2446 if (slice_type.const_token != null) {
2414 try tree.errors.push(.{2447 try tree.errors.push(.{
2415 .ExtraConstQualifier = .{ .token = it.index },2448 .ExtraConstQualifier = .{ .token = it.index - 1 },
2416 });2449 });
2417 return error.ParseError;2450 continue;
2418 }2451 }
2419 slice_type.const_token = const_token;2452 slice_type.const_token = const_token;
2420 continue;2453 continue;
...@@ -2422,9 +2455,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2422,9 +2455,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2422 if (eatToken(it, .Keyword_volatile)) |volatile_token| {2455 if (eatToken(it, .Keyword_volatile)) |volatile_token| {
2423 if (slice_type.volatile_token != null) {2456 if (slice_type.volatile_token != null) {
2424 try tree.errors.push(.{2457 try tree.errors.push(.{
2425 .ExtraVolatileQualifier = .{ .token = it.index },2458 .ExtraVolatileQualifier = .{ .token = it.index - 1 },
2426 });2459 });
2427 return error.ParseError;2460 continue;
2428 }2461 }
2429 slice_type.volatile_token = volatile_token;2462 slice_type.volatile_token = volatile_token;
2430 continue;2463 continue;
...@@ -2432,9 +2465,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -2432,9 +2465,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
2432 if (eatToken(it, .Keyword_allowzero)) |allowzero_token| {2465 if (eatToken(it, .Keyword_allowzero)) |allowzero_token| {
2433 if (slice_type.allowzero_token != null) {2466 if (slice_type.allowzero_token != null) {
2434 try tree.errors.push(.{2467 try tree.errors.push(.{
2435 .ExtraAllowZeroQualifier = .{ .token = it.index },2468 .ExtraAllowZeroQualifier = .{ .token = it.index - 1 },
2436 });2469 });
2437 return error.ParseError;2470 continue;
2438 }2471 }
2439 slice_type.allowzero_token = allowzero_token;2472 slice_type.allowzero_token = allowzero_token;
2440 continue;2473 continue;