sirthias / parboiled2

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

cannot parse null #141

Closed shengc closed 9 years ago

shengc commented 9 years ago

on version 2.1.0

val parser = new Parser(val input: ParserInput) { val inputLine = ("null" | "NULL") ~ push(null) }

parser("null").inputLine.run()

it ends up with scala.MatchError: null at org.parboiled2.ValueStack.pushAll(ValueStack.scala:67)

ppopoff commented 9 years ago

Let me suggest you a workaround. You may create a case object NullValue or something alike and push it instead.

case object NullValue

val parser = new Parser(val input: ParserInput) {
  val inputLine = ("null" | "NULL") ~ push(NullValue)
}

And then, after your AST is generated replace it with null.

shengc commented 9 years ago

That is how I address this as for now, but I still think this is something Parboiled2 should be able to handle it.

sirthias commented 9 years ago

In Scala the commonly accepted convention is that null is not a legal value for anything, unless specifically described to the contrary. The same is true in pb2. You cannot use null for anything, as it will usually break lots of things (proper type inference being one example).