matching utilities #51

Parent #79Owner #36Flags readSource QuestCore.db

Aliases: matching utilities

9 verbs · 9 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
matchthis none thisrxd#5134
match_nththis none thisrxd#5125
match_verbthis none thisrxd#5111
match_listthis none thisrxd#5118
parse_ordinal_reference parse_ordrefthis none thisrxd#5115
parse_possessive_referencethis none thisrxd#5118
object_match_failedthis none thisrx#5134
init_for_corethis none thisrxd#514
match_rememberedthis none thisrxd#5138

Properties

PropertyDefinerFlagsOwnerValue
ordn#51rc#36
list of 10{"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"}
ordw#51rc#36
list of 10{"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th"}
ordinal_regexp#51rc#36"%<%(first%|second%|third%|fourth%|fifth%|sixth%|seventh%|eighth%|ninth%|tenth%|1st%|2nd%|3rd%|4th%|5th%|6th%|7th%|8th%|9th%|10th%)%>"
matching_room#51r#36#-1
help_msg#79rc#36
list of 11{"$match_utils defines the following verbs:", "", "match", "match_nth", "match_verb", "match_list", "parse_ordinal_reference (alias parse_ordref)", "parse_possessive_reference", "object_match_failed", "", "For more documentation, see help $match_utils:<specific verb>."}
key#1c#36<clear>
aliases#1rc#36{"matching utilities"}
description#1rc#36"This object holds useful verbs for matching objects and strings. It is corified as $match_utils."
object_size#1r#36{11933, -1090650497}

Ancestry

Ancestors (nearest first): #79 Generic Utilities Package#1 Root Class

Children: none

Call graph

calls n51_0 #51:match n51_0->n51_0 n20_16 #20:literal_object n51_0->n20_16 n20_17 #20:match n51_0->n20_17 n51_8 #51:match_remembered n51_0->n51_8 n51_4 #51:parse_ordinal_reference n51_0->n51_4 n51_1 #51:match_nth n51_0->n51_1 n51_5 #51:parse_possessive_reference n51_0->n51_5 n52_0 #52:has_property n51_1->n52_0 n51_2 #51:match_verb n52_2 #52:has_verb n51_2->n52_2 n51_6 #51:object_match_failed n42_0 #42:controls n51_6->n42_0 n59_2 #59:toobj n51_6->n59_2 n51_3 #51:match_list n51_6->n51_3 n55_7 #55:remove_duplicates n51_6->n55_7 n52_5 #52:isa n51_6->n52_5 n20_6 #20:english_list n51_6->n20_6 n51_7 #51:init_for_core n1_28 #1:init_for_core n51_7->n1_28

Source

match

Spec this none thisFlags rxdOwner #36Definer #51

Referenced by

Source

1":match(string, object-list)";
2"Return object in 'object-list' aliased to 'string'.";
3"Matches on a wide variety of syntax, including:";
4" \"5th axe\" -- The fifth object matching \"axe\" in the object list.";
5" \"where's sai\" -- The only object contained in 'where' matching \"sai\" (possible $ambiguous_match).";
6" \"where's second staff\" -- The second object contained in 'where' matching \"staff\".";
7" \"my third dagger\" -- The third object in your inventory matching \"dagger\".";
8"Ordinal matches are determined according to the match's position in 'object-list' or, if a possessive (such as \"where\" above) is given, then the ordinal is the nth match in that object's inventory.";
9"In the matching room (#3879@LambdaMOO), the 'object-list' consists of first the player's contents, then the room's, and finally all exits leading from the room.";
10{string, olist} = args;
11if (!string)
12return $nothing;
13elseif (string == "me")
14return player;
15elseif (string == "here")
16return player.location;
17elseif (valid(object = $string_utils:literal_object(string)))
18return object;
19elseif (valid(object = $string_utils:match(string, olist, "aliases")))
20return object;
21elseif (valid(object = $string_utils:match(string, olist, "aliases")) || ((object != $ambiguous_match) && valid(object = this:match_remembered(string, olist))))
22return object;
23elseif (parsed = this:parse_ordinal_reference(string))
24return this:match_nth(parsed[2], olist, parsed[1]);
25elseif (parsed = this:parse_possessive_reference(string))
26{whostr, objstr} = parsed;
27if (valid(whose = this:match(whostr, olist)))
28return this:match(objstr, whose.contents);
29else
30return whose;
31endif
32else
33return object;
34endif

