v2.parser
fn Parser.new #
fn Parser.new(prefs &pref.Preferences) &Parser
struct Parser #
struct Parser {
pref &pref.Preferences
mut:
file &token.File = &token.File{}
scanner &scanner.Scanner
// track state
exp_lcbr bool // expecting `{` parsing `x` in `for|if|match x {` etc
allow_init_in_exp_lcbr bool
exp_pt bool // expecting (p)ossible (t)ype from `p.expr()`
in_top_level bool // inside top-level context (file scope / top-level comptime block)
stop_line_leading_dot bool
selector_names map[int]string
// token info : start
line int
lit string
pos token.Pos
tok token.Token = .unknown
tok_next_ token.Token = .unknown // DO NOT access directly, use `p.peek()`
// token info : end
}
fn (Parser) parse_files #
fn (mut p Parser) parse_files(files []string, mut file_set token.FileSet) []ast.File
fn (Parser) parse_files_to_flat #
fn (mut p Parser) parse_files_to_flat(files []string, mut file_set token.FileSet) ast.FlatAst
parse_files_to_flat parses each input file, immediately appends it to a FlatBuilder, and drops the legacy File. This is the Phase 2 entry point: it produces the same FlatAst that ast.flatten_files(p.parse_files(...)) would produce, but never holds more than one file's legacy AST resident. The result is signature-equivalent to the two-step path (regression-tested).
fn (Parser) parse_files_into_flat #
fn (mut p Parser) parse_files_into_flat(files []string, mut file_set token.FileSet, mut builder ast.FlatBuilder)
parse_files_into_flat streams files into a caller-owned FlatBuilder. Used by the builder to accumulate a single FlatAst across multiple parse batches (core, user, imports) without throwing away the builder between calls.
fn (Parser) parse_file #
fn (mut p Parser) parse_file(filename string, mut file_set token.FileSet) ast.File
fn (Parser) expect_semi #
fn (mut p Parser) expect_semi()