sirthias / parboiled2

A macro-based PEG parser generator for Scala 2.10+
Other
717 stars 86 forks source link

NPE in Parser.__saveState when accessing rule #73

Closed mustajarvi closed 10 years ago

mustajarvi commented 10 years ago

I tried just outputting the rule itself to check it's type, but that resulted in a NPE. Example:

object Nullpointer {
  import org.parboiled2._

  class Bar(val input: ParserInput) extends Parser {
    def Digits = rule { oneOrMore(CharPredicate.Digit) }
  }

  def main(args: Array[String]): Unit = {
    println(new Bar("").Digits)
  }
}

Might be a nonsensical use but a NPE is still a bit surprising.

sirthias commented 10 years ago

As an optimization parboiled encodes "rule mismatch" as null. So, in your example, if Digits returns null it means "rule didn't match". This is expected behavior and a consequence of how parboiled currently works.

"Outputting the rule itself" indeed makes no sense.