The deadly secret of Aaron Reed's "Smarter Parser"

Here’s some sample code:

Include Smarter Parser by Aaron Reed.

The Room_Grassy_Clearing is a room.
The printed name is "Grassy Clearing".
The description is "The water churgles in the nearby creek but you can't see it through the forest of blackberry brambles all around you.".
Understand "grassy/-- clearing" as Room_Grassy_Clearing.

And the deadly secret (at least in Lectrote):

>look
Grassy Clearing
The water churgles in the nearby creek but you can’t see it through the forest of blackberry brambles all around you.

>try again

And… that’s it. It never returns from this command. It hangs the Lectrote window (though you can open another).

Does this happen for you in the IDE?

Any idea what’s happening here?

Obviously it’s a bug, but TRY AGAIN certainly isn’t a standard IF command. The traditional one since Zork is AGAIN. Most games don’t recognize the verb TRY.

In the IDE, the interpreter prints:

>try again
Most connecting and comparative words are not necessary.

Retrying as:
>AGAIN

Type UNDO if this isn't what you wanted to do, or CORRECT OFF to stop automatically correcting commands.

To stop these messages entirely, type NOVICE OFF.

Most connecting and comparative words are not necessary.

Retrying as:
>AGAIN
Most connecting and comparative words are not necessary.

Retrying as:
>AGAIN
Most connecting and comparative words are not necessary.

(and so on, over and over again)

Smarter Parser strips off the “TRY” from “TRY AGAIN”, as per the “stripping pointless words rule”:

A smarter parser rule when sp_normal (this is the stripping pointless words rule):
	if stripping "(anyway|instead|very|almost|this|so|just|ye)" is fruitful or stripping "(now|try|next|around|more)" is fruitful:
		identify error as stripping pointless words rule;
		if the number of words in the reborn command > 0, reparse the command;
		else reject the command. [If there are no more words to deal with.]

… and then tries the command without the stripped part. And I guess that the problem then occurs because the AGAIN command, in this case, does not really have a separate command to repeat (the system/extension presumably does not remember that the next-to-last action was LOOK, and so cannot fall back on that as the referent of AGAIN).

I don’t know what the best fix would be; depends a bit on the desired behaviour.
You could modify the rule above to avoid stripping “try”; but note that the input “PLEASE AGAIN”, for example, will lead to the same problem, because PLEASE will be stripped out by another rule.
So, it would probably be best to make an exception (thus refraining from all Smarter Parser corrections) whenever “AGAIN” occurs in a command.

Here’s an additional related mystery (this time with Inform) I ran into trying to work around the above bug:

Understand "try again" as a mistake ("(Try using the command 'again' or it's shortcut 'g'.)")

I had the understanding that “Understand * as a mistake” treated the text literally. But…

Grassy Clearing

The water churgles in the nearby creek but you can’t see it through the forest of blackberry brambles all around you.

>try again
(Try using the command “again” or it’s shortcut “g”.)

>again
(Try using the command “again” or it’s shortcut “g”.)

What? Why is the mistake matching “again?”

I had a playtester tell me that the prose told them “Try again?” (which I’ve seen somewhere in almost every IF I’ve played). So my tester dutifully typed “try again”. And discovered the bug.

I could turn the rule off, but I kind of like that it strips out some pointless words. So I wanted to remove the stripping of “try” and “around”:

The new stripping pointless words rule substitutes for the stripping pointless words rule.
[ The stripping pointless words rule is not listed in the Smarter Parser rulebook. ]

A smarter parser rule when sp_normal (this is the new stripping pointless words rule):
	if stripping "(anyway|instead|very|almost|this|so|just|ye)" is fruitful or stripping "(now|next|more)" is fruitful:
		identify error as stripping pointless words rule;
		if the number of words in the reborn command > 0, reparse the command;
		else reject the command. [If there are no more words to deal with.]

It is not matching “again”; the system is obeying the “again” command and literally entering the previous command “try again” again, thus getting the same result as for “try again”.
You can verify that by entering “look” and “again” (which will correctly repeat the looking, not match the mistake) or, the other way, by entering a non-recognised command, which will also be repeated:

>bla
That's not a verb I recognise.

>again
That's not a verb I recognise.

I believe the parser offers some means of discarding the AGAIN buffer. If it doesn’t, I can hack one in.

But this would let you keep the convenience rule while avoiding the bug, without needing to manually match every possible option (PLEASE G, G PLEASE, etc).

Looks like this should do it:

To discard the/-- again buffer: (- DiscardAgain(); -).

Include (-
[ DiscardAgain ;
    #ifdef TARGET_ZCODE;
    buffer3->1 = 0;
    #ifnot;
    buffer3-->0 = 0;
    #endif;
];
-).

Just stick this phrase into any command-rewriting rules that lead to this crash. It’s simple enough that it really shouldn’t need a whole routine to do it, but it needs to be done differently on Z-machine vs Glulx because of how they arrange the buffers.

This isn’t quite ideal—it means that if you try to AGAIN after this phrase is called, the game will think you’ve never done anything, and give the relevant error (“You can hardly repeat that.”, aka the parser command internal rule response D). But it’s much better than an infinite loop.

It is not matching “again”; the system is obeying the “again” command and literally entering the previous command “try again” again, thus getting the same result as for “try again”.

OMG, of course. Lol.

Now ideally, I would just have the command “try again” do “again,” but I haven’t found a simple straightforward way to trigger again. Is there one?

