com-lihaoyi / fastparse

Writing Fast Parsers Fast in Scala
https://com-lihaoyi.github.io/fastparse
MIT License
1.09k stars 164 forks source link

Failure `msg` reports incorrect line number on Windows #287

Closed simerplaha closed 1 year ago

simerplaha commented 1 year ago

The following test parser correctly reports line 6 as the errored line on Ubuntu and Mac but incorrectly reports line 5 on Windows (Windows Server 2022).

Expected Behaviour: The output to be consistent across all operating systems, with all of them reporting line 6 as the errored line.

Test

import fastparse._
import MultiLineWhitespace._

def fruits[_: P] =
  P(Start ~ "Apple" ~ "Banana" ~ "Orange" ~ End)

val string =
  """
    |Apple 
    |   Banana
    |     Orange
    |
    |Sugar
    |""".stripMargin

val failure = fastparse.parse(string, fruits(_)).asInstanceOf[Parsed.Failure]
println(s"Error: ${failure.msg}")

Test Output

Error: Position 6:1, found "Sugar\n"   // Ubuntu and Mac
Error: Position 5:1, found "Sugar\r\n" // Windows
lihaoyi commented 1 year ago

what version of fastparse are you on? I fixed some windows line number bugs recently https://github.com/com-lihaoyi/fastparse/pull/282, that IIRC should have gone out in 3.0.1

simerplaha commented 1 year ago

I'm on 2.3.3. I guess that might be it. I will test it now.

simerplaha commented 1 year ago

Yep 3.0.1 resolves it. Thanks heaps. Legend!