From 079fbffaf5183cf0e1ec11c7342cdf1cc8c4628c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 28 Jan 2021 15:21:19 +0200 Subject: [PATCH] scanner: implement s.trace/2 --- vlib/v/scanner/scanner.v | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 34e7e57833..950ff0327f 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -19,13 +19,14 @@ const ( pub struct Scanner { pub mut: - file_path string - text string - pos int - line_nr int - last_nl_pos int // for calculating column - is_inside_string bool - is_inter_start bool // for hacky string interpolation TODO simplify + 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 // 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 @@ -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') + } +}