Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

gourlaysama
Copy link
Contributor

This overrides err in RegexParser to make it consume whitespace just
like regex and literal. The original motivation was:

object parser extends RegexParsers {
  def num = "\\d+".r

  def twoNums =  num ~ (num | err("error!"))
}

// succeeds
parser.parseAll(twoNums, "42    721")

// fails with a parsing Failure instead of an Error
// because err doesn't consume the whitespace but the regex does.
parser.parseAll(twoNums, "42    foo")

This may change the output of some parsers that failed to parse input
(from a Failure to an Error).

Fixes #29

This overrides `err` in RegexParser to make it consume whitespace just
like regex and literal. The original motivation was:

object parser extends RegexParsers {
  def num = "\\d+".r

  def twoNums =  num ~ (num | err("error!"))
}

// succeeds
parser.parseAll(twoNums, "42    721")

// fails with a parsing Failure instead of an Error
// because err doesn't consume the whitespace but the regex does.
parser.parseAll(twoNums, "42    foo")

This may change the output of some parsers that failed to parse input
(from a Failure to an Error).

Fixes scala#29
@gourlaysama
Copy link
Contributor Author

I am still not 100% convinced that this change cannot break somebody's parser, by turning a successful parse into an error (because of no backtracking with errors compared to failures)...

@gourlaysama
Copy link
Contributor Author

... but even if that's a semantic change, it is worth it.

gourlaysama added a commit that referenced this pull request Aug 18, 2014
make RegexParser.err handle whitespace like literal and regex.
@gourlaysama gourlaysama merged commit fc983fe into scala:master Aug 18, 2014
@gourlaysama gourlaysama deleted the wip/i29 branch August 26, 2014 11:48
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