authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2026-06-15 12:23:40+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2026-07-08 11:48:58+02:00
logfb2569461182d62d297a69b1388c8328b9a56932
tree27b20953db25face56d405b6627aac76ca344f6a
parent9303d4be1029dc42845aafeff38c811a08ac29b0
signaturelock-open Commit is signed but in an unrecognized format.

grammar: fix doc comment parsing

/// should not be parsed as a division operator followed by a comment if it appears in a context where a division operator is accepted. Add the missing negative lookahead to the SLASH token.

3 files changed, 6 insertions(+), 1 deletions(-)

doc/langref/grammar.peg+1-1
......@@ -537,7 +537,7 @@ RBRACE <- skip '}'
537537RBRACKET <- skip ']'
538538RPAREN <- skip ')'
539539SEMICOLON <- skip ';'
540SLASH <- skip '/' ![=]
540SLASH <- skip '/' ![=/]
541541SLASHEQUAL <- skip '/='
542542TILDE <- skip '~'
543543
lib/std/zig/parser_fuzz.zig+4
......@@ -25,6 +25,10 @@ test "operator whitespace" {
2525 \\}
2626 );
2727}
28// Found using AFL++
29test "doc comment or division operator" {
30 try checkAgainstOracle("0=0///\n0");
31}
2832
2933fn checkAgainstOracle(source: [:0]const u8) !void {
3034 var fba_buf: [1 << 18]u8 = undefined;
lib/std/zig/parser_generated_oracle.zig+1
......@@ -3927,6 +3927,7 @@ const Parser = struct {
39273927 const pos_1 = p.i;
39283928 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {
39293929 '='...'=',
3930 '/'...'/',
39303931 => blk_2: {
39313932 p.i += 1;
39323933 break :blk_2 true;