v / cmd / tools
Raw file | 28 loc (26 sloc) | 759 bytes | Latest commit hash 017ace6ea
1module main
2
3import os
4import v.scanner
5import v.pref
6import v.token
7import flag
8
9fn main() {
10 mut fp := flag.new_flag_parser(os.args#[2..])
11 fp.application('v scan')
12 fp.version('0.0.1')
13 fp.description('\nScan .v source files, and print the V tokens contained in them.')
14 fp.arguments_description('PATH [PATH]...')
15 fp.limit_free_args_to_at_least(1)!
16 pref_ := pref.new_preferences()
17 mut all_paths := fp.remaining_parameters()
18 for path in all_paths {
19 mut scanner_ := scanner.new_scanner_file(path, .parse_comments, pref_)!
20 mut tok := token.Token{}
21 for tok.kind != .eof {
22 tok = scanner_.scan()
23 pos := tok.pos()
24 location := '${path}:${pos.line_nr + 1}:${pos.col + 1}:'
25 println('${location:-32} | pos: ${pos.pos:-5} | ${tok.debug()}')
26 }
27 }
28}