domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.

Home Page:https://domluna.github.io/JuliaFormatter.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Valid julia expression not parsed properly

mmesiti opened this issue · comments

Tested on 1.43 - The expression

expr = quote
       function a!(b)
           c = (
           +d+
           +e)
           @f g = h
       end
       end

is parsed without errors by Julia, but the text

       function a!(b)
           c = (
           +d+
           +e)
           @f g = h
       end

chokes JuliaFormatter:

julia> text = "
       function a!(b)
           c = (
           +d+
           +e)
           @f g = h
       end
       "
"\nfunction a!(b)\n    c = (\n    +d+\n    +e)\n    @f g = h\nend\n"

julia> format_text(text)
ERROR: Error while PARSING formatted text:

1 
2 function a!(b)
3     c = (d + +e)
4     @fg = h

...

I have tried to trim down the reproduction case to something even smaller, but I have not managed. Interestingly, it seems that the additional + in the firs expression in the function makes the parser fuse the macro with the first symbol in the expression, but only if the first expression is split into multiple lines... what?

Might be related to #770?

CSTParser has trouble with this sort of expressions so I'm guessing it's probably due to that