Parser: many accepts input that ends inside an element

未关闭
#3,270 0 条评论 0 个 reaction 已指派 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 分钟
30 天内合并 PR
3

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

composewell/streamly 的其他 Issue

查看 composewell/streamly 的全部 Issue

相似的 Issue

更多 Haskell Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。