OILS / stdlib / ysh / table.ysh View on Github | oilshell.org

150 lines, 90 significant
1# table.ysh - Library for tables.
2#
3# Usage:
4# source --builtin table.ysh
5
6# make this file a test server
7source --builtin osh/byo-server.sh
8
9proc 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
56proc 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
93proc cols (...names) {
94 # cols name age
95 echo TODO
96}
97
98proc types (...types) {
99 # types - Int? Str?
100 echo TODO
101}
102
103proc attr (name; ...values) {
104 # attr units ('-', 'secs')
105 echo TODO
106}
107
108# is this allowed outside table {} blocks too?
109proc row {
110 echo TODO
111}
112
113#
114# dplyr names
115#
116
117# TODO: can we parse select?
118
119proc where {
120 echo
121}
122
123# TODO: should be able to test argv[0] or something
124# Or pass to _mutate-transmute
125
126proc mutate {
127 echo TODO
128}
129
130proc transmute {
131 echo TODO
132}
133
134proc rename {
135 echo TODO
136}
137
138proc group-by {
139 echo TODO
140}
141
142proc sort-by {
143 echo TODO
144}
145
146proc summary {
147 echo TODO
148}
149
150byo-maybe-run