Object Matching by Xavid


This extension provides support for getting the matched object when matching a snippet against a pattern and for disabling clarification when a command or snippet is ambiguous.

Disambiguation Override by Mike Ciul provides similar functionality with more options, however, it doesn't seem compatible with recent Inform 7.

Chapter 1 - Object Matching

This extension provides one main construct. You can use "if (snippet) object-matches (topic)" in the same way as you use the standard Inform "if (snippet) matches (topic)". The difference is that, if the condition is true, the following code can refer to "the matched object". For example,

if S object-matches "[any thing]":
     say "You sense that that is in [the location of the matched object]."

This is mainly useful for making overly-clever error messages without affecting the parsing of normal commands; for non-error situations you're probably better off using normal understand-based parsing.

Chapter 2 - Disabling Clarification

This extension internally disables clarification while object-matching both because it doesn't make sense and also because it doesn't work and crashes the interpreter. If the snippet matches more than one thing equally well, Inform will pick one arbitrarily instead of asking for clarification.

If you want to disable clarification in some other situation, you can do so with:

Now disable clarification is true.

Note that this will last until you do "now disable clarification is false".

Chapter 3 - Bugs and Comments

This extension is hosted in Github at https://github.com/i7/extensions/tree/master/Xavid. Feel free to email me at extensions@xavid.us with questions, comments, bug reports, suggestions, or improvements.

Section 1 - Known Issues

Something in the current multiple object list won't match as a "[thing]" or similar.

Example: *** Psychic Examiner - Error messages with locations.

"Psychic Examiner"

Include Object Matching by Xavid.
Include Snippetage by Dave Robinson.

Library is a room.

Study is south of Library.

A thing called a laser sword is here.

Rule for printing a parser error when the latest parser error is the can't see any such thing error:
     if the snippet at 2 of length (the command length - 1) object-matches "[any thing]":
         say "[regarding the matched object]You don't see [the matched object] here; your psychic intuition tells you that [it] is in the [location of the matched object].";
     else:
         say "You can't see any such thing."

Test me with "x sword / x wombat / s / x sword".

Example: ** Unit Tests

"Unit Tests"

Include Object Matching by Xavid.
Include Command Unit Testing by Xavid.
Include Snippetage by Dave Robinson.

Library is a room.

A thing called a red apple is here. A thing called a green apple is here.

Study is south of Library.

A thing called a laser sword is here.

Rule for printing a parser error when the latest parser error is the can't see any such thing error:
     if the snippet at 2 of length (the command length - 1) object-matches "[any thing]":
         say "[regarding the matched object]You don't see [the matched object] here; your psychic intuition tells you that [it] is in the [location of the matched object].";
     else:
         say "You can't see any such thing."

Unit test:
     start test "successful match";
     assert that "x sword" produces "You don't see the laser sword here; your psychic intuition tells you that it is in the Study.";
     do "s";
     assert that "x sword" produces "You see nothing special about the laser sword.";
     start test "failure to match";
     assert that "x wombat" produces "You can't see any such thing.";
     start test "ambiguous match";
     assert that "x apple" produces "You don't see the red apple here; your psychic intuition tells you that it is in the Library.";

Test me with "unit".