| ... | @@ -772,6 +772,10 @@ pub const Tokenizer = struct { | ... | @@ -772,6 +772,10 @@ pub const Tokenizer = struct { |
| 772 | }, | 772 | }, |
| 773 | | 773 | |
| 774 | .char_literal_unicode_escape_saw_u => switch (c) { | 774 | .char_literal_unicode_escape_saw_u => switch (c) { |
| | 775 | 0 => { |
| | 776 | result.tag = .invalid; |
| | 777 | break; |
| | 778 | }, |
| 775 | '{' => { | 779 | '{' => { |
| 776 | state = .char_literal_unicode_escape; | 780 | state = .char_literal_unicode_escape; |
| 777 | }, | 781 | }, |
| ... | @@ -782,6 +786,10 @@ pub const Tokenizer = struct { | ... | @@ -782,6 +786,10 @@ pub const Tokenizer = struct { |
| 782 | }, | 786 | }, |
| 783 | | 787 | |
| 784 | .char_literal_unicode_escape => switch (c) { | 788 | .char_literal_unicode_escape => switch (c) { |
| | 789 | 0 => { |
| | 790 | result.tag = .invalid; |
| | 791 | break; |
| | 792 | }, |
| 785 | '0'...'9', 'a'...'f', 'A'...'F' => {}, | 793 | '0'...'9', 'a'...'f', 'A'...'F' => {}, |
| 786 | '}' => { | 794 | '}' => { |
| 787 | state = .char_literal_end; // too many/few digits handled later | 795 | state = .char_literal_end; // too many/few digits handled later |
| ... | @@ -1922,8 +1930,10 @@ test "tokenizer - invalid builtin identifiers" { | ... | @@ -1922,8 +1930,10 @@ test "tokenizer - invalid builtin identifiers" { |
| 1922 | try testTokenize("@0()", &.{ .invalid, .integer_literal, .l_paren, .r_paren }); | 1930 | try testTokenize("@0()", &.{ .invalid, .integer_literal, .l_paren, .r_paren }); |
| 1923 | } | 1931 | } |
| 1924 | | 1932 | |
| 1925 | test "tokenizer - backslash before eof in string literal" { | 1933 | test "tokenizer - invalid token with unfinished escape right before eof" { |
| 1926 | try testTokenize("\"\\", &.{.invalid}); | 1934 | try testTokenize("\"\\", &.{.invalid}); |
| | 1935 | try testTokenize("'\\", &.{.invalid}); |
| | 1936 | try testTokenize("'\\u", &.{.invalid}); |
| 1927 | } | 1937 | } |
| 1928 | | 1938 | |
| 1929 | fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void { | 1939 | fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void { |