Do-Block Syntax with Where Keyword

I figured out it’s a two-liner in JuliaSyntax/src/parser.jl to support where clauses in do, provided the argument list is enclosed in parentheses.

2308c2308,2309
<     emit(ps, m, K"tuple")
---
>     k = peek_behind(ps, position(ps)).kind
>     k != K"where" && emit(ps, m, K"tuple")

Then you can do things like:

julia> foreach([1,2.0,"foo", false]) do (x::T) where T; println(T); end
Int64
Float64
String
Bool

I haven’t got the time to follow up a PR, but please do anyone.

3 Likes