Is there a way to get the text that matches a token?

I’m looking at the “Whither?” example, which does this:

Rule for printing a parser error when the player's command includes "[non-door direction] door": 
    say "There is no door in that direction." instead.

But then I thought it would be nice to indicate which direction they tried to find a door in. For example, “open west door” could say “There is no door to the west.” (assuming there really isn’t one).

Is there a way to get at the text that matched [non-door direction] for that purpose? I tried the topic understood but that doesn’t work.

Or I suppose there may also be a different approach to make it work…

What you can do is get the snippet that matched the topic in the most recent invocation of if [snippet] includes [topic]: it’s in the matched text snippet variable. But this will be what was literally in the player’s command that matched the topic: the direction will probably be abbreviated; there might be an article. You’ll have to futz with it to make it presentable.

2 Likes

Looks like it also includes “door”, wonderful. Though I guess stripping off the last word would be the least of my worries…

Do you really want the text or the object?

Yeah, I’d actually like to get the object… specifically, the direction object (not the door object).

The thing you can be most sure of when you’re dealing with a parser error is that the parser couldn’t parse the command. This makes counting on specifics regarding what it thought about the command prior to failure a risky endeavor. All that said, you can try your luck with this. (I learned the tentative noun trick from @otistdog , though Otis’ examples exhibited a preference for “prospective noun”.)

The temporal vortex is an open door. It is west of Yesterday and east of Today.

The initial appearance of a door is usually "Nearby [an item described] leads [if the other side of the item described is visited][direction of the item described from the location\
] to [other side of the item described][otherwise][direction of the item described from the location][end if]."

Direction-relevance relates a door (called X) to a direction (called Y) when the direction of X from the location is Y. The verb to be directionally-relevant to means the direction\
-relevance relation.

Understand "[something related by direction-relevance] door" as a door.

To decide what object is the tentative first/-- noun: (- parser_results-->INP1_PRES -).

To decide what object is the tentative second noun: (- parser_results-->INP2_PRES -).

Rule for printing a parser error when the player's command includes "[non-door direction] door" and the tentative noun is a direction:
say "There's no door to the [tentative noun].". [needs adjustment for up, down, in, out ]

Rule for printing a parser error when the player's command includes "[non-door direction] door" and the tentative second noun is a direction:
say "There's no door to the [tentative second noun].". [needs adjustment for up, down, in, out ]


Definition: a direction (called direction D) is non-door:
let the target be the room-or-door direction D from the location;
if the target is a door, no;
yes.

Test me with "examine west door / x east door / w / x w door / x e door / tie me to the west door / tie the west door to me / push the west door east / push the east door west".
1 Like

Indeed, that’s pretty much why I wanted the object, since I already have a phrase to adjust for the special directions.

The tentative noun seems to work, thanks!

I learned it from @zarf!

2 Likes