aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-03 14:48:54 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-03 14:48:54 -0400
commit29a87ff325b5d9682593d66bd17964e5c2447510 (patch)
treec51a94d99604b535ece0bd059621908a4e96ae66 /typecheck.c
parentde7b564a91dae14f61732117450e23c5898f75f2 (diff)
Support literal Text("blah") for text that is constant ASCII strings
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/typecheck.c b/typecheck.c
index 27e20b04..b5a4a4c1 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -1377,8 +1377,16 @@ bool is_constant(env_t *env, ast_t *ast)
}
case TextJoin: {
auto text = Match(ast, TextJoin);
- // TODO: support short literal strings
- return !text->children;
+ if (!text->children) return true; // Empty string, OK
+ if (text->children->next) return false; // Concatenation, not constant
+
+ CORD literal = Match(text->children->ast, TextLiteral)->cord;
+ CORD_pos i;
+ CORD_FOR(i, literal) {
+ if (!isascii(CORD_pos_fetch(i)))
+ return false; // Non-ASCII requires grapheme logic, not constant
+ }
+ return true; // Literal ASCII string, OK
}
case Not: return is_constant(env, Match(ast, Not)->value);
case Negative: return is_constant(env, Match(ast, Negative)->value);