Skip to content

v.parser #

fn parse_comptime #

fn parse_comptime(tmpl_path string, text string, table &ast.Table, pref &pref.Preferences, scope &ast.Scope) &ast.File

fn parse_file #

fn parse_file(path string, table &ast.Table, comments_mode scanner.CommentsMode, pref &pref.Preferences) &ast.File

fn parse_files #

fn parse_files(paths []string, table &ast.Table, pref &pref.Preferences) []&ast.File

fn parse_stmt #

fn parse_stmt(text string, table &ast.Table, scope &ast.Scope) ast.Stmt

for tests

fn parse_text #

fn parse_text(text string, path string, table &ast.Table, comments_mode scanner.CommentsMode, pref &pref.Preferences) &ast.File

fn parse_vet_file #

fn parse_vet_file(path string, table_ &ast.Table, pref &pref.Preferences) (&ast.File, []vet.Error)

struct Parser #

struct Parser {
	pref &pref.Preferences
	file_base         string       // "hello.v"
	file_name         string       // "/home/user/hello.v"
	file_name_dir     string       // "/home/user"
	unique_prefix     string       // a hash of p.file_name, used for making anon fn generation unique
	file_backend_mode ast.Language // .c for .c.v|.c.vv|.c.vsh files; .js for .js.v files, .amd64/.rv32/other arches for .amd64.v/.rv32.v/etc. files, .v otherwise.
	scanner           &scanner.Scanner
	comments_mode     scanner.CommentsMode = .skip_comments
// see comment in parse_file
	tok                       token.Token
	prev_tok                  token.Token
	peek_tok                  token.Token
	table                     &ast.Table
	language                  ast.Language
	fn_language               ast.Language // .c for `fn C.abcd()` declarations
	expr_level                int  // prevent too deep recursions for pathological programs
	inside_vlib_file          bool // true for all vlib/ files
	inside_test_file          bool // when inside _test.v or _test.vv file
	inside_if                 bool
	inside_if_expr            bool
	inside_if_cond            bool
	inside_ct_if_expr         bool
	inside_or_expr            bool
	inside_for                bool
	inside_fn                 bool // true even with implicit main
	inside_fn_return          bool
	inside_unsafe_fn          bool
	inside_str_interp         bool
	inside_array_lit          bool
	inside_in_array           bool
	inside_match              bool // to separate `match A { }` from `Struct{}`
	inside_select             bool // to allow `ch <- Struct{} {` inside `select`
	inside_match_case         bool // to separate `match_expr { }` from `Struct{}`
	inside_match_body         bool // to fix eval not used TODO
	inside_unsafe             bool
	inside_sum_type           bool // to prevent parsing inline sum type again
	inside_asm_template       bool
	inside_asm                bool
	inside_defer              bool
	inside_generic_params     bool // indicates if parsing between `<` and `>` of a method/function
	inside_receiver_param     bool // indicates if parsing the receiver parameter inside the first `(` and `)` of a method
	inside_struct_field_decl  bool
	or_is_handled             bool       // ignore `or` in this expression
	builtin_mod               bool       // are we in the `builtin` module?
	mod                       string     // current module name
	is_manualfree             bool       // true when `[manualfree] module abc`, makes *all* fns in the current .v file, opt out of autofree
	has_globals               bool       // `[has_globals] module abc` - allow globals declarations, even without -enable-globals, in that single .v file __only__
	is_generated              bool       // `[generated] module abc` - turn off compiler notices for that single .v file __only__.
	is_translated             bool       // `[translated] module abc` - mark a file as translated, to relax some compiler checks for translated code.
	attrs                     []ast.Attr // attributes before next decl stmt
	expr_mod                  string     // for constructing full type names in parse_type()
	scope                     &ast.Scope
	imports                   map[string]string // alias => mod_name
	ast_imports               []ast.Import      // mod_names
	used_imports              []string // alias
	auto_imports              []string // imports, the user does not need to specify
	imported_symbols          map[string]string
	is_amp                    bool // for generating the right code for `&Foo{}`
	returns                   bool
	is_stmt_ident             bool // true while the beginning of a statement is an ident/selector
	expecting_type            bool // `is Type`, expecting type
	errors                    []errors.Error
	warnings                  []errors.Warning
	notices                   []errors.Notice
	vet_errors                []vet.Error
	cur_fn_name               string
	label_names               []string
	name_error                bool // indicates if the token is not a name or the name is on another line
	n_asm                     int  // controls assembly labels
	global_labels             []string
	comptime_if_cond          bool
	defer_vars                []ast.Ident
	should_abort              bool // when too many errors/warnings/notices are accumulated, should_abort becomes true, and the parser should stop
	codegen_text              string
	struct_init_generic_types []ast.Type
	if_cond_comments          []ast.Comment
	script_mode               bool
	script_mode_start_token   token.Token

fn (Parser) call_args #

fn (mut p Parser) call_args() []ast.CallArg

fn (Parser) call_expr #

fn (mut p Parser) call_expr(language ast.Language, mod string) ast.CallExpr

fn (Parser) check_comment #

fn (mut p Parser) check_comment() ast.Comment

TODO [if vfmt]

fn (Parser) check_expr #

fn (mut p Parser) check_expr(precedence int) ?ast.Expr

fn (Parser) check_for_impure_v #

fn (mut p Parser) check_for_impure_v(language ast.Language, pos token.Pos)

fn (Parser) close_scope #

fn (mut p Parser) close_scope()

fn (Parser) codegen #

fn (mut p Parser) codegen(code string)

codegen allows you to generate V code, so that it can be parsed, checked, markused, cgen-ed etc further, just like user's V code.

fn (Parser) comment #

fn (mut p Parser) comment() ast.Comment

fn (Parser) comment_stmt #

fn (mut p Parser) comment_stmt() ast.ExprStmt

fn (Parser) compile_template_file #

fn (mut p Parser) compile_template_file(template_file string, fn_name string) string

compile_file compiles the content of a file by the given path as a template

fn (Parser) eat_comments #

fn (mut p Parser) eat_comments(cfg EatCommentsConfig) []ast.Comment

fn (Parser) error #

fn (mut p Parser) error(s string) ast.NodeError

fn (Parser) error_with_error #

fn (mut p Parser) error_with_error(error errors.Error)

fn (Parser) error_with_pos #

fn (mut p Parser) error_with_pos(s string, pos token.Pos) ast.NodeError

fn (Parser) expr #

fn (mut p Parser) expr(precedence int) ast.Expr

fn (Parser) expr_with_left #

fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_ident bool) ast.Expr

