Skip to content
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

CharsWhile with rep can produce infinity testing. #313

Closed
He-Pin opened this issue Jun 8, 2024 · 1 comment
Closed

CharsWhile with rep can produce infinity testing. #313

He-Pin opened this issue Jun 8, 2024 · 1 comment

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Jun 8, 2024

function-name       = function-name-first *function-name-char
function-name-first = LCALPHA
function-name-char  = function-name-first / "_" / DIGIT
LCALPHA             = %x61-7A  ; "a".."z"

function-expr       = function-name "(" S [function-argument
                         *(S "," S function-argument)] S ")"

https://www.rfc-editor.org/rfc/rfc9535#name-collected-abnf-grammars

  private def isFunctionNameAcceptable(c: Char): Boolean = {
    println("testing: " + c)
    'a' <= c && c <= 'z'
  }
  private def `function-name-first`[_: P]: P[Unit] = P(CharsWhile(isFunctionNameAcceptable, 1))
  private def isFunctionNameCharAcceptable(c: Char): Boolean =
    isFunctionNameAcceptable(c) || c == '_' || c.isDigit

  private def `function-name`[_: P]: P[String] = P(`function-name-first` ~~ `function-name-char`.rep).!

Which will print:

testing: (
testing: (
testing: (
testing: (
testing: (
testing: (
...

I will change to use CharIn and CharsWhileIn

@lihaoyi
Copy link
Member

lihaoyi commented Jul 4, 2024

Can you minimize the issue and open a discussion? I both don't have enough and have too much code here to see what's wrong, and it's very likely user error.

@lihaoyi lihaoyi closed this as completed Jul 4, 2024
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