Module v.scanner stdlib

v.scanner
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
9
Imported by:
3
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imported by

Aliases

This section is empty.

Constants

This section is empty.

Sum types

This section is empty.

Functions

#fn new_scanner_file

fn new_scanner_file(file_path string, comments_mode CommentsMode, pref_ &v.pref.Preferences) !&Scanner

new scanner from file.

Structs

#struct Scanner

minify
pub 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_nested_string            bool   // '${'abc':-12s}'
	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 <
	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
	inter_cbr_count             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 new_scanner

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

new scanner from string.

#fn (&Scanner) free

unsafe
fn (mut s &Scanner) free()

#fn (&Scanner) should_parse_comment

inline
fn (s &Scanner) should_parse_comment() bool

#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) new_token

inline
fn (mut s &Scanner) new_token(tok_kind v.token.Kind, lit string, len int) v.token.Token

#fn (&Scanner) new_eof_token

inline
fn (s &Scanner) new_eof_token() v.token.Token

#fn (&Scanner) new_multiline_token

inline
fn (mut s &Scanner) new_multiline_token(tok_kind v.token.Kind, lit string, len int, start_line int) v.token.Token

#fn (&Scanner) ident_name

direct_array_accessinline
fn (mut s &Scanner) ident_name() string

#fn (&Scanner) num_lit

fn (s &Scanner) num_lit(start int, end int) string

#fn (&Scanner) ident_bin_number

fn (mut s &Scanner) ident_bin_number() string

#fn (&Scanner) ident_hex_number

direct_array_access
fn (mut s &Scanner) ident_hex_number() string

#fn (&Scanner) ident_oct_number

fn (mut s &Scanner) ident_oct_number() string

#fn (&Scanner) ident_dec_number

direct_array_access
fn (mut s &Scanner) ident_dec_number() string

#fn (&Scanner) ident_number

fn (mut s &Scanner) ident_number() string

#fn (&Scanner) skip_whitespace

direct_array_accessinline
fn (mut s &Scanner) skip_whitespace()

#fn (&Scanner) end_of_file

fn (mut s &Scanner) end_of_file() v.token.Token

#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

direct_array_access
fn (mut s &Scanner) scan() v.token.Token

#fn (&Scanner) peek_token

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

#fn (&Scanner) look_ahead

direct_array_accessinline
fn (s &Scanner) look_ahead(n int) u8

#fn (&Scanner) text_scan

direct_array_access
fn (mut s &Scanner) text_scan() v.token.Token

#fn (&Scanner) invalid_character

fn (mut s &Scanner) invalid_character()

#fn (&Scanner) current_column

fn (s &Scanner) current_column() int

#fn (&Scanner) count_symbol_before

fn (s &Scanner) count_symbol_before(p int, sym u8) int

#fn (&Scanner) ident_string

direct_array_access
fn (mut s &Scanner) ident_string() string

#fn (&Scanner) decode_u_escape_single

fn (mut s &Scanner) decode_u_escape_single(str string, idx int) (int, string)

#fn (&Scanner) decode_u_escapes

fn (mut s &Scanner) decode_u_escapes(str string, start int, escapes_pos []int) string

decode the flagged unicode escape sequences into their utf-8 bytes

#fn (&Scanner) ident_char

fn (mut s &Scanner) ident_char() string

/ ident_char is called when a backtick "single-char" is parsed from the code / it is needed because some runes (chars) are written with escape sequences / the string it returns should be a standardized, simplified version of the character / as it would appear in source code / possibilities:

/ single chars like a, b => 'a', 'b' / escaped single chars like \\, \``, \n => '\\', '', '\n' / escaped single hex bytes like \x01, \x61 => '\x01', 'a' / escaped unicode literals like \u2605 / escaped utf8 runes in hex like \xe2\x98\x85 => (★) / escaped utf8 runes in octal like \342\230\205 => (★)

#fn (&Scanner) expect

direct_array_accessinline
fn (s &Scanner) expect(want string, start_pos int) bool

#fn (&Scanner) ignore_line

inline
fn (mut s &Scanner) ignore_line()

#fn (&Scanner) eat_to_end_of_line

direct_array_accessinline
fn (mut s &Scanner) eat_to_end_of_line()

#fn (&Scanner) inc_line_number

inline
fn (mut s &Scanner) inc_line_number()

#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 v.token.Pos)

#fn (&Scanner) eat_details

fn (mut s &Scanner) eat_details() string

#fn (&Scanner) warn

fn (mut s &Scanner) warn(msg string)

#fn (&Scanner) error

fn (mut s &Scanner) error(msg string)

#fn (&Scanner) vet_error

fn (mut s &Scanner) vet_error(msg string, fix v.vet.FixKind)

#fn (&Scanner) trace

fn (mut s &Scanner) trace(fbase string, message string)

Interfaces

This section is empty.

Enums

#enum CommentsMode

pub enum CommentsMode {
	skip_comments
	parse_comments
	toplevel_comments
}

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.