Debian Codegraph @

demo/kitchen-sink/docs/red.red

raw
1 Red []
2 info: func ['fn /name /intro /args /refinements /locals /return /spec
3 /arg-num /arg-names /arg-types /ref-names /ref-types /ref-num /type
4 /local intr ars refs locs ret arg ref typ
5 ][
6 intr: copy "" ars: make map! copy [] refs: make map! copy [] locs: copy [] ret: copy [] typ: ref-arg: ref-arg-type: none
7 if lit-word? fn [fn: to-word fn]
8 unless find [op! native! function! action!] type?/word get fn [
9 cause-error 'user 'message ["Only function types accepted!"]
10 ]
11 out: make map! copy []
12 specs: spec-of get fn
13 parse specs [
14 opt [set intr string!]
15 any [set arg [word! | lit-word!] opt [set typ block!] opt string! (put ars arg either typ [typ][[any-type!]])]
16 any [set ref refinement! [
17 if (ref <> /local) (put refs to-lit-word ref make map! copy [])
18 opt string!
19 any [set ref-arg word! opt [set ref-arg-type block!]
20 (put refs/(to-word ref) to-lit-word ref-arg either ref-arg-type [ref-arg-type][[any-type!]])
21 ]
22 | any [set loc word! (append locs loc) opt string!]
23 opt [set-word! set ret block!]
24 ]]
25
26 (
27 out: case [
28 name [to-word fn]
29 intro [intr]
30 args [ars]
31 arg-num [length? ars]
32 arg-names [copy keys-of ars]
33 arg-types [copy values-of ars]
34 refinements [refs]
35 ref-names [copy keys-of refs]
36 ref-types [copy values-of refs]
37 ref-num [length? refs]
38 locals [locs]
39 return [ret]
40 spec [specs]
41 true [
42 make object! [
43 name: to-word fn
44 intro: intr
45 args: ars
46 refinements: refs
47 locals: locs
48 return: ret
49 spec: specs
50 type: type? get fn
51 arg-num: length? args
52 arg-names: copy keys-of args
53 arg-types: copy values-of args
54 ref-names: copy keys-of refinements
55 ref-types: copy values-of refinements
56 ref-num: length? refinements
57 ]
58 ]
59 ])
60 ]
61 out
62 ]