#What needs to be changed in Render.zig to emit 2 space indentation and compile without errors?

1 messages · Page 1 of 1 (latest)

twin sky
#

A follow up of this https://github.com/ziglang/zig/issues/11107 I'm trying to compile Render.zig https://codeberg.org/ziglang/zig/src/branch/master/lib/std/zig/Ast/Render.zig to optionally emit 2 space indentation.

I changed this only

const std = @import("std");
// ...
const indent_delta = 2;

I'm getting these errors

error: root source file struct 'render' has no member named 'main'
    const fn_info = @typeInfo(@TypeOf(root.main)).@"fn";
                                      ~~~~^~~~~
render.zig:1:1: note: struct declared here
const std = @import("std");
^~~~~
/media/user/xzig/lib/std/start.zig:629:20: note: called inline here
    return callMain(argv[0..argc], env_block);
           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/media/user/x/zig/lib/std/start.zig:582:38: note: called inline here
    std.process.exit(callMainWithArgs(argc, argv, envp));
                     ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~

GitHub

When writing Zig, it's common to have deeply nested switch statements and/or scopes With 4 spaces, that means you need a wide screen to read the code .fn_proto_simple, .fn_proto_multi, .fn_prot...

crisp mica
#

that file is not the entirety of zig fmt, you need to either recompile the compiler with those changes or make your own program that uses Ast.Render

twin sky
crisp mica
twin sky
#

How do I set default indentation to 2 spaces?

crisp mica
#

i assume by making the change you already did

twin sky
#

Looks like a totally different file. I don't even see the term "indent".

crisp mica
#

the file i sent uses Ast/Render.zig, it just has the main function

#

make the change in Render.zig and compile the file i sent

twin sky
#

I don't understand. I don't see a reference to Render.zig. I've been writing in Zig all of 2 days...

crisp mica
#

Render.zig is part of the standard library

twin sky
#

Still not following. I'm trying to compile Zig's fmt to a standalone executable that indents with 2 spaces by default.

tawny jay
#

If you've only used Zig 2 days, perhaps better to not be in too big of a hurry to depart from standard formatting before determining you really absolutely can't live without 2-space indents.

twin sky
sly marlin
twin sky
#

So, putting it all together the code should look like what?

sly marlin
#

keep the edit you made to lib/std/zig/Ast/Render.zig, then compile src/fmt.zig using your own lib/std folder as the standard library implementation instead of the default (zig build-exe --zig-lib-dir /path/to/zig/lib /path/to/zig/src/fmt.zig)

twin sky
#

I made the change to Render.zig in the lib directory directly. fmt.zig is in current working directory

zig build-exe --zig-lib-dir /media/user/x/zig/lib fmt.zig
fmt.zig:372:29: error: root source file struct 'process' has no member named 'argsAlloc'
    const args = try process.argsAlloc(arena);
                     ~~~~~~~^~~~~~~~~~
/media/user/x/zig/lib/std/process.zig:1:1: note: struct declared here
const builtin = @import("builtin");
^~~~~
referenced by:
    callMain [inlined]: /media/user/x/zig/lib/std/start.zig:677:59
    callMainWithArgs [inlined]: /media/user/x/zig/lib/std/start.zig:629:20
    posixCallMainAndExit: /media/user/x/zig/lib/std/start.zig:582:38
    2 reference(s) hidden; use '-freference-trace=5' to see all references
sly marlin
#

oof, looks like the main function in fmt.zig hasn't kept up with the standard library changes

#

i'm not too familiar with how this all works now but from reading src/main.zig it looks like you can make the main function take one argument init: std.process.Init.Minimal and then change try process.argsAlloc(arena) to try init.args.toSlice(arena)

twin sky
#

I think that's it.

#

Damn, 28.5 MiB executable.