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

plus sign on JuMP expression breaks formatter #642

Open
guilhermebodin opened this issue Oct 5, 2022 · 2 comments
Open

plus sign on JuMP expression breaks formatter #642

guilhermebodin opened this issue Oct 5, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@guilhermebodin
Copy link

I am using JuliaFormatter on version 1.0 and this breaks because of the first plus sign

julia> format_text("@constraint(Lower(model), +x[1] + x[2] <= 2)")
ERROR: Error while PARSING formatted text:

1 @constraint(Lower(model), x[1] + x[2] +  <= 2)

...

Error occurred on line 1, offset 45 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:33
 [2] format_text(cst::CSTParser.EXPR, style::DefaultStyle, s::JuliaFormatter.State)
   @ JuliaFormatter C:\Users\guilhermebodin\.julia\packages\JuliaFormatter\xKNsr\src\JuliaFormatter.jl:699
 [3] format_text(text::String, style::DefaultStyle, opts::JuliaFormatter.Options)
   @ JuliaFormatter C:\Users\guilhermebodin\.julia\packages\JuliaFormatter\xKNsr\src\JuliaFormatter.jl:632
 [4] #format_text#238
   @ C:\Users\guilhermebodin\.julia\packages\JuliaFormatter\xKNsr\src\JuliaFormatter.jl:604 [inlined]
 [5] format_text
   @ C:\Users\guilhermebodin\.julia\packages\JuliaFormatter\xKNsr\src\JuliaFormatter.jl:602 [inlined]
 [6] #format_text#237
   @ C:\Users\guilhermebodin\.julia\packages\JuliaFormatter\xKNsr\src\JuliaFormatter.jl:598 [inlined]
 [7] format_text(text::String)
   @ JuliaFormatter C:\Users\guilhermebodin\.julia\packages\JuliaFormatter\xKNsr\src\JuliaFormatter.jl:598
 [8] top-level scope
   @ REPL[13]:1
@domluna domluna added the bug Something isn't working label Oct 7, 2022
@domluna
Copy link
Owner

domluna commented Oct 7, 2022

looks like this might be a bug with CSTParser

@clizbe
Copy link

clizbe commented Mar 15, 2024

I have the same issue with having a + at the start of a block for consistency:

sum(
        + _shutdown_margin(u, ng, d, s, t0, t, case, part)
        * _unit_flow_capacity(u, ng, d, s, t0, t)
        * _switch(
            d; from_node=nonspin_units_started_up, to_node=nonspin_units_shut_down
        )[u, n, s, t_over]
        * overlap_duration(t_over, t)
        for (u, n, s, t_over) in _switch(
            d; from_node=nonspin_units_started_up_indices, to_node=nonspin_units_shut_down_indices
        )(m; unit=u, stochastic_scenario=s, t=t_overlaps_t(m; t=t));
        init=0
    )

The formatter throws a parsing error which is fixed by removing the "+" before shutdown_margin.

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

3 participants