1 | module main |
2 | |
3 | import os |
4 | import v.scanner |
5 | import v.pref |
6 | import v.token |
7 | import flag |
8 | |
9 | fn 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 | } |