Skip to content

Commit 9863bb4

Browse files
committed
Hack: Test tight binding commas against JuliaSyntax ref parser
1 parent e7000a1 commit 9863bb4

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

test/test_utils.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ function equals_flisp_parse(exprs_equal, tree)
240240
exprs_equal(fl_ex, ex)
241241
end
242242

243-
function _reduce_tree(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum)
244-
if equals_flisp_parse(exprs_equal, tree)
243+
function _reduce_tree(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum,
244+
equals_ref_parse=equals_flisp_parse)
245+
if equals_ref_parse(exprs_equal, tree)
245246
return false
246247
end
247248
if !haschildren(tree)
@@ -254,7 +255,9 @@ function _reduce_tree(failing_subtrees, tree; exprs_equal=exprs_equal_no_linenum
254255
if is_trivia(child) || !haschildren(child)
255256
continue
256257
end
257-
had_failing_subtrees |= _reduce_tree(failing_subtrees, child; exprs_equal=exprs_equal)
258+
had_failing_subtrees |= _reduce_tree(failing_subtrees, child;
259+
exprs_equal=exprs_equal,
260+
equals_ref_parse=equals_ref_parse)
258261
end
259262
end
260263
if !had_failing_subtrees

tools/check_all_packages.jl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
using JuliaSyntax, Logging, TerminalLoggers, ProgressLogging, Serialization
77

8+
using JuliaSyntax: GreenNode
9+
810
include("../test/test_utils.jl")
911
include("../test/fuzz_test.jl")
1012

@@ -19,26 +21,41 @@ exceptions = []
1921

2022
all_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+
2232
Logging.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

Comments
 (0)