forked from superbobry/io-docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMeta.io
72 lines (65 loc) · 2.68 KB
/
Meta.io
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
# Meta data container object, where
# object is the metadata holder name (<ObjectName> to be more exact)
# <tag> is populted from `metadoc <ObjectName> <tag> ...`
# slots are populted from `doc <ObjectName> <slotName> ...`
Meta := Object clone do(
init := method(
list(
"object", "module", "category", "copyright",
"credits", "license", "description"
) map(slotName, self setSlot(slotName, ""))
# Some of the files doesn't declare category :(
self category = "Uncategorized"
self slots := Map clone
)
asString := method("Meta for `#{object}`" interpolate)
with := method(data,
# Extractring meta signature: <ObjectName> [category|description|etc] ...
line := data beforeSeq("\n") split(" ", "\t")
meta := MetaCache[line removeFirst] # Looking up the Meta object.
# IMPORTANT: why afterSeq() returns `nil` if a given sequence is not found
# while beforeSeq() returns ""?
data = data afterSeq("\n")
data ifNil(data = "") # FIXME: ugly :(
# Possible optimization: construct a separate data structure once
# the category metatag value arrives:
#
# if(data first == "category",
# CategoryCache atPut(data first, data rest join(" "))
# )
meta setSlot(
line removeFirst, line join(" ") appendSeq(data) strip
)
meta
)
slot := method(data,
# Extractring slot signature: <ObjectName> <slotWithArgs> ...
# IMPORTANT: Regex should be a Core module, really
#
# We are only interested in the first line, since slot signature
# is usually (must be?) located there.
line := data beforeSeq("\n") split
meta := MetaCache[line removeFirst] # Looking up the Meta object.
slot := line removeFirst
# If the slot chunk is missing a closing paren, we look through
# the remaining pieces until one is found and then update slot
# signature string with the appropriate slice.
if(slot containsSeq("(") and slot containsSeq(")") not,
line foreach(idx, chunk,
if(chunk containsSeq(")"),
slot appendSeq(" " .. line slice(0, idx + 1) join(" "))
description := line slice(idx + 1) join(" ")
break
)
)
,
description := line join(" ")
)
if(data containsSeq("\n"),
description prependSeq(data afterSeq("\n") asMutable strip)
)
# Puting slot signature and docstring into the Meta slot map.
meta slots atPut(slot, description)
meta
)
)