Hi Rebols,

I once again started a little patching within the
system, this time its the help function. Now it'll
work within nested objects.

Examples:

>> a: make object! [
[     b: make object! [
[          c: func ["This is a/b/c" /d][
[            either d [print "c/d is started"]
[                           [print "c   is started"]]
[         e: func ["This is a/e"][print "huhu"]
[         f: 3
[         g: make object! [
[              h: "kjhkjh"
[              i: 10.3
[             ]
[          ]
[    ]
>> help a
Object with fields:
b :  object
>> help a/b
Valid subpath "a/b" is:

Object with fields:
c :  func "This is a/b/c"
e :  func "This is a/e"
f :  integer
g :  object
>> help a/b/c
Valid subpath "a/b/c" is function:

This is a/b/c
Arguments:
Refinements:
    /d
>> help a/b/c/d
Valid subpath "a/b/c" is function:

This is a/b/c
Arguments:
Refinements:
    /d
>> help a/b/f  
Valid subpath "a/b/f" (called obj)

obj is word of value: 3
>> help a/b/x
Valid subpath "a/b" is:

Object with fields:
c :  func "This is a/b/c"
e :  func "This is a/e"
f :  integer
g :  object


And here comes the patched help ...

help: func [
   "Prints information about words and values."
   'word [any-type!]
   /local value args item refmode types
][
   if unset? get/any 'word [
      print trim/auto {
^^-^^-^^-^^-The help function provides a simple way to get
^^-^^-^^-^^-information about words and values.  To use it
^^-^^-^^-^^-supply a word or value as its argument:
^^-^^-^^-^^-
^^-^^-^^-^^-^^-help insert

^^-^^-^^-^^-In addition to help, these other words provide
^^-^^-^^-^^-information about the REBOL language:
^^-^^-^^-^^-
^^-^^-^^-^^-^^-about - for general info
^^-^^-^^-^^-^^-usage - for the command line arguments
^^-^^-^^-^^-^^-license - for the terms of user license
^^-^^-^^-^^-^^-source func - print source for given function
^^-^^-^^-^^-
^^-^^-^^-^^-For more information, see the user guides.
^^-^^-^^-}
      exit
   ]

   ; \/ \/ \/ start changes by iho
   if path? :word [
      use [obj parts i j] [
         i: 2
         parts: parse mold :word "/"
         if error? try [obj: get to-word first parts] [
            print ["Path:" :word "not found"]
            exit
         ]
         while [all [object? :obj i <= length? parts] ] [
            either not error? try [obj: get in obj to-word pick parts i] [
               i: i + 1
            ] [
               break
            ]
         ]
         pth: first parts
         for j 2 i - 1 1 [
            append pth rejoin ["/" pick parts j ]
         ]
         prin rejoin [{Valid subpath "} pth]
         either function? :obj [
            print {" is function:^^/}
            help obj
         ][
            either object? :obj [
               print {" is:^^/}
               help obj
            ] [
               print {" (called obj)^^/}
               help obj
            ]
         ]
         exit
      ]
   ]
   if object? get :word [
      use [wrd hlp] [
         print "Object with fields:"
         foreach wrd next first get word [
            either function? get in get word wrd [
               print [wrd ":  func" either string? hlp: first third get in get word 
wrd [
                     mold first parse/all hlp "^^/"][""]]
            ] [
               print [wrd ": " type? get in get word wrd]
            ]
         ]
         exit
      ]
   ]
   ; /\ /\ /\ end changes by iho

   if not word? :word [
      print [mold word "is" type? word]
      exit
   ]
   if not value? word [
      print ["No information on" word "(word has no value)"]
      exit
   ]
   value: get word
   if not any-function? :value [
      print [mold word "is" type? word "of value:" value]
      exit
   ]
   args: third :value
   refmode: false
   either string? pick args 1 [
      print first args args: next args
   ] [
      print "(undocumented)"
   ]
   if block? pick args 1 [
      print "Attributes:"
      item: first args
      args: next args
      while [not tail? item] [
         value: first item
         item: next item
         if any-word? value [
            prin ["   " value "-- "]
            if string? pick item 1 [prin first item item: next item]
            print ""
         ]
      ]
   ]
   if tail? args [exit]
   print "Arguments:"
   while [not tail? args] [
      item: first args
      args: next args
      if (mold item) = "/local" [break]
      if all [refinement? item not refmode] [
         print "Refinements:"
         refmode: true
      ]
      either refinement? item [
         prin ["   " mold item]
         if string? pick args 1 [prin [" --" first args] args: next args]
         print ""
      ] [
         if any-word? item [
            if refmode [prin "    "]
            prin ["   " item "-- "]
            types: if block? pick args 1 [args: next args first back args]
            if string? pick args 1 [prin first args args: next args]
            if types [prin rejoin [" (" types ")"]]
            print ""
         ]
      ]
   ]
   exit
]


I'm not sure it's the best possible implementation, but
it seems to work.


regards,

Ingo


signature: [
    Name:  "Ingo Hohmann"
    email: [EMAIL PROTECTED]
    home:  http://www.2b1.de/Rebol/
] 

Reply via email to