Skip to content

v2.token #

fn FileSet.new #

fn FileSet.new() &FileSet

fn Token.from_string_tinyv #

fn Token.from_string_tinyv(name string) Token

Note: add keyword tokens here

Todo: allow overriding this method in main v compilerthat is why this method was renamed from from_string vfmt off

enum BindingPower #

enum BindingPower {
	lowest
	one
	two
	three
	four
	highest
}

enum Token #

enum Token {
	amp        // &
	and        // &&
	and_assign // &=
	arrow      // <-
	assign     // =
	// at // @
	attribute
	bit_not // ~
	char    // `A` - rune
	colon   // :
	comma   // ,
	comment
	dec         // --
	decl_assign // :=
	div         // /
	div_assign  // /=
	dollar      // $
	dot         // .
	dotdot      // ..
	ellipsis    // ...
	eof
	eq   // ==
	ge   // >=
	gt   // >
	hash // #
	inc  // ++
	key_as
	key_asm
	key_assert
	key_atomic
	key_break
	key_const
	key_continue
	key_defer
	key_dump
	key_else
	key_enum
	key_false
	key_fn
	key_for
	key_global
	key_go
	key_goto
	key_if
	key_import
	key_in
	key_interface
	key_is
	key_isreftype
	key_likely
	key_lock
	key_match
	key_module
	key_mut
	key_nil
	key_none
	key_offsetof
	key_or
	key_pub
	key_return
	key_rlock
	key_select
	key_shared
	key_sizeof
	key_spawn
	key_static
	key_struct
	key_true
	key_type
	key_typeof
	key_union
	key_unlikely
	key_unsafe
	key_volatile
	lcbr                        // {
	le                          // <=
	left_shift                  // <<
	left_shift_assign           // >>=
	logical_or                  // ||
	lpar                        // (
	lsbr                        // [
	lt                          // <
	minus                       // -
	minus_assign                // -=
	mod                         // %
	mod_assign                  // %=
	mul                         // *
	mul_assign                  // *=
	name                        // user
	ne                          // !=
	not                         // !
	not_in                      // !in
	not_is                      // !is
	number                      // 123
	or_assign                   // |=
	pipe                        // |
	plus                        // +
	plus_assign                 // +=
	question                    // ?
	rcbr                        // }
	right_shift                 // >>
	right_shift_assign          // <<=
	right_shift_unsigned        // >>>
	right_shift_unsigned_assign // >>>=
	rpar                        // )
	rsbr                        // ]
	semicolon                   // ;
	str_dollar
	string // 'foo'
	unknown
	xor        // ^
	xor_assign // ^=
}

fn (Token) left_binding_power #

fn (t Token) left_binding_power() BindingPower

fn (Token) right_binding_power #

fn (t Token) right_binding_power() BindingPower

Todo: double check / fix this. just use what is needed instead of this

fn (Token) is_prefix #

fn (t Token) is_prefix() bool

fn (Token) is_infix #

fn (t Token) is_infix() bool

fn (Token) is_postfix #

fn (t Token) is_postfix() bool

fn (Token) is_assignment #

fn (t Token) is_assignment() bool

fn (Token) is_overloadable #

fn (t Token) is_overloadable() bool

fn (Token) is_comparison #

fn (t Token) is_comparison() bool

fn (Token) str #

fn (t Token) str() string

Note: probably switch back to map again later.for dev this is easier to see if any tokens are missing.

struct File #

struct File {
pub:
	name string
	base int
	size int
mut:
	line_offsets []int = [0] // start of each line
}

fn (File) add_line #

fn (mut f File) add_line(offset int)

pub fn new_file(filename string) File { return File{ name: filename } }

fn (File) line_count #

fn (f &File) line_count() int

fn (File) line_start #

fn (f &File) line_start(line int) int

fn (File) line #

fn (f &File) line(pos Pos) int

fn (File) pos #

fn (f &File) pos(offset int) Pos

fn (File) position #

fn (f &File) position(pos Pos) Position

fn (File) find_line_and_column #

fn (f &File) find_line_and_column(pos int) (int, int)

return (line, column) when passed pos

fn (File) find_line #

fn (f &File) find_line(pos int) int

return line when passed pos (binary search)

Note: only used for error conditions therefore search speed is not an issue

struct FileSet #

struct FileSet {
mut:
	base int = 1 // reserve 0 for no position
	// files shared []&File
	files []&File
	mu    &sync.Mutex = sync.new_mutex()
}

fn (FileSet) add_file #

fn (mut fs FileSet) add_file(filename string, base_ int, size int) &File

Todo:

fn (FileSet) file #

fn (mut fs FileSet) file(pos Pos) &File

struct Position #

struct Position {
pub:
	filename string
	offset   int
	line     int
	column   int
}

fn (Position) str #

fn (p Position) str() string