Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
He-Pin opened this issue Dec 15, 2024 · 2 comments
Closed

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

He-Pin opened this issue Dec 15, 2024 · 2 comments

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Dec 15, 2024

  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
@lihaoyi
Copy link
Member

lihaoyi commented Dec 15, 2024

This is expected

@lihaoyi lihaoyi closed this as completed Dec 15, 2024
@He-Pin
Copy link
Contributor Author

He-Pin commented Dec 15, 2024

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants