beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 138 forks source link

Feature: number search #635

Closed epa closed 7 years ago

epa commented 7 years ago

A feature request for ack 3: search for a given number.

% ack --number 1.3

This would find occurrences of the numbers 1.3, 1.30, 01.300, 1.3e0, and so on, but not 1.34, 11.3, 1a3, etc. For whole numbers it could also search other notations

% ack --number 0xf

finding 15, 0xf, 017 (octal notation), 0b1111 (binary). If you think this latter refinement is a step too far (why should ack know about programming language notation for different bases?) then I would just propose the decimal searching above.

If you like the idea, I think I can make a patch for it some time.

petdance commented 7 years ago

Thanks for the idea. I can't go with this. ack can't know about the significance of the text it's looking at. It's just pattern matching supplied by the user.

epa commented 7 years ago

Thanks for considering it. It's another one of those cases where the smarts is in making the right regular expression given the input text. It could be included in some set of canned regular expressions like Perl's Regexp::Common, but this need not be part of the ack project itself.

% ack `make-regexp number 1.3`
petdance commented 7 years ago

That sounds like a better approach, to construct a given regex based on some rules, rather than trying to have ack parse the content.

epa commented 7 years ago

Yes, that was my intention for having the feature in ack too, that it would just be a transformation applied to the input regexp (as already happens for -w). However it might not fit into the simple framework of "paste some text on the beginning of the regexp, and on the end".

Searching for where a particular constant appears in a codebase can be a fairly common task, and it is annoying if a search for 1.3 doesn't find 1.30 or vice versa. But I understand if it is considered out of scope for ack, which after all is a regular expression tool, not a general code inspector.