diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 00:04:48 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 00:04:48 -0400 |
| commit | 3554c56b209a1544c69e189ddab3b19b4bf80ae6 (patch) | |
| tree | 9d494e7b7ec4da3bad49c516b35e98a5829bb81c /src | |
| parent | 4afc7125ab42437e41508d9953a97333f6f87362 (diff) | |
Add easter egg: `~colorized`
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast.h | 1 | ||||
| -rw-r--r-- | src/compile.c | 3 | ||||
| -rw-r--r-- | src/parse.c | 3 |
3 files changed, 5 insertions, 2 deletions
@@ -179,6 +179,7 @@ struct ast_s { struct { const char *lang; ast_list_t *children; + bool colorize:1; } TextJoin; struct { const char *path; diff --git a/src/compile.c b/src/compile.c index 6cb25de0..40d9ed4e 100644 --- a/src/compile.c +++ b/src/compile.c @@ -2775,6 +2775,7 @@ CORD compile(env_t *env, ast_t *ast) } case TextJoin: { const char *lang = Match(ast, TextJoin)->lang; + const char *colorize = Match(ast, TextJoin)->colorize ? "yes" : "no"; type_t *text_t = lang ? Table$str_get(*env->types, lang) : TEXT_TYPE; if (!text_t || text_t->tag != TextType) @@ -2811,7 +2812,7 @@ CORD compile(env_t *env, ast_t *ast) if (chunk_t->tag == TextType) chunk_code = compile(env, chunk->ast); else - chunk_code = compile_string(env, chunk->ast, "no"); + chunk_code = compile_string(env, chunk->ast, colorize); } else { code_err(chunk->ast, "I don't know how to convert ", type_to_str(chunk_t), " to ", type_to_str(text_t)); } diff --git a/src/parse.c b/src/parse.c index d142e780..fd37fec7 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1306,7 +1306,8 @@ PARSER(parse_text) { bool allow_escapes = (open_quote != '`'); ast_list_t *chunks = _parse_text_helper(ctx, &pos, open_quote, close_quote, open_interp, allow_escapes); - return NewAST(ctx->file, start, pos, TextJoin, .lang=lang, .children=chunks); + bool colorize = match(&pos, "~") && match_word(&pos, "colorized"); + return NewAST(ctx->file, start, pos, TextJoin, .lang=lang, .children=chunks, .colorize=colorize); } PARSER(parse_path) { |
