View/Edit #35:unparse_key_english

Switch to edit mode.

Name(s): unparse_key_english
1:  "Same as $lock_utils:unparse_key except that it generates a string that can be parsed as an English sentance."
2:  "Improvements to make it more English-like would be welcomed  -- Dax"
3:  {key} = args
4:  type = typeof(key)
5:  if (!(type in {$LIST, $OBJ}))
6:    return ""
7:  endif
8:  exp = ""
9:  if (type == $OBJ)
10:   if (valid(key))
11:     exp = key.name || tostr(key)
12:   else
13:     exp = $find_ref(key) || tostr(key)
14:   endif
15: else
16:   op = key[1]
17:   arg1 = this:(verb)(key[2])
18:   if (op == "?")
19:     exp = "[the same key as " + arg1 + "]"
20:   elseif (op == "^")
21:     exp = "children of " + arg1
22:   elseif (op == "!")
23:     if (typeof(key[2]) == $LIST)
24:       exp = "not (" + arg1 + ")"
25:     else
26:       exp = "not " + arg1
27:     endif
28:   elseif (op in {"&&", "||"})
29:     other = op == "&&" ? "||" | "&&"
30:     lhs = arg1
31:     rhs = this:(verb)(key[3])
32:     if (typeof(key[2]) == $OBJ || key[2][1] != other)
33:       exp = lhs
34:     else
35:       exp = "(" + lhs + ")"
36:     endif
37:     exp = exp + (op == "&&" ? " and " | " or ")
38:     if (typeof(key[3]) == $OBJ || key[3][1] != other)
39:       exp = exp + rhs
40:     else
41:       exp = exp + "(" + rhs + ")"
42:     endif
43:     exp
44:   else
45:     raise(E_INVARG)
46:   endif
47: endif
48: return exp
49: "Last modified by Dax (#789) on Mon Aug  7 21:54:26 2006 MDT."

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Hacker (#60)

You are not logged in.

[home | help | who | search | setup | code]