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