Skip to content

Commit

Permalink
0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Oct 28, 2022
1 parent e9ae633 commit df9c906
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 44 deletions.
6 changes: 4 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Revision history for App-Rak

{{$NEXT}}

0.2 2022-10-28T13:38:31+02:00
- Add support for --patterns-from
- Add support for --type=auto|regex|code, make --type leading
- Fixed a (implicit) --smartcase blocking use of --unicode
- Bumped dependency on highlighter to get multiple needle support
- Fix issue with handling unknown extension groups, Mustafa Aydın++
- Add support for --patterns-from
- Add support for --type=auto|regex|code

0.1.12 2022-10-22T13:04:37+02:00
- Add dependency on IO::Path::AutoDecompress to make --auto-decompress
Expand Down
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"as-cli-arguments:ver<0.0.7>:auth<zef:lizmat>",
"CLI::Version:ver<0.0.8>:auth<zef:lizmat>",
"has-word:ver<0.0.3>:auth<zef:lizmat>",
"highlighter:ver<0.0.16>:auth<zef:lizmat>",
"highlighter:ver<0.0.17>:auth<zef:lizmat>",
"IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>",
"JSON::Fast::Hyper:ver<0.0.3>:auth<zef:lizmat>",
"META::constants:ver<0.0.3>:auth<zef:lizmat>",
Expand Down Expand Up @@ -58,5 +58,5 @@
],
"test-depends": [
],
"version": "0.1.12"
"version": "0.2"
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ Flag. If specified with a True value, will accept compressed files with the `.gz

Only applicable if `--csv-per-line` has been specified. Flag. If (implicitly) specified, will show diagnostic information about problems that occurred during parsing of the CSV file. The default is `True`.

backtrace
---------
--backtrace
-----------

Flag. When specified with a True value, will interpret either standard input, or a single file, as a Raku backtrace. And produce a result containing the lines of source code from that backtrace. Can be used together with `--context`, `--before-context`, `--after-context`, `--edit` and `--vimgrep`. Any pattern specification will only be used for highlighting. If **not** used in combination with `--edit` or `--vimgrep`, will assume a context of 2 lines.

Expand Down Expand Up @@ -1113,6 +1113,11 @@ Indicate the path of the file to read path specifications from instead of from a

Alternative way to specify the pattern to search for. If (implicitly) specified, will assume the first positional parameter specified is actually a path specification, rather than a pattern. This allows the pattern to be saved with `--save`, and thus freeze a specific pattern as part of a custom option.

--patterns-from=file
--------------------

Alternative way to specify one or more patterns to search for. Reads the indicated file and interprets each line as a pattern according to the rules (implicitly) set with the `--type` argument.

--per-file[=code]
-----------------

Expand Down
6 changes: 6 additions & 0 deletions doc/App-Rak.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,12 @@ actually a path specification, rather than a pattern. This allows
the pattern to be saved with C<--save>, and thus freeze a specific
pattern as part of a custom option.

=head2 --patterns-from=file

Alternative way to specify one or more patterns to search for. Reads the
indicated file and interprets each line as a pattern according to the rules
(implicitly) set with the C<--type> argument.

=head2 --per-file[=code]

Indicate whether matching should be done per file, rather than per line.
Expand Down
4 changes: 2 additions & 2 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The modules that we need here, with their full identities
use as-cli-arguments:ver<0.0.7>:auth<zef:lizmat>; # as-cli-arguments
use has-word:ver<0.0.3>:auth<zef:lizmat>; # has-word
use highlighter:ver<0.0.16>:auth<zef:lizmat>; # columns highlighter matches
use highlighter:ver<0.0.17>:auth<zef:lizmat>; # columns highlighter matches
use IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>; # IOAD
use JSON::Fast::Hyper:ver<0.0.3>:auth<zef:lizmat>; # from-json to-json
use META::constants:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION;
Expand All @@ -19,7 +19,7 @@ my constant BON = "\e[1m"; # BOLD ON
my constant BOFF = "\e[22m"; # BOLD OFF

#- start of available options --------------------------------------------------
#- Generated on 2022-10-22T22:32:01+02:00 by tools/makeOPTIONS.raku
#- Generated on 2022-10-28T13:23:53+02:00 by tools/makeOPTIONS.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE
my str @options = <absolute accept accessed after-context allow-loose-escapes allow-loose-quotes allow-whitespace auto-decompress auto-diag backtrace backup batch before-context blame-per-file blame-per-line blocks break checkout classify categorize context count-only created csv-per-line degree deny description device-number dir dont-catch dryrun ecosystem edit encoding eol escape exec extensions file file-separator-null files-from files-with-matches files-without-matches filesize find find-all formula frequencies gid group group-matches hard-links has-setgid has-setuid help highlight highlight-after highlight-before human ignorecase ignoremark inode invert-match is-empty is-executable is-group-executable is-group-readable is-group-writable is-owned-by-group is-owned-by-user is-owner-executable is-owner-readable is-owner-writable is-readable is-sticky is-symbolic-link is-world-executable is-world-readable is-world-writable is-writable json-per-elem json-per-file json-per-line keep-meta known-extensions list-custom-options list-expanded-options list-known-extensions matches-only max-matches-per-file meta-modified mode modified modify-files module only-first output-dir output-file pager paragraph-context passthru passthru-context paths paths-from pattern patterns-from per-file per-line proximate rename-files quietly quote rak recurse-symlinked-dir recurse-unmatched-dir repository save sayer sep shell show-blame show-filename show-item-number silently smartcase sourcery stats stats-only strict summary-if-larger-than trim type uid under-version-control unicode unique user verbose version vimgrep with-line-endings>;
#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE
Expand Down
14 changes: 9 additions & 5 deletions resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ Arguments overview:
‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒

Pattern specification:
Either as first argument, or as --pattern=foo option, or as pattern(s)
in --patterns-from=file option.
foo literal string
'/ << bar >> /' Raku regex indicated by being bounded by / /
'{ .ends-with("bar") }' Raku code indicated by being bounded by { }
'*.starts-with("foo")' Raku WhateverCode starting with *
either as first argument, or as --pattern=foo option
--type=auto Interpret special markers in pattern as above (default)
--type=regex Interpret pattern as a regex (without special markers)
--type=code Interpret pattern as code (without special markers)
--type=words Look for pattern as a word
--type=starts-with Look for pattern at start of a line
--type=ends-with Look for pattern at end of a line
--type=contains Look for pattern anywhere (default if no special markers)

String search pattern modifiers:
--ignorecase Ignore distinction between upper, lower and title case letters
--ignoremark Only compare base characters, ignore additional marks
--smartcase As --ignorecase if pattern does *NOT* contain any uppercase
--type=words Look for string as a word
--type=starts-with Look for string at start of a line
--type=ends-with Look for string at end of a line
--type=contains Look for string anywhere (default)

Item producers:
--per-line[=producer] Produce lines for pattern matching
Expand Down
92 changes: 66 additions & 26 deletions resources/help/pattern.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
Pattern specification:
‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒

There are 2 ways in which a pattern can be specified:
There are 3 ways in which pattern(s) can be specified:

1. As the first positional argument
2. With the --pattern argument
2. Or with the --pattern=foo argument
3. Or using the --patterns-from=file argument

The latter can be handy if you want to create a short-cut to searching
for a particular string with --save.
The first is easiest for a quick ad-hoc search. The second can be handy
if you want to create a short-cut to searching for a particular string with
--save. The last one allows you set up a set of patterns to be searched
for simultaneously.

Patterns come in 3 flavours:

1. as a literal string
2. as a regex (the Raku name for "regular expression")
3. as a piece of code (a Callable in Raku)
If the --patterns-from=file argument is specified, it will read the content
of the given file and process each line as a pattern specification, as
described below. When searching, each pattern is tried on an item, and
accepted as soon as a pattern matched. Any highlighting will occur on
*that* match only.

If a literal string is specified as a pattern, then by default
any item of which the stringification contains that string, will
be accepted.
If a literal string is specified as a pattern, then by default any item of
which the stringification contains that string, will be accepted.

Example:
# produce any lines that have "foo" in them
$ rak foo

Literal strings matching can be further specialize with the --type
argument, which can have 4 possible values
Patterns come in 3 flavours:

1. contains string must occur anywhere in item
2. words string must be surrounded by (virtual) whitespace in item
3. starts-with item must *start* with string
4. ends-with item must *end* with string
1. as a literal string
2. as a regex (the Raku name for "regular expression")
3. as a piece of code (a Callable in Raku)

Example:
# produce any lines that have the word "bar" in them
$ rak bar --type=words
Whether something you specified is interpreted as a regex or as code, or
just as a string, is determined by the --type argument. By default, the
--type arguments assumes "auto". When this is (implicitly) specified,
then the string will be checked for special markers to deduce the intended
type of pattern.

Regex:

If a string that starts and ends with '/' is specified as a pattern,
it is considered to be a regex and will be compiled as such. Any
Expand All @@ -45,11 +49,17 @@ Example:
# produce any lines that have the word "bar" in them
$ rak '/ << bar >> /'

Both literal string matching, as well as matching with a regex, are
sensitive to the --ignorecase and --ignoremark arguments.
If --type=regex has been specified, you should omit the '/' at either end of
the string:

Example:
# produce any lines that have the word "bar" in them
$ rak '<< bar >>' --type=regex

Code:

If a string that starts with '{' and ends with '}' is specified, or
a string that starts with '*.', they will be considered to be Raku
a string that starts with '*', they will be considered to be Raku
executable code and compiled as such. Each item will be passed as
a positional argument to the compiled code, and the code is expected
to return a value that is either:
Expand All @@ -61,7 +71,7 @@ to return a value that is either:
5. Slip produce all items in the Slip, always
6. product produce that, always

True and False are returned for any condition.
True or False are returned for any condition.

Empty is returned for any failed conditional construct, such as "if",
"unless", "with" or "without".
Expand All @@ -85,8 +95,38 @@ $ rak '*.uc'
# produce only lines uppercased that have "foo" in them
$ rak '{ .uc if .contains("foo") }'

# produce all lines, only uppercase the ones that have "foo" in them
# produce all lines, only uppercase the ones that have "rakudoc" in them
$ rak '{.contains("rakudoc") ?? .uc !! $_}'

# produce all unique words
$ rak '*.words.Slip'

If --type=code has been specified, you should omit the '{' and '}', or
omit the initial '*':

Examples:
# produce uppercased lines
$ rak '.uc' --type=code

# produce all lines, only uppercase the ones that have "rakudoc" in them
$ rak '.contains("rakudoc") ?? .uc !! $_' --type=code

Other types:

Literal strings matching can be further specialized with other values of the
--type argument:

- contains string must occur anywhere in item
- words string must be surrounded by (virtual) whitespace in item
- starts-with item must *start* with string
- ends-with item must *end* with string

Examples:
# produce any lines that have the word "bar" in them
$ rak bar --type=words

# produce any lines that start with "Example"
$ rak Example --type=starts-with

Both literal string matching, as well as matching with a regex, are
sensitive to the --smartcase, --ignorecase and --ignoremark arguments.
14 changes: 9 additions & 5 deletions xt/02-simple.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ my sub query-ok(
# Checks for "ine"
my @ine = (
<ine>,
<ine --type=auto>,
<ine --type=regex>,
<ine --type=ends-with>,
<INE --type=ends-with --ignorecase>,
<ïñę --type=ends-with --ignoremark>,
Expand Down Expand Up @@ -124,14 +126,16 @@ for (
query-ok .Slip, '--highlight', :ok("\n");
}

query-ok "six",
<--smartcase --/group-matches --/show-item-number --/highlight --/break>,
ok => q:to/OK/;
for "six", ('.lc eq "six"', '--type=code') {
query-ok .Slip,
<--smartcase --/group-matches --/show-item-number --/highlight --/break>,
ok => q:to/OK/;
six:SIX
seven:SIX
eight:SIX
nine:SIX
OK
}

query-ok <seven --type=words>, :head(2), ok => qq:to/OK/;
seven
Expand Down Expand Up @@ -211,7 +215,7 @@ for </\w+/>, <*.words.Slip> {
OK
}

for <*.&defined>, <{$_}> {
for <*.defined>, <{$_}> {
query-ok $_, '--frequencies', ok => q:to/OK/;
10:zero
9:one
Expand Down Expand Up @@ -240,7 +244,7 @@ nine
OK
}

for <*.&defined>, <{$_}> {
for <*.defined>, <{$_}> {
query-ok $_, '--unique', ok => q:to/OK/;
zero
one
Expand Down

0 comments on commit df9c906

Please sign in to comment.