fn (Parser) find_type_or_add_placeholder #

fn (mut p Parser) find_type_or_add_placeholder(name string, language ast.Language) ast.Type

fn (Parser) free #

fn (mut p Parser) free()

fn (Parser) free_scanner #

fn (mut p Parser) free_scanner()

fn (Parser) init_parse_fns #

fn (mut p Parser) init_parse_fns()

fn (Parser) known_import #

fn (p &Parser) known_import(mod string) bool

return true if file being parsed imports mod

fn (Parser) language_not_allowed_error #

fn (mut p Parser) language_not_allowed_error(language ast.Language, pos token.Pos)

fn (Parser) language_not_allowed_warning #

fn (mut p Parser) language_not_allowed_warning(language ast.Language, pos token.Pos)

fn (Parser) mark_var_as_used #

fn (mut p Parser) mark_var_as_used(varname string) bool

returns true if varname is known

fn (Parser) name_expr #

fn (mut p Parser) name_expr() ast.Expr

fn (Parser) note #

fn (mut p Parser) note(s string)

fn (Parser) note_with_pos #

fn (mut p Parser) note_with_pos(s string, pos token.Pos)

fn (Parser) open_scope #

fn (mut p Parser) open_scope()

fn (Parser) parse #

fn (mut p Parser) parse() &ast.File

fn (Parser) parse_any_type #

fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_dot bool) ast.Type

fn (Parser) parse_array_type #

fn (mut p Parser) parse_array_type(expecting token.Kind) ast.Type

fn (Parser) parse_block #

fn (mut p Parser) parse_block() []ast.Stmt

fn (Parser) parse_block_no_scope #

fn (mut p Parser) parse_block_no_scope(is_top_level bool) []ast.Stmt

fn (Parser) parse_chan_type #

fn (mut p Parser) parse_chan_type() ast.Type

fn (Parser) parse_comptime_type #

fn (mut p Parser) parse_comptime_type() ast.ComptimeType

fn (Parser) parse_fn_type #

fn (mut p Parser) parse_fn_type(name string) ast.Type

given anon name based off signature when name is blank

fn (Parser) parse_generic_inst_type #

fn (mut p Parser) parse_generic_inst_type(name string) ast.Type

fn (Parser) parse_generic_type #

fn (mut p Parser) parse_generic_type(name string) ast.Type

fn (Parser) parse_ident #

fn (mut p Parser) parse_ident(language ast.Language) ast.Ident

fn (Parser) parse_inline_sum_type #

fn (mut p Parser) parse_inline_sum_type() ast.Type

parse_inline_sum_type parses the type and registers it in case the type is an anonymous sum type.
It also takes care of inline sum types where parse_type only parses a standalone type.

fn (Parser) parse_language #

fn (mut p Parser) parse_language() ast.Language

Parses any language indicators on a type.

fn (Parser) parse_map_type #

fn (mut p Parser) parse_map_type() ast.Type

fn (Parser) parse_multi_return_type #

fn (mut p Parser) parse_multi_return_type() ast.Type

fn (Parser) parse_sum_type_variants #

fn (mut p Parser) parse_sum_type_variants() []ast.TypeNode

parse_sum_type_variants parses several types separated with a pipe and returns them as a list with at least one node.
If there is less than one node, it will add an error to the error list.

fn (Parser) parse_thread_type #

fn (mut p Parser) parse_thread_type() ast.Type

fn (Parser) parse_type #

fn (mut p Parser) parse_type() ast.Type

fn (Parser) parse_type_with_mut #

fn (mut p Parser) parse_type_with_mut(is_mut bool) ast.Type

fn (Parser) peek_token #

fn (p &Parser) peek_token(n int) token.Token

fn (Parser) read_first_token #

fn (mut p Parser) read_first_token()

fn (Parser) set_path #

fn (mut p Parser) set_path(path string)

fn (Parser) stmt #

fn (mut p Parser) stmt(is_top_level bool) ast.Stmt

fn (Parser) top_stmt #

fn (mut p Parser) top_stmt() ast.Stmt

fn (Parser) vet_error #

fn (mut p Parser) vet_error(msg string, line int, fix vet.FixKind, typ vet.ErrorType)

fn (Parser) warn #

fn (mut p Parser) warn(s string)

fn (Parser) warn_with_pos #

fn (mut p Parser) warn_with_pos(s string, pos token.Pos)