scanner: implement s.trace/2

pull/8392/head
Delyan Angelov 2021-01-28 15:21:19 +02:00
parent 0afe36e153
commit 079fbffaf5
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 16 additions and 7 deletions

View File

@ -19,12 +19,13 @@ const (
pub struct Scanner {
pub mut:
file_path string
text string
pos int
line_nr int
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 // for calculating column
is_inside_string bool
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
@ -109,6 +110,7 @@ pub fn new_vet_scanner_file(file_path string, comments_mode CommentsMode, pref &
}
mut s := new_vet_scanner(raw_text, comments_mode, pref)
s.file_path = file_path
s.file_base = os.base(file_path)
return s
}
@ -127,6 +129,7 @@ pub fn new_vet_scanner(text string, comments_mode CommentsMode, pref &pref.Prefe
is_fmt: pref.is_fmt
comments_mode: comments_mode
file_path: 'internal_memory'
file_base: 'internal_memory'
}
}
@ -1291,3 +1294,9 @@ pub fn (mut s Scanner) codegen(newtext string) {
}
}
}
fn (mut s Scanner) trace(fbase string, message string) {
if s.file_base == fbase {
println('> s.trace | ${fbase:-10s} | $message')
}
}