Skip to content

Commit 65dc02a

Browse files
committed
Remove || and && from tokenizer
As discussed here: https://roc.zulipchat.com/#narrow/channel/395097-compiler-development/topic/zig.20compiler.20-.20spike/near/504579627 I assume in the long term, support will be added to the parser to notice when double opBar or opAmpersand should be consider an `and` or `or`. Then the formatter will fix things up. For now, double bar is always a lambda and double ampersand is invalid.
1 parent 0f49641 commit 65dc02a

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/check/parse/tokenize.zig

+9-27
Original file line numberDiff line numberDiff line change
@@ -954,13 +954,8 @@ pub const Tokenizer = struct {
954954

955955
// Ampersand (&)
956956
'&' => {
957-
if (self.cursor.peekAt(1) == '&') {
958-
self.cursor.pos += 2;
959-
self.output.pushTokenNormal(.OpAnd, start, 2);
960-
} else {
961-
self.cursor.pos += 1;
962-
self.output.pushTokenNormal(.OpAmpersand, start, 1);
963-
}
957+
self.cursor.pos += 1;
958+
self.output.pushTokenNormal(.OpAmpersand, start, 1);
964959
},
965960

966961
// Comma (,)
@@ -982,10 +977,7 @@ pub const Tokenizer = struct {
982977

983978
// Pipe (|)
984979
'|' => {
985-
if (self.cursor.peekAt(1) == '|') {
986-
self.cursor.pos += 2;
987-
self.output.pushTokenNormal(.OpOr, start, 2);
988-
} else if (self.cursor.peekAt(1) == '>') {
980+
if (self.cursor.peekAt(1) == '>') {
989981
self.cursor.pos += 2;
990982
self.output.pushTokenNormal(.OpPizza, start, 2);
991983
} else {
@@ -1620,15 +1612,10 @@ fn rebuildBufferForTesting(buf: []const u8, tokens: *TokenizedBuffer, alloc: std
16201612
try buf2.append(alloc, '!');
16211613
},
16221614
.OpAnd => {
1623-
std.debug.assert(length == 2 or length == 3);
1624-
if (length == 2) {
1625-
try buf2.append(alloc, '&');
1626-
try buf2.append(alloc, '&');
1627-
} else {
1628-
try buf2.append(alloc, 'a');
1629-
try buf2.append(alloc, 'n');
1630-
try buf2.append(alloc, 'd');
1631-
}
1615+
std.debug.assert(length == 3);
1616+
try buf2.append(alloc, 'a');
1617+
try buf2.append(alloc, 'n');
1618+
try buf2.append(alloc, 'd');
16321619
},
16331620
.OpAmpersand => {
16341621
std.debug.assert(length == 1);
@@ -1645,13 +1632,8 @@ fn rebuildBufferForTesting(buf: []const u8, tokens: *TokenizedBuffer, alloc: std
16451632
},
16461633
.OpOr => {
16471634
std.debug.assert(length == 2);
1648-
if (buf[token.offset] == 'o') {
1649-
try buf2.append(alloc, 'o');
1650-
try buf2.append(alloc, 'r');
1651-
} else {
1652-
try buf2.append(alloc, '|');
1653-
try buf2.append(alloc, '|');
1654-
}
1635+
try buf2.append(alloc, 'o');
1636+
try buf2.append(alloc, 'r');
16551637
},
16561638
.OpBar => {
16571639
std.debug.assert(length == 1);

0 commit comments

Comments
 (0)