Skip to content

Commit

Permalink
Either constructor check if all options have matching result_type
Browse files Browse the repository at this point in the history
  • Loading branch information
gkappler committed Nov 4, 2020
1 parent 861527e commit 9e57b77
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/CombinedParsers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2430,8 +2430,14 @@ Either(p::P) where P =
Either{T}(p) where T =
Either{either_state_type(typeof(p)),T}(p)

Either{T}(p...) where {T} =
Either{either_state_type(Vector{Any}),T}(Any[parser.(p)...])
function Either{T}(p_...) where {T}
p = Any[parser.(p_)...]
for x in p
result_type(x) <: T || error("$(result_type(x))<:$T")
end
Either{either_state_type(Vector{Any}),T}(p)
end

function Either(x...; kw...)
Either(Any[ (parser(y) for y in x)..., (with_name(k,v) for (k,v) in kw)... ])
end
Expand Down

0 comments on commit 9e57b77

Please sign in to comment.