Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent formatting for unary operators #281

Open
eschnett opened this issue Sep 4, 2020 · 4 comments
Open

Inconsistent formatting for unary operators #281

eschnett opened this issue Sep 4, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@eschnett
Copy link
Contributor

eschnett commented Sep 4, 2020

The code below is the result of formatting several lines where x is prefixed by a sequence of unary operators (+ and \star). In the input, there was no white space between the operators. JuliaFormatter seems to misinterpret the unary operators as binary operators.

            ++ + x == 0
            ++ ++ x == 0
            ⋆⋆x == 0
            ⋆⋆  x == 0
            ⋆⋆  x == 0
@domluna
Copy link
Owner

domluna commented Sep 4, 2020

@eschnett can you post what the input, output and expected output would be? I'm pretty confused right now lol

@eschnett
Copy link
Contributor Author

eschnett commented Sep 4, 2020

The input and expected output are both

            +++x == 0
            ++++x == 0
            ⋆⋆x == 0
            ⋆⋆⋆x == 0
            ⋆⋆⋆⋆x == 0

It's a variable x with multiple unary operators in front. There shouldn't be any spaces between them.

@domluna
Copy link
Owner

domluna commented Sep 4, 2020

Hmm this might be an issue with CSTParser, the parsed CST looks a little weird

julia> CSTParser.parse("+++x == 0")
  1:9   BinaryOpCall
  1:5    BinaryOpCall
  1:2     OP: PLUSPLUS
  3:3     OP: PLUS
  4:5     x
  6:8    OP: EQEQ
  9:9    INTEGER: 0

I would think those would be UnaryOpCalls.

another 1

julia> CSTParser.parse("+++++x == 0")
  1:11  BinaryOpCall
  1:7    BinaryOpCall
  1:2     OP: PLUSPLUS
  3:4     OP: PLUSPLUS
  5:7     UnaryOpCall
  5:5      OP: PLUS
  6:7      x
  8:10   OP: EQEQ
 11:11   INTEGER: 0

ref julia-vscode/CSTParser.jl#206

@eschnett
Copy link
Contributor Author

eschnett commented Sep 4, 2020

I didn't know where was a ++ operator. If there is, that parse might make sense.

However, there is still the other issue with the \star operators:

julia> CSTParser.parse("⋆⋆⋆⋆x")
  1:13  BinaryOpCall
  1:6    UnaryOpCall
  1:3     OP: STAR_OPERATOR
  4:6     OP: STAR_OPERATOR
  7:9    OP: STAR_OPERATOR
 10:13   UnaryOpCall
 10:12    OP: STAR_OPERATOR
 13:13    x

This parse is different that what Julia itself does:

julia> :(⋆⋆⋆⋆x) |> dump
Expr
  head: Symbol call
  args: Array{Any}((2,))
    1: Symbol 
    2: Expr
      head: Symbol call
      args: Array{Any}((2,))
        1: Symbol 
        2: Expr
          head: Symbol call
          args: Array{Any}((2,))
            1: Symbol 
            2: Expr
              head: Symbol call
              args: Array{Any}((2,))
                1: Symbol 
                2: Symbol x

@domluna domluna added the bug Something isn't working label Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants