Module state
source code
Encapsulate global (per thread) state.
This is for state that can affect the current parse. It's probably simplest to
explain an example of what it can be used for. Memoization records results
for a particular state to avoid repeating matches needlessly. The state used
to identify when "the same thing is happening" is based on:
- the matcher being called
- the stream passed to the matcher
- this state
So a good shorthand for deciding whether or not this state should be used is
to ask whether the state will affect whether or not memoisation will work
correctly.
For example, with offside parsing, the current indentation level should be
stored here, because a (matcher, stream) combination that has previously failed
may work correctly when it changes.
|
|
State
A thread local map from key (typically calling class) to value.
|