py/repl: Refactor autocomplete to reduce nesting.

Originally at adafruit#4548

Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
This commit is contained in:
Artyom Skrobov 2021-04-07 13:09:39 -04:00 committed by Damien George
parent befbff31b7
commit f85ea8d4fe
1 changed files with 111 additions and 108 deletions

View File

@ -161,15 +161,22 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print
mp_obj_t obj = MP_OBJ_FROM_PTR(&mp_module___main__);
mp_obj_t dest[2];
const char *s_start;
size_t s_len;
for (;;) {
// get next word in string to complete
const char *s_start = str;
s_start = str;
while (str < top && *str != '.') {
++str;
}
size_t s_len = str - s_start;
s_len = str - s_start;
if (str == top) {
// end of string, do completion on this partial name
break;
}
if (str < top) {
// a complete word, lookup in current object
qstr q = qstr_find_strn(s_start, s_len);
if (q == MP_QSTRnull) {
@ -186,9 +193,7 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print
// skip '.' to move to next word
++str;
} else {
// end of string, do completion on this partial name
}
// look for matches
const char *match_str = NULL;
@ -284,8 +289,6 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print
mp_print_str(print, "\n");
return (size_t)(-1); // indicate many matches
}
}
}
#endif // MICROPY_HELPER_REPL