Skip to content

v3.gen.v

fn format #

fn format(a &flat.FlatAst) string

format finds every trailing .file node in a and formats them in order, separated by a blank line. Useful when a single file was parsed on its own.

fn format_file #

fn format_file(a &flat.FlatAst, file_id flat.NodeId) string

format_file parses-independent convenience: format the file whose trailing .file node id is file_id within a.

fn Gen.new #

fn Gen.new() &Gen

Gen.new returns a fresh formatter.

struct Gen #

struct Gen {
mut:
	a          &flat.FlatAst = unsafe { nil }
	out        strings.Builder
	indent     int
	on_newline bool
	in_init    bool
	// suppress_mut skips the `mut ` prefix on an assignment (used for C-style
	// `for` loop init clauses, whose variable the parser always marks mutable).
	suppress_mut bool
	// attrs maps a declaration node id to its `@[...]` attribute strings. The
	// parser stores attributes on a separate floating `.directive` node rather
	// than as a child, so they are collected up-front in collect_attrs.
	attrs map[int][]string
}

Gen holds the formatter state for one output buffer.

fn (Gen) reset #

fn (mut g Gen) reset()

reset clears the buffer so a Gen instance can be reused.

fn (Gen) gen_file #

fn (mut g Gen) gen_file(a &flat.FlatAst, file_id flat.NodeId) string

gen_file formats the top-level declarations of the given trailing file node.

fn (Gen) output_string #

fn (mut g Gen) output_string() string

output_string returns the generated V source code.