match_nth

Spec this none thisFlags rxdOwner #36Definer #51

Referenced by

Source

1":match_nth(string, objlist, n)";
2"Find the nth object in 'objlist' that matches 'string'.";
3{what, where, n} = args;
4for v in (where)
5z = 0;
6for q in (v.aliases)
7z = z || (index(q, what) == 1);
8endfor
9"begin remember system code";
10if (!z)
11for q in (`v:short_desc_matches() ! E_VERBNF => {}')
12z = z || (index(q, what) == 1);
13endfor
14if ((!z) && $object_utils:has_property(player, "remembered_names"))
15for rmb in (player.remembered_names)
16z = z || (index(rmb[2], what) == 1);
17endfor
18endif
19endif
20"end remember system code";
21if (z && (!(n = n - 1)))
22return v;
23endif
24endfor
25return $failed_match;

match_verb

Spec this none thisFlags rxdOwner #2Definer #51

Referenced by

Source

1"$match_utils:match_verb(verbname, object) => Looks for a command-line style verb named <verbname> on <object> with current values of prepstr, dobjstr, dobj, iobjstr, and iobj.  If a match is made, the verb is called with @args[3] as arguments and 1 is returned.  Otherwise, 0 is returned.";
2{vrb, what, rest} = args;
3if (where = $object_utils:has_verb(what, vrb))
4if ((vargs = verb_args(where[1], vrb)) != {"this", "none", "this"})
5if (((((((vargs[2] == "any") || ((!prepstr) && (vargs[2] == "none"))) || index(("/" + vargs[2]) + "/", ("/" + prepstr) + "/")) && (((vargs[1] == "any") || ((!dobjstr) && (vargs[1] == "none"))) || ((dobj == what) && (vargs[1] == "this")))) && (((vargs[3] == "any") || ((!iobjstr) && (vargs[3] == "none"))) || ((iobj == what) && (vargs[3] == "this")))) && index(verb_info(where[1], vrb)[2], "x")) && verb_code(where[1], vrb))
6set_task_perms(caller_perms());
7what:(vrb)(@rest);
8return 1;
9endif
10endif
11endif

match_list

Spec this none thisFlags rxdOwner #36Definer #51

Referenced by

Source

1":match_list(string, object_list) -> List of all matches.";
2{what, where} = args;
3if (!what)
4return {};
5endif
6r = {};
7for v in (where)
8if (!(v in r))
9z = 0;
10for q in (v.aliases)
11z = z || (q && (index(q, what) == 1));
12endfor
13if (z)
14r = listappend(r, v);
15endif
16endif
17endfor
18return r;

parse_ordinal_reference parse_ordref

Spec this none thisFlags rxdOwner #36Definer #51

Referenced by

Source

1":parse_ordref(string)";
2"Parses strings referring to an 'nth' object.";
3"=> {INT n, STR object} Where 'n' is the number the ordinal represents, and 'object' is the rest of the string.";
4"=> 0 If the given string is not an ordinal reference.";
5"  Example:";
6":parse_ordref(\"second broadsword\") => {2, \"broadsword\"}";
7":parse_ordref(\"second\") => 0";
8"  Note that there must be more to the string than the ordinal alone.";
9if (m = match(args[1], ("^" + this.ordinal_regexp) + " +%([^ ].+%)$"))
10o = substitute("%1", m);
11n = (o in this.ordn) || (o in this.ordw);
12return n && {n, substitute("%2", m)};
13else
14return 0;
15endif

parse_possessive_reference

Spec this none thisFlags rxdOwner #36Definer #51

Referenced by

Source

1":parse_possessive_reference(string)";
2"Parses strings in a possessive format.";
3"=> {STR whose, STR object}  Where 'whose' is the possessor of 'object'.";
4"If the string consists only of a possessive string (ie: \"my\", or \"yduJ's\"), then 'object' will be an empty string.";
5"=> 0 If the given string is not a possessive reference.";
6"  Example:";
7":parse_possessive_reference(\"joe's cat\") => {\"joe\", \"cat\"}";
8":parse_possessive_reference(\"sis' fish\") => {\"sis\", \"fish\"}";
9"  Strings are returned as a value suitable for a :match routine, thus 'my' becoming 'me'.";
10":parse_possessive_reference(\"my dog\") => {\"me\", \"dog\"}";
11string = args[1];
12if (m = match(string, "^my$%|^my +%(.+%)?"))
13return {"me", substitute("%1", m)};
14elseif (m = match(string, "^%(.+s?%)'s? *%(.+%)?"))
15return {substitute("%1", m), substitute("%2", m)};
16else
17return 0;
18endif

object_match_failed

Spec this none thisFlags rxOwner #36Definer #51

Referenced by

none

Source

1"Usage: object_match_failed(object, string[, ambigs])";
2"Prints a message if string does not match object.  Generally used after object is derived from a :match_object(string).";
3"ambigs is an optional list of the objects that were matched upon.  If given, the message printed will list the ambiguous among them as choices.";
4{match_result, string, ?ambigs = 0} = args;
5tell = (0 && $perm_utils:controls(caller_perms(), player)) ? "notify" | "tell";
6if ((index(string, "#") == 1) && ($code_utils:toobj(string) != E_TYPE))
7"...avoid the `I don't know which `#-2' you mean' message...";
8if (!valid(match_result))
9player:(tell)(tostr("There is no \"", string, "\" that you can see."));
10endif
11return !valid(match_result);
12elseif (match_result == $nothing)
13player:(tell)("You must give the name of some object.");
14elseif (match_result == $failed_match)
15player:(tell)(tostr("There is no \"", string, "\" that you can see."));
16elseif (match_result == $ambiguous_match)
17if (typeof(ambigs) != LIST)
18player:(tell)(tostr("I don't know which \"", string, "\" you mean."));
19return 1;
20endif
21ambigs = $match_utils:match_list(string, ambigs);
22ambigs = $list_utils:map_property(ambigs, "name");
23if ((length($list_utils:remove_duplicates(ambigs)) == 1) && $object_utils:isa(player.location, this.matching_room))
24player:(tell)(tostr("I don't know which \"", string, "\" you mean.  Try using \"first ", string, "\", \"second ", string, "\", etc."));
25else
26player:(tell)(tostr("I don't know which \"", string, "\" you mean: ", $string_utils:english_list(ambigs, "nothing", " or "), "."));
27endif
28return 1;
29elseif (!valid(match_result))
30player:(tell)(tostr("The object you specified does not exist.  Seeing ghosts?"));
31else
32return 0;
33endif
34return 1;

init_for_core

Spec this none thisFlags rxdOwner #2Definer #51

Referenced by

none

Source

1if (caller_perms().wizard)
2pass();
3this.matching_room = $nothing;
4endif

match_remembered

Spec this none thisFlags rxdOwner #36Definer #51

Referenced by

Source

1":match_remembered(string, object-list)";
2"Return object in 'object-list' aliased to 'string'.";
3"Matches on player.remembered_names and object.";
4"Used by $match_utils:match.";
5"Always call $match_utils:match instead of this verb, as it is more thorough.";
6string = args[1];
7olist = args[2];
8if (!string)
9return $nothing;
10endif
11matches = {};
12for object in (olist)
13if (string in `object:short_desc_matches() ! E_VERBNF => {}')
14matches = setadd(matches, object);
15endif
16endfor
17if (length(matches) == 2)
18matches = setremove(matches, player);
19endif
20if (length(matches) > 1)
21return $ambiguous_match;
22elseif (matches)
23return matches[1];
24endif
25object = $failed_match;
26if (`!(!property_info(player, "remembered_names")) ! E_PROPNF => 0')
27for rmbrd in (player.remembered_names)
28if ((string == rmbrd[2]) && (rmbrd[1] in olist))
29matches = {@matches, rmbrd[1]};
30endif
31endfor
32if (length(matches) > 1)
33return $ambiguous_match;
34elseif (matches)
35object = matches[1];
36endif
37endif
38return object;