Skip to content

v3.parser

fn Parser.new #

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

new creates a Parser value for parser.

fn TmplBraceBlockKind.from #

fn TmplBraceBlockKind.from[W](input W) !TmplBraceBlockKind

fn TmplState.from #

fn TmplState.from[W](input W) !TmplState

struct Diagnostic #

struct Diagnostic {
pub:
	file     string
	pos      token.Pos
	line     int
	column   int
	severity string
	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
	prev_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
	veb_tmpl_counter      int      // monotonic id for unique `$veb.html`/`$tmpl` builder var names
	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`
	defer_depth           int      // >0 while parsing a `defer` block body; gates `$res()` to defer contexts only
	defer_result_allowed  bool     // true when the active defer is guaranteed to run during function return
	nested_block_depth    int      // lexical block depth below the current function body's outer scope
	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
	imported_module_names map[string]bool // import aliases in the current file; not captured by inlined template closures
	// local_binding_* track the variable/parameter names currently in scope, so an inlined
	// template closure captures a bare callee only when it is an actual local binding (a
	// function-valued parameter/local) rather than a module/top-level function. Scoped like
	// comptime_value_*: a name is in scope when local_binding_counts[name] > 0.
	local_binding_counts              map[string]int
	local_binding_undos               []string
	local_binding_scopes              []int
	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_typedef                   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_decl_pub                  bool
	pending_decl_attrs                []string
	pending_decl_attr_kinds           []int
	in_for_container                  bool
	in_select_branch_condition        int
	in_array_literal                  int
	in_map_value                      int
	in_struct_init_value              int
	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
	parsed_v_file_paths        []string
	parsed_v_header_files      int
	parsed_v_header_file_paths []string
	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 retained metadata and drops parser/scanner references to raw file buffers. Parsed node text is canonicalized as each file is completed and when parallel worker ASTs are merged.

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.