Skip to content

Commit 56f68f7

Browse files
Introduce RepeatOptions
1 parent 9ac9110 commit 56f68f7

File tree

2 files changed

+275
-136
lines changed

2 files changed

+275
-136
lines changed

examples/expression.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn expr(alloc: std.mem.Allocator) !p.TaggedParser(Value) {
8282

8383
// we can't use Parsers.int to parse numbers here to avoid consumption of the '-' and '+'
8484
// number: Int <- \d+
85-
const number = p.range('0', '9').repeatToSentinelArray(1, 10)
85+
const number = p.range('0', '9').repeatToSentinelArray(.{ .min_count = 1, .max_count = 10 })
8686
.transform(Value, {}, fns.parseInt);
8787

8888
// value: Int <- <number>|<brackets>
@@ -92,14 +92,14 @@ fn expr(alloc: std.mem.Allocator) !p.TaggedParser(Value) {
9292
// product: Int <- <value>([*/]<value>)*
9393
const product = blk: {
9494
const operation = p.oneCharOf("*/").transform(Operation, {}, Operation.parse);
95-
break :blk value.andThen(operation.andThen(value).repeat(alloc))
95+
break :blk value.andThen(operation.andThen(value).repeat(alloc, .{}))
9696
.transform(Value, alloc, fns.calculate);
9797
};
9898

9999
// sum: Int <- <product>([+-]<product>)*
100100
const sum = blk: {
101101
const operation = p.oneCharOf("+-").transform(Operation, {}, Operation.parse);
102-
break :blk product.andThen(operation.andThen(product).repeat(alloc))
102+
break :blk product.andThen(operation.andThen(product).repeat(alloc, .{}))
103103
.transform(Value, alloc, fns.calculate);
104104
};
105105

0 commit comments

Comments
 (0)