Parser: many accepts input that ends inside an element
评估
- 难度
- 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
composewell/streamly 的其他 Issue
-
takeInterval yields nothing, dropInterval drops nothing可能已有人在做 @GuillaumedeVolpiano 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
composewell/streamly#3271 ·
-
aspect:api
难度 4/5 1-2 天 新手友好度 48/100
composewell/streamly#3206 ·
-
api:breaking aspect:api aspect:filesystem
难度 4/5 1-2 天 新手友好度 35/100
composewell/streamly#3203 ·
-
type:performance
难度 4/5 3-5 天 新手友好度 32/100
composewell/streamly#3200 · 2 条评论 ·
-
type:performance
难度 5/5 一周以上 新手友好度 20/100
composewell/streamly#3187 ·
查看 composewell/streamly 的全部 Issue
相似的 Issue
-
bug desktop
难度 2/5 1-3 小时 新手友好度 85/100
simplex-chat/simplex-chat#8291 ·
维护者通常 1 天内回复
-
[BUG]: C# programs with top-level statements fail to compile可能已有人在做 @AsyncNigam 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
compiler-explorer/compiler-explorer#9625 · 1 条评论 ·
维护者通常 1 天内回复
-
needs triage type: enhancement
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
-
reflex-0.10未关闭
难度 1/5 1 小时以内 新手友好度 62/100
commercialhaskell/stackage#8180 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
OpenZeppelin/canton-contracts#140 ·
维护者通常 1 天内回复