|
5 | 5 |
|
6 | 6 | using JuliaSyntax, Logging |
7 | 7 |
|
| 8 | +# like Meta.parseall, but throws |
| 9 | +function parseall_throws(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 | + |
8 | 25 | logio = open(joinpath(@__DIR__, "logs.txt"), "w") |
9 | 26 | logger = Logging.ConsoleLogger(logio) |
10 | 27 |
|
@@ -35,27 +52,54 @@ Logging.with_logger(logger) do |
35 | 52 | t = time() |
36 | 53 | i = 0 |
37 | 54 | iob = IOBuffer() |
| 55 | + ex_count = 0 |
38 | 56 | for (r, _, files) in walkdir(pkgspath) |
39 | 57 | for f in files |
40 | 58 | endswith(f, ".jl") || continue |
41 | 59 | 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_throws(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 |
50 | 93 | end |
51 | 94 | i += 1 |
52 | 95 | if i % 100 == 0 |
53 | 96 | runtime = time() - t |
54 | 97 | avg = round(runtime/i*1000, digits = 2) |
55 | 98 | print(iob, "\e[2J\e[0;0H") |
56 | 99 | 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") |
59 | 103 | println(stderr, String(take!(iob))) |
60 | 104 | end |
61 | 105 | end |
|
0 commit comments