From 1713d4a2e76b350770f70b49d1f324a2e1ee7754 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 1 Feb 2026 15:11:30 +0900 Subject: [PATCH] mruby-bin-mirb: syntax highlight result values and hash key symbols Use syntax highlighter for result values instead of single color. Add support for hash key symbol syntax (e.g., `a:` in `{a: 1}`). Co-authored-by: Claude --- .../mruby-bin-mirb/tools/mirb/mirb_highlight.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c index b196ba971..16e371fc7 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb_highlight.c @@ -443,7 +443,12 @@ mirb_highlight_print_line(mirb_highlighter *hl, const char *line) size_t len = (size_t)(p - token_start); - if (is_const) { + /* Check for hash key symbol syntax: identifier followed by ': ' */ + if (*p == ':' && (p[1] == ' ' || p[1] == '\0' || p[1] == ',' || p[1] == '}')) { + p++; /* include the colon */ + print_colored(hl, token_start, (size_t)(p - token_start), MIRB_TOK_SYMBOL); + } + else if (is_const) { print_colored(hl, token_start, len, MIRB_TOK_CONSTANT); } else if (!after_dot && is_keyword(token_start, len)) { @@ -476,16 +481,16 @@ mirb_highlight_print_result(mirb_highlighter *hl, const char *result) return; } + /* Print arrow in gray */ if (hl->theme == MIRB_THEME_DARK) { fputs(DARK_ARROW " => " COLOR_RESET, stdout); - fputs(DARK_RESULT, stdout); } else { fputs(LIGHT_ARROW " => " COLOR_RESET, stdout); - fputs(LIGHT_RESULT, stdout); } - fputs(result, stdout); - fputs(COLOR_RESET "\n", stdout); + /* Syntax highlight the result value */ + mirb_highlight_print_line(hl, result); + putchar('\n'); } /*