-
Notifications
You must be signed in to change notification settings - Fork 17
FAQ
TODO
This error is thrown by the Parsley compiler when Scala would otherwise have thrown a
NullPointerException
during what's known as "let-finding". This is the very first phase of the
pipeline, and, since Parsley does not use null
anywhere in the front-end, its a symptom of a
parser having been demanded before its actually been defined. So what does mean for you, the user?
Well, unfortunately, Scala doesn't give us any indication about which parser is at fault (and the Java 14 Helpful NPEs don't help much either). But here are the possible causes:
- A parser references one that has been defined below it and it hasn't been marked as
lazy val
- A combinator doesn't have the right laziness characteristics (conventionally, Parsley defines
all its combinators arguments using by-name parameters and
lazy val
s for those that appear multiple times in the body) - Be careful: builder combinators to abstract position tracking (as per the Parsley guide) also will require the same care as (2)
Now, the solution to (1) is simple, just either add a lazy val
, or reorder the grammar clauses so
that there is no forward referencing. Similarly, (2) is simple to fix by adding in the right
laziness to the parameter. However, because Parsley is careful to make as much as possible lazy (be
careful of parsley.implicits.zipped.{Zipped2, Zipped3}
, however, neither of them are lazy!) you
may find that you can define an entire parser without ever running into this problem, even if nothing
is marked lazy
: lucky you! My advice is to try and keep things ordered nicely, or mark everything
as lazy; of course, laziness will have a slight runtime penalty, so its worth seeing how much of the
laziness you can eliminate by just reordering.
You may be helped out by Scala here, either by an error about "crossed-initialisation" or a warning about "Reference to uninitialized value". If you see either of these, check the order and laziness of the parsers concerned!
The Wiki refers to the latest version in the parsley-4.x.y
series.