in reply to Parse::RecDescent and grammar specification

Chromatic answered: In this case, with simple lines composed of only one literal apiece, you'll either have to specify the longest token first, or rewrite the grammar slightly:

This is not entirely true. If you look at the docs for Parse::RecDescent you will see that what he says is that the "best" match is chosen, and this will be the first successful match in an alternation unless you decide to use a scored grammar in which case you suffix each rule with a score directive and all alternatives are tried and the one with the best score wins.

So, in his case, he could have a simple score directive like so:

opcode: /match_text/ <score: { length join '' @item}>
and append such lines in any order for opcode and instead of the alternatives being chosen based on order within alternation, they would be chosen based on how long a string they produced, @item being a list of the things with matched for this production.

Just look for the section "Scored productions" in the .pod documentation.