rust-lang / rust-lang/rust-bindgen

Expanded RegEx Support?

Open
#2,432 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

@pvdrz
Following on the heels of #2328 ... I've changed to start using the new option and it's working great but I ran into a snag...

Some of the older c libs that I'm using have structs that don't always follow proper naming patterns.
Rather than having to exclude them from the bindgen, I'd like to just filter them from having a derive applied to them.

Here's a sample of the RegEx I was trying to use:
https://regex101.com/r/pjeUkB/1

Basically, If the struct starts with "My" and doesn't contain Foo in it, then apply the derive.
This doesn't seem to work, and seems to silently ignore the regex. Am I doing this wrong?

--with-derive-custom-struct '^My((?!Foo).)+$'=MyStructTrait

This doesn't seem to match anything. I have verified that this does though:

--with-derive-custom-struct '^My.+$'=MyStructTrait

But it matches the ones I don't want as well.
Does the regex impl in use not support lookahead or negative lookahead?

I would have expected the regex compile to fail or something.

Bindgen Invocation
--with-derive-custom-struct '^My((?!Foo).)+$'=MyStructTrait
Actual Results

No structs are labeled with a MyStructTrait derive.

Expected Results

I expect to see:

#[derive(MyStructTrait)]
struct MyStruct {}

struct MyFoo {}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the bindgen invocation from the issue with the two shown regular expressions and compare the generated derives against the expected MyStruct and MyFoo results. Investigate the regular-expression handling used by the --with-derive-custom-struct option, then add coverage for the reported lookahead behavior and confirm the intended result.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.