Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Preserve matchdata in rules #141

Closed
avdi opened this issue Jun 15, 2016 · 5 comments · May be fixed by #372
Closed

Idea: Preserve matchdata in rules #141

avdi opened this issue Jun 15, 2016 · 5 comments · May be fixed by #372

Comments

@avdi
Copy link

avdi commented Jun 15, 2016

Here's part of a rule I just wrote the other day:

stampfile_pattern = %r"^members/(?<email>.*)/\d{2}-(?<step>\w+).timestamp$"
rule stampfile_pattern do |t|
  match           = stampfile_pattern.match(t.name)
  email           = match[:email]
  step            = match[:step]
  # ...
end

Notice how, after it matches, I have to re-apply the regex inside the rule definition in order to pull out named matchdata.

I was thinking of introducing something like this as an alternative:

stampfile_pattern = %r"^members/(?<email>.*)/\d{2}-(?<step>\w+).timestamp$"
rule stampfile_pattern do |t|
  email           = t.matchdata[:email]
  step            = t.matchdata[:step]
  # ...
end

Before I dive in, what do you think? And is there another way to accomplish this that I've missed?

@drbrain
Copy link
Member

drbrain commented Jun 16, 2016

I think this would be a nice addition.

I don't think there's a way to accomplish this without adding the feature to the rule.

I've not used a rule without dependencies, it gets triggered by a separate task that depends on the output (regexp)?

@avdi
Copy link
Author

avdi commented Jun 16, 2016

I don't think there's a way to accomplish this without adding the feature to the rule.

Yeah, that's what I was thinking. I feel like it makes sense, since the task object already has the concrete t.name that matched, to also have the matchdata.

I've not used a rule without dependencies, it gets triggered by a separate task that depends on the output (regexp)?

Yep.

@avdi
Copy link
Author

avdi commented Jun 16, 2016

I've also thought about this:

rule %r"^members/(?<email>.*)/\d{2}-(?<step>\w+).timestamp$" => 
  "members/%{email}/some-input-file" do |t|
  email           = t.matchdata[:email]
  step            = t.matchdata[:step]
  # ...
end

I.e. adding the ability to substitute in backreferences in the rule source. Currently, rule sources suffer from the same problem as the rule body: if you want to reference regex matchdata, you have to use a lambda as the dependency and re-apply the regex.

@yeban
Copy link

yeban commented Dec 2, 2016

I stumbled upon this issue looking for how to access matchdata inside a rule. This would be a great addition, imho.

@avdi
Copy link
Author

avdi commented Dec 2, 2016 via email

@ruby ruby locked and limited conversation to collaborators Jun 21, 2022
@hsbt hsbt converted this issue into discussion #437 Jun 21, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants