Skip to content
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

Seq pattern match does not work in action #154

Open
Centaur opened this issue Jul 28, 2015 · 3 comments
Open

Seq pattern match does not work in action #154

Centaur opened this issue Jul 28, 2015 · 3 comments

Comments

@Centaur
Copy link

Centaur commented Jul 28, 2015

Compile fails with message:
Error:scalac: unexpected UnApply collection.this.Seq.unapplySeq[String](<unapply-selector>) <unapply> ((single @ _))

import org.parboiled2.{Rule1, CharPredicate, ParserInput, Parser}

class SeqMatch(val input: ParserInput) extends Parser {
  def id: Rule1[String] = rule {
    capture(CharPredicate.Printable -- '.')
  }

  def root = rule {
    (id + '.') ~> {
      (ids: Seq[String]) =>
        ids match {
          case Seq(single) => MATCH
          case _ => MISMATCH
        }
    }
  }
}
@alexander-myltsev
Copy link
Contributor

Pretty weird syntax: (id + '.'). What did you try to say?

For parser:

  object Parser extends SimpleParser {
    def id: Rule1[String] = rule {
      capture(CharPredicate.Printable -- '.')
    }

    def InputLine = rule {
      (id.+ ~ ch('.'))  ~> ((ids: Seq[String]) => ids match {
          case Seq(single) => MATCH
          case _ => MISMATCH
        }
      )
    }
  }

really weird code is generated:

// ... cut
            if (l)
              {
                val start = __psi.cursor;
                try {
                  val ids = __psi.valueStack.pop().asInstanceOf[scala.collection.immutable.Seq[String]];
                  ids match {
                    case collection.this.Seq.unapplySeq[String](<unapply-selector>) <unapply> ((single @ _)) => true
                    case _ => try {
                      __psi.registerMismatch()
                    } catch {
                      case _root_.org.parboiled2.ParserStateImpl.StartTracingException => __psi.bubbleUp(RuleTrace.MISMATCH)
                    }
                  }
                } catch {
                  case (e @ (_: _root_.org.parboiled2.ParserStateImpl[(_ @ <empty>)]#TracingBubbleException)) => e.bubbleUp(RuleTrace.Action, start)
                }
              }
            else
              false
// ... cut

@sirthias, have you seen this before?

@Centaur
Copy link
Author

Centaur commented Jul 29, 2015

id + '.' means oneOrMore(id).separatedBy('.') but that is not the point. I just try to give a simplified code to get a Seq for matching.

@Jasper-M
Copy link

I ran into the same issue, with the following (not self contained, sorry) code:

def DayValue = rule { "Day" ~ "(" ~ 3.times(Integer).separatedBy(OptWhitespace ~ ",") ~ str(")") ~> {
  (nrs: Seq[Long]) => 
    val Seq(year, month, day) = nrs map {_.toInt}
    Day(year, month, day)
} }

It worked in Scala 2.10.4. Then I bumped versions to 2.11.7 and this issue appeared (among others).
I fixed it by indexing into the Seq instead.

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

No branches or pull requests

3 participants