scala / scala/scala-parser-combinators
Non-capturing group not working
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 679
- Forks
- 131
- Avg merge
- 8h 25m
- Merged PRs (30d)
- 3
Description
I'm testing Scala Parser Combinators but for some reason I can't make non-capturing group work.
When I run the following, it works the way I want, returning only 003:
val cycle = """(?:CLEARING\sCYCLE\s)([0-9]{3})""".r
"CLEARING CYCLE 003" match {
case cycle(a) => println(a)
}
But when I try using RegexParsers, I get the whole string CLEARING CYCLE 003 instead of just the numbers:
class TestParser extends RegexParsers {
def cycle: Parser[String] = """(?:CLEARING\sCYCLE\s)([0-9]{3})""".r
}
object Test extends TestParser {
def parse(text: String) {
parse(cycle, text) match {
case Success(matched,_) => println(matched)
case Failure(msg,_) => println(s"FAILURE: $msg")
case Error(msg,_) => println(s"ERROR: $msg")
}
}
}
Test.parse("CLEARING CYCLE 003")
Am I missing something or is it an issue?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two Scala examples from the issue and compare the result of the regex extractor with the RegexParsers parser. Read the RegexParsers and Parser behavior involved in regex matching, then verify whether the parser should return the capture or the full match; done means the intended result is confirmed and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100