From fd74479a2bf2e4ccc35d1c2fa206de8f28be1e54 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 21 Sep 2025 16:28:57 -0400 Subject: Deprecate optional '?' postfix operator --- src/parse/binops.c | 3 +-- src/parse/expressions.c | 15 ++++++--------- src/parse/suffixes.c | 7 ------- src/parse/suffixes.h | 1 - 4 files changed, 7 insertions(+), 19 deletions(-) (limited to 'src/parse') diff --git a/src/parse/binops.c b/src/parse/binops.c index 4676b249..dd1ac3c2 100644 --- a/src/parse/binops.c +++ b/src/parse/binops.c @@ -73,8 +73,7 @@ ast_t *parse_infix_expr(parse_ctx_t *ctx, const char *pos, int min_tightness) { progress = (false || (new_term = parse_index_suffix(ctx, key)) || (new_term = parse_method_call_suffix(ctx, key)) || (new_term = parse_field_suffix(ctx, key)) - || (new_term = parse_fncall_suffix(ctx, key)) || (new_term = parse_optional_suffix(ctx, key)) - || (new_term = parse_non_optional_suffix(ctx, key))); + || (new_term = parse_fncall_suffix(ctx, key)) || (new_term = parse_non_optional_suffix(ctx, key))); if (progress) key = new_term; } if (key && key->tag == Var) key = NULL; diff --git a/src/parse/expressions.c b/src/parse/expressions.c index 7410f678..3cb47669 100644 --- a/src/parse/expressions.c +++ b/src/parse/expressions.c @@ -54,10 +54,9 @@ ast_t *parse_reduction(parse_ctx_t *ctx, const char *pos) { ast_t *key = NewAST(ctx->file, pos, pos, Var, .name = op_str); for (bool progress = true; progress;) { ast_t *new_term; - progress = - (false || (new_term = parse_index_suffix(ctx, key)) || (new_term = parse_method_call_suffix(ctx, key)) - || (new_term = parse_field_suffix(ctx, key)) || (new_term = parse_fncall_suffix(ctx, key)) - || (new_term = parse_optional_suffix(ctx, key)) || (new_term = parse_non_optional_suffix(ctx, key))); + progress = (false || (new_term = parse_index_suffix(ctx, key)) + || (new_term = parse_method_call_suffix(ctx, key)) || (new_term = parse_field_suffix(ctx, key)) + || (new_term = parse_fncall_suffix(ctx, key)) || (new_term = parse_non_optional_suffix(ctx, key))); if (progress) key = new_term; } if (key && key->tag == Var) key = NULL; @@ -98,8 +97,7 @@ ast_t *parse_heap_alloc(parse_ctx_t *ctx, const char *pos) { ast_t *ast = NewAST(ctx->file, start, pos, HeapAllocate, .value = val); for (;;) { - ast_t *next = parse_optional_suffix(ctx, ast); - if (!next) next = parse_non_optional_suffix(ctx, ast); + ast_t *next = parse_non_optional_suffix(ctx, ast); if (!next) break; ast = next; } @@ -123,8 +121,7 @@ ast_t *parse_stack_reference(parse_ctx_t *ctx, const char *pos) { ast_t *ast = NewAST(ctx->file, start, pos, StackReference, .value = val); for (;;) { - ast_t *next = parse_optional_suffix(ctx, ast); - if (!next) next = parse_non_optional_suffix(ctx, ast); + ast_t *next = parse_non_optional_suffix(ctx, ast); if (!next) break; ast = next; } @@ -212,7 +209,7 @@ ast_t *parse_term(parse_ctx_t *ctx, const char *pos) { progress = (false || (new_term = parse_index_suffix(ctx, term)) || (new_term = parse_method_call_suffix(ctx, term)) || (new_term = parse_field_suffix(ctx, term)) || (new_term = parse_fncall_suffix(ctx, term)) - || (new_term = parse_optional_suffix(ctx, term)) || (new_term = parse_non_optional_suffix(ctx, term))); + || (new_term = parse_non_optional_suffix(ctx, term))); if (progress) term = new_term; } return term; diff --git a/src/parse/suffixes.c b/src/parse/suffixes.c index 312f958f..7493a65d 100644 --- a/src/parse/suffixes.c +++ b/src/parse/suffixes.c @@ -25,13 +25,6 @@ ast_t *parse_field_suffix(parse_ctx_t *ctx, ast_t *lhs) { return NewAST(ctx->file, lhs->start, pos, FieldAccess, .fielded = lhs, .field = field); } -ast_t *parse_optional_suffix(parse_ctx_t *ctx, ast_t *lhs) { - if (!lhs) return NULL; - const char *pos = lhs->end; - if (match(&pos, "?")) return NewAST(ctx->file, lhs->start, pos, Optional, .value = lhs); - else return NULL; -} - ast_t *parse_non_optional_suffix(parse_ctx_t *ctx, ast_t *lhs) { if (!lhs) return NULL; const char *pos = lhs->end; diff --git a/src/parse/suffixes.h b/src/parse/suffixes.h index da2f23a2..23ca7182 100644 --- a/src/parse/suffixes.h +++ b/src/parse/suffixes.h @@ -11,4 +11,3 @@ ast_t *parse_index_suffix(parse_ctx_t *ctx, ast_t *lhs); ast_t *parse_method_call_suffix(parse_ctx_t *ctx, ast_t *self); ast_t *parse_non_optional_suffix(parse_ctx_t *ctx, ast_t *lhs); ast_t *parse_optional_conditional_suffix(parse_ctx_t *ctx, ast_t *stmt); -ast_t *parse_optional_suffix(parse_ctx_t *ctx, ast_t *lhs); -- cgit v1.2.3