Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring Zen language lexical changes #42

Open
anatol opened this issue Oct 25, 2022 · 11 comments
Open

Bring Zen language lexical changes #42

anatol opened this issue Oct 25, 2022 · 11 comments

Comments

@anatol
Copy link
Contributor

anatol commented Oct 25, 2022

Zed is actively evolving, and this plugin should catch up with it.

This ticket is to track this activity.

Here is an example that is not properly parsed by plugin:

const std = @import("std");

pub fn main() !void {
    var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(!general_purpose_allocator.deinit());

    const gpa = general_purpose_allocator.allocator();

    const u32_ptr = try gpa.create(u32);
    _ = u32_ptr; // silences unused variable error

    // oops I forgot to free!
}

This part (.{}){}; is reported as <expr> or RIGHT_PAREN expected, got '.'

@anatol
Copy link
Contributor Author

anatol commented Oct 25, 2022

@linux-china I know you was interested in the lexer modifications. Do you have any changes that can help with this problem?

@linux-china
Copy link

@anatol yes, you should update grammar files https://github.com/ice1000/intellij-zig/tree/master/grammar and grammar files are some old. @ice1000

@anatol
Copy link
Contributor Author

anatol commented Oct 25, 2022

Here is another example that plugin is unable to parse

const std = @import("std");

pub fn Queue(comptime Child: type) type {
    return struct {
        const This = @This();
        const Node = struct {
            data: Child,
            next: ?*Node,
        };
        gpa: std.mem.Allocator,
        start: ?*Node,
        end: ?*Node,

        pub fn init(gpa: std.mem.Allocator) This {
            return This{
                .gpa = gpa,
                .start = null,
                .end = null,
            };
        }
        pub fn enqueue(this: *This, value: Child) !void {
            const node = try this.gpa.create(Node);
            node.* = .{ .data = value, .next = null };
            if (this.end) |end| end.next = node //
            else this.start = node;
            this.end = node;
        }
        pub fn dequeue(this: *This) ?Child {
            const start = this.start orelse return null;
            defer this.gpa.destroy(start);
            if (start.next) |next|
                this.start = next
            else {
                this.start = null;
                this.end = null;
            }
            return start.data;
        }
    };
}

@ice1000
Copy link
Owner

ice1000 commented Oct 25, 2022

Do you have some time to modify the BNF? If you show me very specific code snippets, maybe I can help.... I do not have Java 11 on my computer. I only have Java 19, which does not work with Gradle 7.5.1.

The oldest version of Gradle that is compatible with running on Java 19 is some nightly version of Gradle 7.6, unfortunately.

@linux-china
Copy link

@ice1000 BNF and grammar-kit are still hard for most developers. If you can finish BNF for Zig, and it's good for plugin contributors.

@ice1000
Copy link
Owner

ice1000 commented Oct 25, 2022

@ice1000 BNF and grammar-kit are still hard for most developers. If you can finish BNF for Zig, and it's good for plugin contributors.

I mean I don't have the time to check all the grammar differences. It's too much. I know grammar-kit but I don't want to spend time on zig (for now) anymore.

Grammar-Kit is very easy, compared to implementing stub indices for psi elements. Not to mention type inference.

@ice1000
Copy link
Owner

ice1000 commented Oct 25, 2022

I'm a college student with several part time jobs at the same time. I really really really want 114514 hours every single day.

@anatol
Copy link
Contributor Author

anatol commented Oct 25, 2022

I do not have any experience with BNF. So I ask somebody with one to help bring the lexer up to date.

Is there any official lex file for zig language? Where is the language syntax specification?

@andrewrk
Copy link

@ice1000
Copy link
Owner

ice1000 commented Oct 25, 2022

https://github.com/ziglang/zig-spec/tree/master/grammar

Thanks! If only zig has a spec like that when I first developed the plugin 😢

@xeus2001
Copy link
Contributor

I made a fix for the first problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants