5
5
6
6
using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization
7
7
8
+ using JuliaSyntax: GreenNode
9
+
8
10
include (" ../test/test_utils.jl" )
9
11
include (" ../test/fuzz_test.jl" )
10
12
@@ -19,26 +21,41 @@ exceptions = []
19
21
20
22
all_reduced_failures = String[]
21
23
24
+ function _lowprec_commas_equiv (exprs_equal, tree)
25
+ node_text = sourcetext (tree)
26
+ e1 = parseall (GreenNode, node_text, ignore_errors= true )
27
+ e2 = parseall (GreenNode, node_text, ignore_errors= true ,
28
+ low_precedence_comma_in_brackets= true )
29
+ e1 == e2
30
+ end
31
+
22
32
Logging. with_logger (TerminalLogger ()) do
23
33
global exception_count, mismatch_count, t0
24
34
@withprogress for (ifile, fpath) in enumerate (source_paths)
25
35
@logprogress ifile/ file_count time_ms= round ((time () - t0)/ ifile* 1000 , digits = 2 )
26
36
text = read (fpath, String)
27
37
expr_cache = fpath* " .Expr"
28
- # e2 = JuliaSyntax.fl_parseall(text)
29
- e2 = open (deserialize, fpath* " .Expr" )
30
- @assert Meta. isexpr (e2, :toplevel )
38
+ # e_ref = JuliaSyntax.fl_parseall(text)
39
+ # e_ref = open(deserialize, fpath*".Expr")
40
+ # @assert Meta.isexpr(e_ref, :toplevel)
41
+ e_ref = try
42
+ JuliaSyntax. parseall (GreenNode, text, filename= fpath, ignore_warnings= true )
43
+ catch
44
+ continue
45
+ end
31
46
try
32
- e1 = JuliaSyntax. parseall (Expr, text, filename= fpath, ignore_warnings= true )
33
- if ! exprs_roughly_equal (e2, e1)
47
+ e1 = JuliaSyntax. parseall (GreenNode, text, filename= fpath, ignore_warnings= true , low_precedence_comma_in_brackets= true )
48
+ if e1 != e_ref
49
+ source = SourceFile (text, filename= fpath)
50
+ e1sn = SyntaxNode (source, e1)
34
51
mismatch_count += 1
35
52
failing_source = sprint (context= :color => true ) do io
36
- for c in reduce_tree (parseall (SyntaxNode, text) )
53
+ for c in reduce_tree (e1sn, equals_ref_parse = _lowprec_commas_equiv )
37
54
JuliaSyntax. highlight (io, c. source, range (c), context_lines_inner= 5 )
38
55
println (io, " \n " )
39
56
end
40
57
end
41
- reduced_failures = reduce_text .(reduce_tree (text),
58
+ reduced_failures = reduce_text .(reduce_tree (text, equals_ref_parse = _lowprec_commas_equiv ),
42
59
parsers_fuzzy_disagree)
43
60
append! (all_reduced_failures, reduced_failures)
44
61
@error (" Parsers succeed but disagree" ,
@@ -51,15 +68,6 @@ Logging.with_logger(TerminalLogger()) do
51
68
err isa InterruptException && rethrow ()
52
69
ex = (err, catch_backtrace ())
53
70
push! (exceptions, ex)
54
- ref_parse = " success"
55
- if length (e2. args) >= 1 && Meta. isexpr (last (e2. args), (:error , :incomplete ))
56
- ref_parse = " fail"
57
- if err isa JuliaSyntax. ParseError
58
- # Both parsers agree that there's an error, and
59
- # JuliaSyntax didn't have an internal error.
60
- continue
61
- end
62
- end
63
71
64
72
exception_count += 1
65
73
parse_to_syntax = " success"
0 commit comments