sirthias / parboiled2

A macro-based PEG parser generator for Scala 2.10+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

null pointer trying to run a basic example?

jwaldrop opened this issue · comments

With the following code, depending on parboiled 2.1.0, I get a null pointer exception trying to create my parser:

import org.parboiled2._

class MyParser(val input: ParserInput) extends Parser {
  val number = rule { oneOrMore("0" - "9") }
}

object MyParser {
  def main(args: Array[String]) {
    val parser = new MyParser("111") // null pointer here
    parser.number.run() match {
      case _ => print("woot")
    }
  }
}

The following exception is thrown running the main method:

Exception in thread "main" java.lang.NullPointerException
    at org.parboiled2.Parser.__saveState(Parser.scala:252)
    at com.fitbit.perf_sampler.parser.StackParser.<init>(StackParser.scala:11)
    at com.fitbit.perf_sampler.parser.RunMe$.main(StackParser.scala:25)
    at com.fitbit.perf_sampler.parser.RunMe.main(StackParser.scala)

Specifically in the line below valueStack is null.

  def __saveState: Mark = new Mark((_cursor.toLong << 32) + (_cursorChar.toLong << 16) + valueStack.size)

It seems likely that the examples are out of date, but I haven't been able to find anything that corresponds with 2.1 -- any pointers?

If you change the val number to a def number then things should work.

Thanks!