intellij-zig
intellij-zig copied to clipboard
Bring Zen language lexical changes
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 '.'
@linux-china I know you was interested in the lexer modifications. Do you have any changes that can help with this problem?
@anatol yes, you should update grammar files https://github.com/ice1000/intellij-zig/tree/master/grammar and grammar files are some old. @ice1000
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;
}
};
}
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 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 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.
I'm a college student with several part time jobs at the same time. I really really really want 114514 hours every single day.
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?
https://github.com/ziglang/zig-spec/tree/master/grammar
https://github.com/ziglang/zig-spec/tree/master/grammar
Thanks! If only zig has a spec like that when I first developed the plugin 😢
I made a fix for the first problem.