1 | # table.ysh - Library for tables.
|
2 | #
|
3 | # Usage:
|
4 | # source --builtin table.ysh
|
5 |
|
6 | # make this file a test server
|
7 | source --builtin byo-server-lib.sh
|
8 |
|
9 | proc table (...words; place; ; block) {
|
10 | var n = len(words)
|
11 |
|
12 | # TODO: parse flags
|
13 | #
|
14 | # --by-row
|
15 | # --by-col
|
16 | #
|
17 | # Place is optional
|
18 |
|
19 | if (n === 0) {
|
20 | echo TODO
|
21 | return
|
22 | }
|
23 |
|
24 | var action = words[0]
|
25 |
|
26 | # textual operations
|
27 | case (action) {
|
28 | cat {
|
29 | echo todo
|
30 | }
|
31 | align {
|
32 | echo todo
|
33 | }
|
34 | tabify {
|
35 | echo todo
|
36 | }
|
37 | tabify {
|
38 | echo todo
|
39 | }
|
40 | header {
|
41 | echo todo
|
42 | }
|
43 | slice {
|
44 | # this has typed args
|
45 | # do we do some sort of splat?
|
46 | echo todo
|
47 | }
|
48 | to-tsv {
|
49 | echo todo
|
50 | }
|
51 | }
|
52 |
|
53 | echo TODO
|
54 | }
|
55 |
|
56 | proc test-table {
|
57 | return
|
58 |
|
59 | table (&files1) {
|
60 | cols num_bytes path
|
61 | type Int Str
|
62 |
|
63 | row 10 README.md
|
64 | row 12 main.py
|
65 |
|
66 | row (12, 'lib.py')
|
67 | row (num_bytes=12, path='util.py')
|
68 | }
|
69 |
|
70 | # 2 columns - The default is by column?
|
71 | assert ['Dict' === type(files1)]
|
72 | assert [2 === len(files1)]
|
73 |
|
74 | # Same table
|
75 | table --by-row (&files2) {
|
76 | cols num_bytes path
|
77 | type Int Str
|
78 |
|
79 | row 10 README.md
|
80 | row 12 main.py
|
81 |
|
82 | row (12, 'lib.py')
|
83 | row (num_bytes=12, path='util.py')
|
84 | }
|
85 |
|
86 | # 4 rows
|
87 | assert ['List' === type(files2)]
|
88 | assert [4 === len(files2)]
|
89 | }
|
90 |
|
91 | # "subcommands" of the dialect
|
92 |
|
93 | proc cols (...names) {
|
94 | # cols name age
|
95 | echo TODO
|
96 | }
|
97 |
|
98 | proc types (...types) {
|
99 | # types - Int? Str?
|
100 | echo TODO
|
101 | }
|
102 |
|
103 | proc attr (name; ...values) {
|
104 | # attr units ('-', 'secs')
|
105 | echo TODO
|
106 | }
|
107 |
|
108 | # is this allowed outside table {} blocks too?
|
109 | proc row {
|
110 | echo TODO
|
111 | }
|
112 |
|
113 | #
|
114 | # dplyr names
|
115 | #
|
116 |
|
117 | # TODO: can we parse select?
|
118 |
|
119 | proc where {
|
120 | echo
|
121 | }
|
122 |
|
123 | # TODO: should be able to test argv[0] or something
|
124 | # Or pass to _mutate-transmute
|
125 |
|
126 | proc mutate {
|
127 | echo TODO
|
128 | }
|
129 |
|
130 | proc transmute {
|
131 | echo TODO
|
132 | }
|
133 |
|
134 | proc rename {
|
135 | echo TODO
|
136 | }
|
137 |
|
138 | proc group-by {
|
139 | echo TODO
|
140 | }
|
141 |
|
142 | proc sort-by {
|
143 | echo TODO
|
144 | }
|
145 |
|
146 | proc summary {
|
147 | echo TODO
|
148 | }
|
149 |
|
150 | byo-maybe-main
|