chore: small changes
This commit is contained in:
parent
8dccf94ad5
commit
26f5fed321
@ -24,7 +24,8 @@ Now in Zig!
|
|||||||
|
|
||||||
## v0.0.1
|
## v0.0.1
|
||||||
|
|
||||||
- [ ]
|
- [x] Lex integers & floating point numbers
|
||||||
|
- [ ]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@
|
|||||||
|
|
||||||
// This is a [Semantic Version](https://semver.org/).
|
// This is a [Semantic Version](https://semver.org/).
|
||||||
// In a future version of Zig it will be used for package deduplication.
|
// In a future version of Zig it will be used for package deduplication.
|
||||||
.version = "0.0.0",
|
.version = "0.0.1",
|
||||||
|
|
||||||
// This field is optional.
|
// This field is optional.
|
||||||
// This is currently advisory only; Zig does not yet do anything
|
// This is currently advisory only; Zig does not yet do anything
|
||||||
// with this value.
|
// with this value.
|
||||||
//.minimum_zig_version = "0.11.0",
|
.minimum_zig_version = "0.13.0",
|
||||||
|
|
||||||
// This field is optional.
|
// This field is optional.
|
||||||
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
||||||
|
@ -172,12 +172,18 @@ fn scientific(input: []const u8, cap: usize, token_start: usize, exp_pos: usize)
|
|||||||
return LexError.IncompleteScientificNumber;
|
return LexError.IncompleteScientificNumber;
|
||||||
}
|
}
|
||||||
current_pos += 1;
|
current_pos += 1;
|
||||||
|
const digits_start = current_pos;
|
||||||
|
|
||||||
// lex digits
|
// lex at least 1 digit
|
||||||
while (current_pos < cap and utils.is_decimal_digit(input[current_pos])) {
|
while (current_pos < cap and utils.is_decimal_digit(input[current_pos])) {
|
||||||
current_pos += 1;
|
current_pos += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there is no difference, no extra digits were lexed.
|
||||||
|
if (digits_start == current_pos) {
|
||||||
|
return LexError.IncompleteScientificNumber;
|
||||||
|
}
|
||||||
|
|
||||||
// return the scientific number
|
// return the scientific number
|
||||||
return .{
|
return .{
|
||||||
Token.init(input[token_start..current_pos], TokenType.Float, token_start),
|
Token.init(input[token_start..current_pos], TokenType.Float, token_start),
|
||||||
@ -455,6 +461,23 @@ test "should fail on incomplete scientific number" {
|
|||||||
try std.testing.expect(false);
|
try std.testing.expect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "should fail on incomplete scientific number 2" {
|
||||||
|
const input = "123e+";
|
||||||
|
const result = lex(input, input.len, 0) catch |err| {
|
||||||
|
try std.testing.expect(err == token.LexError.IncompleteScientificNumber);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (result) |tuple| {
|
||||||
|
const r = tuple[0];
|
||||||
|
std.debug.print("{s}\n", .{r.value});
|
||||||
|
} else {
|
||||||
|
std.debug.print("nil returned", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
try std.testing.expect(false);
|
||||||
|
}
|
||||||
|
|
||||||
test "should lex floating scientific number" {
|
test "should lex floating scientific number" {
|
||||||
const input = "0.58e+3";
|
const input = "0.58e+3";
|
||||||
const result = try lex(input, input.len, 0);
|
const result = try lex(input, input.len, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user