
The point is to mark Break as an error outside of a Breakable statement (repeat, while, for, switch, do).
Of course, you could use child states, but that leads to a lot of duplication of pattern groups, since you have to support most patterns from the default state in the new "BreakableStatements" state as well.
One idea is to have a "BreakableLevel" counter in the custom parse data, and increment it on each Breakable-Statement-Start token (in its OnSuccess-Callback), and decrement it on each Breakable-Statement-End token.
So from the custom parse data in an "OnSuccess" callback associated with a "Break" production, I can see that the context for that statement is not correct (BreakableLevel = 0). Now I want to create a specific error like "Break not allowed outside a Breakable statement".
Unfortunately, I can't find a way to do this inside an "OnSuccess" callback.
Any idea how to force a successfully parsed statement to log an error?
thxinadv