2022-03-07 19:07:14 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import v.scanner
|
|
|
|
import v.pref
|
|
|
|
import v.token
|
|
|
|
import flag
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
mut fp := flag.new_flag_parser(os.args#[2..])
|
|
|
|
fp.application('v scan')
|
|
|
|
fp.version('0.0.1')
|
|
|
|
fp.description('\nScan .v source files, and print the V tokens contained in them.')
|
|
|
|
fp.arguments_description('PATH [PATH]...')
|
2022-10-16 09:28:57 +03:00
|
|
|
fp.limit_free_args_to_at_least(1)!
|
2023-02-08 21:37:04 +03:00
|
|
|
pref_ := pref.new_preferences()
|
2022-03-07 19:07:14 +03:00
|
|
|
mut all_paths := fp.remaining_parameters()
|
|
|
|
for path in all_paths {
|
2023-02-08 21:37:04 +03:00
|
|
|
mut scanner_ := scanner.new_scanner_file(path, .parse_comments, pref_)!
|
2022-03-07 19:07:14 +03:00
|
|
|
mut tok := token.Token{}
|
|
|
|
for tok.kind != .eof {
|
2023-02-08 21:37:04 +03:00
|
|
|
tok = scanner_.scan()
|
2022-03-07 19:07:14 +03:00
|
|
|
pos := tok.pos()
|
2022-11-15 16:53:13 +03:00
|
|
|
location := '${path}:${pos.line_nr + 1}:${pos.col + 1}:'
|
|
|
|
println('${location:-32} | pos: ${pos.pos:-5} | ${tok.debug()}')
|
2022-03-07 19:07:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|