AndrasKovacs / flatparse

Fast parsing from bytestrings
MIT License
146 stars 12 forks source link

`posLineCols` fails for more than one `Pos` #40

Closed TheMatten closed 1 year ago

TheMatten commented 1 year ago

posLineCols fails with

*** Exception: FlatParse.Basic.posLineCols: invalid position

on any input with more than one Pos - problem seems to be with initial sorting assuming increasing, not decreasing values of Pos: https://github.com/AndrasKovacs/flatparse/blob/702a2093d8d5171a9faee495cb0ff43878a37b5a/src/FlatParse/Basic.hs#L407

Instead, it should probably sort the opposite way, e.g. with Down:

sorted = sortOn (Down . snd) (zip [0..] poss)

and such modified function seems to work fine on some test inputs.

AndrasKovacs commented 1 year ago

Fixed by ba96008d900935ab118710eb7ee89dffff9949c9. I also updated on Hackage.