| ... | @@ -520,8 +520,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -520,8 +520,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 520 | // - or / on its own is an error | 520 | // - or / on its own is an error |
| 521 | else => { | 521 | else => { |
| 522 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 522 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 523 | var msg_writer = err_details.msg.writer(allocator); | 523 | try err_details.msg.print(allocator, "invalid option: {s}", .{arg.prefixSlice()}); |
| 524 | try msg_writer.print("invalid option: {s}", .{arg.prefixSlice()}); | | |
| 525 | try diagnostics.append(err_details); | 524 | try diagnostics.append(err_details); |
| 526 | arg_i += 1; | 525 | arg_i += 1; |
| 527 | continue :next_arg; | 526 | continue :next_arg; |
| ... | @@ -532,8 +531,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -532,8 +531,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 532 | const args_remaining = args.len - arg_i; | 531 | const args_remaining = args.len - arg_i; |
| 533 | if (args_remaining <= 2 and arg.looksLikeFilepath()) { | 532 | if (args_remaining <= 2 and arg.looksLikeFilepath()) { |
| 534 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i }; | 533 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i }; |
| 535 | var msg_writer = err_details.msg.writer(allocator); | 534 | try err_details.msg.appendSlice(allocator, "this argument was inferred to be a filepath, so argument parsing was terminated"); |
| 536 | try msg_writer.writeAll("this argument was inferred to be a filepath, so argument parsing was terminated"); | | |
| 537 | try diagnostics.append(err_details); | 535 | try diagnostics.append(err_details); |
| 538 | | 536 | |
| 539 | break; | 537 | break; |
| ... | @@ -550,16 +548,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -550,16 +548,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 550 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":output-format")) { | 548 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":output-format")) { |
| 551 | const value = arg.value(":output-format".len, arg_i, args) catch { | 549 | const value = arg.value(":output-format".len, arg_i, args) catch { |
| 552 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 550 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 553 | var msg_writer = err_details.msg.writer(allocator); | 551 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":output-format".len) }); |
| 554 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":output-format".len) }); | | |
| 555 | try diagnostics.append(err_details); | 552 | try diagnostics.append(err_details); |
| 556 | arg_i += 1; | 553 | arg_i += 1; |
| 557 | break :next_arg; | 554 | break :next_arg; |
| 558 | }; | 555 | }; |
| 559 | output_format = std.meta.stringToEnum(Options.OutputFormat, value.slice) orelse blk: { | 556 | output_format = std.meta.stringToEnum(Options.OutputFormat, value.slice) orelse blk: { |
| 560 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 557 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 561 | var msg_writer = err_details.msg.writer(allocator); | 558 | try err_details.msg.print(allocator, "invalid output format setting: {s} ", .{value.slice}); |
| 562 | try msg_writer.print("invalid output format setting: {s} ", .{value.slice}); | | |
| 563 | try diagnostics.append(err_details); | 559 | try diagnostics.append(err_details); |
| 564 | break :blk output_format; | 560 | break :blk output_format; |
| 565 | }; | 561 | }; |
| ... | @@ -569,16 +565,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -569,16 +565,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 569 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":auto-includes")) { | 565 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":auto-includes")) { |
| 570 | const value = arg.value(":auto-includes".len, arg_i, args) catch { | 566 | const value = arg.value(":auto-includes".len, arg_i, args) catch { |
| 571 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 567 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 572 | var msg_writer = err_details.msg.writer(allocator); | 568 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":auto-includes".len) }); |
| 573 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":auto-includes".len) }); | | |
| 574 | try diagnostics.append(err_details); | 569 | try diagnostics.append(err_details); |
| 575 | arg_i += 1; | 570 | arg_i += 1; |
| 576 | break :next_arg; | 571 | break :next_arg; |
| 577 | }; | 572 | }; |
| 578 | options.auto_includes = std.meta.stringToEnum(Options.AutoIncludes, value.slice) orelse blk: { | 573 | options.auto_includes = std.meta.stringToEnum(Options.AutoIncludes, value.slice) orelse blk: { |
| 579 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 574 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 580 | var msg_writer = err_details.msg.writer(allocator); | 575 | try err_details.msg.print(allocator, "invalid auto includes setting: {s} ", .{value.slice}); |
| 581 | try msg_writer.print("invalid auto includes setting: {s} ", .{value.slice}); | | |
| 582 | try diagnostics.append(err_details); | 576 | try diagnostics.append(err_details); |
| 583 | break :blk options.auto_includes; | 577 | break :blk options.auto_includes; |
| 584 | }; | 578 | }; |
| ... | @@ -587,16 +581,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -587,16 +581,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 587 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":input-format")) { | 581 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":input-format")) { |
| 588 | const value = arg.value(":input-format".len, arg_i, args) catch { | 582 | const value = arg.value(":input-format".len, arg_i, args) catch { |
| 589 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 583 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 590 | var msg_writer = err_details.msg.writer(allocator); | 584 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":input-format".len) }); |
| 591 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":input-format".len) }); | | |
| 592 | try diagnostics.append(err_details); | 585 | try diagnostics.append(err_details); |
| 593 | arg_i += 1; | 586 | arg_i += 1; |
| 594 | break :next_arg; | 587 | break :next_arg; |
| 595 | }; | 588 | }; |
| 596 | input_format = std.meta.stringToEnum(Options.InputFormat, value.slice) orelse blk: { | 589 | input_format = std.meta.stringToEnum(Options.InputFormat, value.slice) orelse blk: { |
| 597 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 590 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 598 | var msg_writer = err_details.msg.writer(allocator); | 591 | try err_details.msg.print(allocator, "invalid input format setting: {s} ", .{value.slice}); |
| 599 | try msg_writer.print("invalid input format setting: {s} ", .{value.slice}); | | |
| 600 | try diagnostics.append(err_details); | 592 | try diagnostics.append(err_details); |
| 601 | break :blk input_format; | 593 | break :blk input_format; |
| 602 | }; | 594 | }; |
| ... | @@ -606,16 +598,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -606,16 +598,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 606 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":depfile-fmt")) { | 598 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":depfile-fmt")) { |
| 607 | const value = arg.value(":depfile-fmt".len, arg_i, args) catch { | 599 | const value = arg.value(":depfile-fmt".len, arg_i, args) catch { |
| 608 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 600 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 609 | var msg_writer = err_details.msg.writer(allocator); | 601 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":depfile-fmt".len) }); |
| 610 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":depfile-fmt".len) }); | | |
| 611 | try diagnostics.append(err_details); | 602 | try diagnostics.append(err_details); |
| 612 | arg_i += 1; | 603 | arg_i += 1; |
| 613 | break :next_arg; | 604 | break :next_arg; |
| 614 | }; | 605 | }; |
| 615 | options.depfile_fmt = std.meta.stringToEnum(Options.DepfileFormat, value.slice) orelse blk: { | 606 | options.depfile_fmt = std.meta.stringToEnum(Options.DepfileFormat, value.slice) orelse blk: { |
| 616 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 607 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 617 | var msg_writer = err_details.msg.writer(allocator); | 608 | try err_details.msg.print(allocator, "invalid depfile format setting: {s} ", .{value.slice}); |
| 618 | try msg_writer.print("invalid depfile format setting: {s} ", .{value.slice}); | | |
| 619 | try diagnostics.append(err_details); | 609 | try diagnostics.append(err_details); |
| 620 | break :blk options.depfile_fmt; | 610 | break :blk options.depfile_fmt; |
| 621 | }; | 611 | }; |
| ... | @@ -624,8 +614,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -624,8 +614,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 624 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":depfile")) { | 614 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":depfile")) { |
| 625 | const value = arg.value(":depfile".len, arg_i, args) catch { | 615 | const value = arg.value(":depfile".len, arg_i, args) catch { |
| 626 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 616 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 627 | var msg_writer = err_details.msg.writer(allocator); | 617 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":depfile".len) }); |
| 628 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":depfile".len) }); | | |
| 629 | try diagnostics.append(err_details); | 618 | try diagnostics.append(err_details); |
| 630 | arg_i += 1; | 619 | arg_i += 1; |
| 631 | break :next_arg; | 620 | break :next_arg; |
| ... | @@ -643,8 +632,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -643,8 +632,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 643 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":target")) { | 632 | } else if (std.ascii.startsWithIgnoreCase(arg_name, ":target")) { |
| 644 | const value = arg.value(":target".len, arg_i, args) catch { | 633 | const value = arg.value(":target".len, arg_i, args) catch { |
| 645 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 634 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 646 | var msg_writer = err_details.msg.writer(allocator); | 635 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":target".len) }); |
| 647 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(":target".len) }); | | |
| 648 | try diagnostics.append(err_details); | 636 | try diagnostics.append(err_details); |
| 649 | arg_i += 1; | 637 | arg_i += 1; |
| 650 | break :next_arg; | 638 | break :next_arg; |
| ... | @@ -655,8 +643,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -655,8 +643,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 655 | const arch_str = target_it.first(); | 643 | const arch_str = target_it.first(); |
| 656 | const arch = cvtres.supported_targets.Arch.fromStringIgnoreCase(arch_str) orelse { | 644 | const arch = cvtres.supported_targets.Arch.fromStringIgnoreCase(arch_str) orelse { |
| 657 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 645 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 658 | var msg_writer = err_details.msg.writer(allocator); | 646 | try err_details.msg.print(allocator, "invalid or unsupported target architecture: {s}", .{arch_str}); |
| 659 | try msg_writer.print("invalid or unsupported target architecture: {s}", .{arch_str}); | | |
| 660 | try diagnostics.append(err_details); | 647 | try diagnostics.append(err_details); |
| 661 | arg_i += value.index_increment; | 648 | arg_i += value.index_increment; |
| 662 | continue :next_arg; | 649 | continue :next_arg; |
| ... | @@ -680,13 +667,11 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -680,13 +667,11 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 680 | .prefix_len = arg.prefixSlice().len, | 667 | .prefix_len = arg.prefixSlice().len, |
| 681 | .value_offset = arg.name_offset + 3, | 668 | .value_offset = arg.name_offset + 3, |
| 682 | } }; | 669 | } }; |
| 683 | var msg_writer = err_details.msg.writer(allocator); | 670 | try err_details.msg.print(allocator, "missing value for {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(3) }); |
| 684 | try msg_writer.print("missing value for {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(3) }); | | |
| 685 | try diagnostics.append(err_details); | 671 | try diagnostics.append(err_details); |
| 686 | } | 672 | } |
| 687 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 673 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 688 | var msg_writer = err_details.msg.writer(allocator); | 674 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(3) }); |
| 689 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(3) }); | | |
| 690 | try diagnostics.append(err_details); | 675 | try diagnostics.append(err_details); |
| 691 | arg_i += 1; | 676 | arg_i += 1; |
| 692 | continue :next_arg; | 677 | continue :next_arg; |
| ... | @@ -695,16 +680,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -695,16 +680,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 695 | else if (std.ascii.startsWithIgnoreCase(arg_name, "tn")) { | 680 | else if (std.ascii.startsWithIgnoreCase(arg_name, "tn")) { |
| 696 | const value = arg.value(2, arg_i, args) catch no_value: { | 681 | const value = arg.value(2, arg_i, args) catch no_value: { |
| 697 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 682 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 698 | var msg_writer = err_details.msg.writer(allocator); | 683 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 699 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 700 | try diagnostics.append(err_details); | 684 | try diagnostics.append(err_details); |
| 701 | // dummy zero-length slice starting where the value would have been | 685 | // dummy zero-length slice starting where the value would have been |
| 702 | const value_start = arg.name_offset + 2; | 686 | const value_start = arg.name_offset + 2; |
| 703 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; | 687 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; |
| 704 | }; | 688 | }; |
| 705 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 689 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 706 | var msg_writer = err_details.msg.writer(allocator); | 690 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 707 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 708 | try diagnostics.append(err_details); | 691 | try diagnostics.append(err_details); |
| 709 | arg_i += value.index_increment; | 692 | arg_i += value.index_increment; |
| 710 | continue :next_arg; | 693 | continue :next_arg; |
| ... | @@ -716,16 +699,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -716,16 +699,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 716 | { | 699 | { |
| 717 | const value = arg.value(2, arg_i, args) catch no_value: { | 700 | const value = arg.value(2, arg_i, args) catch no_value: { |
| 718 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 701 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 719 | var msg_writer = err_details.msg.writer(allocator); | 702 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 720 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 721 | try diagnostics.append(err_details); | 703 | try diagnostics.append(err_details); |
| 722 | // dummy zero-length slice starting where the value would have been | 704 | // dummy zero-length slice starting where the value would have been |
| 723 | const value_start = arg.name_offset + 2; | 705 | const value_start = arg.name_offset + 2; |
| 724 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; | 706 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; |
| 725 | }; | 707 | }; |
| 726 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 708 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 727 | var msg_writer = err_details.msg.writer(allocator); | 709 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 728 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 729 | try diagnostics.append(err_details); | 710 | try diagnostics.append(err_details); |
| 730 | arg_i += value.index_increment; | 711 | arg_i += value.index_increment; |
| 731 | continue :next_arg; | 712 | continue :next_arg; |
| ... | @@ -733,8 +714,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -733,8 +714,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 733 | // Unsupported MUI options that do not need a value | 714 | // Unsupported MUI options that do not need a value |
| 734 | else if (std.ascii.startsWithIgnoreCase(arg_name, "g1")) { | 715 | else if (std.ascii.startsWithIgnoreCase(arg_name, "g1")) { |
| 735 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionSpan(2) }; | 716 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionSpan(2) }; |
| 736 | var msg_writer = err_details.msg.writer(allocator); | 717 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 737 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 738 | try diagnostics.append(err_details); | 718 | try diagnostics.append(err_details); |
| 739 | arg.name_offset += 2; | 719 | arg.name_offset += 2; |
| 740 | } | 720 | } |
| ... | @@ -747,15 +727,13 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -747,15 +727,13 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 747 | std.ascii.startsWithIgnoreCase(arg_name, "ta")) | 727 | std.ascii.startsWithIgnoreCase(arg_name, "ta")) |
| 748 | { | 728 | { |
| 749 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionSpan(2) }; | 729 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionSpan(2) }; |
| 750 | var msg_writer = err_details.msg.writer(allocator); | 730 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 751 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 752 | try diagnostics.append(err_details); | 731 | try diagnostics.append(err_details); |
| 753 | arg.name_offset += 2; | 732 | arg.name_offset += 2; |
| 754 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "fo")) { | 733 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "fo")) { |
| 755 | const value = arg.value(2, arg_i, args) catch { | 734 | const value = arg.value(2, arg_i, args) catch { |
| 756 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 735 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 757 | var msg_writer = err_details.msg.writer(allocator); | 736 | try err_details.msg.print(allocator, "missing output path after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 758 | try msg_writer.print("missing output path after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 759 | try diagnostics.append(err_details); | 737 | try diagnostics.append(err_details); |
| 760 | arg_i += 1; | 738 | arg_i += 1; |
| 761 | break :next_arg; | 739 | break :next_arg; |
| ... | @@ -767,8 +745,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -767,8 +745,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 767 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "sl")) { | 745 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "sl")) { |
| 768 | const value = arg.value(2, arg_i, args) catch { | 746 | const value = arg.value(2, arg_i, args) catch { |
| 769 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 747 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 770 | var msg_writer = err_details.msg.writer(allocator); | 748 | try err_details.msg.print(allocator, "missing language tag after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 771 | try msg_writer.print("missing language tag after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 772 | try diagnostics.append(err_details); | 749 | try diagnostics.append(err_details); |
| 773 | arg_i += 1; | 750 | arg_i += 1; |
| 774 | break :next_arg; | 751 | break :next_arg; |
| ... | @@ -776,24 +753,20 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -776,24 +753,20 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 776 | const percent_str = value.slice; | 753 | const percent_str = value.slice; |
| 777 | const percent: u32 = parsePercent(percent_str) catch { | 754 | const percent: u32 = parsePercent(percent_str) catch { |
| 778 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 755 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 779 | var msg_writer = err_details.msg.writer(allocator); | 756 | try err_details.msg.print(allocator, "invalid percent format '{s}'", .{percent_str}); |
| 780 | try msg_writer.print("invalid percent format '{s}'", .{percent_str}); | | |
| 781 | try diagnostics.append(err_details); | 757 | try diagnostics.append(err_details); |
| 782 | var note_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = false, .arg_index = arg_i }; | 758 | var note_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = false, .arg_index = arg_i }; |
| 783 | var note_writer = note_details.msg.writer(allocator); | 759 | try note_details.msg.appendSlice(allocator, "string length percent must be an integer between 1 and 100 (inclusive)"); |
| 784 | try note_writer.writeAll("string length percent must be an integer between 1 and 100 (inclusive)"); | | |
| 785 | try diagnostics.append(note_details); | 760 | try diagnostics.append(note_details); |
| 786 | arg_i += value.index_increment; | 761 | arg_i += value.index_increment; |
| 787 | continue :next_arg; | 762 | continue :next_arg; |
| 788 | }; | 763 | }; |
| 789 | if (percent == 0 or percent > 100) { | 764 | if (percent == 0 or percent > 100) { |
| 790 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 765 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 791 | var msg_writer = err_details.msg.writer(allocator); | 766 | try err_details.msg.print(allocator, "percent out of range: {} (parsed from '{s}')", .{ percent, percent_str }); |
| 792 | try msg_writer.print("percent out of range: {} (parsed from '{s}')", .{ percent, percent_str }); | | |
| 793 | try diagnostics.append(err_details); | 767 | try diagnostics.append(err_details); |
| 794 | var note_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = false, .arg_index = arg_i }; | 768 | var note_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = false, .arg_index = arg_i }; |
| 795 | var note_writer = note_details.msg.writer(allocator); | 769 | try note_details.msg.appendSlice(allocator, "string length percent must be an integer between 1 and 100 (inclusive)"); |
| 796 | try note_writer.writeAll("string length percent must be an integer between 1 and 100 (inclusive)"); | | |
| 797 | try diagnostics.append(note_details); | 770 | try diagnostics.append(note_details); |
| 798 | arg_i += value.index_increment; | 771 | arg_i += value.index_increment; |
| 799 | continue :next_arg; | 772 | continue :next_arg; |
| ... | @@ -805,8 +778,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -805,8 +778,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 805 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "ln")) { | 778 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "ln")) { |
| 806 | const value = arg.value(2, arg_i, args) catch { | 779 | const value = arg.value(2, arg_i, args) catch { |
| 807 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 780 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 808 | var msg_writer = err_details.msg.writer(allocator); | 781 | try err_details.msg.print(allocator, "missing language tag after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); |
| 809 | try msg_writer.print("missing language tag after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(2) }); | | |
| 810 | try diagnostics.append(err_details); | 782 | try diagnostics.append(err_details); |
| 811 | arg_i += 1; | 783 | arg_i += 1; |
| 812 | break :next_arg; | 784 | break :next_arg; |
| ... | @@ -814,16 +786,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -814,16 +786,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 814 | const tag = value.slice; | 786 | const tag = value.slice; |
| 815 | options.default_language_id = lang.tagToInt(tag) catch { | 787 | options.default_language_id = lang.tagToInt(tag) catch { |
| 816 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 788 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 817 | var msg_writer = err_details.msg.writer(allocator); | 789 | try err_details.msg.print(allocator, "invalid language tag: {s}", .{tag}); |
| 818 | try msg_writer.print("invalid language tag: {s}", .{tag}); | | |
| 819 | try diagnostics.append(err_details); | 790 | try diagnostics.append(err_details); |
| 820 | arg_i += value.index_increment; | 791 | arg_i += value.index_increment; |
| 821 | continue :next_arg; | 792 | continue :next_arg; |
| 822 | }; | 793 | }; |
| 823 | if (options.default_language_id.? == lang.LOCALE_CUSTOM_UNSPECIFIED) { | 794 | if (options.default_language_id.? == lang.LOCALE_CUSTOM_UNSPECIFIED) { |
| 824 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 795 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 825 | var msg_writer = err_details.msg.writer(allocator); | 796 | try err_details.msg.print(allocator, "language tag '{s}' does not have an assigned ID so it will be resolved to LOCALE_CUSTOM_UNSPECIFIED (id=0x{x})", .{ tag, lang.LOCALE_CUSTOM_UNSPECIFIED }); |
| 826 | try msg_writer.print("language tag '{s}' does not have an assigned ID so it will be resolved to LOCALE_CUSTOM_UNSPECIFIED (id=0x{x})", .{ tag, lang.LOCALE_CUSTOM_UNSPECIFIED }); | | |
| 827 | try diagnostics.append(err_details); | 797 | try diagnostics.append(err_details); |
| 828 | } | 798 | } |
| 829 | arg_i += value.index_increment; | 799 | arg_i += value.index_increment; |
| ... | @@ -831,8 +801,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -831,8 +801,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 831 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "l")) { | 801 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "l")) { |
| 832 | const value = arg.value(1, arg_i, args) catch { | 802 | const value = arg.value(1, arg_i, args) catch { |
| 833 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 803 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 834 | var msg_writer = err_details.msg.writer(allocator); | 804 | try err_details.msg.print(allocator, "missing language ID after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 835 | try msg_writer.print("missing language ID after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 836 | try diagnostics.append(err_details); | 805 | try diagnostics.append(err_details); |
| 837 | arg_i += 1; | 806 | arg_i += 1; |
| 838 | break :next_arg; | 807 | break :next_arg; |
| ... | @@ -840,8 +809,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -840,8 +809,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 840 | const num_str = value.slice; | 809 | const num_str = value.slice; |
| 841 | options.default_language_id = lang.parseInt(num_str) catch { | 810 | options.default_language_id = lang.parseInt(num_str) catch { |
| 842 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 811 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 843 | var msg_writer = err_details.msg.writer(allocator); | 812 | try err_details.msg.print(allocator, "invalid language ID: {s}", .{num_str}); |
| 844 | try msg_writer.print("invalid language ID: {s}", .{num_str}); | | |
| 845 | try diagnostics.append(err_details); | 813 | try diagnostics.append(err_details); |
| 846 | arg_i += value.index_increment; | 814 | arg_i += value.index_increment; |
| 847 | continue :next_arg; | 815 | continue :next_arg; |
| ... | @@ -860,16 +828,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -860,16 +828,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 860 | { | 828 | { |
| 861 | const value = arg.value(1, arg_i, args) catch no_value: { | 829 | const value = arg.value(1, arg_i, args) catch no_value: { |
| 862 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 830 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 863 | var msg_writer = err_details.msg.writer(allocator); | 831 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 864 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 865 | try diagnostics.append(err_details); | 832 | try diagnostics.append(err_details); |
| 866 | // dummy zero-length slice starting where the value would have been | 833 | // dummy zero-length slice starting where the value would have been |
| 867 | const value_start = arg.name_offset + 1; | 834 | const value_start = arg.name_offset + 1; |
| 868 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; | 835 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; |
| 869 | }; | 836 | }; |
| 870 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 837 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 871 | var msg_writer = err_details.msg.writer(allocator); | 838 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 872 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 873 | try diagnostics.append(err_details); | 839 | try diagnostics.append(err_details); |
| 874 | arg_i += value.index_increment; | 840 | arg_i += value.index_increment; |
| 875 | continue :next_arg; | 841 | continue :next_arg; |
| ... | @@ -882,16 +848,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -882,16 +848,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 882 | { | 848 | { |
| 883 | const value = arg.value(1, arg_i, args) catch no_value: { | 849 | const value = arg.value(1, arg_i, args) catch no_value: { |
| 884 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 850 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 885 | var msg_writer = err_details.msg.writer(allocator); | 851 | try err_details.msg.print(allocator, "missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 886 | try msg_writer.print("missing value after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 887 | try diagnostics.append(err_details); | 852 | try diagnostics.append(err_details); |
| 888 | // dummy zero-length slice starting where the value would have been | 853 | // dummy zero-length slice starting where the value would have been |
| 889 | const value_start = arg.name_offset + 1; | 854 | const value_start = arg.name_offset + 1; |
| 890 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; | 855 | break :no_value Arg.Value{ .slice = arg.full[value_start..value_start] }; |
| 891 | }; | 856 | }; |
| 892 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 857 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 893 | var msg_writer = err_details.msg.writer(allocator); | 858 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 894 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 895 | try diagnostics.append(err_details); | 859 | try diagnostics.append(err_details); |
| 896 | arg_i += value.index_increment; | 860 | arg_i += value.index_increment; |
| 897 | continue :next_arg; | 861 | continue :next_arg; |
| ... | @@ -899,15 +863,13 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -899,15 +863,13 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 899 | // 1 char unsupported LCX/LCE options that do not need a value | 863 | // 1 char unsupported LCX/LCE options that do not need a value |
| 900 | else if (std.ascii.startsWithIgnoreCase(arg_name, "t")) { | 864 | else if (std.ascii.startsWithIgnoreCase(arg_name, "t")) { |
| 901 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionSpan(1) }; | 865 | var err_details = Diagnostics.ErrorDetails{ .type = .err, .arg_index = arg_i, .arg_span = arg.optionSpan(1) }; |
| 902 | var msg_writer = err_details.msg.writer(allocator); | 866 | try err_details.msg.print(allocator, "the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 903 | try msg_writer.print("the {s}{s} option is unsupported", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 904 | try diagnostics.append(err_details); | 867 | try diagnostics.append(err_details); |
| 905 | arg.name_offset += 1; | 868 | arg.name_offset += 1; |
| 906 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "c")) { | 869 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "c")) { |
| 907 | const value = arg.value(1, arg_i, args) catch { | 870 | const value = arg.value(1, arg_i, args) catch { |
| 908 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 871 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 909 | var msg_writer = err_details.msg.writer(allocator); | 872 | try err_details.msg.print(allocator, "missing code page ID after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 910 | try msg_writer.print("missing code page ID after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 911 | try diagnostics.append(err_details); | 873 | try diagnostics.append(err_details); |
| 912 | arg_i += 1; | 874 | arg_i += 1; |
| 913 | break :next_arg; | 875 | break :next_arg; |
| ... | @@ -915,8 +877,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -915,8 +877,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 915 | const num_str = value.slice; | 877 | const num_str = value.slice; |
| 916 | const code_page_id = std.fmt.parseUnsigned(u16, num_str, 10) catch { | 878 | const code_page_id = std.fmt.parseUnsigned(u16, num_str, 10) catch { |
| 917 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 879 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 918 | var msg_writer = err_details.msg.writer(allocator); | 880 | try err_details.msg.print(allocator, "invalid code page ID: {s}", .{num_str}); |
| 919 | try msg_writer.print("invalid code page ID: {s}", .{num_str}); | | |
| 920 | try diagnostics.append(err_details); | 881 | try diagnostics.append(err_details); |
| 921 | arg_i += value.index_increment; | 882 | arg_i += value.index_increment; |
| 922 | continue :next_arg; | 883 | continue :next_arg; |
| ... | @@ -924,16 +885,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -924,16 +885,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 924 | options.default_code_page = code_pages.getByIdentifierEnsureSupported(code_page_id) catch |err| switch (err) { | 885 | options.default_code_page = code_pages.getByIdentifierEnsureSupported(code_page_id) catch |err| switch (err) { |
| 925 | error.InvalidCodePage => { | 886 | error.InvalidCodePage => { |
| 926 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 887 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 927 | var msg_writer = err_details.msg.writer(allocator); | 888 | try err_details.msg.print(allocator, "invalid or unknown code page ID: {}", .{code_page_id}); |
| 928 | try msg_writer.print("invalid or unknown code page ID: {}", .{code_page_id}); | | |
| 929 | try diagnostics.append(err_details); | 889 | try diagnostics.append(err_details); |
| 930 | arg_i += value.index_increment; | 890 | arg_i += value.index_increment; |
| 931 | continue :next_arg; | 891 | continue :next_arg; |
| 932 | }, | 892 | }, |
| 933 | error.UnsupportedCodePage => { | 893 | error.UnsupportedCodePage => { |
| 934 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 894 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 935 | var msg_writer = err_details.msg.writer(allocator); | 895 | try err_details.msg.print(allocator, "unsupported code page: {s} (id={})", .{ |
| 936 | try msg_writer.print("unsupported code page: {s} (id={})", .{ | | |
| 937 | @tagName(code_pages.getByIdentifier(code_page_id) catch unreachable), | 896 | @tagName(code_pages.getByIdentifier(code_page_id) catch unreachable), |
| 938 | code_page_id, | 897 | code_page_id, |
| 939 | }); | 898 | }); |
| ... | @@ -957,8 +916,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -957,8 +916,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 957 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "i")) { | 916 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "i")) { |
| 958 | const value = arg.value(1, arg_i, args) catch { | 917 | const value = arg.value(1, arg_i, args) catch { |
| 959 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 918 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 960 | var msg_writer = err_details.msg.writer(allocator); | 919 | try err_details.msg.print(allocator, "missing include path after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 961 | try msg_writer.print("missing include path after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 962 | try diagnostics.append(err_details); | 920 | try diagnostics.append(err_details); |
| 963 | arg_i += 1; | 921 | arg_i += 1; |
| 964 | break :next_arg; | 922 | break :next_arg; |
| ... | @@ -986,15 +944,13 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -986,15 +944,13 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 986 | // Undocumented option with unknown function | 944 | // Undocumented option with unknown function |
| 987 | // TODO: More investigation to figure out what it does (if anything) | 945 | // TODO: More investigation to figure out what it does (if anything) |
| 988 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = arg.optionSpan(1) }; | 946 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = arg.optionSpan(1) }; |
| 989 | var msg_writer = err_details.msg.writer(allocator); | 947 | try err_details.msg.print(allocator, "option {s}{s} has no effect (it is undocumented and its function is unknown in the Win32 RC compiler)", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 990 | try msg_writer.print("option {s}{s} has no effect (it is undocumented and its function is unknown in the Win32 RC compiler)", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 991 | try diagnostics.append(err_details); | 948 | try diagnostics.append(err_details); |
| 992 | arg.name_offset += 1; | 949 | arg.name_offset += 1; |
| 993 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "d")) { | 950 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "d")) { |
| 994 | const value = arg.value(1, arg_i, args) catch { | 951 | const value = arg.value(1, arg_i, args) catch { |
| 995 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 952 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 996 | var msg_writer = err_details.msg.writer(allocator); | 953 | try err_details.msg.print(allocator, "missing symbol to define after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 997 | try msg_writer.print("missing symbol to define after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 998 | try diagnostics.append(err_details); | 954 | try diagnostics.append(err_details); |
| 999 | arg_i += 1; | 955 | arg_i += 1; |
| 1000 | break :next_arg; | 956 | break :next_arg; |
| ... | @@ -1009,8 +965,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1009,8 +965,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1009 | try options.define(symbol, symbol_value); | 965 | try options.define(symbol, symbol_value); |
| 1010 | } else { | 966 | } else { |
| 1011 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 967 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 1012 | var msg_writer = err_details.msg.writer(allocator); | 968 | try err_details.msg.print(allocator, "symbol \"{s}\" is not a valid identifier and therefore cannot be defined", .{symbol}); |
| 1013 | try msg_writer.print("symbol \"{s}\" is not a valid identifier and therefore cannot be defined", .{symbol}); | | |
| 1014 | try diagnostics.append(err_details); | 969 | try diagnostics.append(err_details); |
| 1015 | } | 970 | } |
| 1016 | arg_i += value.index_increment; | 971 | arg_i += value.index_increment; |
| ... | @@ -1018,8 +973,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1018,8 +973,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1018 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "u")) { | 973 | } else if (std.ascii.startsWithIgnoreCase(arg_name, "u")) { |
| 1019 | const value = arg.value(1, arg_i, args) catch { | 974 | const value = arg.value(1, arg_i, args) catch { |
| 1020 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; | 975 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.missingSpan() }; |
| 1021 | var msg_writer = err_details.msg.writer(allocator); | 976 | try err_details.msg.print(allocator, "missing symbol to undefine after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); |
| 1022 | try msg_writer.print("missing symbol to undefine after {s}{s} option", .{ arg.prefixSlice(), arg.optionWithoutPrefix(1) }); | | |
| 1023 | try diagnostics.append(err_details); | 977 | try diagnostics.append(err_details); |
| 1024 | arg_i += 1; | 978 | arg_i += 1; |
| 1025 | break :next_arg; | 979 | break :next_arg; |
| ... | @@ -1029,16 +983,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1029,16 +983,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1029 | try options.undefine(symbol); | 983 | try options.undefine(symbol); |
| 1030 | } else { | 984 | } else { |
| 1031 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = value.argSpan(arg) }; | 985 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = arg_i, .arg_span = value.argSpan(arg) }; |
| 1032 | var msg_writer = err_details.msg.writer(allocator); | 986 | try err_details.msg.print(allocator, "symbol \"{s}\" is not a valid identifier and therefore cannot be undefined", .{symbol}); |
| 1033 | try msg_writer.print("symbol \"{s}\" is not a valid identifier and therefore cannot be undefined", .{symbol}); | | |
| 1034 | try diagnostics.append(err_details); | 987 | try diagnostics.append(err_details); |
| 1035 | } | 988 | } |
| 1036 | arg_i += value.index_increment; | 989 | arg_i += value.index_increment; |
| 1037 | continue :next_arg; | 990 | continue :next_arg; |
| 1038 | } else { | 991 | } else { |
| 1039 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; | 992 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i, .arg_span = arg.optionAndAfterSpan() }; |
| 1040 | var msg_writer = err_details.msg.writer(allocator); | 993 | try err_details.msg.print(allocator, "invalid option: {s}{s}", .{ arg.prefixSlice(), arg.name() }); |
| 1041 | try msg_writer.print("invalid option: {s}{s}", .{ arg.prefixSlice(), arg.name() }); | | |
| 1042 | try diagnostics.append(err_details); | 994 | try diagnostics.append(err_details); |
| 1043 | arg_i += 1; | 995 | arg_i += 1; |
| 1044 | continue :next_arg; | 996 | continue :next_arg; |
| ... | @@ -1055,16 +1007,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1055,16 +1007,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1055 | | 1007 | |
| 1056 | if (positionals.len == 0) { | 1008 | if (positionals.len == 0) { |
| 1057 | var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i }; | 1009 | var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i }; |
| 1058 | var msg_writer = err_details.msg.writer(allocator); | 1010 | try err_details.msg.appendSlice(allocator, "missing input filename"); |
| 1059 | try msg_writer.writeAll("missing input filename"); | | |
| 1060 | try diagnostics.append(err_details); | 1011 | try diagnostics.append(err_details); |
| 1061 | | 1012 | |
| 1062 | if (args.len > 0) { | 1013 | if (args.len > 0) { |
| 1063 | const last_arg = args[args.len - 1]; | 1014 | const last_arg = args[args.len - 1]; |
| 1064 | if (arg_i > 0 and last_arg.len > 0 and last_arg[0] == '/' and isSupportedInputExtension(std.fs.path.extension(last_arg))) { | 1015 | if (arg_i > 0 and last_arg.len > 0 and last_arg[0] == '/' and isSupportedInputExtension(std.fs.path.extension(last_arg))) { |
| 1065 | var note_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i - 1 }; | 1016 | var note_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i - 1 }; |
| 1066 | var note_writer = note_details.msg.writer(allocator); | 1017 | try note_details.msg.appendSlice(allocator, "if this argument was intended to be the input filename, adding -- in front of it will exclude it from option parsing"); |
| 1067 | try note_writer.writeAll("if this argument was intended to be the input filename, adding -- in front of it will exclude it from option parsing"); | | |
| 1068 | try diagnostics.append(note_details); | 1018 | try diagnostics.append(note_details); |
| 1069 | } | 1019 | } |
| 1070 | } | 1020 | } |
| ... | @@ -1099,16 +1049,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1099,16 +1049,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1099 | if (positionals.len > 1) { | 1049 | if (positionals.len > 1) { |
| 1100 | if (output_filename != null) { | 1050 | if (output_filename != null) { |
| 1101 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i + 1 }; | 1051 | var err_details = Diagnostics.ErrorDetails{ .arg_index = arg_i + 1 }; |
| 1102 | var msg_writer = err_details.msg.writer(allocator); | 1052 | try err_details.msg.appendSlice(allocator, "output filename already specified"); |
| 1103 | try msg_writer.writeAll("output filename already specified"); | | |
| 1104 | try diagnostics.append(err_details); | 1053 | try diagnostics.append(err_details); |
| 1105 | var note_details = Diagnostics.ErrorDetails{ | 1054 | var note_details = Diagnostics.ErrorDetails{ |
| 1106 | .type = .note, | 1055 | .type = .note, |
| 1107 | .arg_index = output_filename_context.arg.index, | 1056 | .arg_index = output_filename_context.arg.index, |
| 1108 | .arg_span = output_filename_context.arg.value.argSpan(output_filename_context.arg.arg), | 1057 | .arg_span = output_filename_context.arg.value.argSpan(output_filename_context.arg.arg), |
| 1109 | }; | 1058 | }; |
| 1110 | var note_writer = note_details.msg.writer(allocator); | 1059 | try note_details.msg.appendSlice(allocator, "output filename previously specified here"); |
| 1111 | try note_writer.writeAll("output filename previously specified here"); | | |
| 1112 | try diagnostics.append(note_details); | 1060 | try diagnostics.append(note_details); |
| 1113 | } else { | 1061 | } else { |
| 1114 | output_filename = positionals[1]; | 1062 | output_filename = positionals[1]; |
| ... | @@ -1173,16 +1121,15 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1173,16 +1121,15 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1173 | var print_output_format_source_note: bool = false; | 1121 | var print_output_format_source_note: bool = false; |
| 1174 | if (options.depfile_path != null and (options.input_format == .res or options.output_format == .rcpp)) { | 1122 | if (options.depfile_path != null and (options.input_format == .res or options.output_format == .rcpp)) { |
| 1175 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = depfile_context.index, .arg_span = depfile_context.value.argSpan(depfile_context.arg) }; | 1123 | var err_details = Diagnostics.ErrorDetails{ .type = .warning, .arg_index = depfile_context.index, .arg_span = depfile_context.value.argSpan(depfile_context.arg) }; |
| 1176 | var msg_writer = err_details.msg.writer(allocator); | | |
| 1177 | if (options.input_format == .res) { | 1124 | if (options.input_format == .res) { |
| 1178 | try msg_writer.print("the {s}{s} option was ignored because the input format is '{s}'", .{ | 1125 | try err_details.msg.print(allocator, "the {s}{s} option was ignored because the input format is '{s}'", .{ |
| 1179 | depfile_context.arg.prefixSlice(), | 1126 | depfile_context.arg.prefixSlice(), |
| 1180 | depfile_context.arg.optionWithoutPrefix(depfile_context.option_len), | 1127 | depfile_context.arg.optionWithoutPrefix(depfile_context.option_len), |
| 1181 | @tagName(options.input_format), | 1128 | @tagName(options.input_format), |
| 1182 | }); | 1129 | }); |
| 1183 | print_input_format_source_note = true; | 1130 | print_input_format_source_note = true; |
| 1184 | } else if (options.output_format == .rcpp) { | 1131 | } else if (options.output_format == .rcpp) { |
| 1185 | try msg_writer.print("the {s}{s} option was ignored because the output format is '{s}'", .{ | 1132 | try err_details.msg.print(allocator, "the {s}{s} option was ignored because the output format is '{s}'", .{ |
| 1186 | depfile_context.arg.prefixSlice(), | 1133 | depfile_context.arg.prefixSlice(), |
| 1187 | depfile_context.arg.optionWithoutPrefix(depfile_context.option_len), | 1134 | depfile_context.arg.optionWithoutPrefix(depfile_context.option_len), |
| 1188 | @tagName(options.output_format), | 1135 | @tagName(options.output_format), |
| ... | @@ -1193,16 +1140,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1193,16 +1140,14 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1193 | } | 1140 | } |
| 1194 | if (!isSupportedTransformation(options.input_format, options.output_format)) { | 1141 | if (!isSupportedTransformation(options.input_format, options.output_format)) { |
| 1195 | var err_details = Diagnostics.ErrorDetails{ .arg_index = input_filename_arg_i, .print_args = false }; | 1142 | var err_details = Diagnostics.ErrorDetails{ .arg_index = input_filename_arg_i, .print_args = false }; |
| 1196 | var msg_writer = err_details.msg.writer(allocator); | 1143 | try err_details.msg.print(allocator, "input format '{s}' cannot be converted to output format '{s}'", .{ @tagName(options.input_format), @tagName(options.output_format) }); |
| 1197 | try msg_writer.print("input format '{s}' cannot be converted to output format '{s}'", .{ @tagName(options.input_format), @tagName(options.output_format) }); | | |
| 1198 | try diagnostics.append(err_details); | 1144 | try diagnostics.append(err_details); |
| 1199 | print_input_format_source_note = true; | 1145 | print_input_format_source_note = true; |
| 1200 | print_output_format_source_note = true; | 1146 | print_output_format_source_note = true; |
| 1201 | } | 1147 | } |
| 1202 | if (options.preprocess == .only and options.output_format != .rcpp) { | 1148 | if (options.preprocess == .only and options.output_format != .rcpp) { |
| 1203 | var err_details = Diagnostics.ErrorDetails{ .arg_index = preprocess_only_context.index }; | 1149 | var err_details = Diagnostics.ErrorDetails{ .arg_index = preprocess_only_context.index }; |
| 1204 | var msg_writer = err_details.msg.writer(allocator); | 1150 | try err_details.msg.print(allocator, "the {s}{s} option cannot be used with output format '{s}'", .{ |
| 1205 | try msg_writer.print("the {s}{s} option cannot be used with output format '{s}'", .{ | | |
| 1206 | preprocess_only_context.arg.prefixSlice(), | 1151 | preprocess_only_context.arg.prefixSlice(), |
| 1207 | preprocess_only_context.arg.optionWithoutPrefix(preprocess_only_context.option_len), | 1152 | preprocess_only_context.arg.optionWithoutPrefix(preprocess_only_context.option_len), |
| 1208 | @tagName(options.output_format), | 1153 | @tagName(options.output_format), |
| ... | @@ -1214,8 +1159,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1214,8 +1159,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1214 | switch (input_format_source) { | 1159 | switch (input_format_source) { |
| 1215 | .inferred_from_input_filename => { | 1160 | .inferred_from_input_filename => { |
| 1216 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .arg_index = input_filename_arg_i }; | 1161 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .arg_index = input_filename_arg_i }; |
| 1217 | var msg_writer = err_details.msg.writer(allocator); | 1162 | try err_details.msg.appendSlice(allocator, "the input format was inferred from the input filename"); |
| 1218 | try msg_writer.writeAll("the input format was inferred from the input filename"); | | |
| 1219 | try diagnostics.append(err_details); | 1163 | try diagnostics.append(err_details); |
| 1220 | }, | 1164 | }, |
| 1221 | .input_format_arg => { | 1165 | .input_format_arg => { |
| ... | @@ -1224,8 +1168,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1224,8 +1168,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1224 | .arg_index = input_format_context.index, | 1168 | .arg_index = input_format_context.index, |
| 1225 | .arg_span = input_format_context.value.argSpan(input_format_context.arg), | 1169 | .arg_span = input_format_context.value.argSpan(input_format_context.arg), |
| 1226 | }; | 1170 | }; |
| 1227 | var msg_writer = err_details.msg.writer(allocator); | 1171 | try err_details.msg.appendSlice(allocator, "the input format was specified here"); |
| 1228 | try msg_writer.writeAll("the input format was specified here"); | | |
| 1229 | try diagnostics.append(err_details); | 1172 | try diagnostics.append(err_details); |
| 1230 | }, | 1173 | }, |
| 1231 | } | 1174 | } |
| ... | @@ -1234,11 +1177,10 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1234,11 +1177,10 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1234 | switch (output_format_source) { | 1177 | switch (output_format_source) { |
| 1235 | .inferred_from_input_filename, .unable_to_infer_from_input_filename => { | 1178 | .inferred_from_input_filename, .unable_to_infer_from_input_filename => { |
| 1236 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .arg_index = input_filename_arg_i }; | 1179 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .arg_index = input_filename_arg_i }; |
| 1237 | var msg_writer = err_details.msg.writer(allocator); | | |
| 1238 | if (output_format_source == .inferred_from_input_filename) { | 1180 | if (output_format_source == .inferred_from_input_filename) { |
| 1239 | try msg_writer.writeAll("the output format was inferred from the input filename"); | 1181 | try err_details.msg.appendSlice(allocator, "the output format was inferred from the input filename"); |
| 1240 | } else { | 1182 | } else { |
| 1241 | try msg_writer.writeAll("the output format was unable to be inferred from the input filename, so the default was used"); | 1183 | try err_details.msg.appendSlice(allocator, "the output format was unable to be inferred from the input filename, so the default was used"); |
| 1242 | } | 1184 | } |
| 1243 | try diagnostics.append(err_details); | 1185 | try diagnostics.append(err_details); |
| 1244 | }, | 1186 | }, |
| ... | @@ -1248,11 +1190,10 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1248,11 +1190,10 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1248 | .arg => |ctx| .{ .type = .note, .arg_index = ctx.index, .arg_span = ctx.value.argSpan(ctx.arg) }, | 1190 | .arg => |ctx| .{ .type = .note, .arg_index = ctx.index, .arg_span = ctx.value.argSpan(ctx.arg) }, |
| 1249 | .unspecified => unreachable, | 1191 | .unspecified => unreachable, |
| 1250 | }; | 1192 | }; |
| 1251 | var msg_writer = err_details.msg.writer(allocator); | | |
| 1252 | if (output_format_source == .inferred_from_output_filename) { | 1193 | if (output_format_source == .inferred_from_output_filename) { |
| 1253 | try msg_writer.writeAll("the output format was inferred from the output filename"); | 1194 | try err_details.msg.appendSlice(allocator, "the output format was inferred from the output filename"); |
| 1254 | } else { | 1195 | } else { |
| 1255 | try msg_writer.writeAll("the output format was unable to be inferred from the output filename, so the default was used"); | 1196 | try err_details.msg.appendSlice(allocator, "the output format was unable to be inferred from the output filename, so the default was used"); |
| 1256 | } | 1197 | } |
| 1257 | try diagnostics.append(err_details); | 1198 | try diagnostics.append(err_details); |
| 1258 | }, | 1199 | }, |
| ... | @@ -1262,14 +1203,12 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn | ... | @@ -1262,14 +1203,12 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 1262 | .arg_index = output_format_context.index, | 1203 | .arg_index = output_format_context.index, |
| 1263 | .arg_span = output_format_context.value.argSpan(output_format_context.arg), | 1204 | .arg_span = output_format_context.value.argSpan(output_format_context.arg), |
| 1264 | }; | 1205 | }; |
| 1265 | var msg_writer = err_details.msg.writer(allocator); | 1206 | try err_details.msg.appendSlice(allocator, "the output format was specified here"); |
| 1266 | try msg_writer.writeAll("the output format was specified here"); | | |
| 1267 | try diagnostics.append(err_details); | 1207 | try diagnostics.append(err_details); |
| 1268 | }, | 1208 | }, |
| 1269 | .inferred_from_preprocess_only => { | 1209 | .inferred_from_preprocess_only => { |
| 1270 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .arg_index = preprocess_only_context.index }; | 1210 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .arg_index = preprocess_only_context.index }; |
| 1271 | var msg_writer = err_details.msg.writer(allocator); | 1211 | try err_details.msg.print(allocator, "the output format was inferred from the usage of the {s}{s} option", .{ |
| 1272 | try msg_writer.print("the output format was inferred from the usage of the {s}{s} option", .{ | | |
| 1273 | preprocess_only_context.arg.prefixSlice(), | 1212 | preprocess_only_context.arg.prefixSlice(), |
| 1274 | preprocess_only_context.arg.optionWithoutPrefix(preprocess_only_context.option_len), | 1213 | preprocess_only_context.arg.optionWithoutPrefix(preprocess_only_context.option_len), |
| 1275 | }); | 1214 | }); |