Hejsil / mecha

A parser combinator library for Zig
MIT License
413 stars 18 forks source link

Add mapConst #40

Closed zenMaya closed 1 year ago

zenMaya commented 1 year ago

This is a analogue to Parsec's <$.

It is similar to how map works, but instead of transforming the inner parser value, it simply discards it.

Usecase:

mecha.mapConst(u21, '\n', mecha.string("\\n"));

This was always possible with plain map but it was quite verbose, as a dummy function inside an anonymous struct needed to be constructed.

Hejsil commented 1 year ago

Hmm. I wouldn't really mind it being a little verbose if it was just something like this:

map(T, fn(_: anytype) T { return T{} }, parser)

Sadly this cannot be written currently, so I'll accept this MR. In the future, I'll probably go over and do some breaking changes while the language itself is still pre 1.0 :)

Hejsil commented 1 year ago

Aaah, cicd fails because mecha is not quite up to date with zig master. I'll see if I can do the update Sunday.

zenMaya commented 1 year ago

Hmm. I wouldn't really mind it being a little verbose if it was just something like this:

map(T, fn(_: anytype) T { return T{} }, parser)

Sadly this cannot be written currently, so I'll accept this MR. In the future, I'll probably go over and do some breaking changes while the language itself is still pre 1.0 :)

Yes, if that was possible, it wouldn't be such a hassle. :)

Hejsil commented 1 year ago

Fixed build issues on master. Can you rebase on master so we can get those green checkmarks?

zenMaya commented 1 year ago

I think I did it correctly :), I don't know much about github workflow so hopefully!

Hejsil commented 1 year ago

Wasn't quite right, but I can work with it from here, so no problem

Hejsil commented 1 year ago

Thanks!