Skip to content

Misleading error message when using optional or repeatedly parser #35

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
wants to merge 1 commit into from

Conversation

ashihaby
Copy link

No description provided.

@ashihaby ashihaby changed the title Fix bug in repeatedly parsing #34 Fix bug in repeatedly parsing Nov 24, 2014
@ashihaby ashihaby force-pushed the master branch 2 times, most recently from d45ff64 to d91ed85 Compare November 24, 2014 20:16
@inkytonik
Copy link

Are you sure about this fix? Your change seems to just make the * method use rep1. But * is supposed to allow zero repetitions, so using rep1 is wrong. If you want at least one repetition, you should use +.

@ashihaby
Copy link
Author

@inkytonik If * is supposed to allow zero repetitions. Then RegexParsers shouldn't override phrase like that

override def phrase[T](p: Parser[T]): Parser[T] =
  super.phrase(p <~ opt("""\z""".r))

Doing that will mask lastNoSuccessVar with failure like that string matching regex '\z' expected but 'b' found.
I have updated the pull request and added another test case for zero repetitions.

@inkytonik
Copy link

Well, * is definitely expected to allow zero repetitions. It's a standard operator in extended grammar notations. If you want to require at least one repetition use +.

I'm not sure what the problem with phrase is supposed to be since you will never get to the "end of input" error message if p fails.Please see my comment on issue #34 which explains why phrase is not doing the wrong thing for your example where you believe there is a bug.

@ashihaby ashihaby changed the title Fix bug in repeatedly parsing Misleading error message when using optional or repeatedly parser Nov 27, 2014
@ashihaby ashihaby closed this Nov 27, 2014
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

Successfully merging this pull request may close these issues.

2 participants