matching utilities #51
Aliases: matching utilities
9 verbs · 10 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
match | this none this | rxd | #51 | 34 |
match_nth | this none this | rxd | #51 | 25 |
match_verb | this none this | rxd | #51 | 11 |
match_list | this none this | rxd | #51 | 18 |
parse_ordinal_reference parse_ordref | this none this | rxd | #51 | 15 |
parse_possessive_reference | this none this | rxd | #51 | 18 |
object_match_failed | this none this | rx | #51 | 34 |
init_for_core | this none this | rxd | #51 | 4 |
match_remembered | this none this | rxd | #51 | 38 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
ordn | #51 | rc | #36 | list of 10{"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"} |
ordw | #51 | rc | #36 | list of 10{"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th"} |
ordinal_regexp | #51 | rc | #36 | "%<%(first%|second%|third%|fourth%|fifth%|sixth%|seventh%|eighth%|ninth%|tenth%|1st%|2nd%|3rd%|4th%|5th%|6th%|7th%|8th%|9th%|10th%)%>" |
matching_room | #51 | r | #36 | #-1 |
help_msg | #79 | rc | #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 | #1 | c | #36 | <clear> |
aliases | #1 | rc | #36 | {"matching utilities"} |
description | #1 | rc | #36 | "This object holds useful verbs for matching objects and strings. It is corified as $match_utils." |
object_size | #1 | r | #36 | {11933, -1090650497} |
html | #1 | rc | #36 | <clear> |
Ancestry
Ancestors (nearest first): #79 Generic Utilities Package → #1 Root Class
Children: none
Call graph
Source
match
Referenced by
- #51:match line 27:
this:match - #51:match line 28:
this:match - #90:whois line 52:
$match_utils:match - #91:follow line 2:
$match_utils:match - #91:g*et line 12:
$match_utils:match - #91:g*et line 17:
$match_utils:match - #91:dr*op line 10:
$match_utils:match - #91:gi*ve line 12:
$match_utils:match - #91:gi*ve line 22:
$match_utils:match - #104:l*ook line 15:
$match_utils:match - #104:l*ook line 38:
$match_utils:match - #104:valid_attack line 4:
$match_utils:match - #104:valid_attack line 5:
$match_utils:match - #104:queue_attack line 4:
$match_utils:match - #104:queue_attack line 5:
$match_utils:match - #104:advance_queue line 6:
$match_utils:match - #104:advance_queue line 7:
$match_utils:match - #104:match line 2:
$match_utils:match - #104:loot line 10:
$match_utils:match
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
Referenced by
- #51:match line 24:
this:match_nth
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
Referenced by
- #90:last_huh line 6:
$match_utils:match_verb - #90:last_huh line 8:
$match_utils:match_verb - #118:here_huh line 9:
$match_utils:match_verb - #118:here_huh line 13:
$match_utils:match_verb - #118:here_huh line 19:
$match_utils:match_verb
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
Referenced by
- #51:object_match_failed line 21:
$match_utils:match_list - #90:@stats line 6:
$match_utils:match_list - #118:here_huh line 16:
$match_utils:match_list
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
Referenced by
- #51:match line 23:
this:parse_ordinal_reference
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
Referenced by
- #51:match line 25:
this:parse_possessive_reference
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
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
Referenced by
none
Source
1if (caller_perms().wizard) 2pass(); 3this.matching_room = $nothing; 4endif
match_remembered
Referenced by
- #51:match line 21:
this:match_remembered
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;