Skip to content

Commit

Permalink
Merge pull request #19 from ARCJ137442/master
Browse files Browse the repository at this point in the history
Detailed message for "rule unreachable" error
  • Loading branch information
exaexa authored Aug 17, 2023
2 parents 5c85452 + 7c306a1 commit fa28e91
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PikaParser"
uuid = "3bbf5609-3e7b-44cd-8549-7c69f321e792"
authors = ["The developers of PikaParser.jl"]
version = "0.6.0"
version = "0.6.1"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand Down
10 changes: 9 additions & 1 deletion src/grammar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ function make_grammar(
end
end

all(opened .> 0) || error("some grammar rules not reachable from starts")
# At this point, all rules should be opened at least once. If some grammar
# rules are unreachable from the starts, report them explicitly in the
# error message to ease the debugging.
if !all(opened .> 0)
unreachable_names = map(Base.first, rules)[opened.==0]
error(
"grammar rules not reachable from starts: $(join(repr.(unreachable_names), ", "))",
)
end

reordered = rules[topo_order]

Expand Down
21 changes: 21 additions & 0 deletions test/clauses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ end
@test_throws DomainError P.flatten(rules, Char)
end

@testset "Unreachable rules are reported" begin
rules = Dict(:xxx => P.seq(:yyy, P.fail), :yyy => P.epsilon, :zzz => P.epsilon)

@test_throws ErrorException P.make_grammar([:xxx], P.flatten(rules, Char))
@test begin
# this should simply not throw anything
P.make_grammar([:xxx, :zzz], P.flatten(rules, Char))
true
end

@test try
P.make_grammar([:xxx], P.flatten(rules, Char))
catch e
b = IOBuffer()
showerror(b, e)
errorstring = String(take!(b))

(occursin(":zzz", errorstring) && all(!occursin(errorstring), [":xxx", ":yyy"]))
end
end

@testset "Corner-case epsilon matches" begin
str = "whateveρ"

Expand Down

2 comments on commit fa28e91

@exaexa
Copy link
Collaborator Author

@exaexa exaexa commented on fa28e91 Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/89825

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" fa28e918de19fc65b3d2282b126aceaef9cc7f04
git push origin v0.6.1

Please sign in to comment.