lock utilities #53
Aliases: lock utilities
11 verbs · 11 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
init_scanner | this none this | rxd | #53 | 4 |
scan_token | this none this | rxd | #53 | 34 |
canonicalize_spaces | this none this | rxd | #53 | 5 |
parse_keyexp | this none this | rxd | #53 | 15 |
parse_E | this none this | rxd | #53 | 13 |
parse_A | this none this | rxd | #53 | 43 |
eval_key | this none this | rxd | #53 | 30 |
match_object | this none this | rxd | #53 | 20 |
unparse_key | this none this | rxd | #53 | 46 |
eval_key_new | this none this | rxd | #53 | 42 |
parse_A_new | this none this | rxd | #53 | 47 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
player | #53 | rc | #2 | #2 |
input_index | #53 | rc | #2 | 5 |
input_length | #53 | rc | #2 | 4 |
input_string | #53 | rc | #2 | "here" |
index_incremented | #53 | rc | #2 | 0 |
help_msg | #79 | rc | #2 | list of 13{"These routines are used when locking objects, and when testing an object's lock before allowing use (such as in an exit).", "", ":parse_keyexp (string keyexpression, object player)", " => returns an object or list for the new key as defined by the", " keyexpression or a string describing the error if it failed.", "", ":eval_key (LIST|OBJ key, testobject)", " => returns true if the given testobject satisfies the key.", "", ":unparse_key (LIST|OBJ key)", " => returns a string describing the key in english/moo-code terms.", "", "For more information on keys and locking, read `help locking', `help keys', and `help @lock'."} |
key | #1 | c | #2 | <clear> |
aliases | #1 | rc | #2 | {"lock utilities"} |
description | #1 | rc | #2 | "This the lock utilities package, used by the MOOwide locking mechanisms. See `help $lock_utils' for more details." |
object_size | #1 | r | #36 | {11190, -1090650497} |
html | #1 | rc | #2 | <clear> |
Ancestry
Ancestors (nearest first): #79 Generic Utilities Package → #1 Root Class
Children: none
Call graph
Source
init_scanner
Referenced by
- #53:parse_keyexp line 13:
this:init_scanner
Source
1this.input_string = args[1]; 2this.input_length = length(args[1]); 3this.input_index = 1; 4this.index_incremented = 0;
scan_token
Referenced by
- #53:parse_E line 3:
this:scan_token - #53:parse_A line 1:
this:scan_token - #53:parse_A line 4:
this:scan_token - #53:parse_A line 24:
this:scan_token - #53:parse_A_new line 1:
this:scan_token - #53:parse_A_new line 4:
this:scan_token - #53:parse_A_new line 17:
this:scan_token - #53:parse_A_new line 31:
this:scan_token
Source
1string = this.input_string; 2len = this.input_length; 3i = this.input_index; 4while ((i <= len) && (string[i] == " ")) 5i = i + 1; 6endwhile 7if (i > len) 8this.index_incremented = 0; 9return ""; 10elseif ((ch = string[i]) in {"(", ")", "!", "?", "~"}) 11this.input_index = i + 1; 12this.index_incremented = 1; 13return ch; 14elseif (ch in {"&", "|"}) 15this.input_index = i = i + 1; 16this.index_incremented = 1; 17if ((i <= len) && (string[i] == ch)) 18this.input_index = i + 1; 19this.index_incremented = 2; 20endif 21return ch + ch; 22else 23start = i; 24while ((i <= len) && (!((ch = string[i]) in {"(", ")", "!", "?", "&", "|", "~"}))) 25i = i + 1; 26endwhile 27this.input_index = i; 28i = i - 1; 29while (string[i] == " ") 30i = i - 1; 31endwhile 32this.index_incremented = (i - start) + 1; 33return this:canonicalize_spaces(string[start..i]); 34endif
canonicalize_spaces
Referenced by
- #53:scan_token line 33:
this:canonicalize_spaces
Source
1name = args[1]; 2while (index(name, " ")) 3name = strsub(name, " ", " "); 4endwhile 5return name;
parse_keyexp
Referenced by
- #4:@lock line 6:
$lock_utils:parse_keyexp - #8:@lock_for_open line 2:
$lock_utils:parse_keyexp - #9:encrypt line 2:
$lock_utils:parse_keyexp - #118:@vlock line 31:
$lock_utils:parse_keyexp
Source
1"parse_keyexp(STRING keyexpression, OBJ player) => returns a list containing the coded key, or a string containing an error message if the attempt failed."; 2""; 3"Grammar for key expressions:"; 4""; 5" E ::= A "; 6" | E || A "; 7" | E && A "; 8" A ::= ( E ) "; 9" | ! A "; 10" | object "; 11" | ? object "; 12" | ~ object "; 13this:init_scanner(args[1]); 14this.player = args[2]; 15return this:parse_E();
parse_E
Referenced by
- #53:parse_keyexp line 15:
this:parse_E - #53:parse_A line 3:
this:parse_E - #53:parse_A_new line 3:
this:parse_E
Source
1exp = this:parse_A(); 2if (typeof(exp) != STR) 3while ((token = this:scan_token()) in {"&&", "||"}) 4rhs = this:parse_A(); 5if (typeof(rhs) == STR) 6return rhs; 7endif 8exp = {token, exp, rhs}; 9endwhile 10"The while loop above always eats a token. Reset it back so the iteration can find it again. Always losing `)'. Ho_Yan 3/9/95"; 11this.input_index = this.input_index - this.index_incremented; 12endif 13return exp;
parse_A
Referenced by
- #53:parse_E line 1:
this:parse_A - #53:parse_E line 4:
this:parse_A - #53:parse_A line 10:
this:parse_A - #53:parse_A line 17:
this:parse_A - #53:parse_A_new line 10:
this:parse_A
Source
1token = this:scan_token(); 2if (token == "(") 3exp = this:parse_E(); 4if ((typeof(exp) != STR) && (this:scan_token() != ")")) 5return "Missing ')'"; 6else 7return exp; 8endif 9elseif (token == "~") 10exp = this:parse_A(); 11if (typeof(exp) == STR) 12return exp; 13else 14return {"~", exp}; 15endif 16elseif (token == "!") 17exp = this:parse_A(); 18if (typeof(exp) == STR) 19return exp; 20else 21return {"!", exp}; 22endif 23elseif (token == "?") 24next = this:scan_token(); 25if (next in {"(", ")", "!", "&&", "||", "?", "~"}) 26return ("Missing object-name before '" + token) + "'"; 27elseif (next == "") 28return "Missing object-name at end of key expression"; 29else 30what = this:match_object(next); 31if (typeof(what) == OBJ) 32return {"?", this:match_object(next)}; 33else 34return what; 35endif 36endif 37elseif (token in {"&&", "||"}) 38return ("Missing expression before '" + token) + "'"; 39elseif (token == "") 40return "Missing expression at end of key expression"; 41else 42return this:match_object(token); 43endif
eval_key
Referenced by
- #1:is_unlocked_for line 1:
$lock_utils:eval_key - #8:is_openable_by line 3:
$lock_utils:eval_key - #9:is_readable_by line 2:
$lock_utils:eval_key - #53:eval_key line 21:
this:eval_key - #53:eval_key line 25:
this:eval_key - #53:eval_key line 25:
this:eval_key - #53:eval_key line 27:
this:eval_key - #53:eval_key line 27:
this:eval_key - #53:eval_key_new line 11:
this:eval_key - #53:eval_key_new line 15:
this:eval_key - #53:eval_key_new line 15:
this:eval_key - #53:eval_key_new line 17:
this:eval_key - #53:eval_key_new line 17:
this:eval_key - #104:is_unlocked_for line 5:
$lock_utils:eval_key - #118:exit_unlocked_for line 5:
$lock_utils:eval_key
Source
1"eval_key(LIST|OBJ coded key, OBJ testobject) => returns true if testobject will solve the provided key."; 2{key, who} = args; 3type = typeof(key); 4if (!(type in {LIST, OBJ})) 5return 1; 6elseif (typeof(key) == OBJ) 7return (who == key) || $object_utils:contains(who, key); 8endif 9op = key[1]; 10if (op == "~") 11if ($object_utils:isa(who, key[2])) 12return 1; 13endif 14for k in (who.contents) 15(ticks_left() < 4000) && suspend(0); 16if ($object_utils:isa(k, key[2])) 17return 1; 18endif 19endfor 20elseif (op == "!") 21return !this:eval_key(key[2], who); 22elseif (op == "?") 23return key[2]:is_unlocked_for(who); 24elseif (op == "&&") 25return this:eval_key(key[2], who) && this:eval_key(key[3], who); 26elseif (op == "||") 27return this:eval_key(key[2], who) || this:eval_key(key[3], who); 28else 29raise(E_DIV); 30endif
match_object
Referenced by
- #53:parse_A line 30:
this:match_object - #53:parse_A line 32:
this:match_object - #53:parse_A line 42:
this:match_object - #53:parse_A_new line 23:
this:match_object - #53:parse_A_new line 25:
this:match_object - #53:parse_A_new line 46:
this:match_object
Source
1"used by $lock_utils to unparse a key expression so one can use `here' and `me' as well as doing the regular object matching."; 2token = args[1]; 3if (token == "me") 4return this.player; 5elseif (token == "here") 6if (valid(this.player.location)) 7return this.player.location; 8else 9return ("'here' has no meaning where " + this.player.name) + " is"; 10endif 11else 12what = this.player.location:match_object(token); 13if (what == $failed_match) 14return ("Can't find an object named '" + token) + "'"; 15elseif (what == $ambiguous_match) 16return ("Multiple objects named '" + token) + "'"; 17else 18return what; 19endif 20endif
unparse_key
Referenced by
- #1:examine_key line 6:
$lock_utils:unparse_key - #3:examine_key line 6:
$lock_utils:unparse_key - #4:@lock line 14:
$lock_utils:unparse_key - #5:examine_key line 6:
$lock_utils:unparse_key - #6:@exam*ine line 19:
$lock_utils:unparse_key - #7:examine_key line 6:
$lock_utils:unparse_key - #8:@lock_for_open line 10:
$lock_utils:unparse_key - #9:encrypt line 10:
$lock_utils:unparse_key - #53:unparse_key line 16:
this:unparse_key - #53:unparse_key line 30:
this:unparse_key - #118:@vlock line 37:
$lock_utils:unparse_key
Source
1":unparse_key(LIST|OBJ coded key) => returns a string describing the key in english/moo-code terms."; 2"Example:"; 3"$lock_utils:unparse_key({\"||\", $hacker, $housekeeper}) => \"#18105[Hacker] || #36830[housekeeper]\""; 4key = args[1]; 5type = typeof(key); 6if (!(type in {LIST, OBJ})) 7return "(None.)"; 8elseif (type == OBJ) 9if (valid(key)) 10return tostr(key, "[", key.name, "]"); 11else 12return tostr(key); 13endif 14else 15op = key[1]; 16arg1 = this:unparse_key(key[2]); 17if (op == "?") 18return "?" + arg1; 19elseif (op == "~") 20return "children of " + arg1; 21elseif (op == "!") 22if (typeof(key[2]) == LIST) 23return ("!(" + arg1) + ")"; 24else 25return "!" + arg1; 26endif 27elseif (op in {"&&", "||"}) 28other = (op == "&&") ? "||" | "&&"; 29lhs = arg1; 30rhs = this:unparse_key(key[3]); 31if ((typeof(key[2]) == OBJ) || (key[2][1] != other)) 32exp = lhs; 33else 34exp = ("(" + lhs) + ")"; 35endif 36exp = ((exp + " ") + op) + " "; 37if ((typeof(key[3]) == OBJ) || (key[3][1] != other)) 38exp = exp + rhs; 39else 40exp = ((exp + "(") + rhs) + ")"; 41endif 42return exp; 43else 44raise(E_DIV); 45endif 46endif
eval_key_new
Referenced by
none
Source
1set_task_perms($no_one); 2{key, who} = args; 3type = typeof(key); 4if (!(type in {LIST, OBJ})) 5return 1; 6elseif (typeof(key) == OBJ) 7return (who == key) || $object_utils:contains(who, key); 8endif 9op = key[1]; 10if (op == "!") 11return !this:eval_key(key[2], who); 12elseif (op == "?") 13return key[2]:is_unlocked_for(who); 14elseif (op == "&&") 15return this:eval_key(key[2], who) && this:eval_key(key[3], who); 16elseif (op == "||") 17return this:eval_key(key[2], who) || this:eval_key(key[3], who); 18elseif (op == ".") 19if ($object_utils:has_property(who, key[2]) && who.(key[2])) 20return 1; 21else 22for thing in ($object_utils:all_contents(who)) 23if ($object_utils:has_property(thing, key[2]) && thing.(key[2])) 24return 1; 25endif 26endfor 27endif 28return 0; 29elseif (op == ":") 30if ($object_utils:has_verb(who, key[2]) && who:(key[2])()) 31return 1; 32else 33for thing in ($object_utils:all_contents(who)) 34if ($object_utils:has_verb(thing, key[2]) && thing:(key[2])()) 35return 1; 36endif 37endfor 38endif 39return 0; 40else 41raise(E_DIV); 42endif
parse_A_new
Referenced by
none
Source
1token = this:scan_token(); 2if (token == "(") 3exp = this:parse_E(); 4if ((typeof(exp) != STR) && (this:scan_token() != ")")) 5return "Missing ')'"; 6else 7return exp; 8endif 9elseif (token == "!") 10exp = this:parse_A(); 11if (typeof(exp) == STR) 12return exp; 13else 14return {"!", exp}; 15endif 16elseif (token == "?") 17next = this:scan_token(); 18if (next in {":", ".", "(", ")", "!", "&&", "||", "?", "~"}) 19return ("Missing object-name before '" + token) + "'"; 20elseif (next == "") 21return "Missing object-name at end of key expression"; 22else 23what = this:match_object(next); 24if (typeof(what) == OBJ) 25return {"?", this:match_object(next)}; 26else 27return what; 28endif 29endif 30elseif (token in {":", "."}) 31next = this:scan_token(); 32if (next in {":", ".", "(", ")", "!", "&&", "||", "?", "~"}) 33return ("Missing verb-or-property-name before '" + token) + "'"; 34elseif (next == "") 35return "Missing verb-or-property-name at end of key expression"; 36elseif (typeof(next) != STR) 37return "Non-string verb-or-property-name at end of key expression"; 38else 39return {token, next}; 40endif 41elseif (token in {"&&", "||"}) 42return ("Missing expression before '" + token) + "'"; 43elseif (token == "") 44return "Missing expression at end of key expression"; 45else 46return this:match_object(token); 47endif