Skip to content

Commit d16aa25

Browse files
authored
tools: add --check flag to v ast (#23938)
1 parent c69b125 commit d16aa25

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/tools/vast/vast.v

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import v.parser
88
import v.ast
99
import v.pref
1010
import v.errors
11+
import v.checker
1112
import strings
1213

1314
struct Context {
@@ -17,6 +18,7 @@ mut:
1718
is_print bool
1819
is_terse bool
1920
is_skip_defaults bool
21+
check bool
2022
hide_names map[string]bool
2123
}
2224

@@ -43,6 +45,7 @@ fn main() {
4345
ctx.is_compile = fp.bool('compile', `c`, false, 'watch the .v file for changes, rewrite the .json file, *AND* generate a .c file too on any change')
4446
ctx.is_terse = fp.bool('terse', `t`, false, 'terse output, only with tree node names (AST structure), no details')
4547
ctx.is_skip_defaults = fp.bool('skip-defaults', `s`, false, 'skip properties that have default values like false, 0, "", etc')
48+
ctx.check = fp.bool('check', `k`, false, 'run v.checker as well (it may modify the AST)')
4649
hfields := fp.string_multi('hide', 0, 'hide the specified fields. You can give several, by separating them with `,`').join(',')
4750
for hf in hfields.split(',') {
4851
ctx.hide_names[hf] = true
@@ -170,7 +173,12 @@ fn json(file string) string {
170173
pref: pref_
171174
}
172175
// parse file with comment
173-
ast_file := parser.parse_file(file, mut t.table, .parse_comments, t.pref)
176+
mut ast_file := parser.parse_file(file, mut t.table, .parse_comments, t.pref)
177+
178+
if context.check {
179+
mut the_checker := checker.new_checker(t.table, pref_)
180+
the_checker.check(mut ast_file)
181+
}
174182
t.root = t.ast_file(ast_file)
175183
// generate the ast string
176184
s := json_print(mut t.root)

0 commit comments

Comments
 (0)