| ... | ... | @@ -215,32 +215,33 @@ const Tokenizer = struct { |
| 215 | 215 | } |
| 216 | 216 | }; |
| 217 | 217 | |
| 218 | | fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: ...) anyerror { |
| 218 | fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: var) anyerror { |
| 219 | 219 | const loc = tokenizer.getTokenLocation(token); |
| 220 | | warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args); |
| 220 | const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 }; |
| 221 | warn("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args); |
| 221 | 222 | if (loc.line_start <= loc.line_end) { |
| 222 | | warn("{}\n", tokenizer.buffer[loc.line_start..loc.line_end]); |
| 223 | warn("{}\n", .{tokenizer.buffer[loc.line_start..loc.line_end]}); |
| 223 | 224 | { |
| 224 | 225 | var i: usize = 0; |
| 225 | 226 | while (i < loc.column) : (i += 1) { |
| 226 | | warn(" "); |
| 227 | warn(" ", .{}); |
| 227 | 228 | } |
| 228 | 229 | } |
| 229 | 230 | { |
| 230 | 231 | const caret_count = token.end - token.start; |
| 231 | 232 | var i: usize = 0; |
| 232 | 233 | while (i < caret_count) : (i += 1) { |
| 233 | | warn("~"); |
| 234 | warn("~", .{}); |
| 234 | 235 | } |
| 235 | 236 | } |
| 236 | | warn("\n"); |
| 237 | warn("\n", .{}); |
| 237 | 238 | } |
| 238 | 239 | return error.ParseError; |
| 239 | 240 | } |
| 240 | 241 | |
| 241 | 242 | fn assertToken(tokenizer: *Tokenizer, token: Token, id: Token.Id) !void { |
| 242 | 243 | if (token.id != id) { |
| 243 | | return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id)); |
| 244 | return parseError(tokenizer, token, "expected {}, found {}", .{ @tagName(id), @tagName(token.id) }); |
| 244 | 245 | } |
| 245 | 246 | } |
| 246 | 247 | |
| ... | ... | @@ -339,7 +340,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 339 | 340 | switch (token.id) { |
| 340 | 341 | Token.Id.Eof => { |
| 341 | 342 | if (header_stack_size != 0) { |
| 342 | | return parseError(tokenizer, token, "unbalanced headers"); |
| 343 | return parseError(tokenizer, token, "unbalanced headers", .{}); |
| 343 | 344 | } |
| 344 | 345 | try toc.write(" </ul>\n"); |
| 345 | 346 | break; |
| ... | ... | @@ -373,10 +374,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 373 | 374 | if (mem.eql(u8, param, "3col")) { |
| 374 | 375 | columns = 3; |
| 375 | 376 | } else { |
| 376 | | return parseError(tokenizer, bracket_tok, "unrecognized header_open param: {}", param); |
| 377 | return parseError( |
| 378 | tokenizer, |
| 379 | bracket_tok, |
| 380 | "unrecognized header_open param: {}", |
| 381 | .{param}, |
| 382 | ); |
| 377 | 383 | } |
| 378 | 384 | }, |
| 379 | | else => return parseError(tokenizer, bracket_tok, "invalid header_open token"), |
| 385 | else => return parseError(tokenizer, bracket_tok, "invalid header_open token", .{}), |
| 380 | 386 | } |
| 381 | 387 | } |
| 382 | 388 | |
| ... | ... | @@ -391,15 +397,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 391 | 397 | }, |
| 392 | 398 | }); |
| 393 | 399 | if (try urls.put(urlized, tag_token)) |entry| { |
| 394 | | parseError(tokenizer, tag_token, "duplicate header url: #{}", urlized) catch {}; |
| 395 | | parseError(tokenizer, entry.value, "other tag here") catch {}; |
| 400 | parseError(tokenizer, tag_token, "duplicate header url: #{}", .{urlized}) catch {}; |
| 401 | parseError(tokenizer, entry.value, "other tag here", .{}) catch {}; |
| 396 | 402 | return error.ParseError; |
| 397 | 403 | } |
| 398 | 404 | if (last_action == Action.Open) { |
| 399 | 405 | try toc.writeByte('\n'); |
| 400 | 406 | try toc.writeByteNTimes(' ', header_stack_size * 4); |
| 401 | 407 | if (last_columns) |n| { |
| 402 | | try toc.print("<ul style=\"columns: {}\">\n", n); |
| 408 | try toc.print("<ul style=\"columns: {}\">\n", .{n}); |
| 403 | 409 | } else { |
| 404 | 410 | try toc.write("<ul>\n"); |
| 405 | 411 | } |
| ... | ... | @@ -408,10 +414,10 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 408 | 414 | } |
| 409 | 415 | last_columns = columns; |
| 410 | 416 | try toc.writeByteNTimes(' ', 4 + header_stack_size * 4); |
| 411 | | try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", urlized, urlized, content); |
| 417 | try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", .{ urlized, urlized, content }); |
| 412 | 418 | } else if (mem.eql(u8, tag_name, "header_close")) { |
| 413 | 419 | if (header_stack_size == 0) { |
| 414 | | return parseError(tokenizer, tag_token, "unbalanced close header"); |
| 420 | return parseError(tokenizer, tag_token, "unbalanced close header", .{}); |
| 415 | 421 | } |
| 416 | 422 | header_stack_size -= 1; |
| 417 | 423 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| ... | ... | @@ -442,7 +448,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 442 | 448 | try nodes.append(Node{ .SeeAlso = list.toOwnedSlice() }); |
| 443 | 449 | break; |
| 444 | 450 | }, |
| 445 | | else => return parseError(tokenizer, see_also_tok, "invalid see_also token"), |
| 451 | else => return parseError(tokenizer, see_also_tok, "invalid see_also token", .{}), |
| 446 | 452 | } |
| 447 | 453 | } |
| 448 | 454 | } else if (mem.eql(u8, tag_name, "link")) { |
| ... | ... | @@ -459,7 +465,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 459 | 465 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 460 | 466 | break :blk tokenizer.buffer[explicit_text.start..explicit_text.end]; |
| 461 | 467 | }, |
| 462 | | else => return parseError(tokenizer, tok, "invalid link token"), |
| 468 | else => return parseError(tokenizer, tok, "invalid link token", .{}), |
| 463 | 469 | } |
| 464 | 470 | }; |
| 465 | 471 | |
| ... | ... | @@ -482,7 +488,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 482 | 488 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 483 | 489 | }, |
| 484 | 490 | Token.Id.BracketClose => {}, |
| 485 | | else => return parseError(tokenizer, token, "invalid token"), |
| 491 | else => return parseError(tokenizer, token, "invalid token", .{}), |
| 486 | 492 | } |
| 487 | 493 | const code_kind_str = tokenizer.buffer[code_kind_tok.start..code_kind_tok.end]; |
| 488 | 494 | var code_kind_id: Code.Id = undefined; |
| ... | ... | @@ -512,7 +518,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 512 | 518 | code_kind_id = Code.Id{ .Obj = null }; |
| 513 | 519 | is_inline = true; |
| 514 | 520 | } else { |
| 515 | | return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", code_kind_str); |
| 521 | return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", .{code_kind_str}); |
| 516 | 522 | } |
| 517 | 523 | |
| 518 | 524 | var mode = builtin.Mode.Debug; |
| ... | ... | @@ -550,7 +556,12 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 550 | 556 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 551 | 557 | break content_tok; |
| 552 | 558 | } else { |
| 553 | | return parseError(tokenizer, end_code_tag, "invalid token inside code_begin: {}", end_tag_name); |
| 559 | return parseError( |
| 560 | tokenizer, |
| 561 | end_code_tag, |
| 562 | "invalid token inside code_begin: {}", |
| 563 | .{end_tag_name}, |
| 564 | ); |
| 554 | 565 | } |
| 555 | 566 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 556 | 567 | } else |
| ... | ... | @@ -575,15 +586,20 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 575 | 586 | const end_syntax_tag = try eatToken(tokenizer, Token.Id.TagContent); |
| 576 | 587 | const end_tag_name = tokenizer.buffer[end_syntax_tag.start..end_syntax_tag.end]; |
| 577 | 588 | if (!mem.eql(u8, end_tag_name, "endsyntax")) { |
| 578 | | return parseError(tokenizer, end_syntax_tag, "invalid token inside syntax: {}", end_tag_name); |
| 589 | return parseError( |
| 590 | tokenizer, |
| 591 | end_syntax_tag, |
| 592 | "invalid token inside syntax: {}", |
| 593 | .{end_tag_name}, |
| 594 | ); |
| 579 | 595 | } |
| 580 | 596 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 581 | 597 | try nodes.append(Node{ .Syntax = content_tok }); |
| 582 | 598 | } else { |
| 583 | | return parseError(tokenizer, tag_token, "unrecognized tag name: {}", tag_name); |
| 599 | return parseError(tokenizer, tag_token, "unrecognized tag name: {}", .{tag_name}); |
| 584 | 600 | } |
| 585 | 601 | }, |
| 586 | | else => return parseError(tokenizer, token, "invalid token"), |
| 602 | else => return parseError(tokenizer, token, "invalid token", .{}), |
| 587 | 603 | } |
| 588 | 604 | } |
| 589 | 605 | |
| ... | ... | @@ -729,7 +745,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 729 | 745 | try out.write("</span>"); |
| 730 | 746 | } |
| 731 | 747 | if (first_number != 0 or second_number != 0) { |
| 732 | | try out.print("<span class=\"t{}_{}\">", first_number, second_number); |
| 748 | try out.print("<span class=\"t{}_{}\">", .{ first_number, second_number }); |
| 733 | 749 | open_span_count += 1; |
| 734 | 750 | } |
| 735 | 751 | }, |
| ... | ... | @@ -960,6 +976,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok |
| 960 | 976 | docgen_tokenizer, |
| 961 | 977 | source_token, |
| 962 | 978 | "syntax error", |
| 979 | .{}, |
| 963 | 980 | ), |
| 964 | 981 | } |
| 965 | 982 | index = token.end; |
| ... | ... | @@ -987,9 +1004,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 987 | 1004 | }, |
| 988 | 1005 | Node.Link => |info| { |
| 989 | 1006 | if (!toc.urls.contains(info.url)) { |
| 990 | | return parseError(tokenizer, info.token, "url not found: {}", info.url); |
| 1007 | return parseError(tokenizer, info.token, "url not found: {}", .{info.url}); |
| 991 | 1008 | } |
| 992 | | try out.print("<a href=\"#{}\">{}</a>", info.url, info.name); |
| 1009 | try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name }); |
| 993 | 1010 | }, |
| 994 | 1011 | Node.Nav => { |
| 995 | 1012 | try out.write(toc.toc); |
| ... | ... | @@ -1002,12 +1019,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1002 | 1019 | Node.HeaderOpen => |info| { |
| 1003 | 1020 | try out.print( |
| 1004 | 1021 | "<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">§</a></h{}>\n", |
| 1005 | | info.n, |
| 1006 | | info.url, |
| 1007 | | info.url, |
| 1008 | | info.name, |
| 1009 | | info.url, |
| 1010 | | info.n, |
| 1022 | .{ info.n, info.url, info.url, info.name, info.url, info.n }, |
| 1011 | 1023 | ); |
| 1012 | 1024 | }, |
| 1013 | 1025 | Node.SeeAlso => |items| { |
| ... | ... | @@ -1015,9 +1027,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1015 | 1027 | for (items) |item| { |
| 1016 | 1028 | const url = try urlize(allocator, item.name); |
| 1017 | 1029 | if (!toc.urls.contains(url)) { |
| 1018 | | return parseError(tokenizer, item.token, "url not found: {}", url); |
| 1030 | return parseError(tokenizer, item.token, "url not found: {}", .{url}); |
| 1019 | 1031 | } |
| 1020 | | try out.print("<li><a href=\"#{}\">{}</a></li>\n", url, item.name); |
| 1032 | try out.print("<li><a href=\"#{}\">{}</a></li>\n", .{ url, item.name }); |
| 1021 | 1033 | } |
| 1022 | 1034 | try out.write("</ul>\n"); |
| 1023 | 1035 | }, |
| ... | ... | @@ -1026,17 +1038,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1026 | 1038 | }, |
| 1027 | 1039 | Node.Code => |code| { |
| 1028 | 1040 | code_progress_index += 1; |
| 1029 | | warn("docgen example code {}/{}...", code_progress_index, tokenizer.code_node_count); |
| 1041 | warn("docgen example code {}/{}...", .{ code_progress_index, tokenizer.code_node_count }); |
| 1030 | 1042 | |
| 1031 | 1043 | const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end]; |
| 1032 | 1044 | const trimmed_raw_source = mem.trim(u8, raw_source, " \n"); |
| 1033 | 1045 | if (!code.is_inline) { |
| 1034 | | try out.print("<p class=\"file\">{}.zig</p>", code.name); |
| 1046 | try out.print("<p class=\"file\">{}.zig</p>", .{code.name}); |
| 1035 | 1047 | } |
| 1036 | 1048 | try out.write("<pre>"); |
| 1037 | 1049 | try tokenizeAndPrint(tokenizer, out, code.source_token); |
| 1038 | 1050 | try out.write("</pre>"); |
| 1039 | | const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name); |
| 1051 | const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", .{code.name}); |
| 1040 | 1052 | const tmp_source_file_name = try fs.path.join( |
| 1041 | 1053 | allocator, |
| 1042 | 1054 | &[_][]const u8{ tmp_dir_name, name_plus_ext }, |
| ... | ... | @@ -1045,7 +1057,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1045 | 1057 | |
| 1046 | 1058 | switch (code.id) { |
| 1047 | 1059 | Code.Id.Exe => |expected_outcome| code_block: { |
| 1048 | | const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext); |
| 1060 | const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, exe_ext }); |
| 1049 | 1061 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1050 | 1062 | defer build_args.deinit(); |
| 1051 | 1063 | try build_args.appendSlice(&[_][]const u8{ |
| ... | ... | @@ -1059,40 +1071,40 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1059 | 1071 | "--cache", |
| 1060 | 1072 | "on", |
| 1061 | 1073 | }); |
| 1062 | | try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", code.name); |
| 1074 | try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", .{code.name}); |
| 1063 | 1075 | switch (code.mode) { |
| 1064 | 1076 | builtin.Mode.Debug => {}, |
| 1065 | 1077 | builtin.Mode.ReleaseSafe => { |
| 1066 | 1078 | try build_args.append("--release-safe"); |
| 1067 | | try out.print(" --release-safe"); |
| 1079 | try out.print(" --release-safe", .{}); |
| 1068 | 1080 | }, |
| 1069 | 1081 | builtin.Mode.ReleaseFast => { |
| 1070 | 1082 | try build_args.append("--release-fast"); |
| 1071 | | try out.print(" --release-fast"); |
| 1083 | try out.print(" --release-fast", .{}); |
| 1072 | 1084 | }, |
| 1073 | 1085 | builtin.Mode.ReleaseSmall => { |
| 1074 | 1086 | try build_args.append("--release-small"); |
| 1075 | | try out.print(" --release-small"); |
| 1087 | try out.print(" --release-small", .{}); |
| 1076 | 1088 | }, |
| 1077 | 1089 | } |
| 1078 | 1090 | for (code.link_objects) |link_object| { |
| 1079 | | const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext); |
| 1091 | const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ link_object, obj_ext }); |
| 1080 | 1092 | const full_path_object = try fs.path.join( |
| 1081 | 1093 | allocator, |
| 1082 | 1094 | &[_][]const u8{ tmp_dir_name, name_with_ext }, |
| 1083 | 1095 | ); |
| 1084 | 1096 | try build_args.append("--object"); |
| 1085 | 1097 | try build_args.append(full_path_object); |
| 1086 | | try out.print(" --object {}", name_with_ext); |
| 1098 | try out.print(" --object {}", .{name_with_ext}); |
| 1087 | 1099 | } |
| 1088 | 1100 | if (code.link_libc) { |
| 1089 | 1101 | try build_args.append("-lc"); |
| 1090 | | try out.print(" -lc"); |
| 1102 | try out.print(" -lc", .{}); |
| 1091 | 1103 | } |
| 1092 | 1104 | if (code.target_str) |triple| { |
| 1093 | 1105 | try build_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1094 | 1106 | if (!code.is_inline) { |
| 1095 | | try out.print(" -target {}", triple); |
| 1107 | try out.print(" -target {}", .{triple}); |
| 1096 | 1108 | } |
| 1097 | 1109 | } |
| 1098 | 1110 | if (expected_outcome == .BuildFail) { |
| ... | ... | @@ -1106,29 +1118,29 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1106 | 1118 | switch (result.term) { |
| 1107 | 1119 | .Exited => |exit_code| { |
| 1108 | 1120 | if (exit_code == 0) { |
| 1109 | | warn("{}\nThe following command incorrectly succeeded:\n", result.stderr); |
| 1121 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1110 | 1122 | for (build_args.toSliceConst()) |arg| |
| 1111 | | warn("{} ", arg) |
| 1123 | warn("{} ", .{arg}) |
| 1112 | 1124 | else |
| 1113 | | warn("\n"); |
| 1114 | | return parseError(tokenizer, code.source_token, "example incorrectly compiled"); |
| 1125 | warn("\n", .{}); |
| 1126 | return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{}); |
| 1115 | 1127 | } |
| 1116 | 1128 | }, |
| 1117 | 1129 | else => { |
| 1118 | | warn("{}\nThe following command crashed:\n", result.stderr); |
| 1130 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1119 | 1131 | for (build_args.toSliceConst()) |arg| |
| 1120 | | warn("{} ", arg) |
| 1132 | warn("{} ", .{arg}) |
| 1121 | 1133 | else |
| 1122 | | warn("\n"); |
| 1123 | | return parseError(tokenizer, code.source_token, "example compile crashed"); |
| 1134 | warn("\n", .{}); |
| 1135 | return parseError(tokenizer, code.source_token, "example compile crashed", .{}); |
| 1124 | 1136 | }, |
| 1125 | 1137 | } |
| 1126 | 1138 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1127 | 1139 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1128 | | try out.print("\n{}</code></pre>\n", colored_stderr); |
| 1140 | try out.print("\n{}</code></pre>\n", .{colored_stderr}); |
| 1129 | 1141 | break :code_block; |
| 1130 | 1142 | } |
| 1131 | | const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile"); |
| 1143 | const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1132 | 1144 | |
| 1133 | 1145 | if (code.target_str) |triple| { |
| 1134 | 1146 | if (mem.startsWith(u8, triple, "wasm32") or |
| ... | ... | @@ -1137,7 +1149,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1137 | 1149 | (builtin.os != .linux or builtin.arch != .x86_64)) |
| 1138 | 1150 | { |
| 1139 | 1151 | // skip execution |
| 1140 | | try out.print("</code></pre>\n"); |
| 1152 | try out.print("</code></pre>\n", .{}); |
| 1141 | 1153 | break :code_block; |
| 1142 | 1154 | } |
| 1143 | 1155 | } |
| ... | ... | @@ -1152,12 +1164,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1152 | 1164 | switch (result.term) { |
| 1153 | 1165 | .Exited => |exit_code| { |
| 1154 | 1166 | if (exit_code == 0) { |
| 1155 | | warn("{}\nThe following command incorrectly succeeded:\n", result.stderr); |
| 1167 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1156 | 1168 | for (run_args) |arg| |
| 1157 | | warn("{} ", arg) |
| 1169 | warn("{} ", .{arg}) |
| 1158 | 1170 | else |
| 1159 | | warn("\n"); |
| 1160 | | return parseError(tokenizer, code.source_token, "example incorrectly compiled"); |
| 1171 | warn("\n", .{}); |
| 1172 | return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{}); |
| 1161 | 1173 | } |
| 1162 | 1174 | }, |
| 1163 | 1175 | .Signal => exited_with_signal = true, |
| ... | ... | @@ -1165,7 +1177,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1165 | 1177 | } |
| 1166 | 1178 | break :blk result; |
| 1167 | 1179 | } else blk: { |
| 1168 | | break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed"); |
| 1180 | break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{}); |
| 1169 | 1181 | }; |
| 1170 | 1182 | |
| 1171 | 1183 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| ... | ... | @@ -1174,11 +1186,11 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1174 | 1186 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1175 | 1187 | const colored_stdout = try termColor(allocator, escaped_stdout); |
| 1176 | 1188 | |
| 1177 | | try out.print("\n$ ./{}\n{}{}", code.name, colored_stdout, colored_stderr); |
| 1189 | try out.print("\n$ ./{}\n{}{}", .{ code.name, colored_stdout, colored_stderr }); |
| 1178 | 1190 | if (exited_with_signal) { |
| 1179 | | try out.print("(process terminated by signal)"); |
| 1191 | try out.print("(process terminated by signal)", .{}); |
| 1180 | 1192 | } |
| 1181 | | try out.print("</code></pre>\n"); |
| 1193 | try out.print("</code></pre>\n", .{}); |
| 1182 | 1194 | }, |
| 1183 | 1195 | Code.Id.Test => { |
| 1184 | 1196 | var test_args = std.ArrayList([]const u8).init(allocator); |
| ... | ... | @@ -1191,34 +1203,34 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1191 | 1203 | "--cache", |
| 1192 | 1204 | "on", |
| 1193 | 1205 | }); |
| 1194 | | try out.print("<pre><code class=\"shell\">$ zig test {}.zig", code.name); |
| 1206 | try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name}); |
| 1195 | 1207 | switch (code.mode) { |
| 1196 | 1208 | builtin.Mode.Debug => {}, |
| 1197 | 1209 | builtin.Mode.ReleaseSafe => { |
| 1198 | 1210 | try test_args.append("--release-safe"); |
| 1199 | | try out.print(" --release-safe"); |
| 1211 | try out.print(" --release-safe", .{}); |
| 1200 | 1212 | }, |
| 1201 | 1213 | builtin.Mode.ReleaseFast => { |
| 1202 | 1214 | try test_args.append("--release-fast"); |
| 1203 | | try out.print(" --release-fast"); |
| 1215 | try out.print(" --release-fast", .{}); |
| 1204 | 1216 | }, |
| 1205 | 1217 | builtin.Mode.ReleaseSmall => { |
| 1206 | 1218 | try test_args.append("--release-small"); |
| 1207 | | try out.print(" --release-small"); |
| 1219 | try out.print(" --release-small", .{}); |
| 1208 | 1220 | }, |
| 1209 | 1221 | } |
| 1210 | 1222 | if (code.link_libc) { |
| 1211 | 1223 | try test_args.append("-lc"); |
| 1212 | | try out.print(" -lc"); |
| 1224 | try out.print(" -lc", .{}); |
| 1213 | 1225 | } |
| 1214 | 1226 | if (code.target_str) |triple| { |
| 1215 | 1227 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1216 | | try out.print(" -target {}", triple); |
| 1228 | try out.print(" -target {}", .{triple}); |
| 1217 | 1229 | } |
| 1218 | | const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed"); |
| 1230 | const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1219 | 1231 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1220 | 1232 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1221 | | try out.print("\n{}{}</code></pre>\n", escaped_stderr, escaped_stdout); |
| 1233 | try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout }); |
| 1222 | 1234 | }, |
| 1223 | 1235 | Code.Id.TestError => |error_match| { |
| 1224 | 1236 | var test_args = std.ArrayList([]const u8).init(allocator); |
| ... | ... | @@ -1233,50 +1245,50 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1233 | 1245 | "--output-dir", |
| 1234 | 1246 | tmp_dir_name, |
| 1235 | 1247 | }); |
| 1236 | | try out.print("<pre><code class=\"shell\">$ zig test {}.zig", code.name); |
| 1248 | try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name}); |
| 1237 | 1249 | switch (code.mode) { |
| 1238 | 1250 | builtin.Mode.Debug => {}, |
| 1239 | 1251 | builtin.Mode.ReleaseSafe => { |
| 1240 | 1252 | try test_args.append("--release-safe"); |
| 1241 | | try out.print(" --release-safe"); |
| 1253 | try out.print(" --release-safe", .{}); |
| 1242 | 1254 | }, |
| 1243 | 1255 | builtin.Mode.ReleaseFast => { |
| 1244 | 1256 | try test_args.append("--release-fast"); |
| 1245 | | try out.print(" --release-fast"); |
| 1257 | try out.print(" --release-fast", .{}); |
| 1246 | 1258 | }, |
| 1247 | 1259 | builtin.Mode.ReleaseSmall => { |
| 1248 | 1260 | try test_args.append("--release-small"); |
| 1249 | | try out.print(" --release-small"); |
| 1261 | try out.print(" --release-small", .{}); |
| 1250 | 1262 | }, |
| 1251 | 1263 | } |
| 1252 | 1264 | const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size); |
| 1253 | 1265 | switch (result.term) { |
| 1254 | 1266 | .Exited => |exit_code| { |
| 1255 | 1267 | if (exit_code == 0) { |
| 1256 | | warn("{}\nThe following command incorrectly succeeded:\n", result.stderr); |
| 1268 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1257 | 1269 | for (test_args.toSliceConst()) |arg| |
| 1258 | | warn("{} ", arg) |
| 1270 | warn("{} ", .{arg}) |
| 1259 | 1271 | else |
| 1260 | | warn("\n"); |
| 1261 | | return parseError(tokenizer, code.source_token, "example incorrectly compiled"); |
| 1272 | warn("\n", .{}); |
| 1273 | return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{}); |
| 1262 | 1274 | } |
| 1263 | 1275 | }, |
| 1264 | 1276 | else => { |
| 1265 | | warn("{}\nThe following command crashed:\n", result.stderr); |
| 1277 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1266 | 1278 | for (test_args.toSliceConst()) |arg| |
| 1267 | | warn("{} ", arg) |
| 1279 | warn("{} ", .{arg}) |
| 1268 | 1280 | else |
| 1269 | | warn("\n"); |
| 1270 | | return parseError(tokenizer, code.source_token, "example compile crashed"); |
| 1281 | warn("\n", .{}); |
| 1282 | return parseError(tokenizer, code.source_token, "example compile crashed", .{}); |
| 1271 | 1283 | }, |
| 1272 | 1284 | } |
| 1273 | 1285 | if (mem.indexOf(u8, result.stderr, error_match) == null) { |
| 1274 | | warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match); |
| 1275 | | return parseError(tokenizer, code.source_token, "example did not have expected compile error"); |
| 1286 | warn("{}\nExpected to find '{}' in stderr", .{ result.stderr, error_match }); |
| 1287 | return parseError(tokenizer, code.source_token, "example did not have expected compile error", .{}); |
| 1276 | 1288 | } |
| 1277 | 1289 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1278 | 1290 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1279 | | try out.print("\n{}</code></pre>\n", colored_stderr); |
| 1291 | try out.print("\n{}</code></pre>\n", .{colored_stderr}); |
| 1280 | 1292 | }, |
| 1281 | 1293 | |
| 1282 | 1294 | Code.Id.TestSafety => |error_match| { |
| ... | ... | @@ -1311,38 +1323,37 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1311 | 1323 | switch (result.term) { |
| 1312 | 1324 | .Exited => |exit_code| { |
| 1313 | 1325 | if (exit_code == 0) { |
| 1314 | | warn("{}\nThe following command incorrectly succeeded:\n", result.stderr); |
| 1326 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1315 | 1327 | for (test_args.toSliceConst()) |arg| |
| 1316 | | warn("{} ", arg) |
| 1328 | warn("{} ", .{arg}) |
| 1317 | 1329 | else |
| 1318 | | warn("\n"); |
| 1319 | | return parseError(tokenizer, code.source_token, "example test incorrectly succeeded"); |
| 1330 | warn("\n", .{}); |
| 1331 | return parseError(tokenizer, code.source_token, "example test incorrectly succeeded", .{}); |
| 1320 | 1332 | } |
| 1321 | 1333 | }, |
| 1322 | 1334 | else => { |
| 1323 | | warn("{}\nThe following command crashed:\n", result.stderr); |
| 1335 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1324 | 1336 | for (test_args.toSliceConst()) |arg| |
| 1325 | | warn("{} ", arg) |
| 1337 | warn("{} ", .{arg}) |
| 1326 | 1338 | else |
| 1327 | | warn("\n"); |
| 1328 | | return parseError(tokenizer, code.source_token, "example compile crashed"); |
| 1339 | warn("\n", .{}); |
| 1340 | return parseError(tokenizer, code.source_token, "example compile crashed", .{}); |
| 1329 | 1341 | }, |
| 1330 | 1342 | } |
| 1331 | 1343 | if (mem.indexOf(u8, result.stderr, error_match) == null) { |
| 1332 | | warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match); |
| 1333 | | return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message"); |
| 1344 | warn("{}\nExpected to find '{}' in stderr", .{ result.stderr, error_match }); |
| 1345 | return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message", .{}); |
| 1334 | 1346 | } |
| 1335 | 1347 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1336 | 1348 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1337 | | try out.print( |
| 1338 | | "<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n", |
| 1349 | try out.print("<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n", .{ |
| 1339 | 1350 | code.name, |
| 1340 | 1351 | mode_arg, |
| 1341 | 1352 | colored_stderr, |
| 1342 | | ); |
| 1353 | }); |
| 1343 | 1354 | }, |
| 1344 | 1355 | Code.Id.Obj => |maybe_error_match| { |
| 1345 | | const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext); |
| 1356 | const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, obj_ext }); |
| 1346 | 1357 | const tmp_obj_file_name = try fs.path.join( |
| 1347 | 1358 | allocator, |
| 1348 | 1359 | &[_][]const u8{ tmp_dir_name, name_plus_obj_ext }, |
| ... | ... | @@ -1350,7 +1361,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1350 | 1361 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1351 | 1362 | defer build_args.deinit(); |
| 1352 | 1363 | |
| 1353 | | const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name); |
| 1364 | const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", .{code.name}); |
| 1354 | 1365 | const output_h_file_name = try fs.path.join( |
| 1355 | 1366 | allocator, |
| 1356 | 1367 | &[_][]const u8{ tmp_dir_name, name_plus_h_ext }, |
| ... | ... | @@ -1369,7 +1380,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1369 | 1380 | }); |
| 1370 | 1381 | |
| 1371 | 1382 | if (!code.is_inline) { |
| 1372 | | try out.print("<pre><code class=\"shell\">$ zig build-obj {}.zig", code.name); |
| 1383 | try out.print("<pre><code class=\"shell\">$ zig build-obj {}.zig", .{code.name}); |
| 1373 | 1384 | } |
| 1374 | 1385 | |
| 1375 | 1386 | switch (code.mode) { |
| ... | ... | @@ -1377,26 +1388,26 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1377 | 1388 | builtin.Mode.ReleaseSafe => { |
| 1378 | 1389 | try build_args.append("--release-safe"); |
| 1379 | 1390 | if (!code.is_inline) { |
| 1380 | | try out.print(" --release-safe"); |
| 1391 | try out.print(" --release-safe", .{}); |
| 1381 | 1392 | } |
| 1382 | 1393 | }, |
| 1383 | 1394 | builtin.Mode.ReleaseFast => { |
| 1384 | 1395 | try build_args.append("--release-fast"); |
| 1385 | 1396 | if (!code.is_inline) { |
| 1386 | | try out.print(" --release-fast"); |
| 1397 | try out.print(" --release-fast", .{}); |
| 1387 | 1398 | } |
| 1388 | 1399 | }, |
| 1389 | 1400 | builtin.Mode.ReleaseSmall => { |
| 1390 | 1401 | try build_args.append("--release-small"); |
| 1391 | 1402 | if (!code.is_inline) { |
| 1392 | | try out.print(" --release-small"); |
| 1403 | try out.print(" --release-small", .{}); |
| 1393 | 1404 | } |
| 1394 | 1405 | }, |
| 1395 | 1406 | } |
| 1396 | 1407 | |
| 1397 | 1408 | if (code.target_str) |triple| { |
| 1398 | 1409 | try build_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1399 | | try out.print(" -target {}", triple); |
| 1410 | try out.print(" -target {}", .{triple}); |
| 1400 | 1411 | } |
| 1401 | 1412 | |
| 1402 | 1413 | if (maybe_error_match) |error_match| { |
| ... | ... | @@ -1404,35 +1415,35 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1404 | 1415 | switch (result.term) { |
| 1405 | 1416 | .Exited => |exit_code| { |
| 1406 | 1417 | if (exit_code == 0) { |
| 1407 | | warn("{}\nThe following command incorrectly succeeded:\n", result.stderr); |
| 1418 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1408 | 1419 | for (build_args.toSliceConst()) |arg| |
| 1409 | | warn("{} ", arg) |
| 1420 | warn("{} ", .{arg}) |
| 1410 | 1421 | else |
| 1411 | | warn("\n"); |
| 1412 | | return parseError(tokenizer, code.source_token, "example build incorrectly succeeded"); |
| 1422 | warn("\n", .{}); |
| 1423 | return parseError(tokenizer, code.source_token, "example build incorrectly succeeded", .{}); |
| 1413 | 1424 | } |
| 1414 | 1425 | }, |
| 1415 | 1426 | else => { |
| 1416 | | warn("{}\nThe following command crashed:\n", result.stderr); |
| 1427 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1417 | 1428 | for (build_args.toSliceConst()) |arg| |
| 1418 | | warn("{} ", arg) |
| 1429 | warn("{} ", .{arg}) |
| 1419 | 1430 | else |
| 1420 | | warn("\n"); |
| 1421 | | return parseError(tokenizer, code.source_token, "example compile crashed"); |
| 1431 | warn("\n", .{}); |
| 1432 | return parseError(tokenizer, code.source_token, "example compile crashed", .{}); |
| 1422 | 1433 | }, |
| 1423 | 1434 | } |
| 1424 | 1435 | if (mem.indexOf(u8, result.stderr, error_match) == null) { |
| 1425 | | warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match); |
| 1426 | | return parseError(tokenizer, code.source_token, "example did not have expected compile error message"); |
| 1436 | warn("{}\nExpected to find '{}' in stderr", .{ result.stderr, error_match }); |
| 1437 | return parseError(tokenizer, code.source_token, "example did not have expected compile error message", .{}); |
| 1427 | 1438 | } |
| 1428 | 1439 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1429 | 1440 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1430 | | try out.print("\n{}", colored_stderr); |
| 1441 | try out.print("\n{}", .{colored_stderr}); |
| 1431 | 1442 | } else { |
| 1432 | | _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile"); |
| 1443 | _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1433 | 1444 | } |
| 1434 | 1445 | if (!code.is_inline) { |
| 1435 | | try out.print("</code></pre>\n"); |
| 1446 | try out.print("</code></pre>\n", .{}); |
| 1436 | 1447 | } |
| 1437 | 1448 | }, |
| 1438 | 1449 | Code.Id.Lib => { |
| ... | ... | @@ -1446,33 +1457,33 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1446 | 1457 | "--output-dir", |
| 1447 | 1458 | tmp_dir_name, |
| 1448 | 1459 | }); |
| 1449 | | try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", code.name); |
| 1460 | try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", .{code.name}); |
| 1450 | 1461 | switch (code.mode) { |
| 1451 | 1462 | builtin.Mode.Debug => {}, |
| 1452 | 1463 | builtin.Mode.ReleaseSafe => { |
| 1453 | 1464 | try test_args.append("--release-safe"); |
| 1454 | | try out.print(" --release-safe"); |
| 1465 | try out.print(" --release-safe", .{}); |
| 1455 | 1466 | }, |
| 1456 | 1467 | builtin.Mode.ReleaseFast => { |
| 1457 | 1468 | try test_args.append("--release-fast"); |
| 1458 | | try out.print(" --release-fast"); |
| 1469 | try out.print(" --release-fast", .{}); |
| 1459 | 1470 | }, |
| 1460 | 1471 | builtin.Mode.ReleaseSmall => { |
| 1461 | 1472 | try test_args.append("--release-small"); |
| 1462 | | try out.print(" --release-small"); |
| 1473 | try out.print(" --release-small", .{}); |
| 1463 | 1474 | }, |
| 1464 | 1475 | } |
| 1465 | 1476 | if (code.target_str) |triple| { |
| 1466 | 1477 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1467 | | try out.print(" -target {}", triple); |
| 1478 | try out.print(" -target {}", .{triple}); |
| 1468 | 1479 | } |
| 1469 | | const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed"); |
| 1480 | const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1470 | 1481 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1471 | 1482 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1472 | | try out.print("\n{}{}</code></pre>\n", escaped_stderr, escaped_stdout); |
| 1483 | try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout }); |
| 1473 | 1484 | }, |
| 1474 | 1485 | } |
| 1475 | | warn("OK\n"); |
| 1486 | warn("OK\n", .{}); |
| 1476 | 1487 | }, |
| 1477 | 1488 | } |
| 1478 | 1489 | } |
| ... | ... | @@ -1483,20 +1494,20 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u |
| 1483 | 1494 | switch (result.term) { |
| 1484 | 1495 | .Exited => |exit_code| { |
| 1485 | 1496 | if (exit_code != 0) { |
| 1486 | | warn("{}\nThe following command exited with code {}:\n", result.stderr, exit_code); |
| 1497 | warn("{}\nThe following command exited with code {}:\n", .{ result.stderr, exit_code }); |
| 1487 | 1498 | for (args) |arg| |
| 1488 | | warn("{} ", arg) |
| 1499 | warn("{} ", .{arg}) |
| 1489 | 1500 | else |
| 1490 | | warn("\n"); |
| 1501 | warn("\n", .{}); |
| 1491 | 1502 | return error.ChildExitError; |
| 1492 | 1503 | } |
| 1493 | 1504 | }, |
| 1494 | 1505 | else => { |
| 1495 | | warn("{}\nThe following command crashed:\n", result.stderr); |
| 1506 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1496 | 1507 | for (args) |arg| |
| 1497 | | warn("{} ", arg) |
| 1508 | warn("{} ", .{arg}) |
| 1498 | 1509 | else |
| 1499 | | warn("\n"); |
| 1510 | warn("\n", .{}); |
| 1500 | 1511 | return error.ChildCrashed; |
| 1501 | 1512 | }, |
| 1502 | 1513 | } |