| author | |
| committer | |
| log | dcbc52ec85d00fbd3603c314aaaab98fb3866892 |
| tree | cda1709af1515d51ada13319119f9f79544ff4f3 |
| parent | b9a95f2dd94e6175322d3388c3936eb600ec90ea |
- set state rather than result.tag in tokenizer.zig
- add test to tokenizer.zig for <<, <<|, <<|=3 files changed, 10 insertions(+), 5 deletions(-)
lib/std/zig/tokenizer.zig+7-1| ... | @@ -1007,7 +1007,7 @@ pub const Tokenizer = struct { | ... | @@ -1007,7 +1007,7 @@ pub const Tokenizer = struct { |
| 1007 | break; | 1007 | break; |
| 1008 | }, | 1008 | }, |
| 1009 | '|' => { | 1009 | '|' => { |
| 1010 | result.tag = .angle_bracket_angle_bracket_left_pipe; | 1010 | state = .angle_bracket_angle_bracket_left_pipe; |
| 1011 | }, | 1011 | }, |
| 1012 | else => { | 1012 | else => { |
| 1013 | result.tag = .angle_bracket_angle_bracket_left; | 1013 | result.tag = .angle_bracket_angle_bracket_left; |
| ... | @@ -2015,6 +2015,12 @@ test "tokenizer - invalid token with unfinished escape right before eof" { | ... | @@ -2015,6 +2015,12 @@ test "tokenizer - invalid token with unfinished escape right before eof" { |
| 2015 | try testTokenize("'\\u", &.{.invalid}); | 2015 | try testTokenize("'\\u", &.{.invalid}); |
| 2016 | } | 2016 | } |
| 2017 | 2017 | ||
| 2018 | test "tokenizer - saturating" { | ||
| 2019 | try testTokenize("<<", &.{.angle_bracket_angle_bracket_left}); | ||
| 2020 | try testTokenize("<<|", &.{.angle_bracket_angle_bracket_left_pipe}); | ||
| 2021 | try testTokenize("<<|=", &.{.angle_bracket_angle_bracket_left_pipe_equal}); | ||
| 2022 | } | ||
| 2023 | |||
| 2018 | fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void { | 2024 | fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void { |
| 2019 | var tokenizer = Tokenizer.init(source); | 2025 | var tokenizer = Tokenizer.init(source); |
| 2020 | for (expected_tokens) |expected_token_id| { | 2026 | for (expected_tokens) |expected_token_id| { |
src/Air.zig+3-3| ... | @@ -44,7 +44,7 @@ pub const Inst = struct { | ... | @@ -44,7 +44,7 @@ pub const Inst = struct { |
| 44 | /// is the same as both operands. | 44 | /// is the same as both operands. |
| 45 | /// Uses the `bin_op` field. | 45 | /// Uses the `bin_op` field. |
| 46 | addwrap, | 46 | addwrap, |
| 47 | /// Saturating integer addition. | 47 | /// Saturating integer addition. |
| 48 | /// Both operands are guaranteed to be the same type, and the result type | 48 | /// Both operands are guaranteed to be the same type, and the result type |
| 49 | /// is the same as both operands. | 49 | /// is the same as both operands. |
| 50 | /// Uses the `bin_op` field. | 50 | /// Uses the `bin_op` field. |
| ... | @@ -59,7 +59,7 @@ pub const Inst = struct { | ... | @@ -59,7 +59,7 @@ pub const Inst = struct { |
| 59 | /// is the same as both operands. | 59 | /// is the same as both operands. |
| 60 | /// Uses the `bin_op` field. | 60 | /// Uses the `bin_op` field. |
| 61 | subwrap, | 61 | subwrap, |
| 62 | /// Saturating integer subtraction. | 62 | /// Saturating integer subtraction. |
| 63 | /// Both operands are guaranteed to be the same type, and the result type | 63 | /// Both operands are guaranteed to be the same type, and the result type |
| 64 | /// is the same as both operands. | 64 | /// is the same as both operands. |
| 65 | /// Uses the `bin_op` field. | 65 | /// Uses the `bin_op` field. |
| ... | @@ -74,7 +74,7 @@ pub const Inst = struct { | ... | @@ -74,7 +74,7 @@ pub const Inst = struct { |
| 74 | /// is the same as both operands. | 74 | /// is the same as both operands. |
| 75 | /// Uses the `bin_op` field. | 75 | /// Uses the `bin_op` field. |
| 76 | mulwrap, | 76 | mulwrap, |
| 77 | /// Saturating integer multiplication. | 77 | /// Saturating integer multiplication. |
| 78 | /// Both operands are guaranteed to be the same type, and the result type | 78 | /// Both operands are guaranteed to be the same type, and the result type |
| 79 | /// is the same as both operands. | 79 | /// is the same as both operands. |
| 80 | /// Uses the `bin_op` field. | 80 | /// Uses the `bin_op` field. |
src/stage1/tokenizer.cpp-1| ... | @@ -995,7 +995,6 @@ void tokenize(const char *source, Tokenization *out) { | ... | @@ -995,7 +995,6 @@ void tokenize(const char *source, Tokenization *out) { |
| 995 | t.state = TokenizeState_start; | 995 | t.state = TokenizeState_start; |
| 996 | break; | 996 | break; |
| 997 | case '|': | 997 | case '|': |
| 998 | // t.out->ids.last() = TokenIdBitShiftLeftPipe; | ||
| 999 | t.state = TokenizeState_angle_bracket_angle_bracket_left_pipe; | 998 | t.state = TokenizeState_angle_bracket_angle_bracket_left_pipe; |
| 1000 | break; | 999 | break; |
| 1001 | default: | 1000 | default: |