Here’s a way to do that:

After reading a command:
	if the player's command matches "try again", replace the player's command with "again".

Cf. 18.33. Reading a command.

I think more extensions should come with deadly secrets.

Super helpful. Thanks. No more infinite loops and totally transparent to the player.

Extra helpful in my WIP as trying again is kinda critical to gameplay.

Here’s what I had as a temporary-don’t-infinite-loop workaround:

Understand "try again" as a mistake ("(Try using the command [em]again[/em] or it's shortcut [em]g[/em].)") ]

But I found playtesters were entering their own kind of infinite loop based on what the game was telling them:

>climb the tree
You can’t reach the lower branches.
>try again
(Try using the command again or it’s shortcut g.)
>again
(Try using the command again or it’s shortcut g.)
>g
(Try using the command again or it’s shortcut g.)
>again
(Try using the command again or it’s shortcut g.)

::laugh to keep from crying emoji::

Sadly, this bug is still in Smarter Parser 16.1, though it was discovered four years ago. At a guess, Smarter Parser is no longer being maintained. Is there a list anywhere showing which Extensions are being actively maintained and which aren’t? (Looking in the mirror here. Haven’t checked my own solitary Extension for years.)

The reason I started looking into this is because I just now tried including Smarter Parser and at the prompt, for no particular reason, typed WHAT CAN I DO HERE? This caused a runtime error. The game crashed.

Is there any graceful way to handle situations of this type, or will they all involve one-off solutions that work by intercepting specific text strings?

In theory, since Inform hasn’t had a new release in years, anything that says it’s been updated for Inform 10 should still work fine.

But that doesn’t tell you if people are actively fixing new bugs that get found. In this case, I see that I found a solution four years ago, though I have absolutely no recollection of this. So I can try to put that into the “official” version of the extension on Github. But I don’t use Inform enough nowadays to properly stress-test things beyond what the extension author already thought of.

About this second issue: I’m not getting a runtime error in a minimal I7 project with Smarter Parser:

Include Smarter Parser by Aaron Reed.

The Lab is a room.

When I type “what can i do here?”, the result is:

>what can i do here?
>WHAT CAN I DO HERE
Try typing LOOK for a description of your surroundings. Any directions indicate exits which you can use by typing (for example) NORTH (or N). Some of the objects mentioned in the description might be worth a closer look with a command like EXAMINE FLOWER (if one were here). You can also TAKE or DROP some things, type INVENTORY to see a list of what you’re carrying already, OPEN or CLOSE containers or doors, and so on.

To stop these messages entirely, type NOVICE OFF.

I’ve not looked at all the implementation details, but AFAICT, first the question mark is stripped off, then the command is automatically retried, and then the signs of confusion rule prints the message, because the command started with “what can”. So far, this seems to work as intended (in an otherwise blank project).

Granted, my project is far from minimal. At the moment the source text is more than 14,000 words, plus six or seven Extensions. When I go back to the story tab, what I find is that the standard “Try typing LOOK…” message is indeed printing.

However, this is followed in the story output by:

*** Run-time problem P11: Although nothing is allowed to have the property "printed name", no value was ever given, so it can't now be used.

This is useful information, although as far as I can see, the non-object called nothing is NOT allowed to have a printed name, so the message is a bit mystifying. The big red error message is a little more detailed. It says:

It sometimes happens that - although something could in principle have a given
property - in fact it doesn't. That makes it impossible to use.

For instance, although every thing is allowed to have a description property, it
will only be given one if the source text says so explicitly. That makes writing
the description of the noun (say) a little chancy, because it assumes the noun
will be a thing which has a description - which might not always be true. If you
would like to make sure everything does have a description property, you can
always write a sentence like The description of a thing is usually 'Dull.'.

However, when I add the line "The description of a thing is usually “Boring.” to the game, I still get the same run-time error. This seems to be because (as it says above), the compiled game is trying to refer to the printed name of the non-object called “nothing.” And I can’t give a printed name to nothing. The compiler won’t let me.

The problem seems to originate in the Extension line, “To say get noun example:”. I’m guessing this is referred to by the asking unparseable questions rule in the Table of Smarter Parser Messages, since that’s the code block that deals with inputs that start with “who/what/where/how” etc. Or so one would think. However, when I add the following line to my game, as suggested in the docs for Smarter Parser itself:

The asking unparseable questions rule is not listed in the Smarter Parser rulebook.

…nothing changes. I still get the same runtime error. Evidently some other part of Smarter Parser is also being called on to say get noun example. I can’t very well rule out the whole darn Extension. That would kind of defeat the purpose of using it.

At the moment, that’s as far as I’ve gone down this particular rabbit hole.

Okay, I think I’ve found it. My testing suggests that the runtime error occurs only in rooms that have an underside object, which is defined in Eric Eve’s Underside extension. My best guess is that the culprit is this line in Underside:

The printed name of an underside is normally "[printed name of the holder of the item described]"

And indeed, when I change that line to “…is normally “Fred Flintstone”,” the runtime error vanishes. Whether giving an underside a silly name will have any undesired side effects is unknown, but I suspect it’s safe, as the player is unlikely ever to refer to the underside object in a command, or even to be able to refer to it.

Perhaps related, perhaps not, but I filed a similar bug a while ago which was fixed in dev (ie. Inform 11):

I think that only fixes the example shown in the error message – the “description” property – but your problem is with the “printed name” property.