Skip to content

Commit

Permalink
feat: Enum type is between <> rather than ()
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Nov 22, 2024
1 parent 53004ce commit 6195ed4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions examples/sdl-wrapped.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ zdef("SDL2", `
fn SDL_GetTicks() u32;
`);

export enum(int) EventType {
export enum<int> EventType {
FirstEvent = 0,
Quit = 256,
AppTerminating = 257,
Expand Down Expand Up @@ -107,7 +107,7 @@ export enum(int) EventType {
LastEvent = 65535,
}

export enum(int) WindowFlag {
export enum<int> WindowFlag {
Fullscreen = 1,
OpenGL = 2,
Shown = 4,
Expand All @@ -131,14 +131,14 @@ export enum(int) WindowFlag {
Vulkan = 268435456,
}

export enum(int) RendererFlag {
export enum<int> RendererFlag {
Software = 1,
Accelerated = 2,
PresentVsync = 4,
TargetTexture = 8,
}

export enum(int) Subsystem {
export enum<int> Subsystem {
Timer = 0x0001,
Audio = 0x0010,
Video = 0x0020,
Expand All @@ -150,7 +150,7 @@ export enum(int) Subsystem {
}

// Those don't seem to fit in i32
export enum(int) PixelFormat {
export enum<int> PixelFormat {
UNKNOWN = 0,
INDEX1LSB = 286261504,
INDEX1MSB = 287310080,
Expand Down Expand Up @@ -196,7 +196,7 @@ export enum(int) PixelFormat {
EXTERNAL_OES = 542328143,
}

export enum(int) TextureAccess {
export enum<int> TextureAccess {
Static = 0,
Streaming = 1,
Target = 2,
Expand Down
6 changes: 3 additions & 3 deletions examples/sqlite.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ zdef("sqlite3", `
fn sqlite3_mprintf(str: [*:0]const u8) ?[*:0]const u8;
`);

enum(int) ResultCode {
enum<int> ResultCode {
Ok = 0, // Successful result
Error = 1, // Generic error
Internal = 2, // Internal logic error in SQLite
Expand Down Expand Up @@ -64,7 +64,7 @@ export object SQLiteError {
message: str? = "Error occured while interacting with SQLite database",
}

export enum(int) OpenFlag {
export enum<int> OpenFlag {
Readonly = 0x00000001,
ReadWrite = 0x00000002,
Create = 0x00000004,
Expand All @@ -89,7 +89,7 @@ export enum(int) OpenFlag {
ExResCode = 0x02000000,
}

enum(int) Type {
enum<int> Type {
Integer = 1,
Double = 2,
Text = 3,
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion src/lib/http.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export enum HttpError {

// https://datatracker.ietf.org/doc/html/rfc2616

export enum(str) Method {
export enum<str> Method {
GET,
HEAD,
POST,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/testing.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace testing;
import "os";
import "io";

export enum(int) Color {
export enum<int> Color {
// attributes
reset = 0,
bright = 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/006-enums.buzz
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "std";

enum(str) StrEnum {
enum<str> StrEnum {
one,
two,
three,
}

enum(int) IntEnum {
enum<int> IntEnum {
one = 1,
two = 2,
three = 3,
Expand Down
2 changes: 1 addition & 1 deletion tests/032-debug.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum MyEnum {
Three,
}

enum(str) MyStringEnum {
enum<str> MyStringEnum {
One,
Two,
Three,
Expand Down

0 comments on commit 6195ed4

Please sign in to comment.