Skip to content

Commit 39dc8b3

Browse files
committed
improve example
1 parent 5ca7066 commit 39dc8b3

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/example.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,17 @@ pub const Value = union(enum) {
191191
}
192192

193193
pub fn fromIntegerLiteral(bytes: []const u8) Value {
194-
_ = bytes;
195-
return .{ .int = .{ .value = 0 } };
194+
const num = std.fmt.parseInt(i64, bytes, 10) catch {
195+
return .{ .err = "error parsing int" };
196+
};
197+
return .{ .int = .{ .value = num } };
196198
}
197199

198200
pub fn fromFloatLiteral(bytes: []const u8) Value {
199-
_ = bytes;
200-
return .{ .float = .{ .value = 0 } };
201+
const num = std.fmt.parseFloat(f64, bytes) catch {
202+
return .{ .err = "error parsing float" };
203+
};
204+
return .{ .float = .{ .value = num } };
201205
}
202206

203207
pub fn fromBooleanLiteral(b: bool) Value {

0 commit comments

Comments
 (0)