Skip to content

Commit 7b6ad27

Browse files
committed
improve diagnostics script
1 parent 62d6226 commit 7b6ad27

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/Manifest.toml
2+
/tools/pkgs
3+
/tools/logs.txt

tools/check_all_packages.jl

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55

66
using JuliaSyntax, Logging
77

8+
# like Meta.parseall, but throws
9+
function parseall(str)
10+
pos = firstindex(str)
11+
exs = []
12+
while pos <= lastindex(str)
13+
ex, pos = Meta.parse(str, pos)
14+
push!(exs, ex)
15+
end
16+
if length(exs) == 0
17+
throw(Meta.ParseError("end of input"))
18+
elseif length(exs) == 1
19+
return exs[1]
20+
else
21+
return Expr(:toplevel, exs...)
22+
end
23+
end
24+
825
logio = open(joinpath(@__DIR__, "logs.txt"), "w")
926
logger = Logging.ConsoleLogger(logio)
1027

@@ -35,27 +52,54 @@ Logging.with_logger(logger) do
3552
t = time()
3653
i = 0
3754
iob = IOBuffer()
55+
ex_count = 0
3856
for (r, _, files) in walkdir(pkgspath)
3957
for f in files
4058
endswith(f, ".jl") || continue
4159
fpath = joinpath(r, f)
42-
try
43-
JuliaSyntax.parse(Expr, read(fpath, String))
44-
catch err
45-
err isa InterruptException && rethrow()
46-
ex = (err, catch_backtrace())
47-
push!(exceptions, ex)
48-
@error "parsing failed for $(fpath)" ex
49-
flush(logio)
60+
if isfile(fpath)
61+
file = read(fpath, String)
62+
try
63+
e1 = JuliaSyntax.parse(Expr, file)
64+
catch err
65+
err isa InterruptException && rethrow()
66+
ex_count += 1
67+
ex = (err, catch_backtrace())
68+
push!(exceptions, ex)
69+
meta_parse = "success"
70+
try
71+
parseall(file)
72+
catch err2
73+
meta_parse = "fail"
74+
ex_count -= 1
75+
end
76+
parse_to_syntax = "success"
77+
try
78+
JuliaSyntax.parse(JuliaSyntax.SyntaxNode, file)
79+
catch err2
80+
parse_to_syntax = "fail"
81+
end
82+
severity = parse_to_syntax == "fail" ? "error" :
83+
meta_parse == "fail" ? "warn" : "error"
84+
println(logio, """
85+
[$(severity)] $(fpath)
86+
parse-to-expr: fail
87+
parse-to-syntaxtree: $(parse_to_syntax)
88+
reference: $(meta_parse)
89+
""")
90+
@error "" exception = ex
91+
flush(logio)
92+
end
5093
end
5194
i += 1
5295
if i % 100 == 0
5396
runtime = time() - t
5497
avg = round(runtime/i*1000, digits = 2)
5598
print(iob, "\e[2J\e[0;0H")
5699
println(iob, "$i files parsed")
57-
println(iob, " $(length(exceptions)) failures")
58-
println(iob, " $(avg)ms per file, $(round(Int, runtime))s in total")
100+
println(iob, "> $(ex_count) failures compared to Meta.parse")
101+
println(iob, "> $(length(exceptions)) errors in total")
102+
println(iob, "> $(avg)ms per file, $(round(Int, runtime))s in total")
59103
println(stderr, String(take!(iob)))
60104
end
61105
end

0 commit comments

Comments
 (0)