Current section

Files

Jump to
zigler lib zig .Elixir.Zig.Formatter.zig
Raw

lib/zig/.Elixir.Zig.Formatter.zig

// this code is autogenerated, do not check it into to your code repository
// ref lib/zig/formatter.ex:19
const std = @import("std");
const beam = @import("beam");
pub fn format_string(source_code: []u8) !beam.term {
const source_z = try beam.allocator.allocSentinel(u8, source_code.len, 0);
defer beam.allocator.free(source_z);
@memcpy(source_z.ptr, source_code);
var tree = try std.zig.Ast.parse(beam.allocator, source_z, .zig);
defer tree.deinit(beam.allocator);
// no-op if parsing errors
if (tree.errors.len == 0) {
const formatted = try tree.render(beam.allocator);
defer beam.allocator.free(formatted);
return beam.make(formatted, .{});
} else {
return beam.make(source_code, .{});
}
}