-
Notifications
You must be signed in to change notification settings - Fork 0
/
json-docs.nk
76 lines (54 loc) · 1.75 KB
/
json-docs.nk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"Outputs to STDOUT JSON documentation for all toplevel entries
defined at the time of running this script."
"Do these before everything else so that the 'names*' result
doesn't include the JSON generation words."
this $: _toplevel
_toplevel entry:names* $: _toplevelWords
[ "( Q -- Js ): leaves a JSON string literal for Quote.
Use for properties with string values."
asQuote
'\n' '\\n' replaceAll
'\t' '\\t' replaceAll
'"' '\\"' replaceAll
'\\\\\'' '\\\'' replaceAll "FIXME: this fucks up highlighting but at least is valid JSON"
'\\\'' '\'' replaceAll
$: quote
[ '"' quote '"' ] ~*
] @: string
[ "( D -- Jn ): leaves a JSON number literal for Decimal.
Use for properties with numeric values."
asDecimal toQuote
] @: number
[ "( K V -- Jp ): leaves JSON property with the given Key
and Value quotes."
asQuote $: value
asQuote $: key
[ '"' key '": ' value ] ~*
] @: property
[ "( Mq -- Jo ): leaves JSON object with the given Member
quotes, i.e., results of running `property`."
asBlock vals $: members
[ '{ ' members sepBy: ', ' ' }' ] vals join
] @: object
[ "( Iq -- Ja ): leaves JSON array with the given Item
quotes, i.e., results of running `object`, `string`,
`decimal`, or `array`."
asBlock vals $: items
[ '[ ' items sepBy: ', ' ' ]' ] vals join
] @: array
[
'words'
_toplevelWords map: [ $: word
word private? => next
word #__preambles__ = => next
_toplevel word entry:fetch $: form
form typedesc
anyof: [ 'builtin' 'block' 'foreign struct layout' 'foreign function' ]
or: next
word toQuote [
'name' word toQuote string property
'desc' form desc string property
] object property
] object property
] object
echo