Skip to content

v.scanner #

fn new_scanner #

fn new_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner

new scanner from string.

fn new_scanner_file #

fn new_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences) ?&Scanner

new scanner from file.

enum CommentsMode #

enum CommentsMode {

The different kinds of scanner modes:

.skip_comments - simplest/fastest, just ignores all comments early.
This mode is used by the compiler itself.

.parse_comments is used by vfmt. Ideally it should handle inline /* */ comments too, i.e. it returns every kind of comment as a new token.

.toplevel_comments is used by vdoc, parses only top level ones that are outside structs/enums/fns.

struct Scanner #

struct Scanner {
pub mut:
	file_path         string // '/path/to/file.v'
	file_base         string // 'file.v'
	text              string // the whole text of the file
	pos               int    // current position in the file, first character is s.text[0]
	line_nr           int    // current line number
	last_nl_pos       int = -1 // for calculating column
	is_crlf           bool   // special check when computing columns
	is_inside_string  bool   // set to true in a string, *at the start* of an $var or ${expr}
	is_inter_start    bool   // for hacky string interpolation TODO simplify
	is_inter_end      bool
	is_enclosed_inter bool
	line_comment      string
	last_lt           int = -1 // position of latest <
// prev_tok                 TokenKind
	is_started                  bool
	is_print_line_on_error      bool
	is_print_colored_error      bool
	is_print_rel_paths_on_error bool
	quote                       u8  // which quote is used to denote current string: ' or "
	inter_quote                 u8
	nr_lines                    int // total number of lines in the source file that were scanned
	is_vh                       bool // Keep newlines
	is_fmt                      bool // Used for v fmt.
	comments_mode               CommentsMode
	is_inside_toplvl_statement  bool // *only* used in comments_mode: .toplevel_comments, toggled by parser
	all_tokens                  []token.Token // *only* used in comments_mode: .toplevel_comments, contains all tokens
	tidx                        int
	eofs                        int
	pref                        &pref.Preferences
	error_details               []string
	errors                      []errors.Error
	warnings                    []errors.Warning
	notices                     []errors.Notice
	vet_errors                  []vet.Error
	should_abort                bool // when too many errors/warnings/notices are accumulated, should_abort becomes true, and the scanner should stop

fn (Scanner) free #

fn (mut s Scanner) free()

fn (Scanner) set_is_inside_toplevel_statement #

fn (mut s Scanner) set_is_inside_toplevel_statement(newstate bool)

Note: this is called by v's parser

fn (Scanner) set_current_tidx #

fn (mut s Scanner) set_current_tidx(cidx int)

fn (Scanner) scan_all_tokens_in_buffer #

fn (mut s Scanner) scan_all_tokens_in_buffer()

fn (Scanner) scan_remaining_text #

fn (mut s Scanner) scan_remaining_text()

fn (Scanner) scan #

fn (mut s Scanner) scan() token.Token

fn (Scanner) peek_token #

fn (s &Scanner) peek_token(n int) token.Token

fn (Scanner) note #

fn (mut s Scanner) note(msg string)

fn (Scanner) add_error_detail #

fn (mut s Scanner) add_error_detail(msg string)

call this before calling error or warn

fn (Scanner) add_error_detail_with_pos #

fn (mut s Scanner) add_error_detail_with_pos(msg string, pos token.Pos)

fn (Scanner) warn #

fn (mut s Scanner) warn(msg string)

fn (Scanner) error #

fn (mut s Scanner) error(msg string)