scala/scala-parser-combinators

Non-capturing group not working

hissashirocha opened this issue · 0 comments

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?