Skip to content

Commit 223902b

Browse files
authored
Fix parser comparison tool. stdlib now parses for 1.6 - 1.8 (#9)
It turns out that SparseArrays has some unused .jl files in the tests with broken syntax in 1.8 dev. Fix the JuliaSyntax parser comparison tool to ignore these cases.
1 parent a56904d commit 223902b

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/parser.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,6 @@ end
26772677
# tightest: ... < `;;;` < `;;` < `;`,`\n` < whitespace. We choose binding
26782678
# power of 0 for whitespace and negative numbers for other separators.
26792679
#
2680-
# FIXME: Error messages for mixed spaces and ;; delimiters
26812680
function parse_array_separator(ps, array_order)
26822681
sep_mismatch_err = "cannot mix space and ;; separators in an array expression, except to wrap a line"
26832682
mark = position(ps)

test/parse_packages.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ end
2121

2222
end
2323

24-
if VERSION < v"1.8-DEV" || haskey(ENV, "PARSE_STDLIB")
25-
# TODO: Fix on 1.8
26-
2724
@testset "Parse Julia stdlib at $(Sys.STDLIB)" begin
2825
for stdlib in readdir(Sys.STDLIB)
2926
fulldir = joinpath(Sys.STDLIB, stdlib)
@@ -34,5 +31,3 @@ if VERSION < v"1.8-DEV" || haskey(ENV, "PARSE_STDLIB")
3431
end
3532
end
3633
end
37-
38-
end

test/test_utils.jl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,30 @@ function remove_all_linenums!(ex)
3838
remove_macro_linenums!(ex)
3939
end
4040

41-
function parsers_agree_on_file(path)
42-
text = read(path, String)
43-
ex = parseall(Expr, text, filename=path)
44-
fl_ex = flisp_parse_all(text, filename=path)
45-
JuliaSyntax.remove_linenums!(ex) == JuliaSyntax.remove_linenums!(fl_ex)
41+
function parsers_agree_on_file(filename)
42+
text = try
43+
read(filename, String)
44+
catch
45+
# Something went wrong reading the file. This isn't a parser failure so
46+
# ignore this case.
47+
return true
48+
end
49+
fl_ex = flisp_parse_all(text, filename=filename)
50+
if Meta.isexpr(fl_ex, :toplevel) && !isempty(fl_ex.args) &&
51+
Meta.isexpr(fl_ex.args[end], (:error, :incomplete))
52+
# Reference parser failed. This generally indicates a broken file not a
53+
# parser problem, so ignore this case.
54+
return true
55+
end
56+
try
57+
ex, diagnostics, _ = parse(Expr, text, filename=filename)
58+
return !JuliaSyntax.any_error(diagnostics) &&
59+
JuliaSyntax.remove_linenums!(ex) ==
60+
JuliaSyntax.remove_linenums!(fl_ex)
61+
catch exc
62+
@error "Parsing failed" path exception=current_exceptions()
63+
return false
64+
end
4665
end
4766

4867
function find_source_in_path(basedir)
@@ -155,7 +174,7 @@ function reduce_all_failures_in_path(basedir, outdir)
155174
rm(outdir, force=true, recursive=true)
156175
mkpath(outdir)
157176
for filename in find_source_in_path(basedir)
158-
if !(try parsers_agree_on_file(filename) catch exc false end)
177+
if !parsers_agree_on_file(filename)
159178
@info "Found failure" filename
160179
bn,_ = splitext(basename(filename))
161180
outname = joinpath(outdir, "$bn.jl")

0 commit comments

Comments
 (0)