How to trigger more specific parser errors?

It’s not quite so simple as that, and the documentation on this subject (17.22 Precedence) is confusing if not downright wrong. It suggests that ‘mistakes’ that match as grammar lines are considered before all other possibilities, but as your own experience has already shown, that’s not the case.

‘Mistakes’ which match as exact given text, like the example in the documentation, are given precedence over matching grammar lines involving tokens. So

Understand "take foo" as a mistake ("You can't take foos.").

takes precedence over

Understand "take [something]" as taking.

if typing ‘take foo’.
Also,

Understand "take [something]" as a mistake ("You can't take foos.").

still takes precedence over

Understand "take [something]" as taking.

But [text] tokens seem to be given lower precedence than more specific tokens like [something] or [number] and this ‘token priority’ overrides the precedence usually given to ‘mistakes’, which is why your code is working for you, i.e.

Understand "take [something]" as taking.

takes precedence over

Understand "take [text]" as a mistake ("You can't take foos.").

This ‘token priority override’ is somewhat inconsistent, because for example

Understand "take [a stek thing]" as taking.

does not take precedence over

Understand "take [something]" as a mistake ("You can't take foos.").

despite being a more specific token.

1 Like