From 6195ed4c9c6712db8e63d7fee211369828044fe5 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 22 Nov 2024 14:39:50 +0100 Subject: [PATCH] feat: Enum type is between `<>` rather than `()` --- CHANGELOG.md | 3 ++- examples/sdl-wrapped.buzz | 12 ++++++------ examples/sqlite.buzz | 6 +++--- src/Parser.zig | 4 ++-- src/lib/http.buzz | 2 +- src/lib/testing.buzz | 2 +- tests/006-enums.buzz | 4 ++-- tests/032-debug.buzz | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21cacfbf..52c9688f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,11 @@ - Comments and docblocks must now be prefixed by `//` and `///` instead of `|` and `||` - Bitwise or operator is `|` instead of `\` - Function type now use `fun` keyword instead of `Function` -- If a function type has multiple error types, they must be put them in parenthesis +- If a function type has multiple error types, they must be put in parenthesis - Namespace can now be multiple `\` separated identifiers - Qualified name now use `\` separator instead of `.` - The `float` type is renamed to `double` (https://github.com/buzz-language/buzz/issues/311) +- Enum type is declared between `<>` rather than `()` ## Added - Object can have `const` properties (https://github.com/buzz-language/buzz/issues/13). A object with only `const` properties is considered itself `const`. Although we don't do anything yet with that concept. https://github.com/buzz-language/buzz/issues/114 is the objective but it requires being able to build objects and instances at compile time which is not yet possible. diff --git a/examples/sdl-wrapped.buzz b/examples/sdl-wrapped.buzz index 8b202364..fc5ff666 100644 --- a/examples/sdl-wrapped.buzz +++ b/examples/sdl-wrapped.buzz @@ -53,7 +53,7 @@ zdef("SDL2", ` fn SDL_GetTicks() u32; `); -export enum(int) EventType { +export enum EventType { FirstEvent = 0, Quit = 256, AppTerminating = 257, @@ -107,7 +107,7 @@ export enum(int) EventType { LastEvent = 65535, } -export enum(int) WindowFlag { +export enum WindowFlag { Fullscreen = 1, OpenGL = 2, Shown = 4, @@ -131,14 +131,14 @@ export enum(int) WindowFlag { Vulkan = 268435456, } -export enum(int) RendererFlag { +export enum RendererFlag { Software = 1, Accelerated = 2, PresentVsync = 4, TargetTexture = 8, } -export enum(int) Subsystem { +export enum Subsystem { Timer = 0x0001, Audio = 0x0010, Video = 0x0020, @@ -150,7 +150,7 @@ export enum(int) Subsystem { } // Those don't seem to fit in i32 -export enum(int) PixelFormat { +export enum PixelFormat { UNKNOWN = 0, INDEX1LSB = 286261504, INDEX1MSB = 287310080, @@ -196,7 +196,7 @@ export enum(int) PixelFormat { EXTERNAL_OES = 542328143, } -export enum(int) TextureAccess { +export enum TextureAccess { Static = 0, Streaming = 1, Target = 2, diff --git a/examples/sqlite.buzz b/examples/sqlite.buzz index 621bece6..207f7937 100644 --- a/examples/sqlite.buzz +++ b/examples/sqlite.buzz @@ -25,7 +25,7 @@ zdef("sqlite3", ` fn sqlite3_mprintf(str: [*:0]const u8) ?[*:0]const u8; `); -enum(int) ResultCode { +enum ResultCode { Ok = 0, // Successful result Error = 1, // Generic error Internal = 2, // Internal logic error in SQLite @@ -64,7 +64,7 @@ export object SQLiteError { message: str? = "Error occured while interacting with SQLite database", } -export enum(int) OpenFlag { +export enum OpenFlag { Readonly = 0x00000001, ReadWrite = 0x00000002, Create = 0x00000004, @@ -89,7 +89,7 @@ export enum(int) OpenFlag { ExResCode = 0x02000000, } -enum(int) Type { +enum Type { Integer = 1, Double = 2, Text = 3, diff --git a/src/Parser.zig b/src/Parser.zig index 47daae79..bf122f32 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -6848,13 +6848,13 @@ fn enumDeclaration(self: *Self) Error!Ast.Node.Index { } const enum_case_type_node = - if (try self.match(.LeftParen)) + if (try self.match(.Less)) try self.parseTypeDef(null, true) else null; if (enum_case_type_node != null) { - try self.consume(.RightParen, "Expected `)` after enum type."); + try self.consume(.Greater, "Expected `>` after enum type."); } const enum_case_type = if (enum_case_type_node) |enum_type| diff --git a/src/lib/http.buzz b/src/lib/http.buzz index 3c4357a5..d9a2e9c6 100644 --- a/src/lib/http.buzz +++ b/src/lib/http.buzz @@ -51,7 +51,7 @@ export enum HttpError { // https://datatracker.ietf.org/doc/html/rfc2616 -export enum(str) Method { +export enum Method { GET, HEAD, POST, diff --git a/src/lib/testing.buzz b/src/lib/testing.buzz index 06cf3dfa..fffd7b59 100644 --- a/src/lib/testing.buzz +++ b/src/lib/testing.buzz @@ -3,7 +3,7 @@ namespace testing; import "os"; import "io"; -export enum(int) Color { +export enum Color { // attributes reset = 0, bright = 1, diff --git a/tests/006-enums.buzz b/tests/006-enums.buzz index 2a63a916..38b522de 100644 --- a/tests/006-enums.buzz +++ b/tests/006-enums.buzz @@ -1,12 +1,12 @@ import "std"; -enum(str) StrEnum { +enum StrEnum { one, two, three, } -enum(int) IntEnum { +enum IntEnum { one = 1, two = 2, three = 3, diff --git a/tests/032-debug.buzz b/tests/032-debug.buzz index 603691a0..21e36510 100644 --- a/tests/032-debug.buzz +++ b/tests/032-debug.buzz @@ -20,7 +20,7 @@ enum MyEnum { Three, } -enum(str) MyStringEnum { +enum MyStringEnum { One, Two, Three,