Skip to content

Commit b289c7b

Browse files
committed
Fix CR being rejected when used as whitespace
Missed this comment from ziglang/zig-spec#83: > CR used as whitespace, whether directly preceding NL or stray, is still unambiguously whitespace. It is accepted by the grammar and replaced by the canonical whitespace by zig fmt.
1 parent e676305 commit b289c7b

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

lib/std/zig/tokenizer.zig

+1-13
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub const Tokenizer = struct {
442442
switch (state) {
443443
.start => switch (c) {
444444
0 => break,
445-
' ', '\n', '\t' => {
445+
' ', '\n', '\t', '\r' => {
446446
result.loc.start = self.index + 1;
447447
},
448448
'"' => {
@@ -565,18 +565,6 @@ pub const Tokenizer = struct {
565565
state = .int_literal_dec;
566566
result.tag = .integer_literal;
567567
},
568-
'\r' => {
569-
// Carriage returns are *only* allowed just before a linefeed as part of a CRLF pair, otherwise
570-
// they constitute an illegal byte!
571-
if (self.index + 1 < self.buffer.len and self.buffer[self.index + 1] == '\n') {
572-
result.loc.start = self.index + 1;
573-
} else {
574-
result.tag = .invalid;
575-
result.loc.end = self.index;
576-
self.index += 1;
577-
return result;
578-
}
579-
},
580568
else => {
581569
result.tag = .invalid;
582570
result.loc.end = self.index;

0 commit comments

Comments
 (0)