DPMR for wrong action?

Hoo boy. DPMR is a weird beast. Try this:

[code]Test is a room.

There is a container called a red box in Test.

There is a red ball in Test.

First does the player mean: say “DPM [the current action]?”;

test me with “rules/put red in box”[/code]

The output is:

Obviously, this is a problem if your DPMR refer to inserting something into another thing. Should I just write DPMR for wearing, or is there a better solution?

I am approaching the conclusion that the Does the Player Mean rulebook is a wretchedly inadequate means of resolving actions that take two objects.

This has been turning up for a while (see mantis bug 943). The easy way out is to write DTPM rules of the form:

Does the player mean doing something when the noun is … and the second noun is …:

That is, don’t specify an action at all, just filter on the two objects.

Oooookay, I can try that. But I can’t say I understand what’s going on here…

Does the player mean doing something when the noun is the ball and the second noun is the box: It is very likely.

The DTPM rule is running for an action that doesn’t take a second noun - the first noun matches, but what’s going on with the second noun?

Also, if I change my DTPM rule so the second noun is the ball or yourself, it doesn’t run at all. Why?

The parser tries to match the command against grammar lines word by word.

The first grammar line the parser tries to match the command “put red in box” against is ‘put on [something preferably held]’ (which triggers the wearing action); but ‘on’ doesn’t match so it tries the second grammar line.

The second grammar line beginning with ‘put’ is ‘put [something preferably held] on’ (which also triggers the wearing action); here it first disambiguates the ‘[something preferably held]’ token, before it gives up on the ‘on’.

The third grammar line it tries is ‘put down [things held]’ (which triggers the dropping action); that one of course fails already by ‘down’.

The fourth grammar line it tries is ‘put [things held] down’ (which triggers the dropping action, too); here it first disambiguates the ‘[things held]’ token, before it detects the mismatch with the word ‘down’.

The fifth grammar line tried is 'put [other things] in [something] (which triggers the inserting it into action); and here every word and token matches – and actually here the parser has no need of the DTPM rules at all! You can confirm that by typing “insert red into box”.

The parser doesn’t have to disambiguate this last grammar line, because there are only two things in the game word whose names include the word ‘red’ and one of them is the box, which it knows is the second noun (for in this case the parser tries to identify the second noun before identifying the noun), and thanks to the ‘[other things]’ token, the parser will know that the noun cannot be the same as the second noun.

I think I sort of get it. But these two statements seem contradictory. How do you know when the parser starts with the last noun in the grammar line?

Also, why does the parser go to disambiguation in the case where every single noun choice would cause the grammar line to fail? Or is that the bug?

I also still don’t understand why these rules apply. They are both being matched against actions that have no second noun, and yet their preamble specifies a value for the second noun. Shouldn’t the second noun be ‘nothing’ when wearing or dropping?

I think this is covered in section 16.19 of Writing with Inform:

So it’s the “[other things]” token that is causing the parser to start with the last noun.

I guess the parser first checks if the first noun matches before it even cares whether the second noun does (internally perhaps there is always a value for the second noun variable to match, even if it is just the default ‘nothing’).