1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays generic hashtables io kernel assocs math
4 namespaces prettyprint sequences strings io.styles vectors words
5 quotations mirrors splitting math.parser classes vocabs refs
6 sets sorting summary debugger continuations ;
9 : value-editor ( path -- )
11 [ pprint-short ] presented-printer set
12 dup presented-path set
14 [ get-ref pprint-short ] with-nesting ;
20 : write-slot-editor ( path -- )
29 : write-key ( mirror key -- )
31 [ 2drop ] [ <key-ref> write-slot-editor ] if ;
33 : write-value ( mirror key -- )
34 <value-ref> write-slot-editor ;
36 : describe-row ( obj key n -- )
38 +number-rows+ get [ pprint-cell ] [ drop ] if
39 2dup write-key write-value
42 : summary. ( obj -- ) [ summary ] keep write-object nl ;
44 : sorted-keys ( assoc -- alist )
47 [ [ unparse-short ] keep ] { } map>assoc
51 : describe* ( obj flags -- )
54 make-mirror dup sorted-keys dup empty? [
57 dup enum? [ +sequence+ on ] when
58 standard-table-style [
60 rot [ -rot describe-row ] curry 2each
65 : describe ( obj -- ) H{ } describe* ;
67 M: tuple error. describe ;
69 : namestack. ( seq -- )
70 [ [ global eq? not ] filter [ keys ] gather ] keep
71 [ dupd assoc-stack ] curry H{ } map>assoc describe ;
74 namestack namestack. ;
77 error-continuation get continuation-name namestack. ;
79 SYMBOL: inspector-hook
81 [ H{ { +number-rows+ t } } describe* ] inspector-hook set-global
83 SYMBOL: inspector-stack
87 : reinspect ( obj -- )
89 dup make-mirror dup mirror set keys \ keys set
90 inspector-hook get call ;
92 : (inspect) ( obj -- )
93 dup inspector-stack get push reinspect ;
95 : key@ ( n -- key ) \ keys get nth ;
97 : &push ( -- obj ) me get ;
99 : &at ( n -- ) key@ mirror get at (inspect) ;
103 dup length 1 <= [ drop ] [ dup pop* peek reinspect ] if ;
105 : &add ( value key -- ) mirror get set-at &push reinspect ;
107 : &put ( value n -- ) key@ &add ;
109 : &delete ( n -- ) key@ mirror get delete-at &push reinspect ;
111 : &rename ( key n -- ) key@ mirror get rename-at &push reinspect ;
114 #! A tribute to Slate:
115 "You are in a twisty little maze of objects, all alike." print
117 "'n' is a slot number in the following:" print
119 "&back -- return to previous object" print
120 "&push ( -- obj ) push this object" print
121 "&at ( n -- ) inspect nth slot" print
122 "&put ( value n -- ) change nth slot" print
123 "&add ( value key -- ) add new slot" print
124 "&delete ( n -- ) remove a slot" print
125 "&rename ( key n -- ) change a slot's key" print
126 "&help -- display this message" print
129 : inspector ( obj -- )
131 V{ } clone inspector-stack set
135 inspector-stack get [ (inspect) ] [ inspector ] if ;