Skip to content

Commit

Permalink
sat-arithmetic: correctly tokenize <<|, <<|=
Browse files Browse the repository at this point in the history
- set state rather than result.tag in tokenizer.zig
- add test to tokenizer.zig for <<, <<|, <<|=
  • Loading branch information
travisstaloch committed Sep 8, 2021
1 parent 80b8d97 commit 1659b97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/std/zig/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ pub const Tokenizer = struct {
break;
},
'|' => {
result.tag = .angle_bracket_angle_bracket_left_pipe;
state = .angle_bracket_angle_bracket_left_pipe;
},
else => {
result.tag = .angle_bracket_angle_bracket_left;
Expand Down Expand Up @@ -1998,6 +1998,12 @@ test "tokenizer - invalid builtin identifiers" {
try testTokenize("@0()", &.{ .invalid, .integer_literal, .l_paren, .r_paren });
}

test "tokenizer - saturating" {
try testTokenize("<<", &.{ .angle_bracket_angle_bracket_left });
try testTokenize("<<|", &.{ .angle_bracket_angle_bracket_left_pipe });
try testTokenize("<<|=", &.{ .angle_bracket_angle_bracket_left_pipe_equal });
}

fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void {
var tokenizer = Tokenizer.init(source);
for (expected_tokens) |expected_token_id| {
Expand Down
1 change: 0 additions & 1 deletion src/stage1/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,6 @@ void tokenize(const char *source, Tokenization *out) {
t.state = TokenizeState_start;
break;
case '|':
// t.out->ids.last() = TokenIdBitShiftLeftPipe;
t.state = TokenizeState_angle_bracket_angle_bracket_left_pipe;
break;
default:
Expand Down

0 comments on commit 1659b97

Please sign in to comment.