Method code for $foundation.match_environment()

[Turn off line numbering]
  1: arg str;
  2: var obj, env, found, match, target;
  3: 
  4: if (!str)
  5:     throw(~objnf, "No object specified.", str);
  6: str = str.strip_article();
  7: 
  8: // Handle special cases.
  9: if (str in ["me", "my"]) {
 10:     return this();
 11: } else if (str[1] == "$" || str[1] == "#") {
 12:     return (> $object_lib.to_dbref(str) <);
 13: } else if (str[1] == "~") {
 14:     str = str.subrange(2);
 15:     if (str[1] != "~")
 16:         return $user_db.match_begin(str);
 17: } else if (str in ["it", "him", "her"]) {
 18:     return (| .match_context(str) |) || throw(~context, "I don't see " + str + " here, do you?");
 19: }
 20: 
 21: // Start matching
 22: found = [];
 23: env = .environment();
 24: 
 25: // special case ordinal references
 26: if ((match = $parse_lib.ordinal_reference(str)))
 27:     return (> env.match_nth(@match) <);
 28: if ((match = $parse_lib.possessive_reference(str))) {
 29:     if (match[1] == "me")
 30:         obj = this();
 31:     else
 32:         obj = (> env.match_object(match[1]) <);
 33:     if (!obj.match_name(str)) {
 34:         catch ~objnf, ~ambig, ~range {
 35:             env = (| obj.contents() |) || [];
 36:             if ((found = $parse_lib.ordinal_reference(match[2])))
 37:                 return (> env.match_nth(@found) <);
 38:             else
 39:                 return (> env.match_object(match[2]) <);
 40:         } with {
 41:             if (error() == ~objnf)
 42:                 throw(~objnf, obj.name() + " does not have " + match[2].add_indefinite() + ".");
 43:             else if (error() == ~ambig)
 44:                 throw(~ambig, "\"" + str + "\" can match " + traceback()[1][3].mmap('namef, 'ref).to_english("", " or ") + ".");
 45:             else
 46:                 throw(~objnf, obj.name() + "'s what?");
 47:         }
 48:     }
 49: }
 50: catch any {
 51:     return (> env.match_object(str) <);
 52: } with {
 53:     if (error() == ~badfrob) {
 54:         target = traceback()[1][3];
 55:         obj = frob_value(target)['location];
 56:         obj.del_frob_from_contents(target);
 57:         throw(~badfrob, "Cleaned up bogus frob in your environment, try again..");
 58:     }
 59:     if (error() == ~objnf)
 60:         throw(~objnf, "You do not see " + str.add_indefinite() + " anywhere.");
 61:     if (error() == ~ambig) {
 62:         found = filter obj in (traceback()[1][3]) where (obj.name() == str);
 63:         if (listlen(found) == 1)
 64:             return found[1];
 65:         if (found)
 66:             found = found.mmap('namef, 'ref).to_english("", " or ");
 67:         else
 68:             found = traceback()[1][3].mmap('namef, 'ref).to_english("", " or ");
 69:         throw(~ambig, "\"" + str + "\" can match " + found + ".");
 70:     }
 71:     rethrow(error());
 72: }

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon