diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.c index 06ca3317d..e889af07b 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_completion.c @@ -5,6 +5,7 @@ */ #include "mirb_completion.h" +#include "mirb_highlight.h" #include #include #include @@ -58,17 +59,6 @@ strndup(const char *s, size_t n) #define ISALNUM(c) isalnum((unsigned char)(c)) #endif -/* Ruby keywords */ -static const char *ruby_keywords[] = { - "BEGIN", "END", "__ENCODING__", "__FILE__", "__LINE__", - "alias", "and", "begin", "break", "case", "class", "def", - "defined?", "do", "else", "elsif", "end", "ensure", "false", - "for", "if", "in", "module", "next", "nil", "not", "or", - "redo", "rescue", "retry", "return", "self", "super", "then", - "true", "undef", "unless", "until", "when", "while", "yield", - NULL -}; - /* ============================================================ * Core Completion Engine * ============================================================ */ @@ -377,8 +367,8 @@ void mirb_complete_keywords(mirb_completion_ctx *ctx) { int i; - for (i = 0; ruby_keywords[i] != NULL; i++) { - mirb_add_completion(ctx, ruby_keywords[i]); + for (i = 0; mirb_keywords[i] != NULL; i++) { + mirb_add_completion(ctx, mirb_keywords[i]); } } diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c index 16e371fc7..132a8f35e 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c @@ -43,16 +43,17 @@ #define COLOR_RESET "\033[0m" -/* Keyword list - must be sorted alphabetically for bsearch */ -static const char *keywords[] = { +/* Keyword list - sorted alphabetically for bsearch, NULL-terminated */ +const char *mirb_keywords[] = { "BEGIN", "END", "__ENCODING__", "__FILE__", "__LINE__", "alias", "and", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "false", "for", "if", "in", "module", "next", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "super", "then", - "true", "undef", "unless", "until", "when", "while", "yield" + "true", "undef", "unless", "until", "when", "while", "yield", + NULL }; -#define NUM_KEYWORDS (sizeof(keywords) / sizeof(keywords[0])) +const size_t mirb_num_keywords = sizeof(mirb_keywords) / sizeof(mirb_keywords[0]) - 1; static int keyword_cmp(const void *a, const void *b) @@ -68,7 +69,7 @@ is_keyword(const char *word, size_t len) if (len >= sizeof(buf)) return FALSE; memcpy(buf, word, len); buf[len] = '\0'; - return bsearch(buf, keywords, NUM_KEYWORDS, sizeof(keywords[0]), keyword_cmp) != NULL; + return bsearch(buf, mirb_keywords, mirb_num_keywords, sizeof(mirb_keywords[0]), keyword_cmp) != NULL; } static mrb_bool diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h index a6383f9fa..3fab33a94 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h @@ -48,6 +48,12 @@ typedef struct mirb_highlighter { mrb_bool in_regexp; } mirb_highlighter; +/* + * Ruby keyword list (sorted alphabetically, NULL-terminated) + */ +extern const char *mirb_keywords[]; +extern const size_t mirb_num_keywords; + /* * Initialize highlighter with auto-detected or specified theme */