From d0b71a92542bbe10aa16afa3f37e58cb0c1062b7 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 15 May 2024 16:47:10 +0200 Subject: [PATCH] fix: range -> rg All other type are abbreviation, no reason to use a full word for ranges --- CHANGELOG.md | 2 +- src/Token.zig | 2 +- src/obj.zig | 4 ++-- tests/053-range.buzz | 26 +++++++++++++------------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 173f69c5..09bae0b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ var value = from { - By default, imported symbols from another script will be under `libprefix.XXXX` - When importing something, you can still redefine its namespace prefix with `import "..." as mynewnamespace` or remove it altogether with `import "..." _` - Ranges are now an actual buzz value (https://github.com/buzz-language/buzz/issues/170) - - new `range` type + - new `rg` type - `myrange.toList()` transforms a range into a list of integers - `myrange.low` and `myrange.high` to get a range bounds - works with `foreach` diff --git a/src/Token.zig b/src/Token.zig index 40b19c03..4a0fb587 100644 --- a/src/Token.zig +++ b/src/Token.zig @@ -217,7 +217,7 @@ pub const keywords = std.StaticStringMap(Type).initComptime( .{ "out", .Out }, .{ "pat", .Pat }, .{ "protocol", .Protocol }, - .{ "range", .Range }, + .{ "rg", .Range }, .{ "resolve", .Resolve }, .{ "resume", .Resume }, .{ "return", .Return }, diff --git a/src/obj.zig b/src/obj.zig index 609bfe94..054daa6f 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -2524,7 +2524,7 @@ pub const ObjRange = struct { .{ .{ "toList", "extern Function toList() > [int]" }, .{ "len", "extern Function len() > int" }, - .{ "invert", "extern Function invert() > range" }, + .{ "invert", "extern Function invert() > rg" }, }, ); @@ -4025,7 +4025,7 @@ pub const ObjTypeDef = struct { .String => try writer.writeAll("str"), .Pattern => try writer.writeAll("pat"), .Any => try writer.writeAll("any"), - .Range => try writer.writeAll("range"), + .Range => try writer.writeAll("rg"), .Fiber => { try writer.writeAll("fib<"); try self.resolved_type.?.Fiber.return_type.toStringRaw(writer, qualified); diff --git a/tests/053-range.buzz b/tests/053-range.buzz index 993aab8b..21d0ffef 100644 --- a/tests/053-range.buzz +++ b/tests/053-range.buzz @@ -2,13 +2,13 @@ import "std"; test "Range" { int limit = 10; - range rg = 0..limit; + rg range = 0..limit; - std.assert(rg == 0..10, message: "Could compare ranges"); - std.assert(rg.low == 0, message: "Could get low limit of range"); - std.assert(rg.high == 10, message: "Could get high limit of range"); + std.assert(range == 0..10, message: "Could compare ranges"); + std.assert(range.low == 0, message: "Could get low limit of range"); + std.assert(range.high == 10, message: "Could get high limit of range"); - [int] list = rg.toList(); + [int] list = range.toList(); std.assert(list.len() == 10, message: "Could create list from range"); int sum = 0; @@ -17,18 +17,18 @@ test "Range" { } std.assert(sum == 45, message: "Could iterate over range"); - std.assert(rg.len() == 10, message: "Could get range length"); + std.assert(range.len() == 10, message: "Could get range length"); } test "Inverted range" { int limit = 0; - range rg = 10..limit; + rg range = 10..limit; - std.assert((0..10).invert() == rg, message: "Could invert range"); - std.assert(rg.low == 10, message: "Could get low limit of range"); - std.assert(rg.high == 0, message: "Could get high limit of range"); + std.assert((0..10).invert() == range, message: "Could invert range"); + std.assert(range.low == 10, message: "Could get low limit of range"); + std.assert(range.high == 0, message: "Could get high limit of range"); - [int] list = rg.toList(); + [int] list = range.toList(); std.assert(list.len() == 10, message: "Could create list from inverted range"); int sum = 0; @@ -37,5 +37,5 @@ test "Inverted range" { } std.assert(sum == 55, message: "Could iterate over inverted range"); - std.assert(rg.len() == 10, message: "Could get range length"); -} \ No newline at end of file + std.assert(range.len() == 10, message: "Could get range length"); +}