diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.c index 92d3e5df4..411f6fee2 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.c @@ -8,7 +8,6 @@ #include #include #include -#include #ifdef MRB_UTF8_STRING /* @@ -782,15 +781,6 @@ mirb_buffer_cursor_finish(mirb_buffer *buf) buf->cursor_col = buf->lines[buf->cursor_line].len; } -/* - * Helper: Check if character is word character - */ -static mrb_bool -is_word_char(char c) -{ - return isalnum((unsigned char)c) || c == '_'; -} - /* * Move cursor back one word */ @@ -810,7 +800,7 @@ mirb_buffer_cursor_word_back(mirb_buffer *buf) } char c = buf->lines[buf->cursor_line].data[buf->cursor_col - 1]; - if (is_word_char(c)) break; + if (mirb_is_word_char(c)) break; buf->cursor_col--; moved = TRUE; } @@ -818,7 +808,7 @@ mirb_buffer_cursor_word_back(mirb_buffer *buf) /* Move through word chars */ while (buf->cursor_col > 0) { char c = buf->lines[buf->cursor_line].data[buf->cursor_col - 1]; - if (!is_word_char(c)) break; + if (!mirb_is_word_char(c)) break; buf->cursor_col--; moved = TRUE; } @@ -837,7 +827,7 @@ mirb_buffer_cursor_word_forward(mirb_buffer *buf) /* Move through current word chars */ while (buf->cursor_col < line->len) { - if (!is_word_char(line->data[buf->cursor_col])) break; + if (!mirb_is_word_char(line->data[buf->cursor_col])) break; buf->cursor_col++; moved = TRUE; } @@ -853,7 +843,7 @@ mirb_buffer_cursor_word_forward(mirb_buffer *buf) continue; } - if (is_word_char(line->data[buf->cursor_col])) break; + if (mirb_is_word_char(line->data[buf->cursor_col])) break; buf->cursor_col++; moved = TRUE; } @@ -960,12 +950,12 @@ mirb_buffer_kill_word_forward(mirb_buffer *buf) size_t end_col = start_col; /* Skip word chars */ - while (end_col < line->len && is_word_char(line->data[end_col])) { + while (end_col < line->len && mirb_is_word_char(line->data[end_col])) { end_col++; } /* Skip non-word chars */ - while (end_col < line->len && !is_word_char(line->data[end_col])) { + while (end_col < line->len && !mirb_is_word_char(line->data[end_col])) { end_col++; } diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.h b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.h index 5c1164e89..dd6d0b122 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.h +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_buffer.h @@ -182,4 +182,14 @@ size_t mirb_buffer_line_len(mirb_buffer *buf, size_t index); */ size_t mirb_buffer_cursor_display_col(mirb_buffer *buf); +/* + * Check if character is a word character (alphanumeric or underscore) + */ +static inline mrb_bool +mirb_is_word_char(char c) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || c == '_'; +} + #endif /* MIRB_BUFFER_H */ diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_editor.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_editor.c index a350a56cb..b397baa7d 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_editor.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_editor.c @@ -11,7 +11,6 @@ /* ANSI color codes */ #define COLOR_GREEN "\033[32m" -#define COLOR_RESET "\033[0m" /* * Check if line contains only whitespace before given column diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c index 132a8f35e..44b4bb8d2 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c @@ -5,11 +5,11 @@ */ #include "mirb_highlight.h" +#include "mirb_buffer.h" #include "mirb_term.h" #include #include #include -#include /* ANSI color codes - using standard 16-color palette for compatibility */ @@ -41,8 +41,6 @@ #define LIGHT_ERROR "\033[31m" /* red */ #define LIGHT_ARROW "\033[90m" /* gray */ -#define COLOR_RESET "\033[0m" - /* Keyword list - sorted alphabetically for bsearch, NULL-terminated */ const char *mirb_keywords[] = { "BEGIN", "END", "__ENCODING__", "__FILE__", "__LINE__", @@ -72,13 +70,6 @@ is_keyword(const char *word, size_t len) return bsearch(buf, mirb_keywords, mirb_num_keywords, sizeof(mirb_keywords[0]), keyword_cmp) != NULL; } -static mrb_bool -is_word_char(char c) -{ - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || c == '_'; -} - static mrb_bool is_word_start(char c) { @@ -365,7 +356,7 @@ mirb_highlight_print_line(mirb_highlighter *hl, const char *line) } else { /* Regular symbol */ - while (*p && (is_word_char(*p) || *p == '?' || *p == '!')) p++; + while (*p && (mirb_is_word_char(*p) || *p == '?' || *p == '!')) p++; } print_colored(hl, token_start, (size_t)(p - token_start), MIRB_TOK_SYMBOL); continue; @@ -375,7 +366,7 @@ mirb_highlight_print_line(mirb_highlighter *hl, const char *line) if (*p == '@') { token_start = p++; if (*p == '@') p++; /* @@class_var */ - while (*p && is_word_char(*p)) p++; + while (*p && mirb_is_word_char(*p)) p++; print_colored(hl, token_start, (size_t)(p - token_start), MIRB_TOK_IVAR); continue; } @@ -384,11 +375,11 @@ mirb_highlight_print_line(mirb_highlighter *hl, const char *line) if (*p == '$') { token_start = p++; /* Special globals like $!, $?, $1, etc. */ - if (*p && !is_word_char(*p) && *p != ' ') { + if (*p && !mirb_is_word_char(*p) && *p != ' ') { p++; } else { - while (*p && is_word_char(*p)) p++; + while (*p && mirb_is_word_char(*p)) p++; } print_colored(hl, token_start, (size_t)(p - token_start), MIRB_TOK_GVAR); continue; @@ -396,7 +387,7 @@ mirb_highlight_print_line(mirb_highlighter *hl, const char *line) /* Numbers */ if ((*p >= '0' && *p <= '9') || - (*p == '-' && p[1] >= '0' && p[1] <= '9' && (p == line || !is_word_char(p[-1])))) { + (*p == '-' && p[1] >= '0' && p[1] <= '9' && (p == line || !mirb_is_word_char(p[-1])))) { token_start = p; if (*p == '-') p++; if (*p == '0' && (p[1] == 'x' || p[1] == 'X')) { @@ -440,7 +431,7 @@ mirb_highlight_print_line(mirb_highlighter *hl, const char *line) mrb_bool is_const = is_upper(*p); /* Check if preceded by dot (method call like obj.class) */ mrb_bool after_dot = (token_start > line && token_start[-1] == '.'); - while (*p && (is_word_char(*p) || *p == '?' || *p == '!')) p++; + while (*p && (mirb_is_word_char(*p) || *p == '?' || *p == '!')) p++; size_t len = (size_t)(p - token_start); diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h index 3fab33a94..06d9e9a11 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.h @@ -98,4 +98,7 @@ void mirb_highlight_print_result(mirb_highlighter *hl, const char *result); */ void mirb_highlight_print_error(mirb_highlighter *hl, const char *error); +/* Common ANSI reset code shared across modules */ +#define COLOR_RESET "\033[0m" + #endif /* MIRB_HIGHLIGHT_H */