standardize return values + errno
[protos/libecoli.git] / lib / todo.txt
1 tk_cmd
2 ======
3
4 X evaluate expression tree in ec_tk_expr
5 X cmd token
6 - example
7 X tk_re
8
9 cleanup / rework
10 ================
11
12 X ec_completed_item_update()
13 X ec_completed_item_set_display_value()
14 X add_no_match
15 X add_partial_match
16 - check XXX in code
17 X properly manage quotes in shlex
18 X remove the _new() functions
19 X iterate children nodes without chaining them
20 - add a node vector type: will be used in several nodes (ex: or, seq, ...)
21 - check allocation model everywhere
22 - checkpatch?
23 - use linux style (update .emacs)
24 - better logs
25 - check return values (-1 or NULL) + use errno
26 - check missing static / const
27 - license: SPDX
28 - check all completion nodes
29 X split ecoli_tk.h
30 - size_t or unsigned int?
31 X rename:
32   X ec_tk -> ec_node
33   X ec_parsed_tk -> ec_parsed
34   X ec_completed_tk -> ec_completed
35   X tk, gen_tk, token, ... -> node
36   X tokens -> input_str / input_strvec ?
37 X save node path in completion to fix help string
38 - code coverage
39 - try to hide structures
40 - anything better than weakref?
41 - add ec_node_defaults.[ch] providing usual implementations of node methods
42 X use vec for strvec
43 - ELOOP in case of loop
44 - remove weakref?
45
46 dependencies
47 ============
48
49 X pass the current parsed state when parsing/completing
50 X new node "once"
51 - new node "condition"
52
53 logs
54 ====
55
56 X register log types
57
58 yaml
59 ====
60
61 X register nodes by name
62 - interface to add attributes: all nodes must be configurable through a
63   generic api
64   - attr string
65   - attr string list
66   - attr node
67   - attr node list
68   - attr int
69
70 - yaml interface to create nodes
71 - example
72
73 examples
74 ========
75
76 - example which parses arguments (argc/argv)
77 - example that acts as bash completion (ip link ?)
78 - calculator example (var assignation, expression evaluation)
79 - example with libedit
80 - mini script language
81 - configuration file
82 - mini shell: cd, ls, cat, stat
83 - mini network console based on ip
84
85 doc
86 ===
87
88 - overview
89 - add api doc in .h
90 - generate automatic api doc
91 - architecture
92 - coding rules, process
93 - each node
94 - allocation model
95 - say that it stops at first match (no ambigous support)
96 - say that completion must be exhaustive
97
98 build framework
99 ===============
100
101 - .map files for API
102 - split libs, tests and examples
103 - add make help
104 - add make config
105 - -fvisibility=
106
107 tests
108 =====
109
110 - complete automatic tests with "make test"
111
112 new nodes
113 =========
114
115 - regexp
116 - node which always matches
117 - file + partial completion
118 - ether, ip, network
119 - fusion node: need to match several children, same for completion
120 - float
121 - not
122
123 encoding
124 ========
125
126 - support utf-8 and other encodings
127 - example
128 - documentation
129
130 netconf example
131 ===============
132
133 - demonstration example that parses yang file and generate cli
134
135
136
137 -----------------------
138
139 readline:
140
141 [tab]  list possible completions (matches/partial only)
142 [?]    list what is expected, example:
143
144 "command [foo] toto|titi|<int>"
145
146 help("command f") ->
147   foo     (help of foo)
148   toto    (help of toto)
149   titi    (help of titi)
150   <int>   (help of int)
151
152
153 ----------------
154
155 struct names
156 ============
157
158 ideas:
159
160 - ec_node: a node that can be parsed/completed
161 - ec_parse: a tree describing the result of parse(node, input)
162 - ec_comp: a list describing the result of complete(node, input)
163
164 ec_comp_item
165
166
167 ---------------
168
169 node tree
170 =========
171
172 Example:
173
174 1  seq
175 2    option
176 3      str(foo)
177 4    or
178 5      int(1,10)
179 6      str(bar)
180 7      str(foo)
181
182 parse() returns a tree
183 =======
184
185 - each node of the tree refers to a ec_node
186 - each node points to the strvec that matches
187 - parse returns the first matching solution
188 - usually try to match as many str in the vecs (seq node)
189
190 [foo] ->
191 1 seq
192 2   option
193 4   or
194 7     str(foo)
195
196 The parse cb of the node is:
197
198 parse_cb(node, current_parse_state, strvec, *nmatch)
199
200 return values:
201 - 0: success, child->strvec is set by node (NULL = no_match)
202 - -1: error (errno is set)
203 maybe complex to use:
204 - the node must set the match (ex: "return ec_parsed_node_match()")
205 - the caller must use accessor to check if it matches or not
206
207 alternative idea for return values:
208 - >= 0: match, ret == nb_tk
209 - -1: error (errno is set)
210 - -2 or MAX_INT: success, but no match
211 This is strange to have a specific value for no match
212 With MAX_INT, this is the best (less bad) alternative
213
214 alternative idea for return values:
215 - ec_parse_result_match(n_tokens >= 0)
216 - ec_parse_result_nomatch()
217 - ec_parse_result_error(errno)
218
219 A node always try to consume the maximum number of tokens.
220 Example:
221 1  seq
222 2    option
223 3      str(foo)
224 4    str(foo)
225 5    str(bar)
226
227 [foo, foo, bar] matches
228 [foo, bar] does *not* match
229
230 complete() returns a list of possible completions
231 ==========
232
233 problems:
234 - partial completion: in a path dir/file, completion stops once
235   after the directory
236 - displayed value is not the completion token: when completing a
237   file in several subdirectories, the full path is not displayed
238 - any parent node can modify the completions, ex: add missing quotes
239   in ec_node_sh_lex(), filter completions in case of a ec_node_filter()
240 - a command line may want to display the help from the most specific
241   token, or not.
242 - some specific nodes can complete several tokens
243
244 struct item {
245   const char *str;
246   type: full, partial, unknown
247 }
248
249 full: the completion item matches token
250 partial: beginning of a completion, does not match the token
251          (good example is a directory in a path)
252 unknown: could complete, but the node does not know how
253
254 struct completion_item {
255   const char *value;
256   const char *disp;
257 }
258
259 struct completed_elt {
260   ec_parsed *parse_tree; // current tree state
261   ec_node *last;         // last node of the tree
262   list of items;         // list of items for this parse tree
263 }
264
265 struct completed {
266   list(elt)
267 }
268
269 The callback is:
270
271 complete_cb(node, current_complete_state, current_parse_state, strvec)
272 return:
273 - 0 = success, the current complete state is updated
274 - -1 = error (set errno?)
275
276
277 a node can filter the completions
278
279
280 [] ->
281   foo   3 str(foo)
282     seq
283       option
284         str(foo) <-
285
286   ""    5 int(1,10)
287     seq
288       option
289       or
290         int <-
291
292   bar   6 str(bar)
293   foo   7 str(bar)
294 ...
295
296
297 [foo, ] ->
298
299   ?       5 int(1,10)
300   seq
301     option
302       str(foo)
303     or
304       int <-
305
306   bar   6 str(bar)
307   foo   7 str(bar)
308
309
310
311 -----
312
313 changes:
314 - a completion item should contain a strvec for the value
315   (the display string remains a string)
316 - there is maybe no good reason to split in:
317   - ec_completed_item()
318   - ec_completed_item_set()
319   - ec_completed_item_set_display()
320   - ec_completed_item_add()
321
322 -----
323
324 sh_lex
325   or
326     str(foo)
327     str(foo2)
328     str(bar)
329
330 complete(sh_lex, ["'fo"])
331   complete(sh_lex, ["fo"]) -> ["foo", "foo2"]
332   
333
334 -----
335
336 #include <stdio.h>
337 #include <stdbool.h>
338
339
340 struct res {
341         int a;
342 };
343
344 static inline bool is_success(struct res r)
345 {
346         if (r.a == 0)
347                 return true;
348         return false;
349 }
350
351
352 static inline struct res res(int a)
353 {
354         struct res r;
355         r.a = a;
356         return r;
357 }
358
359 int main(void)
360 {
361         struct res r;
362
363         r = res(0);
364
365         printf("%d\n", r.a);
366         if (is_success(r))
367                 printf("success: %d\n", r.a);
368
369         r = res(1);
370
371         printf("%d\n", r.a);
372         if (is_success(r))
373                 printf("success: %d\n", r.a);
374
375         return 0;
376 }
377
378
379 ----
380
381
382 expr expr expr
383
384 [toto] | tutu
385
386 [toto [titi]]
387
388
389
390 pre_op = "!"
391 post_op = "^"
392 post = val |
393        pre_op expr |
394        "(" expr ")"
395 term = post post_op*
396 prod = term ( "*" term )*
397 sum = prod ( "+" prod )*
398 expr = sum
399
400
401 -----
402
403 break on malloc:
404
405 b debug_malloc
406 run <args...>
407 watch seq
408 condition <breakpoint num> seq == <value>
409 c