Support predicates for matched patterns
marxin opened this issue · 8 comments
I have a motivation example I noticed in binutils
and gcc
code base:
if (strncmp (var, "foo", 3) == 0))
...
which can be transformed to:
if (startswith(var, "foo")))
So I would need something like where strlen(:[string]) == :[n]
.
Would it be possible to implement that? Thanks.
Good idea--you mean for checking the length of a constant string here right? How about just an attribute on the matched part, so
:[thing].length == 3
Good idea--you mean for checking the length of a constant string here right?
Yes, exactly.
How about just an attribute on the matched part, so
:[thing].length == 3
Works for me.
Any progress on this, please?
Hiya, unfortunately no, I haven't had time to do this yet. Lots of refactoring to make this easier to implement.
I see, thanks for working on that.
This is now available in the release here: https://github.com/comby-tools/comby/releases/tag/1.6.0. This is not available in brew yet, and I haven't updated the doc site yet, I'll close this issue once that's done. Just giving a heads up.
One small note: there's no integer comparison in comby, you can write where :[thing].length == 3
as I wrote it there, and it is valid, but it is textual, and it's only possible to compare textual equality/inequality. (And, pointing to your previous example, where :[thing].length == :[n]
is also OK, since, :[n]
also substitutes for just a text value.
FYI: https://comby.dev/docs/rewrite-properties
Most of those should work with 1.6.0
, including .length
. There were a couple of additions in 1.7.0
that aren't live via brew install
yet but should be soon.
Thanks for it!