Skip to content

Commit dce53ac

Browse files
committed
Document CaT library
1 parent 6a63bf0 commit dce53ac

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
The CaT module is available via `require "pluto:cat"` and provides encoding and decoding for [the Colons and Tabs format](https://docs.soup.do/user/cat).
2+
3+
### `cat.encode`
4+
Returns a string of CaT.
5+
#### Parameters
6+
1. `data` — The table to encode in CaT.
7+
```pluto
8+
local cat = require "pluto:cat"
9+
10+
cat.encode {
11+
List = {
12+
__value = "With Value",
13+
Child = "Also With Value"
14+
}
15+
} |> io.write
16+
--> List: With Value
17+
--> Child: Also With Value
18+
```
19+
20+
### `cat.decode`
21+
Returns a table representing the CaT data.
22+
#### Parameters
23+
1. `data` — The CaT data to decode.
24+
2. `presentation` — How to represent the data as a table. Can be "flat", "flatwithorder", or "full" (default).
25+
26+
```pluto
27+
local cat = require "pluto:cat"
28+
29+
local data = cat.decode [[
30+
List: With Value
31+
Child: Also With Value
32+
]]
33+
34+
print(dumpvar(data))
35+
--> {
36+
--> [1] = {
37+
--> ["value"] = string(10) "With Value",
38+
--> ["name"] = string(4) "List",
39+
--> ["children"] = {
40+
--> [1] = {
41+
--> ["name"] = string(5) "Child",
42+
--> ["value"] = string(15) "Also With Value",
43+
--> },
44+
--> },
45+
--> },
46+
--> }
47+
```
48+
49+
With the default "full" representation, the retuned table has an `__index` metamethod for ease of use:
50+
51+
```pluto
52+
print(data.List.value) --> With Value
53+
print(data.List.Child.value) --> Also With Value
54+
```
55+
56+
Alternatively, the other representations are available:
57+
```pluto
58+
local cat = require "pluto:cat"
59+
60+
print(dumpvar(cat.decode([[
61+
home
62+
john
63+
hello.txt: Hello, world!
64+
]], "flat")))
65+
--> {
66+
--> ["home"] = {
67+
--> ["john"] = {
68+
--> ["hello.txt"] = string(13) "Hello, world!",
69+
--> },
70+
--> },
71+
--> }
72+
```
73+
```pluto
74+
local cat = require "pluto:cat"
75+
76+
print(dumpvar(cat.decode([[
77+
Primary Color: Purple
78+
Secondary Color: White
79+
]], "flatwithorder")))
80+
--> {
81+
--> ["__order"] = {
82+
--> [1] = string(13) "Primary Color",
83+
--> [2] = string(15) "Secondary Color",
84+
--> },
85+
--> ["Primary Color"] = string(6) "Purple",
86+
--> ["Secondary Color"] = string(5) "White",
87+
--> }
88+
```

src/theme/pluto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Prism.languages.pluto = {
44
'function': [
55
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!new)\w+(?=\s*(?:\??\())/, // func()
66
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!not)\w+(?=\s*(?:\??[{"]))/, // func "", func {}
7+
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!not)\w+(?=\s*(?:\??\[\[))/, // func [[
78
/(?<=\|>)\s[\w.]+/, // |> func
89
/\b(function|enum|class)\b/,
910
/\b(os\.platform|json\.null|json\.withnull|json\.withorder)\b/, // standard library constants

0 commit comments

Comments
 (0)