Parser: many accepts input that ends inside an element

オープン
#3,270 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@GuillaumedeVolpiano がすでに取り組んでいます。

2026年11月20日 から。

  • #3273 @GuillaumedeVolpiano による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Haskell
スター
926
フォーク
71
平均マージ
6時間 49分
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

composewell/streamly のほかの issue

composewell/streamly の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。