16521f03241bd2ab2b986322c87645f29e730e85
[protos/libecoli.git] / todo.txt
1 tk_cmd
2 ======
3
4 X evaluate expression tree in ec_tk_expr
5 X cmd token
6 X 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 X 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 X 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 X remove weakref?
45 - sh_lex to provide offsets in attributes
46 - accessors for all structs
47 - private vs user attributes?
48
49 dependencies
50 ============
51
52 X pass the current parsed state when parsing/completing
53 X new node "once"
54 - new node "condition"
55
56 logs
57 ====
58
59 X register log types
60
61 yaml
62 ====
63
64 X register nodes by name
65 X interface to add attributes: all nodes must be configurable through a
66   generic api:
67   X attr string
68   X attr string list
69   X attr node
70   X attr node list
71   X attr int
72
73 X yaml interface to create nodes
74 - example
75
76 examples
77 ========
78
79 - example which parses arguments (argc/argv)
80 - example that acts as bash completion (ip link ?)
81 - calculator example (var assignation, expression evaluation)
82 - example with libedit
83 - mini script language
84 - configuration file
85 - mini shell: cd, ls, cat, stat
86 - mini network console based on ip
87 - dialog-like for use in shell
88
89 doc
90 ===
91
92 - overview
93 - add api doc in .h
94 - generate automatic api doc
95 - architecture
96 - coding rules, process
97 - each node
98 - allocation model
99 - say that it stops at first match (no ambigous support)
100 - say that completion must be exhaustive
101
102 build framework
103 ===============
104
105 - .map files for API
106 - split libs, tests and examples
107 - add make help
108 - add make config
109 - -fvisibility=
110 - use meson
111
112 tests
113 =====
114
115 - complete automatic tests with "make test"
116
117 new nodes
118 =========
119
120 - regexp
121 X node which always matches
122 X file + partial completion
123 - ether, ip, network
124 - fusion node: need to match several children, same for completion?
125 - float
126 - not
127 - reparse: parse a tree with received strvec, then another tree
128   with strvec generated from first tree
129
130 encoding
131 ========
132
133 - support utf-8 and other encodings
134 - example
135 - documentation
136
137 netconf example
138 ===============
139
140 / demonstration example that parses yang file and generate cli
141
142
143
144 -----------------------
145
146 readline:
147
148 [tab]  list possible completions (matches/partial only)
149 [?]    list what is expected, example:
150
151 "command [foo] toto|titi|<int>"
152
153 help("command f") ->
154   foo     (help of foo)
155   toto    (help of toto)
156   titi    (help of titi)
157   <int>   (help of int)
158
159
160 ----------------
161
162 struct names
163 ============
164
165 ideas:
166
167 - ec_node: a node that can be parsed/completed
168 - ec_parse: a tree describing the result of parse(node, input)
169 - ec_comp: a list describing the result of complete(node, input)
170
171 ec_comp_item
172
173
174 ---------------
175
176 node tree
177 =========
178
179 Example:
180
181 1  seq
182 2    option
183 3      str(foo)
184 4    or
185 5      int(1,10)
186 6      str(bar)
187 7      str(foo)
188
189 parse() returns a tree
190 =======
191
192 - each node of the tree refers to a ec_node
193 - each node points to the strvec that matches
194 - parse returns the first matching solution
195 - usually try to match as many str in the vecs (seq node)
196
197 [foo] ->
198 1 seq
199 2   option
200 4   or
201 7     str(foo)
202
203 The parse cb of the node is:
204
205 parse_cb(node, current_parse_state, strvec, *nmatch)
206
207 return values:
208 - 0: success, child->strvec is set by node (NULL = no_match)
209 - -1: error (errno is set)
210 maybe complex to use:
211 - the node must set the match (ex: "return ec_parsed_node_match()")
212 - the caller must use accessor to check if it matches or not
213
214 alternative idea for return values:
215 - >= 0: match, ret == nb_tk
216 - -1: error (errno is set)
217 - -2 or MAX_INT: success, but no match
218 This is strange to have a specific value for no match
219 With MAX_INT, this is the best (less bad) alternative
220
221 alternative idea for return values:
222 - ec_parse_result_match(n_tokens >= 0)
223 - ec_parse_result_nomatch()
224 - ec_parse_result_error(errno)
225
226 A node always try to consume the maximum number of tokens.
227 Example:
228 1  seq
229 2    option
230 3      str(foo)
231 4    str(foo)
232 5    str(bar)
233
234 [foo, foo, bar] matches
235 [foo, bar] does *not* match
236
237 complete() returns a list of possible completions
238 ==========
239
240 problems:
241 - partial completion: in a path dir/file, completion stops once
242   after the directory
243 - displayed value is not the completion token: when completing a
244   file in several subdirectories, the full path is not displayed
245 - any parent node can modify the completions, ex: add missing quotes
246   in ec_node_sh_lex(), filter completions in case of a ec_node_filter()
247 - a command line may want to display the help from the most specific
248   token, or not.
249 - some specific nodes can complete several tokens
250
251 struct item {
252   const char *str;
253   type: full, partial, unknown
254 }
255
256 full: the completion item matches token
257 partial: beginning of a completion, does not match the token
258          (good example is a directory in a path)
259 unknown: could complete, but the node does not know how
260
261 struct completion_item {
262   const char *value;
263   const char *disp;
264 }
265
266 struct completed_elt {
267   ec_parsed *parse_tree; // current tree state
268   ec_node *last;         // last node of the tree
269   list of items;         // list of items for this parse tree
270 }
271
272 struct completed {
273   list(elt)
274 }
275
276 The callback is:
277
278 complete_cb(node, current_complete_state, current_parse_state, strvec)
279 return:
280 - 0 = success, the current complete state is updated
281 - -1 = error (set errno?)
282
283
284 a node can filter the completions
285
286
287 [] ->
288   foo   3 str(foo)
289     seq
290       option
291         str(foo) <-
292
293   ""    5 int(1,10)
294     seq
295       option
296       or
297         int <-
298
299   bar   6 str(bar)
300   foo   7 str(bar)
301 ...
302
303
304 [foo, ] ->
305
306   ?       5 int(1,10)
307   seq
308     option
309       str(foo)
310     or
311       int <-
312
313   bar   6 str(bar)
314   foo   7 str(bar)
315
316
317
318 -----
319
320 changes:
321 - a completion item should contain a strvec for the value
322   (the display string remains a string)
323 - there is maybe no good reason to split in:
324   - ec_completed_item()
325   - ec_completed_item_set()
326   - ec_completed_item_set_display()
327   - ec_completed_item_add()
328
329 -----
330
331 sh_lex
332   or
333     str(foo)
334     str(foo2)
335     str(bar)
336
337 complete(sh_lex, ["'fo"])
338   complete(sh_lex, ["fo"]) -> ["foo", "foo2"]
339   
340
341 -----
342
343 #include <stdio.h>
344 #include <stdbool.h>
345
346
347 struct res {
348         int a;
349 };
350
351 static inline bool is_success(struct res r)
352 {
353         if (r.a == 0)
354                 return true;
355         return false;
356 }
357
358
359 static inline struct res res(int a)
360 {
361         struct res r;
362         r.a = a;
363         return r;
364 }
365
366 int main(void)
367 {
368         struct res r;
369
370         r = res(0);
371
372         printf("%d\n", r.a);
373         if (is_success(r))
374                 printf("success: %d\n", r.a);
375
376         r = res(1);
377
378         printf("%d\n", r.a);
379         if (is_success(r))
380                 printf("success: %d\n", r.a);
381
382         return 0;
383 }
384
385
386 ----
387
388
389 expr expr expr
390
391 [toto] | tutu
392
393 [toto [titi]]
394
395
396
397 pre_op = "!"
398 post_op = "^"
399 post = val |
400        pre_op expr |
401        "(" expr ")"
402 term = post post_op*
403 prod = term ( "*" term )*
404 sum = prod ( "+" prod )*
405 expr = sum
406
407
408 -----
409
410 break on malloc:
411
412 b debug_malloc
413 # or: b debug_realloc
414 condition <breakoint num> malloc_seq >= <value>
415
416 alternative
417
418 watch malloc_seq
419 condition <watchpoint num> malloc_seq == <value + 1>
420 run <args...>
421 c
422
423
424 ---------------
425
426
427 about split in several libraries
428
429 There are several options:
430
431 1/ one library, config options to select libyaml, libedit
432    - need to manage dependencies in build system
433
434 2/ one library for ecoli-core, one for ecoli-yaml, one for
435    ecoli-edit
436    - extra complexity
437
438 3/ one library with core + yaml + edit
439    dependency is managed at runtime
440
441
442 --------------
443
444 current naming: ec_node_parse* and ec_comp_complete* are not
445 so good names
446
447 struct          ec_comp
448 alloc           ec_complete()
449 free            ec_complete_free()
450 action          ec_comp_complete()
451 action          ec_comp_complete_strvec()
452 action          ec_comp_dump()
453 action          ec_comp_merge()
454 accessors       ec_comp_get()
455
456 struct          ec_parse
457 alloc           ec_parse()
458 free            ec_parse_free()
459 action          ec_node_parse()
460 action          ec_node_parse_strvec()
461 accessors       ...
462
463 struct          ec_node
464 alloc           ec_node()
465 free            ec_node_free()
466 action          ...
467 accessors       ...
468
469 struct          ec_strvec
470 alloc           ec_strvec()
471 free            ec_strvec_free()
472 action          ec_strvec_*()
473
474 ---------
475
476 proposal
477
478 - struct name must not be a verb (ex: not ec_parse)
479 - allocator is the name of struct
480 - actions are <structname>_<verb>() except for basic/common actions
481 - basic actions are ec_<verb>()
482 - accessors (get) are <structname>_<field>()
483 - accessors (set) are <structname>_set_<field>()
484
485
486 XXX list all functions to be sure
487 XXX this could go in documentation (coding rules)
488
489 struct          ec_comp
490 alloc           ec_comp()
491 free            ec_comp_free()
492 action          ec_complete()
493 action          ec_complete_strvec()
494 action          ec_comp_dump()
495 action          ec_comp_merge()
496 accessors       ec_comp_id()
497 accessors       ec_comp_attrs()
498
499 (pnode means parsed node)
500 struct          ec_pnode
501 alloc           ec_pnode()
502 free            ec_pnode_free()
503 action          ec_parse()
504 action          ec_parse_strvec()
505 accessors       ...
506
507 (node means grammar node)
508 struct          ec_node
509 alloc           ec_node()
510 free            ec_node_free()
511 action          ...
512 accessors       ec_node_get*()
513
514 struct          ec_strvec
515 alloc           ec_strvec()
516 free            ec_strvec_free()
517 action          ec_strvec_*()
518