Skip to content

v3.parser

fn Parser.new #

fn Parser.new(prefs &pref.Preferences) &Parser

new creates a Parser value for parser.

struct Diagnostic #

struct Diagnostic {
pub:
	file    string
	pos     token.Pos
	line    int
	column  int
	message string
}

Diagnostic is a structured source-ingestion, lexical, or parse diagnostic.

struct Parser #

struct Parser {
	prefs &pref.Preferences
mut:
	s                                 scanner.Scanner
	tok                               token.Token
	lit                               string
	tok_pos                           int
	tok_end                           int
	peek_tok                          token.Token = .eof
	peek_lit                          string
	peek_pos                          int
	peek_end                          int
	has_peek                          bool
	cur_file                          string
	cur_file_id                       int
	next_file_id                      int = 1
	cur_module                        string
	cur_fn                            string
	cur_struct                        string   // receiver type name of the current method, for `@STRUCT`
	cur_method_is_static              bool     // distinguishes `Type.method()` from `(x Type) method()` for `@LOCATION`
	comptime_for_vars                 []string // active `$for` loop variables; a `$if` that reads one is deferred to unroll time
	comptime_method_var               string   // innermost active `$for method in Type.methods` loop variable
	comptime_const_values             map[string]string
	comptime_local_values             map[string]string
	comptime_value_undos              []ComptimeValueUndo
	comptime_value_scopes             []int
	pending_flag                      bool
	pending_json_as_number            bool // `@[json_as_number]` seen before the next enum decl
	pending_params                    bool
	pending_export                    string
	pending_noreturn                  bool
	pending_soa                       bool
	pending_has_aligned               bool
	pending_aligned                   string
	skip_next_decl                    bool
	disable_fn_body                   bool
	pending_fn_pub                    bool
	pending_decl_attrs                []string
	pending_decl_attr_kinds           []int
	in_for_container                  bool
	unsupported_inline_asm_guards     map[int]bool
	parsing_inferred_fixed_array_type bool
	diagnostic_limit_reached          bool
	local_type_names                  map[string]string
	local_type_scopes                 []string
	anonymous_struct_types            map[string][]string
	anonymous_struct_count            int
	sql_query_data_aliases            map[string]bool
	export_records                    []ExportRecord
pub mut:
	a              &flat.FlatAst = unsafe { nil }
	parsed_v_files int
	diagnostics    []Diagnostic
}

Parser represents parser data used by parser.

fn (Parser) parse_file #

fn (mut p Parser) parse_file(path string) &flat.FlatAst

parse_file reads parse file input for parser.

fn (Parser) parse_files #

fn (mut p Parser) parse_files(paths []string) &flat.FlatAst

parse_files reads parse files input for parser.

fn (Parser) parse_files_dispatch #

fn (mut p Parser) parse_files_dispatch(paths []string, allow_parallel bool) ([]int, bool)

parse_files_dispatch parses paths in order, appending to p.a exactly like a serial parse_into loop, across worker threads when there is enough work. Returns each file's first node id in p.a and whether threads were used.

fn (Parser) parse_files_with_starts #

fn (mut p Parser) parse_files_with_starts(paths []string) []int

parse_files_with_starts parses paths in order like parse_files, recording the first node id of each file's region. Import resolution uses the starts to bound per-file post-processing (module-name canonicalization) when files are parsed in batches instead of one at a time.

fn (Parser) parse_into #

fn (mut p Parser) parse_into(path string)

parse_into reads parse into input for parser.

fn (Parser) release_source_storage #

fn (mut p Parser) release_source_storage()

release_source_storage canonicalizes every retained source slice and drops parser/scanner references to raw file buffers. Source files keep only their compact line indexes for later diagnostic lookup.

fn (Parser) reserve_selfhost_ast #

fn (mut p Parser) reserve_selfhost_ast()

reserve_selfhost_ast prepares the shared AST for a compiler-sized input without retaining successively doubled backing arrays during transform.