diff --git a/doc/langref/grammar.peg b/doc/langref/grammar.peg index 59bd42eda107d6f4483dbbb8d8d32e1ae92a34c8..570da9b37ee869770ee5bc3a8ce856f2cc782949 100644 --- a/doc/langref/grammar.peg +++ b/doc/langref/grammar.peg @@ -430,10 +430,13 @@ string_char <- '\\"' / !["] non_control_utf8 -container_doc_comment <- ('//!' non_control_utf8* [ \n]* skip)+ -doc_comment <- ('///' non_control_utf8* [ \n]* skip)+ -line_comment <- '//' ![!/] non_control_utf8* / '////' non_control_utf8* -line_string <- '\\\\' non_control_utf8* [ \n]* +container_doc_comment <- ('//!' non_control_utf8* newline skip)+ +doc_comment <- ('///' non_control_utf8* newline skip)+ +line_comment + <- '//' ![!/] non_control_utf8* newline + / '////' non_control_utf8* newline +line_string <- '\\\\' non_control_utf8* newline +newline <- "\n" / "\r\n" / eof skip <- ([ \n\t\r] / line_comment)* CHAR_LITERAL <- ['] char_char* ['] skip diff --git a/lib/std/zig/parser_generated_oracle.zig b/lib/std/zig/parser_generated_oracle.zig index e5764fdd1a510af2869a869789c947a48d9e4d7e..669c7a4a35fa1aefc350ec570306176e043bf7fe 100644 --- a/lib/std/zig/parser_generated_oracle.zig +++ b/lib/std/zig/parser_generated_oracle.zig @@ -2194,18 +2194,7 @@ const Parser = struct { } and blk_4: { while (p.parsenon_control_utf8()) {} break :blk_4 true; - } and blk_4: { - while ((p.i < p.source.len and switch (p.source[p.i]) { - ' '...' ', - '\n'...'\n', - => blk_5: { - p.i += 1; - break :blk_5 true; - }, - else => false, - })) {} - break :blk_4 true; - } and p.parseskip()) break :blk_3 true; + } and p.parsenewline() and p.parseskip()) break :blk_3 true; p.i = pos_3; break :blk_3 false; }) { @@ -2233,18 +2222,7 @@ const Parser = struct { } and blk_4: { while (p.parsenon_control_utf8()) {} break :blk_4 true; - } and blk_4: { - while ((p.i < p.source.len and switch (p.source[p.i]) { - ' '...' ', - '\n'...'\n', - => blk_5: { - p.i += 1; - break :blk_5 true; - }, - else => false, - })) {} - break :blk_4 true; - } and p.parseskip()) break :blk_3 true; + } and p.parsenewline() and p.parseskip()) break :blk_3 true; p.i = pos_3; break :blk_3 false; }) { @@ -2281,7 +2259,7 @@ const Parser = struct { } and blk_1: { while (p.parsenon_control_utf8()) {} break :blk_1 true; - }) break :blk_0 true; + } and p.parsenewline()) break :blk_0 true; p.i = pos_0; if (blk_1: { if (std.mem.startsWith(u8, p.source[p.i..], "////")) { @@ -2292,7 +2270,7 @@ const Parser = struct { } and blk_1: { while (p.parsenon_control_utf8()) {} break :blk_1 true; - }) break :blk_0 true; + } and p.parsenewline()) break :blk_0 true; p.i = pos_0; break :blk_0 false; }; @@ -2309,19 +2287,32 @@ const Parser = struct { } and blk_1: { while (p.parsenon_control_utf8()) {} break :blk_1 true; - } and blk_1: { - while ((p.i < p.source.len and switch (p.source[p.i]) { - ' '...' ', - '\n'...'\n', - => blk_2: { - p.i += 1; - break :blk_2 true; - }, - else => false, - })) {} - break :blk_1 true; + } and p.parsenewline()) break :blk_0 true; + p.i = pos_0; + break :blk_0 false; + }; + } + pub fn parsenewline(p: *Parser) bool { + return blk_0: { + const pos_0 = p.i; + if (blk_1: { + if (std.mem.startsWith(u8, p.source[p.i..], "\n")) { + p.i += 1; + break :blk_1 true; + } + break :blk_1 false; }) break :blk_0 true; p.i = pos_0; + if (blk_1: { + if (std.mem.startsWith(u8, p.source[p.i..], "\r\n")) { + p.i += 2; + break :blk_1 true; + } + break :blk_1 false; + }) break :blk_0 true; + p.i = pos_0; + if (p.parseeof()) break :blk_0 true; + p.i = pos_0; break :blk_0 false; }; }