| ... | ... | @@ -111,13 +111,13 @@ const Token = struct { |
| 111 | 111 | end: usize, |
| 112 | 112 | |
| 113 | 113 | const Id = enum { |
| 114 | | Invalid, |
| 115 | | Content, |
| 116 | | BracketOpen, |
| 117 | | TagContent, |
| 118 | | Separator, |
| 119 | | BracketClose, |
| 120 | | Eof, |
| 114 | invalid, |
| 115 | content, |
| 116 | bracket_open, |
| 117 | tag_content, |
| 118 | separator, |
| 119 | bracket_close, |
| 120 | eof, |
| 121 | 121 | }; |
| 122 | 122 | }; |
| 123 | 123 | |
| ... | ... | @@ -129,18 +129,18 @@ const Tokenizer = struct { |
| 129 | 129 | code_node_count: usize, |
| 130 | 130 | |
| 131 | 131 | const State = enum { |
| 132 | | Start, |
| 133 | | LBracket, |
| 134 | | Hash, |
| 135 | | TagName, |
| 136 | | Eof, |
| 132 | start, |
| 133 | l_bracket, |
| 134 | hash, |
| 135 | tag_name, |
| 136 | eof, |
| 137 | 137 | }; |
| 138 | 138 | |
| 139 | 139 | fn init(source_file_name: []const u8, buffer: []const u8) Tokenizer { |
| 140 | 140 | return Tokenizer{ |
| 141 | 141 | .buffer = buffer, |
| 142 | 142 | .index = 0, |
| 143 | | .state = State.Start, |
| 143 | .state = .start, |
| 144 | 144 | .source_file_name = source_file_name, |
| 145 | 145 | .code_node_count = 0, |
| 146 | 146 | }; |
| ... | ... | @@ -148,84 +148,84 @@ const Tokenizer = struct { |
| 148 | 148 | |
| 149 | 149 | fn next(self: *Tokenizer) Token { |
| 150 | 150 | var result = Token{ |
| 151 | | .id = Token.Id.Eof, |
| 151 | .id = .eof, |
| 152 | 152 | .start = self.index, |
| 153 | 153 | .end = undefined, |
| 154 | 154 | }; |
| 155 | 155 | while (self.index < self.buffer.len) : (self.index += 1) { |
| 156 | 156 | const c = self.buffer[self.index]; |
| 157 | 157 | switch (self.state) { |
| 158 | | State.Start => switch (c) { |
| 158 | .start => switch (c) { |
| 159 | 159 | '{' => { |
| 160 | | self.state = State.LBracket; |
| 160 | self.state = .l_bracket; |
| 161 | 161 | }, |
| 162 | 162 | else => { |
| 163 | | result.id = Token.Id.Content; |
| 163 | result.id = .content; |
| 164 | 164 | }, |
| 165 | 165 | }, |
| 166 | | State.LBracket => switch (c) { |
| 166 | .l_bracket => switch (c) { |
| 167 | 167 | '#' => { |
| 168 | | if (result.id != Token.Id.Eof) { |
| 168 | if (result.id != .eof) { |
| 169 | 169 | self.index -= 1; |
| 170 | | self.state = State.Start; |
| 170 | self.state = .start; |
| 171 | 171 | break; |
| 172 | 172 | } else { |
| 173 | | result.id = Token.Id.BracketOpen; |
| 173 | result.id = .bracket_open; |
| 174 | 174 | self.index += 1; |
| 175 | | self.state = State.TagName; |
| 175 | self.state = .tag_name; |
| 176 | 176 | break; |
| 177 | 177 | } |
| 178 | 178 | }, |
| 179 | 179 | else => { |
| 180 | | result.id = Token.Id.Content; |
| 181 | | self.state = State.Start; |
| 180 | result.id = .content; |
| 181 | self.state = .start; |
| 182 | 182 | }, |
| 183 | 183 | }, |
| 184 | | State.TagName => switch (c) { |
| 184 | .tag_name => switch (c) { |
| 185 | 185 | '|' => { |
| 186 | | if (result.id != Token.Id.Eof) { |
| 186 | if (result.id != .eof) { |
| 187 | 187 | break; |
| 188 | 188 | } else { |
| 189 | | result.id = Token.Id.Separator; |
| 189 | result.id = .separator; |
| 190 | 190 | self.index += 1; |
| 191 | 191 | break; |
| 192 | 192 | } |
| 193 | 193 | }, |
| 194 | 194 | '#' => { |
| 195 | | self.state = State.Hash; |
| 195 | self.state = .hash; |
| 196 | 196 | }, |
| 197 | 197 | else => { |
| 198 | | result.id = Token.Id.TagContent; |
| 198 | result.id = .tag_content; |
| 199 | 199 | }, |
| 200 | 200 | }, |
| 201 | | State.Hash => switch (c) { |
| 201 | .hash => switch (c) { |
| 202 | 202 | '}' => { |
| 203 | | if (result.id != Token.Id.Eof) { |
| 203 | if (result.id != .eof) { |
| 204 | 204 | self.index -= 1; |
| 205 | | self.state = State.TagName; |
| 205 | self.state = .tag_name; |
| 206 | 206 | break; |
| 207 | 207 | } else { |
| 208 | | result.id = Token.Id.BracketClose; |
| 208 | result.id = .bracket_close; |
| 209 | 209 | self.index += 1; |
| 210 | | self.state = State.Start; |
| 210 | self.state = .start; |
| 211 | 211 | break; |
| 212 | 212 | } |
| 213 | 213 | }, |
| 214 | 214 | else => { |
| 215 | | result.id = Token.Id.TagContent; |
| 216 | | self.state = State.TagName; |
| 215 | result.id = .tag_content; |
| 216 | self.state = .tag_name; |
| 217 | 217 | }, |
| 218 | 218 | }, |
| 219 | | State.Eof => unreachable, |
| 219 | .eof => unreachable, |
| 220 | 220 | } |
| 221 | 221 | } else { |
| 222 | 222 | switch (self.state) { |
| 223 | | State.Start, State.LBracket, State.Eof => {}, |
| 223 | .start, .l_bracket, .eof => {}, |
| 224 | 224 | else => { |
| 225 | | result.id = Token.Id.Invalid; |
| 225 | result.id = .invalid; |
| 226 | 226 | }, |
| 227 | 227 | } |
| 228 | | self.state = State.Eof; |
| 228 | self.state = .eof; |
| 229 | 229 | } |
| 230 | 230 | result.end = self.index; |
| 231 | 231 | return result; |
| ... | ... | @@ -311,9 +311,9 @@ const SeeAlsoItem = struct { |
| 311 | 311 | }; |
| 312 | 312 | |
| 313 | 313 | const ExpectedOutcome = enum { |
| 314 | | Succeed, |
| 315 | | Fail, |
| 316 | | BuildFail, |
| 314 | succeed, |
| 315 | fail, |
| 316 | build_fail, |
| 317 | 317 | }; |
| 318 | 318 | |
| 319 | 319 | const Code = struct { |
| ... | ... | @@ -331,12 +331,12 @@ const Code = struct { |
| 331 | 331 | additional_options: []const []const u8, |
| 332 | 332 | |
| 333 | 333 | const Id = union(enum) { |
| 334 | | Test, |
| 335 | | TestError: []const u8, |
| 336 | | TestSafety: []const u8, |
| 337 | | Exe: ExpectedOutcome, |
| 338 | | Obj: ?[]const u8, |
| 339 | | Lib, |
| 334 | @"test", |
| 335 | test_error: []const u8, |
| 336 | test_safety: []const u8, |
| 337 | exe: ExpectedOutcome, |
| 338 | obj: ?[]const u8, |
| 339 | lib, |
| 340 | 340 | }; |
| 341 | 341 | }; |
| 342 | 342 | |
| ... | ... | @@ -379,8 +379,8 @@ const Toc = struct { |
| 379 | 379 | }; |
| 380 | 380 | |
| 381 | 381 | const Action = enum { |
| 382 | | Open, |
| 383 | | Close, |
| 382 | open, |
| 383 | close, |
| 384 | 384 | }; |
| 385 | 385 | |
| 386 | 386 | fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| ... | ... | @@ -388,7 +388,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 388 | 388 | errdefer urls.deinit(); |
| 389 | 389 | |
| 390 | 390 | var header_stack_size: usize = 0; |
| 391 | | var last_action = Action.Open; |
| 391 | var last_action: Action = .open; |
| 392 | 392 | var last_columns: ?u8 = null; |
| 393 | 393 | |
| 394 | 394 | var toc_buf = std.ArrayList(u8).init(allocator); |
| ... | ... | @@ -404,38 +404,38 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 404 | 404 | while (true) { |
| 405 | 405 | const token = tokenizer.next(); |
| 406 | 406 | switch (token.id) { |
| 407 | | Token.Id.Eof => { |
| 407 | .eof => { |
| 408 | 408 | if (header_stack_size != 0) { |
| 409 | 409 | return parseError(tokenizer, token, "unbalanced headers", .{}); |
| 410 | 410 | } |
| 411 | 411 | try toc.writeAll(" </ul>\n"); |
| 412 | 412 | break; |
| 413 | 413 | }, |
| 414 | | Token.Id.Content => { |
| 414 | .content => { |
| 415 | 415 | try nodes.append(Node{ .Content = tokenizer.buffer[token.start..token.end] }); |
| 416 | 416 | }, |
| 417 | | Token.Id.BracketOpen => { |
| 418 | | const tag_token = try eatToken(tokenizer, Token.Id.TagContent); |
| 417 | .bracket_open => { |
| 418 | const tag_token = try eatToken(tokenizer, .tag_content); |
| 419 | 419 | const tag_name = tokenizer.buffer[tag_token.start..tag_token.end]; |
| 420 | 420 | |
| 421 | 421 | if (mem.eql(u8, tag_name, "nav")) { |
| 422 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 422 | _ = try eatToken(tokenizer, .bracket_close); |
| 423 | 423 | |
| 424 | 424 | try nodes.append(Node.Nav); |
| 425 | 425 | } else if (mem.eql(u8, tag_name, "builtin")) { |
| 426 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 426 | _ = try eatToken(tokenizer, .bracket_close); |
| 427 | 427 | try nodes.append(Node{ .Builtin = tag_token }); |
| 428 | 428 | } else if (mem.eql(u8, tag_name, "header_open")) { |
| 429 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 430 | | const content_token = try eatToken(tokenizer, Token.Id.TagContent); |
| 429 | _ = try eatToken(tokenizer, .separator); |
| 430 | const content_token = try eatToken(tokenizer, .tag_content); |
| 431 | 431 | const content = tokenizer.buffer[content_token.start..content_token.end]; |
| 432 | 432 | var columns: ?u8 = null; |
| 433 | 433 | while (true) { |
| 434 | 434 | const bracket_tok = tokenizer.next(); |
| 435 | 435 | switch (bracket_tok.id) { |
| 436 | | .BracketClose => break, |
| 437 | | .Separator => continue, |
| 438 | | .TagContent => { |
| 436 | .bracket_close => break, |
| 437 | .separator => continue, |
| 438 | .tag_content => { |
| 439 | 439 | const param = tokenizer.buffer[bracket_tok.start..bracket_tok.end]; |
| 440 | 440 | if (mem.eql(u8, param, "2col")) { |
| 441 | 441 | columns = 2; |
| ... | ... | @@ -467,7 +467,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 467 | 467 | parseError(tokenizer, kv.value, "other tag here", .{}) catch {}; |
| 468 | 468 | return error.ParseError; |
| 469 | 469 | } |
| 470 | | if (last_action == Action.Open) { |
| 470 | if (last_action == .open) { |
| 471 | 471 | try toc.writeByte('\n'); |
| 472 | 472 | try toc.writeByteNTimes(' ', header_stack_size * 4); |
| 473 | 473 | if (last_columns) |n| { |
| ... | ... | @@ -476,7 +476,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 476 | 476 | try toc.writeAll("<ul>\n"); |
| 477 | 477 | } |
| 478 | 478 | } else { |
| 479 | | last_action = Action.Open; |
| 479 | last_action = .open; |
| 480 | 480 | } |
| 481 | 481 | last_columns = columns; |
| 482 | 482 | try toc.writeByteNTimes(' ', 4 + header_stack_size * 4); |
| ... | ... | @@ -486,14 +486,14 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 486 | 486 | return parseError(tokenizer, tag_token, "unbalanced close header", .{}); |
| 487 | 487 | } |
| 488 | 488 | header_stack_size -= 1; |
| 489 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 489 | _ = try eatToken(tokenizer, .bracket_close); |
| 490 | 490 | |
| 491 | | if (last_action == Action.Close) { |
| 491 | if (last_action == .close) { |
| 492 | 492 | try toc.writeByteNTimes(' ', 8 + header_stack_size * 4); |
| 493 | 493 | try toc.writeAll("</ul></li>\n"); |
| 494 | 494 | } else { |
| 495 | 495 | try toc.writeAll("</li>\n"); |
| 496 | | last_action = Action.Close; |
| 496 | last_action = .close; |
| 497 | 497 | } |
| 498 | 498 | } else if (mem.eql(u8, tag_name, "see_also")) { |
| 499 | 499 | var list = std.ArrayList(SeeAlsoItem).init(allocator); |
| ... | ... | @@ -502,15 +502,15 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 502 | 502 | while (true) { |
| 503 | 503 | const see_also_tok = tokenizer.next(); |
| 504 | 504 | switch (see_also_tok.id) { |
| 505 | | Token.Id.TagContent => { |
| 505 | .tag_content => { |
| 506 | 506 | const content = tokenizer.buffer[see_also_tok.start..see_also_tok.end]; |
| 507 | 507 | try list.append(SeeAlsoItem{ |
| 508 | 508 | .name = content, |
| 509 | 509 | .token = see_also_tok, |
| 510 | 510 | }); |
| 511 | 511 | }, |
| 512 | | Token.Id.Separator => {}, |
| 513 | | Token.Id.BracketClose => { |
| 512 | .separator => {}, |
| 513 | .bracket_close => { |
| 514 | 514 | try nodes.append(Node{ .SeeAlso = try list.toOwnedSlice() }); |
| 515 | 515 | break; |
| 516 | 516 | }, |
| ... | ... | @@ -518,17 +518,17 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | } else if (mem.eql(u8, tag_name, "link")) { |
| 521 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 522 | | const name_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 521 | _ = try eatToken(tokenizer, .separator); |
| 522 | const name_tok = try eatToken(tokenizer, .tag_content); |
| 523 | 523 | const name = tokenizer.buffer[name_tok.start..name_tok.end]; |
| 524 | 524 | |
| 525 | 525 | const url_name = blk: { |
| 526 | 526 | const tok = tokenizer.next(); |
| 527 | 527 | switch (tok.id) { |
| 528 | | Token.Id.BracketClose => break :blk name, |
| 529 | | Token.Id.Separator => { |
| 530 | | const explicit_text = try eatToken(tokenizer, Token.Id.TagContent); |
| 531 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 528 | .bracket_close => break :blk name, |
| 529 | .separator => { |
| 530 | const explicit_text = try eatToken(tokenizer, .tag_content); |
| 531 | _ = try eatToken(tokenizer, .bracket_close); |
| 532 | 532 | break :blk tokenizer.buffer[explicit_text.start..explicit_text.end]; |
| 533 | 533 | }, |
| 534 | 534 | else => return parseError(tokenizer, tok, "invalid link token", .{}), |
| ... | ... | @@ -543,45 +543,45 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 543 | 543 | }, |
| 544 | 544 | }); |
| 545 | 545 | } else if (mem.eql(u8, tag_name, "code_begin")) { |
| 546 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 547 | | const code_kind_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 548 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 549 | | const name_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 546 | _ = try eatToken(tokenizer, .separator); |
| 547 | const code_kind_tok = try eatToken(tokenizer, .tag_content); |
| 548 | _ = try eatToken(tokenizer, .separator); |
| 549 | const name_tok = try eatToken(tokenizer, .tag_content); |
| 550 | 550 | const name = tokenizer.buffer[name_tok.start..name_tok.end]; |
| 551 | 551 | var error_str: []const u8 = ""; |
| 552 | 552 | const maybe_sep = tokenizer.next(); |
| 553 | 553 | switch (maybe_sep.id) { |
| 554 | | Token.Id.Separator => { |
| 555 | | const error_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 554 | .separator => { |
| 555 | const error_tok = try eatToken(tokenizer, .tag_content); |
| 556 | 556 | error_str = tokenizer.buffer[error_tok.start..error_tok.end]; |
| 557 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 557 | _ = try eatToken(tokenizer, .bracket_close); |
| 558 | 558 | }, |
| 559 | | Token.Id.BracketClose => {}, |
| 559 | .bracket_close => {}, |
| 560 | 560 | else => return parseError(tokenizer, token, "invalid token", .{}), |
| 561 | 561 | } |
| 562 | 562 | const code_kind_str = tokenizer.buffer[code_kind_tok.start..code_kind_tok.end]; |
| 563 | 563 | var code_kind_id: Code.Id = undefined; |
| 564 | 564 | var just_check_syntax = false; |
| 565 | 565 | if (mem.eql(u8, code_kind_str, "exe")) { |
| 566 | | code_kind_id = Code.Id{ .Exe = ExpectedOutcome.Succeed }; |
| 566 | code_kind_id = Code.Id{ .exe = .succeed }; |
| 567 | 567 | } else if (mem.eql(u8, code_kind_str, "exe_err")) { |
| 568 | | code_kind_id = Code.Id{ .Exe = ExpectedOutcome.Fail }; |
| 568 | code_kind_id = Code.Id{ .exe = .fail }; |
| 569 | 569 | } else if (mem.eql(u8, code_kind_str, "exe_build_err")) { |
| 570 | | code_kind_id = Code.Id{ .Exe = ExpectedOutcome.BuildFail }; |
| 570 | code_kind_id = Code.Id{ .exe = .build_fail }; |
| 571 | 571 | } else if (mem.eql(u8, code_kind_str, "test")) { |
| 572 | | code_kind_id = Code.Id.Test; |
| 572 | code_kind_id = .@"test"; |
| 573 | 573 | } else if (mem.eql(u8, code_kind_str, "test_err")) { |
| 574 | | code_kind_id = Code.Id{ .TestError = error_str }; |
| 574 | code_kind_id = Code.Id{ .test_error = error_str }; |
| 575 | 575 | } else if (mem.eql(u8, code_kind_str, "test_safety")) { |
| 576 | | code_kind_id = Code.Id{ .TestSafety = error_str }; |
| 576 | code_kind_id = Code.Id{ .test_safety = error_str }; |
| 577 | 577 | } else if (mem.eql(u8, code_kind_str, "obj")) { |
| 578 | | code_kind_id = Code.Id{ .Obj = null }; |
| 578 | code_kind_id = Code.Id{ .obj = null }; |
| 579 | 579 | } else if (mem.eql(u8, code_kind_str, "obj_err")) { |
| 580 | | code_kind_id = Code.Id{ .Obj = error_str }; |
| 580 | code_kind_id = Code.Id{ .obj = error_str }; |
| 581 | 581 | } else if (mem.eql(u8, code_kind_str, "lib")) { |
| 582 | | code_kind_id = Code.Id.Lib; |
| 582 | code_kind_id = Code.Id.lib; |
| 583 | 583 | } else if (mem.eql(u8, code_kind_str, "syntax")) { |
| 584 | | code_kind_id = Code.Id{ .Obj = null }; |
| 584 | code_kind_id = Code.Id{ .obj = null }; |
| 585 | 585 | just_check_syntax = true; |
| 586 | 586 | } else { |
| 587 | 587 | return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {s}", .{code_kind_str}); |
| ... | ... | @@ -599,9 +599,9 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 599 | 599 | defer additional_options.deinit(); |
| 600 | 600 | |
| 601 | 601 | const source_token = while (true) { |
| 602 | | const content_tok = try eatToken(tokenizer, Token.Id.Content); |
| 603 | | _ = try eatToken(tokenizer, Token.Id.BracketOpen); |
| 604 | | const end_code_tag = try eatToken(tokenizer, Token.Id.TagContent); |
| 602 | const content_tok = try eatToken(tokenizer, .content); |
| 603 | _ = try eatToken(tokenizer, .bracket_open); |
| 604 | const end_code_tag = try eatToken(tokenizer, .tag_content); |
| 605 | 605 | const end_tag_name = tokenizer.buffer[end_code_tag.start..end_code_tag.end]; |
| 606 | 606 | if (mem.eql(u8, end_tag_name, "code_release_fast")) { |
| 607 | 607 | mode = .ReleaseFast; |
| ... | ... | @@ -612,8 +612,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 612 | 612 | } else if (mem.eql(u8, end_tag_name, "code_verbose_cimport")) { |
| 613 | 613 | verbose_cimport = true; |
| 614 | 614 | } else if (mem.eql(u8, end_tag_name, "code_link_object")) { |
| 615 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 616 | | const obj_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 615 | _ = try eatToken(tokenizer, .separator); |
| 616 | const obj_tok = try eatToken(tokenizer, .tag_content); |
| 617 | 617 | try link_objects.append(tokenizer.buffer[obj_tok.start..obj_tok.end]); |
| 618 | 618 | } else if (mem.eql(u8, end_tag_name, "target_windows")) { |
| 619 | 619 | target_str = "x86_64-windows"; |
| ... | ... | @@ -630,11 +630,11 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 630 | 630 | } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { |
| 631 | 631 | link_mode = .Dynamic; |
| 632 | 632 | } else if (mem.eql(u8, end_tag_name, "additonal_option")) { |
| 633 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 634 | | const option = try eatToken(tokenizer, Token.Id.TagContent); |
| 633 | _ = try eatToken(tokenizer, .separator); |
| 634 | const option = try eatToken(tokenizer, .tag_content); |
| 635 | 635 | try additional_options.append(tokenizer.buffer[option.start..option.end]); |
| 636 | 636 | } else if (mem.eql(u8, end_tag_name, "code_end")) { |
| 637 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 637 | _ = try eatToken(tokenizer, .bracket_close); |
| 638 | 638 | break content_tok; |
| 639 | 639 | } else { |
| 640 | 640 | return parseError( |
| ... | ... | @@ -644,7 +644,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 644 | 644 | .{end_tag_name}, |
| 645 | 645 | ); |
| 646 | 646 | } |
| 647 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 647 | _ = try eatToken(tokenizer, .bracket_close); |
| 648 | 648 | } else unreachable; // TODO issue #707 |
| 649 | 649 | try nodes.append(Node{ |
| 650 | 650 | .Code = Code{ |
| ... | ... | @@ -664,10 +664,10 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 664 | 664 | }); |
| 665 | 665 | tokenizer.code_node_count += 1; |
| 666 | 666 | } else if (mem.eql(u8, tag_name, "syntax")) { |
| 667 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 668 | | const content_tok = try eatToken(tokenizer, Token.Id.Content); |
| 669 | | _ = try eatToken(tokenizer, Token.Id.BracketOpen); |
| 670 | | const end_syntax_tag = try eatToken(tokenizer, Token.Id.TagContent); |
| 667 | _ = try eatToken(tokenizer, .bracket_close); |
| 668 | const content_tok = try eatToken(tokenizer, .content); |
| 669 | _ = try eatToken(tokenizer, .bracket_open); |
| 670 | const end_syntax_tag = try eatToken(tokenizer, .tag_content); |
| 671 | 671 | const end_tag_name = tokenizer.buffer[end_syntax_tag.start..end_syntax_tag.end]; |
| 672 | 672 | if (!mem.eql(u8, end_tag_name, "endsyntax")) { |
| 673 | 673 | return parseError( |
| ... | ... | @@ -677,13 +677,13 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 677 | 677 | .{end_tag_name}, |
| 678 | 678 | ); |
| 679 | 679 | } |
| 680 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 680 | _ = try eatToken(tokenizer, .bracket_close); |
| 681 | 681 | try nodes.append(Node{ .InlineSyntax = content_tok }); |
| 682 | 682 | } else if (mem.eql(u8, tag_name, "shell_samp")) { |
| 683 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 684 | | const content_tok = try eatToken(tokenizer, Token.Id.Content); |
| 685 | | _ = try eatToken(tokenizer, Token.Id.BracketOpen); |
| 686 | | const end_syntax_tag = try eatToken(tokenizer, Token.Id.TagContent); |
| 683 | _ = try eatToken(tokenizer, .bracket_close); |
| 684 | const content_tok = try eatToken(tokenizer, .content); |
| 685 | _ = try eatToken(tokenizer, .bracket_open); |
| 686 | const end_syntax_tag = try eatToken(tokenizer, .tag_content); |
| 687 | 687 | const end_tag_name = tokenizer.buffer[end_syntax_tag.start..end_syntax_tag.end]; |
| 688 | 688 | if (!mem.eql(u8, end_tag_name, "end_shell_samp")) { |
| 689 | 689 | return parseError( |
| ... | ... | @@ -693,20 +693,20 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 693 | 693 | .{end_tag_name}, |
| 694 | 694 | ); |
| 695 | 695 | } |
| 696 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 696 | _ = try eatToken(tokenizer, .bracket_close); |
| 697 | 697 | try nodes.append(Node{ .Shell = content_tok }); |
| 698 | 698 | } else if (mem.eql(u8, tag_name, "syntax_block")) { |
| 699 | | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 700 | | const source_type_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 699 | _ = try eatToken(tokenizer, .separator); |
| 700 | const source_type_tok = try eatToken(tokenizer, .tag_content); |
| 701 | 701 | var name: []const u8 = "sample_code"; |
| 702 | 702 | const maybe_sep = tokenizer.next(); |
| 703 | 703 | switch (maybe_sep.id) { |
| 704 | | Token.Id.Separator => { |
| 705 | | const name_tok = try eatToken(tokenizer, Token.Id.TagContent); |
| 704 | .separator => { |
| 705 | const name_tok = try eatToken(tokenizer, .tag_content); |
| 706 | 706 | name = tokenizer.buffer[name_tok.start..name_tok.end]; |
| 707 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 707 | _ = try eatToken(tokenizer, .bracket_close); |
| 708 | 708 | }, |
| 709 | | Token.Id.BracketClose => {}, |
| 709 | .bracket_close => {}, |
| 710 | 710 | else => return parseError(tokenizer, token, "invalid token", .{}), |
| 711 | 711 | } |
| 712 | 712 | const source_type_str = tokenizer.buffer[source_type_tok.start..source_type_tok.end]; |
| ... | ... | @@ -723,12 +723,12 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 723 | 723 | return parseError(tokenizer, source_type_tok, "unrecognized code kind: {s}", .{source_type_str}); |
| 724 | 724 | } |
| 725 | 725 | const source_token = while (true) { |
| 726 | | const content_tok = try eatToken(tokenizer, Token.Id.Content); |
| 727 | | _ = try eatToken(tokenizer, Token.Id.BracketOpen); |
| 728 | | const end_code_tag = try eatToken(tokenizer, Token.Id.TagContent); |
| 726 | const content_tok = try eatToken(tokenizer, .content); |
| 727 | _ = try eatToken(tokenizer, .bracket_open); |
| 728 | const end_code_tag = try eatToken(tokenizer, .tag_content); |
| 729 | 729 | const end_tag_name = tokenizer.buffer[end_code_tag.start..end_code_tag.end]; |
| 730 | 730 | if (mem.eql(u8, end_tag_name, "end_syntax_block")) { |
| 731 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 731 | _ = try eatToken(tokenizer, .bracket_close); |
| 732 | 732 | break content_tok; |
| 733 | 733 | } else { |
| 734 | 734 | return parseError( |
| ... | ... | @@ -738,7 +738,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 738 | 738 | .{end_tag_name}, |
| 739 | 739 | ); |
| 740 | 740 | } |
| 741 | | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 741 | _ = try eatToken(tokenizer, .bracket_close); |
| 742 | 742 | }; |
| 743 | 743 | try nodes.append(Node{ .SyntaxBlock = SyntaxBlock{ .source_type = source_type, .name = name, .source_token = source_token } }); |
| 744 | 744 | } else { |
| ... | ... | @@ -1371,7 +1371,7 @@ fn genHtml( |
| 1371 | 1371 | var shell_out = shell_buffer.writer(); |
| 1372 | 1372 | |
| 1373 | 1373 | switch (code.id) { |
| 1374 | | Code.Id.Exe => |expected_outcome| code_block: { |
| 1374 | .exe => |expected_outcome| code_block: { |
| 1375 | 1375 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1376 | 1376 | defer build_args.deinit(); |
| 1377 | 1377 | try build_args.appendSlice(&[_][]const u8{ |
| ... | ... | @@ -1420,7 +1420,7 @@ fn genHtml( |
| 1420 | 1420 | |
| 1421 | 1421 | try shell_out.print("\n", .{}); |
| 1422 | 1422 | |
| 1423 | | if (expected_outcome == .BuildFail) { |
| 1423 | if (expected_outcome == .build_fail) { |
| 1424 | 1424 | const result = try ChildProcess.exec(.{ |
| 1425 | 1425 | .allocator = allocator, |
| 1426 | 1426 | .argv = build_args.items, |
| ... | ... | @@ -1476,7 +1476,7 @@ fn genHtml( |
| 1476 | 1476 | |
| 1477 | 1477 | var exited_with_signal = false; |
| 1478 | 1478 | |
| 1479 | | const result = if (expected_outcome == ExpectedOutcome.Fail) blk: { |
| 1479 | const result = if (expected_outcome == .fail) blk: { |
| 1480 | 1480 | const result = try ChildProcess.exec(.{ |
| 1481 | 1481 | .allocator = allocator, |
| 1482 | 1482 | .argv = run_args, |
| ... | ... | @@ -1513,7 +1513,7 @@ fn genHtml( |
| 1513 | 1513 | } |
| 1514 | 1514 | try shell_out.writeAll("\n"); |
| 1515 | 1515 | }, |
| 1516 | | Code.Id.Test => { |
| 1516 | .@"test" => { |
| 1517 | 1517 | var test_args = std.ArrayList([]const u8).init(allocator); |
| 1518 | 1518 | defer test_args.deinit(); |
| 1519 | 1519 | |
| ... | ... | @@ -1565,7 +1565,7 @@ fn genHtml( |
| 1565 | 1565 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1566 | 1566 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); |
| 1567 | 1567 | }, |
| 1568 | | Code.Id.TestError => |error_match| { |
| 1568 | .test_error => |error_match| { |
| 1569 | 1569 | var test_args = std.ArrayList([]const u8).init(allocator); |
| 1570 | 1570 | defer test_args.deinit(); |
| 1571 | 1571 | |
| ... | ... | @@ -1621,8 +1621,7 @@ fn genHtml( |
| 1621 | 1621 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1622 | 1622 | try shell_out.print("\n{s}\n", .{colored_stderr}); |
| 1623 | 1623 | }, |
| 1624 | | |
| 1625 | | Code.Id.TestSafety => |error_match| { |
| 1624 | .test_safety => |error_match| { |
| 1626 | 1625 | var test_args = std.ArrayList([]const u8).init(allocator); |
| 1627 | 1626 | defer test_args.deinit(); |
| 1628 | 1627 | |
| ... | ... | @@ -1685,7 +1684,7 @@ fn genHtml( |
| 1685 | 1684 | colored_stderr, |
| 1686 | 1685 | }); |
| 1687 | 1686 | }, |
| 1688 | | Code.Id.Obj => |maybe_error_match| { |
| 1687 | .obj => |maybe_error_match| { |
| 1689 | 1688 | const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, obj_ext }); |
| 1690 | 1689 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1691 | 1690 | defer build_args.deinit(); |
| ... | ... | @@ -1758,7 +1757,7 @@ fn genHtml( |
| 1758 | 1757 | } |
| 1759 | 1758 | try shell_out.writeAll("\n"); |
| 1760 | 1759 | }, |
| 1761 | | Code.Id.Lib => { |
| 1760 | .lib => { |
| 1762 | 1761 | const bin_basename = try std.zig.binNameAlloc(allocator, .{ |
| 1763 | 1762 | .root_name = code.name, |
| 1764 | 1763 | .target = builtin.target, |