| ... | @@ -56,6 +56,8 @@ pub const Error = union(enum) { | ... | @@ -56,6 +56,8 @@ pub const Error = union(enum) { |
| 56 | invalid_character: usize, | 56 | invalid_character: usize, |
| 57 | /// [+-] not immediately after [pPeE] | 57 | /// [+-] not immediately after [pPeE] |
| 58 | invalid_exponent_sign: usize, | 58 | invalid_exponent_sign: usize, |
| | 59 | /// Period comes directly after exponent. |
| | 60 | period_after_exponent: usize, |
| 59 | }; | 61 | }; |
| 60 | | 62 | |
| 61 | /// Parse Zig number literal accepted by fmt.parseInt, fmt.parseFloat and big_int.setString. | 63 | /// Parse Zig number literal accepted by fmt.parseInt, fmt.parseFloat and big_int.setString. |
| ... | @@ -108,6 +110,9 @@ pub fn parseNumberLiteral(bytes: []const u8) Result { | ... | @@ -108,6 +110,9 @@ pub fn parseNumberLiteral(bytes: []const u8) Result { |
| 108 | continue; | 110 | continue; |
| 109 | }, | 111 | }, |
| 110 | 'p', 'P' => if (base == 16) { | 112 | 'p', 'P' => if (base == 16) { |
| | 113 | if (i == 2) { |
| | 114 | return .{ .failure = .{ .digit_after_base = {} } }; |
| | 115 | } |
| 111 | float = true; | 116 | float = true; |
| 112 | if (exponent) return .{ .failure = .{ .duplicate_exponent = i } }; | 117 | if (exponent) return .{ .failure = .{ .duplicate_exponent = i } }; |
| 113 | if (underscore) return .{ .failure = .{ .exponent_after_underscore = i } }; | 118 | if (underscore) return .{ .failure = .{ .exponent_after_underscore = i } }; |
| ... | @@ -116,6 +121,15 @@ pub fn parseNumberLiteral(bytes: []const u8) Result { | ... | @@ -116,6 +121,15 @@ pub fn parseNumberLiteral(bytes: []const u8) Result { |
| 116 | continue; | 121 | continue; |
| 117 | }, | 122 | }, |
| 118 | '.' => { | 123 | '.' => { |
| | 124 | if (exponent) { |
| | 125 | const digit_index = i - ".e".len; |
| | 126 | if (digit_index < bytes.len) { |
| | 127 | switch (bytes[digit_index]) { |
| | 128 | '0'...'9' => return .{ .failure = .{ .period_after_exponent = i } }, |
| | 129 | else => {}, |
| | 130 | } |
| | 131 | } |
| | 132 | } |
| 119 | float = true; | 133 | float = true; |
| 120 | if (base != 10 and base != 16) return .{ .failure = .{ .invalid_float_base = 2 } }; | 134 | if (base != 10 and base != 16) return .{ .failure = .{ .invalid_float_base = 2 } }; |
| 121 | if (period) return .{ .failure = .duplicate_period }; | 135 | if (period) return .{ .failure = .duplicate_period }; |