55
66using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization
77
8+ using JuliaSyntax: GreenNode
9+
810include (" ../test/test_utils.jl" )
911include (" ../test/fuzz_test.jl" )
1012
@@ -19,26 +21,41 @@ exceptions = []
1921
2022all_reduced_failures = String[]
2123
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+
2232Logging. with_logger (TerminalLogger ()) do
2333 global exception_count, mismatch_count, t0
2434 @withprogress for (ifile, fpath) in enumerate (source_paths)
2535 @logprogress ifile/ file_count time_ms= round ((time () - t0)/ ifile* 1000 , digits = 2 )
2636 text = read (fpath, String)
2737 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
3146 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)
3451 mismatch_count += 1
3552 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 )
3754 JuliaSyntax. highlight (io, c. source, range (c), context_lines_inner= 5 )
3855 println (io, " \n " )
3956 end
4057 end
41- reduced_failures = reduce_text .(reduce_tree (text),
58+ reduced_failures = reduce_text .(reduce_tree (text, equals_ref_parse = _lowprec_commas_equiv ),
4259 parsers_fuzzy_disagree)
4360 append! (all_reduced_failures, reduced_failures)
4461 @error (" Parsers succeed but disagree" ,
@@ -51,15 +68,6 @@ Logging.with_logger(TerminalLogger()) do
5168 err isa InterruptException && rethrow ()
5269 ex = (err, catch_backtrace ())
5370 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
6371
6472 exception_count += 1
6573 parse_to_syntax = " success"
0 commit comments