Skip to content

Commit

Permalink
Fix trans macro for parser changes on Julia 0.6 (#45) (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 authored Feb 7, 2017
1 parent ba9df4b commit 77cb9bf
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,39 @@ function Base.show(io::IO, s::State)
end

# do state transition
macro trans(obj, ts)
if ts.head == :(=>)
ts = :($(ts),)
if VERSION < v"0.6.0-dev.2577" # after which `A=>B` is parsed as a `call`
macro trans(obj, ts)
if ts.head == :(=>)
ts = :($(ts),)
end
@assert ts.head == :tuple
foldr(:(error("invalid state: ", $(esc(obj)).state)), ts.args) do t, elblk
@assert t.head == :(=>)
from, to = t.args
quote
if $(esc(obj)).state == $(esc(from))
$(esc(obj)).state = $(esc(to))
else
$(elblk)
end
end
end
end
@assert ts.head == :tuple
foldr(:(error("invalid state: ", $(esc(obj)).state)), ts.args) do t, elblk
@assert t.head == :(=>)
from, to = t.args
quote
if $(esc(obj)).state == $(esc(from))
$(esc(obj)).state = $(esc(to))
else
$(elblk)
else
macro trans(obj, ts)
if ts.head == :call && ts.args[1] == :(=>)
ts = :($(ts),)
end
@assert ts.head == :tuple
foldr(:(error("invalid state: ", $(esc(obj)).state)), ts.args) do t, elblk
@assert t.head == :call && t.args[1] == :(=>)
from, to = t.args[2], t.args[3]
quote
if $(esc(obj)).state == $(esc(from))
$(esc(obj)).state = $(esc(to))
else
$(elblk)
end
end
end
end
Expand Down

0 comments on commit 77cb9bf

Please sign in to comment.