typelevel / typelevel/cats-parse
idea for safe repetition on Parser0
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 245
- Forks
- 51
- Avg merge
- 3h 20m
- Merged PRs (30d)
- 1
Description
We don't allow p.rep on a p: Parser0[_] because if you parse nothing and that is valid, at parse time you would loop infinitely not making progress.
Another idea could be:
def safeRep: Parser0[(NonEmptyList[A], Boolean)] =
(Parser.index, this, Parser.index)
.tupled
.flatMap {
case (s, a, e) =>
if (s == e) {
// No progress, stop
Parser.pure((NonEmptyList(a, Nil), false))
}
else safeRep.?.map {
case None => (NonEmptyList(a, Nil), true)
case Some((tail, r)) => (a :: tail, r)
}
}
the boolean tells if the last item made progress or not.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing Parser0 and the existing p.rep behavior described in the issue. Examine how Parser.index, tupled, flatMap, Parser.pure, and safeRep.?. would compose, then determine whether the proposed safe repetition semantics prevent non-progress loops while preserving the boolean result. Done means the design is agreed and the safe repetition behavior is implemented and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100