JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
267 stars 32 forks source link

Begining blocks with colons #354

Open ParadaCarleton opened 10 months ago

ParadaCarleton commented 10 months ago

Python users moving to Julia often make a mistake like this:

julia> for i in randint(3):  # includes colon
           println(i)
    # no `end`
ERROR: ParseError:
# Error @ REPL[4]:1:21
#                   ┌
for i in randint(3):
    println(i)
#──┘ ── line break after `:` in range expression
# Error @ REPL[4]:2:15
for i in randint(3):
    println(i)
#             └ ── Expected `end`

Ideally, the error message should explain that colons aren't needed at the start of a block, and that end blocks are.

julia> for i in randint(3):  # includes colon
           println(i)
ERROR: ParseError:
# Error @ REPL[4]:1:21
#                   ┌
for i in randint(3):
    println(i)
#──┘ ── Colon (`:`) not needed to begin blocks
# Error @ REPL[4]:2:15
for i in randint(3):
    println(i)
#             └ ── `for` blocks must be closed with `end` keyword