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

feat(zig): multiline #253

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions queries/zig/context.scm
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
([
(LoopStatement)
(LoopExpr)
(LoopTypeExpr)
(IfStatement)
(IfTypeExpr)
(TestDecl)
(SwitchExpr)
(SwitchProng)
] @context)

(Decl
(FnProto (_))
(Block (_) @context.end)
) @context

(VarDecl
(ErrorUnionExpr (_))
) @context

(IfStatement
(BlockExpr (_) @context.end)
) @context

(LoopStatement
(_ (BlockExpr (_) @context.end))
) @context

(LoopExpr
(_ (Block (_) @context.end))
) @context

(SwitchProng
(AssignExpr) @context.end
) @context

61 changes: 31 additions & 30 deletions test/test.zig
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
test "stuff" {
while (i < 3) {
while (i < 3 &&
j > 4) {
i += 1;


if (i == 2) {
if (i == 2
&& j == 3) {
// stuff




} else if (i == 3) {
} else if (i == 3 &&
j == 4) {
// stuff


Expand Down Expand Up @@ -48,19 +51,13 @@ test "stuff" {

const items = [_]i32 { 4, 5, 3, 4, 0 };

for (items) |value| {






sum += value;
}
// counting for loop
for


var sum: i32 = 0;
const result = for (items) |value| {
const result = for (
items) |value| {
if (value != null) {
sum += value.?;
}
Expand Down Expand Up @@ -109,9 +106,23 @@ const Stuff = struct {
d: i8,
}

fn bar(a: i8) {
fn bar(a: i8,
b: i8) {
switch (a) {
42,
1 => {

}
}
const b = switch (a) {
101 => blk: {
42,
1 => {


},

101,
102=> blk: {



Expand All @@ -128,7 +139,9 @@ fn bar(a: i8) {
};

}
fn foo(a: i8, b:i8) Stuff {
fn foo(a: i8,

b:i8) Stuff {
var p = Stuff {
a: 1,

Expand All @@ -146,22 +159,10 @@ fn foo(a: i8, b:i8) Stuff {
};

return Stuff {
a: a,




b: b,




c: 0,


.a = a,


d: 0,
.b = b,


};
Expand Down