aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-17 15:23:42 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-17 15:23:42 -0400
commit1647fb4bed03fe5e3d0332049c73fb21a48ef05f (patch)
tree6b9f2c783c0cfd539de35aa620886bf48befc699
parent993284153011006a1164b4b1f6bb1522e5131cb0 (diff)
Unary ops should only parse terms not full expressions
-rw-r--r--parse.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/parse.c b/parse.c
index dd993ed9..50f3ac2d 100644
--- a/parse.c
+++ b/parse.c
@@ -618,9 +618,10 @@ PARSER(parse_array) {
ast_t *item = optional(ctx, &pos, parse_extended_expr);
if (!item) break;
ast_t *suffixed = parse_comprehension_suffix(ctx, item);
- if (suffixed) {
+ while (suffixed) {
item = suffixed;
pos = suffixed->end;
+ suffixed = parse_comprehension_suffix(ctx, item);
}
items = new(ast_list_t, .ast=item, .next=items);
if (!match_separator(&pos))
@@ -663,9 +664,10 @@ PARSER(parse_table) {
ast_t *value = expect(ctx, pos-1, &pos, parse_expr, "I couldn't parse the value for this table entry");
ast_t *entry = NewAST(ctx->file, entry_start, pos, TableEntry, .key=key, .value=value);
ast_t *suffixed = parse_comprehension_suffix(ctx, entry);
- if (suffixed) {
+ while (suffixed) {
entry = suffixed;
pos = suffixed->end;
+ suffixed = parse_comprehension_suffix(ctx, entry);
}
entries = new(ast_list_t, .ast=entry, .next=entries);
if (!match_separator(&pos))
@@ -923,7 +925,7 @@ PARSER(parse_length) {
const char *start = pos;
if (!match(&pos, "#")) return NULL;
spaces(&pos);
- ast_t *val = expect(ctx, start, &pos, parse_expr, "I expected an expression for this '#'");
+ ast_t *val = expect(ctx, start, &pos, parse_term, "I expected an expression for this '#'");
return NewAST(ctx->file, start, pos, Length, .value=val);
}
@@ -931,7 +933,7 @@ PARSER(parse_heap_alloc) {
const char *start = pos;
if (!match(&pos, "@")) return NULL;
spaces(&pos);
- ast_t *val = expect(ctx, start, &pos, parse_expr, "I expected an expression for this '@'");
+ ast_t *val = expect(ctx, start, &pos, parse_term, "I expected an expression for this '@'");
return NewAST(ctx->file, start, pos, HeapAllocate, .value=val);
}
@@ -939,7 +941,7 @@ PARSER(parse_stack_reference) {
const char *start = pos;
if (!match(&pos, "&")) return NULL;
spaces(&pos);
- ast_t *val = expect(ctx, start, &pos, parse_expr, "I expected an expression for this '&'");
+ ast_t *val = expect(ctx, start, &pos, parse_term, "I expected an expression for this '&'");
return NewAST(ctx->file, start, pos, StackReference, .value=val);
}
@@ -947,7 +949,7 @@ PARSER(parse_not) {
const char *start = pos;
if (!match_word(&pos, "not")) return NULL;
spaces(&pos);
- ast_t *val = expect(ctx, start, &pos, parse_expr, "I expected an expression for this 'not'");
+ ast_t *val = expect(ctx, start, &pos, parse_term, "I expected an expression for this 'not'");
return NewAST(ctx->file, start, pos, Not, .value=val);
}