Skip to content

Commit 8fcc8a1

Browse files
mlechuc42ftopolarity
committed
Apply suggestions from code review (vcx struct, @stm's run)
Co-authored-by: Claire Foster <[email protected]> Co-authored-by: Cody Tapscott <[email protected]>
1 parent 19c7bd6 commit 8fcc8a1

File tree

2 files changed

+80
-85
lines changed

2 files changed

+80
-85
lines changed

src/syntax_graph.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,8 @@ may check for some form of tree equivalence in a future implementation.
865865
## Extra conditions: `when`, `run`
866866
867867
Like an escape hatch to the structure-matching mechanism. `when=cond` requires
868-
`cond`'s value be `true` for this pattern to match. `run=code` evaluates
869-
`code`, usually to bind variables. For convenience, the value of `code` is
870-
bound to the local `run`, which can be opted out of by quoting `run`.
868+
`cond`'s value be `true` for this pattern to match. `run=code` simply evaluates
869+
`code`, usually to bind variables or debug the matching process.
871870
872871
`when` and `run` clauses may appear multiple times in any order after the
873872
pattern. They are executed left-to-right, stopping if any `when=cond` evaluates
@@ -891,8 +890,8 @@ julia> JuliaLowering.@stm st begin
891890
"zero-method function $fname"
892891
[K"function" [K"call" fname args...] body] ->
893892
"normal function $fname"
894-
([K"=" [K"call" _...] _...], run=if_valid_get_args(st[1]), when=!isnothing(run)) ->
895-
"deprecated call-equals form with args $run"
893+
([K"=" [K"call" _...] _...], when=(args=if_valid_get_args(st[1]); !isnothing(args))) ->
894+
"deprecated call-equals form with args $args"
896895
(_, run=show("printf debugging is great")) -> "something else"
897896
_ -> "something else"
898897
end
@@ -923,8 +922,7 @@ function _stm(line::LineNumberNode, st, pats; debug=false)
923922
# needs to live in the first argument of :if with the extra conditions.
924923
e_check = Expr(:&&)
925924
for (ek, ev) in extras
926-
push!(e_check.args, ek === :when ? ev :
927-
Expr(:block, ek === :run ? :(local run = $ev) : ev, true))
925+
push!(e_check.args, ek === :when ? ev : Expr(:block, ev, true))
928926
end
929927
# final arg to e_check: successful match
930928
push!(e_check.args, Expr(:block, line, :($result_gs = $result), true))
@@ -1033,7 +1031,7 @@ function _stm_check_usage(pats)
10331031
if Meta.isexpr(per.args[1], :tuple)
10341032
@assert length(per.args[1].args) >= 2 "Unnecessary tuple in $(per.args[1])"
10351033
for e in per.args[1].args[2:end]
1036-
@assert(Meta.isexpr(e, :(=), 2) && e.args[1] in (:when, :run, QuoteNode(:run)),
1034+
@assert(Meta.isexpr(e, :(=), 2) && e.args[1] in (:when, :run),
10371035
"Expected `when=<cond>` or `run=<stmts>`, got $e")
10381036
end
10391037
p = per.args[1].args[1]

0 commit comments

Comments
 (0)