lock utilities #46

Parent #72Owner #361Flags readSource hellcore/hellcore.db

Aliases: lock utilities

11 verbs · 16 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
init_scannerthis none thisrxd#464
scan_tokenthis none thisrxd#4634
canonicalize_spacesthis none thisrxd#465
parse_keyexpthis none thisrxd#4614
parse_Ethis none thisrxd#4613
parse_Athis none thisrxd#4636
eval_keythis none thisrxd#4620
match_objectthis none thisrxd#4620
unparse_keythis none thisrxd#4644
eval_key_newthis none thisrxd#4642
parse_A_newthis none thisrxd#4647

Properties

PropertyDefinerFlagsOwnerValue
player#46rc#361#309
input_index#46rc#3613
input_length#46rc#3612
input_string#46rc#361"me"
index_incremented#46rc#3610
help_msg#72rc#361
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'."}
aliases#1rc#361{"lock utilities"}
description#1rc#361"This the lock utilities package, used by the MOOwide locking mechanisms. See `help $lock_utils' for more details."
object_size#1r#29{9883, 1298433815}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rc#361<clear>
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n46_1 #46:scan_token n46_2 #46:canonicalize_spaces n46_1->n46_2 n46_3 #46:parse_keyexp n46_0 #46:init_scanner n46_3->n46_0 n46_4 #46:parse_E n46_3->n46_4 n46_4->n46_1 n46_5 #46:parse_A n46_4->n46_5 n46_5->n46_1 n46_5->n46_4 n46_5->n46_5 n46_7 #46:match_object n46_5->n46_7 n46_6 #46:eval_key n46_6->n46_6 n45_8 #45:contains n46_6->n45_8 n46_8 #46:unparse_key n46_8->n46_8 n46_9 #46:eval_key_new n46_9->n46_6 n46_9->n45_8 n45_0 #45:has_property n46_9->n45_0 n45_9 #45:all_contents n46_9->n45_9 n45_2 #45:has_verb n46_9->n45_2 n46_10 #46:parse_A_new n46_10->n46_1 n46_10->n46_4 n46_10->n46_5 n46_10->n46_7

Source

init_scanner

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

Source

1this.input_string = args[1];
2this.input_length = length(args[1]);
3this.input_index = 1;
4this.index_incremented = 0;

scan_token

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

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

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

Source

1name = args[1];
2while (index(name, "  "))
3name = strsub(name, "  ", " ");
4endwhile
5return name;

parse_keyexp

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

none

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  ";
12this:init_scanner(args[1]);
13this.player = args[2];
14return this:parse_E();

parse_E

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

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

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

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 {"&&", "||"})
31return ("Missing expression before '" + token) + "'";
32elseif (token == "")
33return "Missing expression at end of key expression";
34else
35return this:match_object(token);
36endif

eval_key

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

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 == "!")
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);
18else
19raise(E_DIV);
20endif

match_object

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

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

Spec this none thisFlags rxdOwner #361Definer #46

Referenced by

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 == "!")
20if (typeof(key[2]) == LIST)
21return ("!(" + arg1) + ")";
22else
23return "!" + arg1;
24endif
25elseif (op in {"&&", "||"})
26other = (op == "&&") ? "||" | "&&";
27lhs = arg1;
28rhs = this:unparse_key(key[3]);
29if ((typeof(key[2]) == OBJ) || (key[2][1] != other))
30exp = lhs;
31else
32exp = ("(" + lhs) + ")";
33endif
34exp = ((exp + " ") + op) + " ";
35if ((typeof(key[3]) == OBJ) || (key[3][1] != other))
36exp = exp + rhs;
37else
38exp = ((exp + "(") + rhs) + ")";
39endif
40return exp;
41else
42raise(E_DIV);
43endif
44endif

eval_key_new

Spec this none thisFlags rxdOwner #361Definer #46

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

Spec this none thisFlags rxdOwner #361Definer #46

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