intellij-zig icon indicating copy to clipboard operation
intellij-zig copied to clipboard

Bring Zen language lexical changes

Open anatol opened this issue 3 years ago • 11 comments

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 avatar Oct 25 '22 05:10 anatol

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

anatol avatar Oct 25 '22 05:10 anatol

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

linux-china avatar Oct 25 '22 05:10 linux-china

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;
        }
    };
}

anatol avatar Oct 25 '22 05:10 anatol

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.

ice1000 avatar Oct 25 '22 07:10 ice1000

@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.

linux-china avatar Oct 25 '22 07:10 linux-china

@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 avatar Oct 25 '22 09:10 ice1000

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

ice1000 avatar Oct 25 '22 09:10 ice1000

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?

anatol avatar Oct 25 '22 13:10 anatol

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

andrewrk avatar Oct 25 '22 16:10 andrewrk

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

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

ice1000 avatar Oct 25 '22 18:10 ice1000

I made a fix for the first problem.

xeus2001 avatar Nov 27 '22 20:11 xeus2001