Closed joelreymont closed 3 weeks ago
This can be reduced to
test "asStr1" {
const allocator = testing.failing_allocator;
const parser = comptime oneOf(.{
combine(.{ascii.char('0')}),
combine(.{ ascii.char('1'), ascii.char('2') }),
}).asStr();
try expectResult([]const u8, .{ .value = "4" }, parser.parse(allocator, "4"));
}
and the problem seems to be with combine
within oneOf
.
The actual problem is that the result type of oneOf
is the type of the first parser.
This should be documented somewhere.
The actual problem is that the result type of
oneOf
is the type of the first parser.This should be documented somewhere.
It's kinda documented here
https://github.com/Hejsil/mecha/blob/master/mecha.zig#L405-L406
But I do see how this is not entirely clear.
Right. It will return the result of the first parser that succeeds but the result type will be the type of the first parser in the combinator.
I was under the impression that I only needed 1
asStr
at the end of my parser for all to be well.Why does this
results in this error then
whereas adding
.asStr()
to each parser withinoneOf
fixes it?