From ecc3a13c342622a8876c46e3b76d61a23fe32dbb Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 28 Mar 2020 16:47:42 +0100 Subject: [PATCH] bistromathic: use symbol numbers instead of YYTRANSLATE * examples/c/bistromathic/parse.y: here. --- examples/c/bistromathic/parse.y | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y index 3ada1ff3..a5d15694 100644 --- a/examples/c/bistromathic/parse.y +++ b/examples/c/bistromathic/parse.y @@ -386,23 +386,25 @@ completion (const char *text, int start, int end) char **matches = calloc (ntokens + symbol_count () + 2, sizeof *matches); int match = 1; for (int i = 0; i < ntokens; ++i) - if (tokens[i] == YYTRANSLATE (TOK_VAR)) - { - for (symrec *s = sym_table; s; s = s->next) - if (s->type == TOK_VAR && strncmp (text, s->name, len) == 0) - matches[match++] = strdup (s->name); - } - else if (tokens[i] == YYTRANSLATE (TOK_FUN)) + switch (tokens[i]) { + case YYSYMBOL_FUN: for (symrec *s = sym_table; s; s = s->next) if (s->type == TOK_FUN && strncmp (text, s->name, len) == 0) matches[match++] = strdup (s->name); - } - else - { - const char* token = yysymbol_name (tokens[i]); - if (strncmp (token, text, strlen (text)) == 0) - matches[match++] = strdup (token); + break; + case YYSYMBOL_VAR: + for (symrec *s = sym_table; s; s = s->next) + if (s->type == TOK_VAR && strncmp (text, s->name, len) == 0) + matches[match++] = strdup (s->name); + break; + default: + { + const char* token = yysymbol_name (tokens[i]); + if (strncmp (text, token, len) == 0) + matches[match++] = strdup (token); + break; + } } // Find the longest common prefix, and install it in matches[0], as