aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-18 01:27:25 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-18 01:27:25 -0500
commiteabff011ea552a4fecc13de129e0a205b77bc289 (patch)
tree21fd0c14e9d7dcadab6d3e3339193476eb850793 /parse.c
parent733ebfd234906aac08a66e6c2ebe7ed2a0c4d375 (diff)
Add in '#' operator for length
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index 571f5676..5c9520ea 100644
--- a/parse.c
+++ b/parse.c
@@ -839,6 +839,14 @@ PARSER(parse_while) {
return NewAST(ctx->file, start, pos, While, .condition=condition, .body=body);
}
+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 '#'");
+ return NewAST(ctx->file, start, pos, Length, .value=val);
+}
+
PARSER(parse_heap_alloc) {
const char *start = pos;
if (!match(&pos, "@")) return NULL;
@@ -1070,6 +1078,7 @@ PARSER(parse_term_no_suffix) {
|| (term=parse_nil(ctx, pos))
|| (term=parse_num(ctx, pos))
|| (term=parse_int(ctx, pos))
+ || (term=parse_length(ctx, pos))
|| (term=parse_negative(ctx, pos))
|| (term=parse_heap_alloc(ctx, pos))
|| (term=parse_stack_reference(ctx, pos))