Parser: many accepts input that ends inside an element

Aperta
#3,270 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@GuillaumedeVolpiano ci sta già lavorando.

Dal 20/11/2026.

  • #3273 di @GuillaumedeVolpiano — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
backend

Direzione di ricerca

Start with the reproduction using P.many, line, and P.eof, and compare the reported results for parse and parsePos. The issue links #1491 as possibly related; read it for context on parser alternatives and backtracking. Done means malformed final elements fail consistently, with behavior verified against all four inputs in the reproduction.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Package: streamly-core 0.3.3
GHC: 9.12.4

Reproduction

import Data.Functor.Identity
import qualified Streamly.Data.Fold as Fold
import qualified Streamly.Data.Parser as P
import qualified Streamly.Data.Stream as S

-- "many" of ('n', then one or more non-':' characters, then ':'), then eof.
line :: P.Parser Char Identity String
line = P.satisfy (== 'n') *> P.takeWhile1 (/= ':') Fold.toList <* P.satisfy (== ':')

p :: P.Parser Char Identity [String]
p = P.many line Fold.toList <* P.eof

main :: IO ()
main = do
  let run s = (runIdentity (S.parse p (S.fromList s)), runIdentity (S.parsePos p (S.fromList s)))
  print (run "nab:ncd:")
  print (run "nab:ncd")
  print (run "nab:x")
  print (run "ncd")
Input Expected Actual
nab:ncd: Right ["ab","cd"] Right ["ab","cd"]
nab:ncd Left: ncd is not a line Right ["ab"]
nab:x Left: x is not a line Left (ParseError "eof: not at end of input")
ncd Left Right []

What happens

When the input ends while many is in the middle of an element, the element
fails, many stops with the elements it had, and the input the failed element
had consumed is not given back: eof then succeeds. When the element fails on
a character instead (nab:x), the input is given back and eof fails as
expected.

So a malformed last element goes unnoticed whenever the input stops inside it.
I expected many to backtrack to the start of the failed element in both
cases, as it does for nab:x.

The same happens with parsePos.

Possibly related, though about the alternative of parsers and closed: #1491.

Lingua principale
Haskell
Stelle
926
Fork
71
Merge medio
6h 49m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di composewell/streamly

Tutte le issue di composewell/streamly

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.