@@ -132,6 +132,14 @@ pub mut:
132132 warnings []errors.Warning
133133 notices []errors.Notice
134134 template_paths []string // record all compiled $tmpl files; needed for `v watch run webserver.v`
135+ content ParseContentKind
136+ }
137+
138+ enum ParseContentKind {
139+ file
140+ text
141+ stmt
142+ comptime
135143}
136144
137145// for tests
@@ -140,6 +148,7 @@ pub fn parse_stmt(text string, mut table ast.Table, mut scope ast.Scope) ast.Stm
140148 eprintln ('> ${@MOD} .${@FN} text: ${text} ' )
141149 }
142150 mut p := Parser{
151+ content: .stmt
143152 scanner: scanner.new_scanner (text, .skip_comments, & pref.Preferences{})
144153 inside_test_file: true
145154 table: table
@@ -160,6 +169,7 @@ pub fn parse_comptime(tmpl_path string, text string, mut table ast.Table, pref_
160169 eprintln ('> ${@MOD} .${@FN} text: ${text} ' )
161170 }
162171 mut p := Parser{
172+ content: .comptime
163173 file_path: tmpl_path
164174 scanner: scanner.new_scanner (text, .skip_comments, pref_)
165175 table: table
@@ -179,6 +189,7 @@ pub fn parse_text(text string, path string, mut table ast.Table, comments_mode s
179189 eprintln ('> ${@MOD} .${@FN} comments_mode: ${comments_mode:-20} | path: ${path:-20} | text: ${text} ' )
180190 }
181191 mut p := Parser{
192+ content: .text
182193 scanner: scanner.new_scanner (text, comments_mode, pref_)
183194 table: table
184195 pref: pref_
@@ -267,6 +278,7 @@ pub fn parse_file(path string, mut table ast.Table, comments_mode scanner.Commen
267278 table.filelist << path
268279 }
269280 mut p := Parser{
281+ content: .file
270282 scanner: scanner.new_scanner_file (path, file_idx, comments_mode, pref_) or { panic (err) }
271283 table: table
272284 pref: pref_
@@ -289,6 +301,9 @@ pub fn parse_file(path string, mut table ast.Table, comments_mode scanner.Commen
289301}
290302
291303pub fn (mut p Parser) parse () & ast.File {
304+ $if trace_parse ? {
305+ eprintln ('> ${@FILE} :${@LINE} | p.path: ${p.file_path} | content: ${p.content} | nr_tokens: ${p.scanner.all_tokens.len} | nr_lines: ${p.scanner.line_nr} | nr_bytes: ${p.scanner.text.len} ' )
306+ }
292307 util.timing_start ('PARSE' )
293308 defer {
294309 util.timing_measure_cumulative ('PARSE' )
0 commit comments