Skip to content
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

--and $pattern to require non-ordered conjunction of RE matches #172

Open
n1vux opened this issue Dec 1, 2018 · 3 comments
Open

--and $pattern to require non-ordered conjunction of RE matches #172

n1vux opened this issue Dec 1, 2018 · 3 comments
Labels

Comments

@n1vux
Copy link
Contributor

n1vux commented Dec 1, 2018

In the Slack we've discussed --and a few times, and most recently it was favorable, but never opened a ticket, so here is one.

--and $pattern opens a can of semantics worms: it could mean any of

  • in the same line (obvious meaning / likely intent usually)
  • in the same file (possibly ditto with -f but files with patA --and patB in same line equally plausible)
  • same paragraph Paragraph mode (aka paragrep, multiline) #171
  • mutual -C12 context
@n1vux
Copy link
Contributor Author

n1vux commented Dec 1, 2018

(For --and with N>2 patterns, I'd consider allowing chained in-context but not fully-mutal matches (meaning each match within -C$nn lines of at least one other pattern's match in the current match context, but possibly more than $nn lines from some other matches) if and only if --proximate also set, as that is our existing feature that requires merging match contexts. Without it, each match context is exactly 1+2*$nn lines or with -B$bb -A$aa, $bb+1+$aa lines, and all N patterns must match at least once within that context, and at least one matches the current line.)

@n1vux
Copy link
Contributor Author

n1vux commented Dec 1, 2018

Slack discussion 2018-11-29 https://beyondgrep.slack.com/archives/C4J886HT2/p1543503390000600 highlights -

Andy > One thing to think about when we purse --and switches: Does the --and apply to the same line, or the same file? I think we’d want to support both.
ack loggingfunction --and Log4perl. Does that mean that the two things have to appear on the same line? Or is it that they are both in the same file somewhere?
I don’t think it makes sense to introduce one without the other.
Although the “both in the same file” can be done now with two ack invocations.

Bill > --and could be useful for several scopes --

  • Same line (for which there is a regex workaround in cookbook)
  • Same paragraph (doable with perl oneliner but not with any Ack cookbook today Paragraph mode (aka paragrep, multiline) #171 )
  • Within each-other's -C$n (doable with pipe in cookbook approximately)
  • Same file (particularly useful with -f; emulable with pipe )

Andy > My first thought would be --and means same line.
Clearly we need two different --ands.

Bill > Same line is the simplest and probably most useful particularly if we allow multiple of them
(Same line And of two isn't hard to make in regex but 3+ gets ugly) (Cookbook has examples...)

@petdance
Copy link
Collaborator

petdance commented Dec 1, 2018

I think we must have two --ands and --ors. They might be --andononesameline and --orononeline and --andinthesamefile and --orinthesamefile. Those names are horrible, of course, but they need to be explicit in how they're differnet.

Also, we can't combine any --and and --or options together. Also, we can't combine ononeline and inthesamefile options. It will be a nightmare.

And if we open this can of worms, are we going to want --not versions of everything too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants