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

Error formatting code containing multiline comment #822

Closed
Heptazhou opened this issue Mar 9, 2024 · 5 comments · Fixed by #823
Closed

Error formatting code containing multiline comment #822

Heptazhou opened this issue Mar 9, 2024 · 5 comments · Fixed by #823

Comments

@Heptazhou
Copy link
Contributor

julia> using JuliaFormatter

julia> str = "π => #= comment\ncomment =#\nim"; println(str)
π => #= comment
comment =#
im

julia> Meta.parse(str) |> eval
π => im

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

1 π => = comment
2 comment =#

...

Error occurred on line 2, offset 9 of formatted text.

The error might not be precisely on this line but it should be in the region of the code block. Try commenting the region out and see if that removes the error.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] format_text(cst::CSTParser.EXPR, style::DefaultStyle, s::JuliaFormatter.State)
   @ JuliaFormatter ~\.julia\packages\JuliaFormatter\rcw7l\src\JuliaFormatter.jl:314
 [3] format_text(text::String, style::DefaultStyle, opts::JuliaFormatter.Options)
   @ JuliaFormatter ~\.julia\packages\JuliaFormatter\rcw7l\src\JuliaFormatter.jl:243
 [4] #format_text#276
   @ ~\.julia\packages\JuliaFormatter\rcw7l\src\JuliaFormatter.jl:215 [inlined]
 [5] format_text
   @ ~\.julia\packages\JuliaFormatter\rcw7l\src\JuliaFormatter.jl:212 [inlined]
 [6] #format_text#275
   @ ~\.julia\packages\JuliaFormatter\rcw7l\src\JuliaFormatter.jl:209 [inlined]
 [7] format_text(text::String)
   @ JuliaFormatter ~\.julia\packages\JuliaFormatter\rcw7l\src\JuliaFormatter.jl:208
 [8] top-level scope
   @ REPL[4]:1

(@v1.10) pkg> status JuliaFormatter
Status `~\.julia\environments\v1.10\Project.toml`
  [98e50ef6] JuliaFormatter v1.0.52
@Heptazhou
Copy link
Contributor Author

I guess this is not a CSTParser issue.

(@v1.10) pkg> why CSTParser
  JuliaFormatter  CSTParser

(@v1.10) pkg> status -m CSTParser
Status `~\.julia\environments\v1.10\Manifest.toml`
  [00ebfdb7] CSTParser v3.4.2

julia> using JuliaFormatter: CSTParser

julia> str = "π => #= comment\ncomment =#\nim";

julia> CSTParser.parse(str)
  1:30  call
  1:25   OP: =>
 26:28   π
 29:30   im

@domluna
Copy link
Owner

domluna commented Mar 9, 2024 via email

@domluna
Copy link
Owner

domluna commented Mar 9, 2024 via email

@Heptazhou
Copy link
Contributor Author

CSTParser ignores comments entirely

Oops, I forgot that.

@domluna
Copy link
Owner

domluna commented Mar 9, 2024

I should rewrite to JuliaSyntax one of these days. I think that would make stuff like this easier.

Heptazhou added a commit to Heptazhou/JLfmt.jl that referenced this issue Mar 9, 2024
Heptazhou added a commit to Heptazhou/JLfmt.jl that referenced this issue Mar 9, 2024
Heptazhou added a commit to Heptazhou/JLfmt.jl that referenced this issue Mar 9, 2024
@Heptazhou Heptazhou mentioned this issue Mar 9, 2024
domluna pushed a commit that referenced this issue Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants