Skip to content

Commit

Permalink
push linenumber nodes into scopelines, use @switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Brown authored and olynch committed Sep 11, 2023
1 parent 2bd2751 commit 1e4dfeb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/syntax/Presentations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ compose(f, g) == h == h′
function ExprInterop.fromexpr(ctx::Context, e, ::Type{Presentation})
e.head == :block || error("expected a block to parse into a GATSegment, got: $e")
scopelines, eqlines = [], Vector{Expr0}[]
for line in filter(x->!(x isa LineNumberNode), e.args)
@match line begin
Expr(:call, :(==), a, b) => push!(eqlines, [a, b])
Expr(:comparison, xs...) => push!(eqlines, xs[1:2:end])
_ => push!(scopelines, line)
for line in e.args
@switch line begin
@case Expr(:call, :(==), a, b)
push!(eqlines, [a, b])
@case Expr(:comparison, xs...)
er = "Bad comparison $line"
all(((i,v),)-> iseven(i) == (v == :(==)), enumerate(line.args)) || error(er)
push!(eqlines, xs[1:2:end])
@case _
push!(scopelines, line)
end
end
scope = GATs.parsetypescope(ctx, scopelines)
Expand Down

0 comments on commit 1e4dfeb

Please sign in to comment.