Skip to content

Commit e08cc4e

Browse files
committed
v.parser: support -d trace_parse to ease diagnosing problems related to the order of parsing of .v files in modules
1 parent 54b2c86 commit e08cc4e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ a copy of the compiler rather than replacing it with `v self`.
322322
| `time_checking` | Prints the time spent checking files and other related information |
323323
| `time_parsing` | Prints the time spent parsing files and other related information |
324324
| | |
325-
| `trace_scanner` | Prints details about the recognized tokens. *Very* verbose. Use `./vnew -no-builtin -check-syntax file.v` later. |
325+
| `trace_scanner` | Prints details about the recognized tokens. *Very* verbose. Use with `./vnew -no-builtin -check-syntax file.v` . |
326+
| `trace_parse` | Prints details about the parsed files (number of tokens, lines, bytes). Use it for parsing order issues. |
326327
| `trace_parser` | Prints details about parsed statements and expressions. Very verbose. Use it for panics in the parser. |
327328
| `trace_checker` | Prints details about the statements being checked. Very verbose. Use it for panics in the checker. |
328329
| `trace_transformer` | Prints details about the statements being transformed. Very verbose. Use it for panics in the transformer stage. |

vlib/v/parser/parser.v

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

291303
pub 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

Comments
 (0)