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
-
25
8
logio = open (joinpath (@__DIR__ , " logs.txt" ), " w" )
26
9
logger = Logging. ConsoleLogger (logio)
27
10
28
11
pkgspath = joinpath (@__DIR__ , " pkgs" )
29
12
30
- parallel = 50
31
13
exceptions = []
32
14
Logging. with_logger (logger) do
33
- for tars in Iterators. partition (readdir (pkgspath), parallel)
34
- @sync for tar in tars
35
- endswith (tar, " .tgz" ) || continue
36
- @async begin
37
- dir = joinpath (@__DIR__ , " pkgs" , replace (tar, r" \. tgz$" => " " ))
38
- if ! isdir (dir) || ! isdir (joinpath (dir, " src" ))
39
- rm (dir; recursive= true , force= true )
40
- mkpath (dir)
41
- tar_path = joinpath (@__DIR__ , " pkgs" , tar)
42
- try
43
- run (` tar -xf $tar_path -C $dir ` )
44
- catch err
45
- @error " could not untar $tar_path "
46
- end
47
- end
48
- end
49
- end
50
- end
51
-
52
15
t = time ()
53
16
i = 0
54
17
iob = IOBuffer ()
@@ -60,35 +23,31 @@ Logging.with_logger(logger) do
60
23
if isfile (fpath)
61
24
file = read (fpath, String)
62
25
try
63
- e1 = JuliaSyntax. parse (Expr, file)
26
+ e1 = JuliaSyntax. parseall (Expr, file)
64
27
catch err
65
28
err isa InterruptException && rethrow ()
66
- ex_count += 1
67
29
ex = (err, catch_backtrace ())
68
30
push! (exceptions, ex)
69
- meta_parse = " success"
70
- try
71
- parseall_throws (file)
72
- catch err2
73
- meta_parse = " fail"
74
- ex_count -= 1
31
+ ref_parse = " success"
32
+ e2 = JuliaSyntax. fl_parseall (file)
33
+ @assert Meta. isexpr (e2, :toplevel )
34
+ if length (e2. args) >= 1 && Meta. isexpr (last (e2. args), (:error , :incomplete ))
35
+ ref_parse = " fail"
36
+ if err isa JuliaSyntax. ParseError
37
+ # Both parsers agree that there's an error, and
38
+ # JuliaSyntax didn't have an internal error.
39
+ continue
40
+ end
75
41
end
42
+
43
+ ex_count += 1
76
44
parse_to_syntax = " success"
77
45
try
78
- JuliaSyntax. parse (JuliaSyntax. SyntaxNode, file)
46
+ JuliaSyntax. parseall (JuliaSyntax. SyntaxNode, file)
79
47
catch err2
80
48
parse_to_syntax = " fail"
81
49
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)
50
+ @error " Parse failed" fpath exception= ex parse_to_syntax
92
51
end
93
52
end
94
53
i += 1
@@ -97,7 +56,7 @@ Logging.with_logger(logger) do
97
56
avg = round (runtime/ i* 1000 , digits = 2 )
98
57
print (iob, " \e [2J\e [0;0H" )
99
58
println (iob, " $i files parsed" )
100
- println (iob, " > $(ex_count) failures compared to Meta.parse " )
59
+ println (iob, " > $(ex_count) failures compared to reference parser " )
101
60
println (iob, " > $(length (exceptions)) errors in total" )
102
61
println (iob, " > $(avg) ms per file, $(round (Int, runtime)) s in total" )
103
62
println (stderr , String (take! (iob)))
0 commit comments