Module v.fmt stdlib

Dependencies from vmod:
Imported by:
Show selected OS-specific symbols.
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imported by


This section is empty.


This section is empty.

Sum types

This section is empty.


#fn fmt

fn fmt(file v.ast.File, table &v.ast.Table, pref_ &v.pref.Preferences, is_debug bool, options FmtOptions) string


#struct AttrsOptions

pub struct AttrsOptions {
	inline bool

#struct CommentsOptions

pub struct CommentsOptions {
	has_nl    bool = true
	inline    bool
	level     CommentsLevel
	iembed    bool
	prev_line int = -1

CommentsOptions defines the way comments are going to be written - has_nl: adds an newline at the end of a list of comments

  • inline: line comments will be on the same line as the last statement

  • level: either .keep (don't indent), or .indent (increment indentation)

  • iembed: a /* ... */ block comment used inside expressions; // comments the whole line

  • prev_line: the line number of the previous token to save linebreaks

#struct Fmt

pub struct Fmt {
pub mut:
	file               ast.File
	table              &ast.Table        = unsafe { nil }
	pref               &pref.Preferences = unsafe { nil }
	is_debug           bool
	out                strings.Builder
	out_imports        strings.Builder
	indent             int
	empty_line         bool
	line_len           int    // the current line length, Note: it counts \t as 4 spaces, and starts at 0 after f.writeln
	buffering          bool   // disables line wrapping for exprs that will be analyzed later
	par_level          int    // how many parentheses are put around the current expression
	array_init_break   []bool // line breaks after elements in hierarchy level of multi dimensional array
	array_init_depth   int    // current level of hierarchy in array init
	single_line_if     bool
	cur_mod            string
	did_imports        bool
	is_assign          bool
	is_struct_init     bool
	auto_imports       []string          // automatically inserted imports that the user forgot to specify
	import_pos         int               // position of the imports in the resulting string for later autoimports insertion
	used_imports       []string          // to remove unused imports
	import_syms_used   map[string]bool   // to remove unused import symbols.
	mod2alias          map[string]string // for `import time as t`, will contain: 'time'=>'t'
	mod2syms           map[string]string // import time { now } ''=>'now'
	use_short_fn_args  bool
	single_line_fields bool   // should struct fields be on a single line
	it_name            string // the name to replace `it` with
	in_lambda_depth    int
	inside_const       bool
	inside_unsafe      bool
	inside_comptime_if bool
	is_mbranch_expr    bool // match a { x...y { } }
	fn_scope           &ast.Scope = unsafe { nil }
	wsinfix_depth      int
	format_state       FormatState
	source_text        string // can be set by `echo "println('hi')" | v fmt`, i.e. when processing source not from a file, but from stdin. In this case, it will contain the entire input text. You can use f.file.path otherwise, and read from that file.

#fn (&Fmt) asm_stmt

fn (mut f &Fmt) asm_stmt(stmt v.ast.AsmStmt)

#fn (&Fmt) asm_arg

fn (mut f &Fmt) asm_arg(arg v.ast.AsmArg)

#fn (&Fmt) asm_reg

fn (mut f &Fmt) asm_reg(reg v.ast.AsmRegister)

#fn (&Fmt) asm_templates

fn (mut f &Fmt) asm_templates(templates []v.ast.AsmTemplate)

#fn (&Fmt) asm_clobbered

fn (mut f &Fmt) asm_clobbered(clobbered []v.ast.AsmClobbered)

#fn (&Fmt) asm_ios

fn (mut f &Fmt) asm_ios(ios []v.ast.AsmIO)

#fn (&Fmt) attrs

fn (mut f &Fmt) attrs(attrs []v.ast.Attr)

#fn (&Fmt) single_line_attrs

fn (mut f &Fmt) single_line_attrs(attrs []v.ast.Attr, options AttrsOptions)

#fn (&Fmt) comment

fn (mut f &Fmt) comment(node v.ast.Comment, options CommentsOptions)

#fn (&Fmt) comments

fn (mut f &Fmt) comments(comments []v.ast.Comment, options CommentsOptions)

#fn (&Fmt) comments_before_field

fn (mut f &Fmt) comments_before_field(comments []v.ast.Comment)

#fn (&Fmt) comments_after_last_field

fn (mut f &Fmt) comments_after_last_field(comments []v.ast.Comment)

#fn (&Fmt) import_comments

fn (mut f &Fmt) import_comments(comments []v.ast.Comment, options CommentsOptions)

#fn (&Fmt) process_file_imports

fn (mut f &Fmt) process_file_imports(file &v.ast.File)

#fn (&Fmt) write

fn (mut f &Fmt) write(s string)

#fn (&Fmt) writeln

fn (mut f &Fmt) writeln(s string)

#fn (&Fmt) write_indent

fn (mut f &Fmt) write_indent()

#fn (&Fmt) wrap_long_line

fn (mut f &Fmt) wrap_long_line(penalty_idx int, add_indent bool) bool

#fn (&Fmt) remove_new_line

fn (mut f &Fmt) remove_new_line(cfg RemoveNewLineConfig) string

When the removal action actually occurs, the string of the last line after the removal is returned

#fn (&Fmt) write_language_prefix

fn (mut f &Fmt) write_language_prefix(lang v.ast.Language)

#fn (&Fmt) write_generic_types

fn (mut f &Fmt) write_generic_types(gtypes []v.ast.Type)

#fn (&Fmt) set_current_module_name

fn (mut f &Fmt) set_current_module_name(cmodname string)

#fn (&Fmt) get_modname_prefix

fn (f &Fmt) get_modname_prefix(mname string) (string, string)

#fn (&Fmt) is_external_name

fn (mut f &Fmt) is_external_name(name string) bool

#fn (&Fmt) no_cur_mod

fn (mut f &Fmt) no_cur_mod(typename string) string

#fn (&Fmt) short_module

fn (mut f &Fmt) short_module(name string) string => bar.fn()

#fn (&Fmt) mark_types_import_as_used

fn (mut f &Fmt) mark_types_import_as_used(typ v.ast.Type)

#fn (&Fmt) mark_import_as_used

fn (mut f &Fmt) mark_import_as_used(name string)

name is a function ( or type (foo.Bar{})

#fn (&Fmt) imports

fn (mut f &Fmt) imports(imports []v.ast.Import)

#fn (&Fmt) imp_stmt_str

fn (f &Fmt) imp_stmt_str(imp v.ast.Import) string

#fn (&Fmt) should_insert_newline_before_node

fn (f &Fmt) should_insert_newline_before_node(node v.ast.Node, prev_node v.ast.Node) bool

#fn (&Fmt) node_str

fn (mut f &Fmt) node_str(node v.ast.Node) string

#fn (&Fmt) stmts

fn (mut f &Fmt) stmts(stmts []v.ast.Stmt)

#fn (&Fmt) stmt

fn (mut f &Fmt) stmt(node v.ast.Stmt)

#fn (&Fmt) expr

fn (mut f &Fmt) expr(node_ v.ast.Expr)

#fn (&Fmt) assert_stmt

fn (mut f &Fmt) assert_stmt(node v.ast.AssertStmt)

#fn (&Fmt) assign_stmt

fn (mut f &Fmt) assign_stmt(node v.ast.AssignStmt)

#fn (&Fmt) block

fn (mut f &Fmt) block(node v.ast.Block)

#fn (&Fmt) branch_stmt

fn (mut f &Fmt) branch_stmt(node v.ast.BranchStmt)

#fn (&Fmt) comptime_for

fn (mut f &Fmt) comptime_for(node v.ast.ComptimeFor)

#fn (&Fmt) const_decl

fn (mut f &Fmt) const_decl(node v.ast.ConstDecl)

#fn (&Fmt) defer_stmt

fn (mut f &Fmt) defer_stmt(node v.ast.DeferStmt)

#fn (&Fmt) expr_stmt

fn (mut f &Fmt) expr_stmt(node v.ast.ExprStmt)

#fn (&Fmt) enum_decl

fn (mut f &Fmt) enum_decl(node v.ast.EnumDecl)

#fn (&Fmt) fn_decl

fn (mut f &Fmt) fn_decl(node v.ast.FnDecl)

#fn (&Fmt) anon_fn

fn (mut f &Fmt) anon_fn(node v.ast.AnonFn)

#fn (&Fmt) fn_body

fn (mut f &Fmt) fn_body(node v.ast.FnDecl)

#fn (&Fmt) for_c_stmt

fn (mut f &Fmt) for_c_stmt(node v.ast.ForCStmt)

#fn (&Fmt) for_in_stmt

fn (mut f &Fmt) for_in_stmt(node v.ast.ForInStmt)

#fn (&Fmt) for_stmt

fn (mut f &Fmt) for_stmt(node v.ast.ForStmt)

#fn (&Fmt) global_decl

fn (mut f &Fmt) global_decl(node v.ast.GlobalDecl)

#fn (&Fmt) go_expr

fn (mut f &Fmt) go_expr(node v.ast.GoExpr)

#fn (&Fmt) goto_label

fn (mut f &Fmt) goto_label(node v.ast.GotoLabel)

#fn (&Fmt) goto_stmt

fn (mut f &Fmt) goto_stmt(node v.ast.GotoStmt)

#fn (&Fmt) hash_stmt

fn (mut f &Fmt) hash_stmt(node v.ast.HashStmt)

#fn (&Fmt) interface_decl

fn (mut f &Fmt) interface_decl(node v.ast.InterfaceDecl)

#fn (&Fmt) interface_field

fn (mut f &Fmt) interface_field(field v.ast.StructField)

#fn (&Fmt) interface_method

fn (mut f &Fmt) interface_method(method v.ast.FnDecl)

#fn (&Fmt) module_stmt

fn (mut f &Fmt) module_stmt(mod v.ast.Module)

#fn (&Fmt) return_stmt

fn (mut f &Fmt) return_stmt(node v.ast.Return)

#fn (&Fmt) sql_stmt

fn (mut f &Fmt) sql_stmt(node v.ast.SqlStmt)

#fn (&Fmt) sql_stmt_line

fn (mut f &Fmt) sql_stmt_line(node v.ast.SqlStmtLine)

#fn (&Fmt) type_decl

fn (mut f &Fmt) type_decl(node v.ast.TypeDecl)

#fn (&Fmt) alias_type_decl

fn (mut f &Fmt) alias_type_decl(node v.ast.AliasTypeDecl)

#fn (&Fmt) fn_type_decl

fn (mut f &Fmt) fn_type_decl(node v.ast.FnTypeDecl)

#fn (&Fmt) sum_type_decl

fn (mut f &Fmt) sum_type_decl(node v.ast.SumTypeDecl)

#fn (&Fmt) array_decompose

fn (mut f &Fmt) array_decompose(node v.ast.ArrayDecompose)

#fn (&Fmt) array_init

fn (mut f &Fmt) array_init(node v.ast.ArrayInit)

#fn (&Fmt) as_cast

fn (mut f &Fmt) as_cast(node v.ast.AsCast)

#fn (&Fmt) assoc

fn (mut f &Fmt) assoc(node v.ast.Assoc)

#fn (&Fmt) at_expr

fn (mut f &Fmt) at_expr(node v.ast.AtExpr)

#fn (&Fmt) call_expr

fn (mut f &Fmt) call_expr(node v.ast.CallExpr)

#fn (&Fmt) write_generic_call_if_require

fn (mut f &Fmt) write_generic_call_if_require(node v.ast.CallExpr)

#fn (&Fmt) call_args

fn (mut f &Fmt) call_args(args []v.ast.CallArg)

#fn (&Fmt) cast_expr

fn (mut f &Fmt) cast_expr(node v.ast.CastExpr)

#fn (&Fmt) chan_init

fn (mut f &Fmt) chan_init(mut node &v.ast.ChanInit)

#fn (&Fmt) comptime_call

fn (mut f &Fmt) comptime_call(node v.ast.ComptimeCall)

#fn (&Fmt) comptime_selector

fn (mut f &Fmt) comptime_selector(node v.ast.ComptimeSelector)

#fn (&Fmt) concat_expr

fn (mut f &Fmt) concat_expr(node v.ast.ConcatExpr)

#fn (&Fmt) dump_expr

fn (mut f &Fmt) dump_expr(node v.ast.DumpExpr)

#fn (&Fmt) enum_val

fn (mut f &Fmt) enum_val(node v.ast.EnumVal)

#fn (&Fmt) ident

fn (mut f &Fmt) ident(node v.ast.Ident)

#fn (&Fmt) if_expr

fn (mut f &Fmt) if_expr(node v.ast.IfExpr)

#fn (&Fmt) if_guard_expr

fn (mut f &Fmt) if_guard_expr(node v.ast.IfGuardExpr)

#fn (&Fmt) index_expr

fn (mut f &Fmt) index_expr(node v.ast.IndexExpr)

#fn (&Fmt) infix_expr

fn (mut f &Fmt) infix_expr(node v.ast.InfixExpr)

#fn (&Fmt) wrap_infix

fn (mut f &Fmt) wrap_infix(start_pos int, start_len int, is_cond bool)

#fn (&Fmt) write_splitted_infix

fn (mut f &Fmt) write_splitted_infix(conditions []string, penalties []int, ignore_paren bool, is_cond bool)

#fn (&Fmt) likely

fn (mut f &Fmt) likely(node v.ast.Likely)

#fn (&Fmt) lock_expr

fn (mut f &Fmt) lock_expr(node v.ast.LockExpr)

#fn (&Fmt) map_init

fn (mut f &Fmt) map_init(node v.ast.MapInit)

#fn (&Fmt) match_branch

fn (mut f &Fmt) match_branch(branch v.ast.MatchBranch, single_line bool)

#fn (&Fmt) match_expr

fn (mut f &Fmt) match_expr(node v.ast.MatchExpr)

#fn (&Fmt) offset_of

fn (mut f &Fmt) offset_of(node v.ast.OffsetOf)

#fn (&Fmt) or_expr

fn (mut f &Fmt) or_expr(node v.ast.OrExpr)

#fn (&Fmt) par_expr

fn (mut f &Fmt) par_expr(node v.ast.ParExpr)

#fn (&Fmt) postfix_expr

fn (mut f &Fmt) postfix_expr(node v.ast.PostfixExpr)

#fn (&Fmt) prefix_expr

fn (mut f &Fmt) prefix_expr(node v.ast.PrefixExpr)

#fn (&Fmt) range_expr

fn (mut f &Fmt) range_expr(node v.ast.RangeExpr)

#fn (&Fmt) select_expr

fn (mut f &Fmt) select_expr(node v.ast.SelectExpr)

#fn (&Fmt) selector_expr

fn (mut f &Fmt) selector_expr(node v.ast.SelectorExpr)

#fn (&Fmt) size_of

fn (mut f &Fmt) size_of(node v.ast.SizeOf)

#fn (&Fmt) is_ref_type

fn (mut f &Fmt) is_ref_type(node v.ast.IsRefType)

#fn (&Fmt) sql_expr

fn (mut f &Fmt) sql_expr(node v.ast.SqlExpr)

#fn (&Fmt) char_literal

fn (mut f &Fmt) char_literal(node v.ast.CharLiteral)

#fn (&Fmt) string_literal

fn (mut f &Fmt) string_literal(node v.ast.StringLiteral)

#fn (&Fmt) string_inter_literal

fn (mut f &Fmt) string_inter_literal(node v.ast.StringInterLiteral)

#fn (&Fmt) type_expr

fn (mut f &Fmt) type_expr(node v.ast.TypeNode)

#fn (&Fmt) type_of

fn (mut f &Fmt) type_of(node v.ast.TypeOf)

#fn (&Fmt) unsafe_expr

fn (mut f &Fmt) unsafe_expr(node v.ast.UnsafeExpr)

#fn (&Fmt) trace

fn (mut f &Fmt) trace(fbase string, message string)

#fn (&Fmt) struct_decl

fn (mut f &Fmt) struct_decl(node v.ast.StructDecl, is_anon bool)

#fn (&Fmt) write_anon_struct_field_decl

fn (mut f &Fmt) write_anon_struct_field_decl(field_typ v.ast.Type, field_anon_decl v.ast.StructDecl) bool

#fn (&Fmt) struct_init

fn (mut f &Fmt) struct_init(node v.ast.StructInit)

#fn (&Fmt) vfmt_off

fn (mut f &Fmt) vfmt_off(off_line int)

#fn (&Fmt) vfmt_on

fn (mut f &Fmt) vfmt_on(on_line int)

#fn (&Fmt) get_source_lines

fn (mut f &Fmt) get_source_lines() []string

#struct FmtOptions

pub struct FmtOptions {
	source_text string

#struct RemoveNewLineConfig

pub struct RemoveNewLineConfig {
	imports_buffer bool // Work on f.out_imports instead of f.out


This section is empty.


#enum CommentsLevel

pub enum CommentsLevel {