Reduce.jl icon indicating copy to clipboard operation
Reduce.jl copied to clipboard

parsing of REDUCE for expression broken in Julia 1.10

Open chakravala opened this issue 2 years ago • 4 comments

The parsing of REDUCE for statements is broken with Julia 1.10 and I am not currently planning on figuring out how to fix it:

julia> Expr(:for, :(i = 2:34), :(product(i))) |> RExpr |> Reduce.parse
:($(Expr(:incomplete, Base.Meta.ParseError("ParseError:\n# Error @ none:1:6\nfor i\n#    └ ── premature end of input", Base.JuliaSyntax.ParseError(Base.JuliaSyntax.SourceFile("for i", 0, "none", 1, [1, 6]), Base.JuliaSyntax.Diagnostic[Base.JuliaSyntax.Diagnostic(6, 5, :error, "premature end of input"), Base.JuliaSyntax.Diagnostic(6, 5, :error, "invalid iteration spec: expected one of `=` `in` or `∈`"), Base.JuliaSyntax.Diagnostic(6, 5, :error, "premature end of input"), Base.JuliaSyntax.Diagnostic(6, 5, :error, "Expected `end`")], :other)))) = 2:34 * product(im))

julia> ans |> dump
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: Expr
      head: Symbol incomplete
      args: Array{Any}((1,))
        1: Base.Meta.ParseError
          msg: String "ParseError:\n# Error @ none:1:6\nfor i\n#    └ ── premature end of input"
          detail: Base.JuliaSyntax.ParseError
            source: Base.JuliaSyntax.SourceFile
              code: SubString{String}
                string: String "for i:=2:34 product(i)"
                offset: Int64 0
                ncodeunits: Int64 5
              byte_offset: Int64 0
              filename: String "none"
              first_line: Int64 1
              line_starts: Array{Int64}((2,)) [1, 6]
            diagnostics: Array{Base.JuliaSyntax.Diagnostic}((4,))
              1: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "premature end of input"
              2: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "invalid iteration spec: expected one of `=` `in` or `∈`"
              3: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "premature end of input"
              4: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "Expected `end`"
            incomplete_tag: Symbol other
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol :
        2: Int64 2
        3: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol *
            2: Int64 34
            3: Expr
              head: Symbol call
              args: Array{Any}((2,))
                1: Symbol product
                2: Symbol im

chakravala avatar Feb 16 '24 09:02 chakravala

Perhaps you can replace the "won't fix" with a "help wanted" label?

ufechner7 avatar Sep 07 '25 06:09 ufechner7

@ufechner7 thanks for the suggestion, but I highly doubt that this issue will get a contribution, and I don't want to encourage people to waste their time trying. If someone is very determined to fix something, they will do it anyway.

chakravala avatar Sep 07 '25 09:09 chakravala

Perhaps I was not reading the issue correctly. Does it work on 1.11? If not, which feature is missing?

ufechner7 avatar Sep 07 '25 12:09 ufechner7

It's an issue which affects the parsing of special statements, such as "for loops" .. which I don't believe the users of this package actually make use of, as treating "for loops" as expressions to pass back and forth was possible but never actually used in practice.

chakravala avatar Sep 07 '25 14:09 chakravala