scala / scala/scala-parser-combinators

Non-capturing group not working

Open
#383 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.