typelevel / typelevel/cats-parse

idea for safe repetition on Parser0

Open
#344 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.