Skip to content

Charswhile(..,0) with rep will cause infinitely loop #326

Closed
@He-Pin

Description

@He-Pin
  private def `name-first`[_: P]: P[Unit] = P(CharsWhile(isNameFirstAcceptable, 1))

  private def `name-char`[_: P]: P[Unit] = P(CharsWhile(isNameCharAcceptable, 1))

 /**
   * https://www.rfc-editor.org/rfc/rfc9535#section-2.5.1.1
   *
   * {{{
   * member-name-shorthand = name-first *name-char
   * name-first          = ALPHA /
   *                       "_"   /
   *                       %x80-D7FF /
   *                          ; skip surrogate code points
   *                       %xE000-10FFFF
   * name-char           = name-first / DIGIT
   *
   * DIGIT               = %x30-39              ; 0-9
   * ALPHA               = %x41-5A / %x61-7A    ; A-Z / a-z
   * }}}
   * */
  private def `member-name-shorthandIdentifier`[_: P]: P[String] = P(`name-first` ~ `name-char`.rep).!

Works well, but if I change the name-char to 0 then it will never end, eg:

  private def `name-char`[_: P]: P[Unit] = P(CharsWhile(isNameCharAcceptable, 0))
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions