Skip to content

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Oct 30, 2022
1 parent df9c906 commit 4ddb32c
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 84 deletions.
15 changes: 13 additions & 2 deletions Changes
Expand Up @@ -2,6 +2,17 @@ Revision history for App-Rak

{{$NEXT}}

0.2.1 2022-10-30T12:50:04+01:00
- Add support for --type=equal
- Add support for ^string as a shortcut for --type=starts-with
- Add support for string$ as a shortcut for --type=ends-with
- Add support for ^string$ as a shortcut for --type=equal
- Add support for §string as a shortcut for --type=words
- Bump dependency on highlighter to get support for "equal" and
the Type role for annotating strings with a type of search
- Rewrote the "pattern" section in the documentation, to give
a better overview from the start

0.2 2022-10-28T13:38:31+02:00
- Add support for --patterns-from
- Add support for --type=auto|regex|code, make --type leading
Expand All @@ -10,8 +21,8 @@ Revision history for App-Rak
- Fix issue with handling unknown extension groups, Mustafa Aydın++

0.1.12 2022-10-22T13:04:37+02:00
- Add dependency on IO::Path::AutoDecompress to make --auto-decompress
option an option that is always available
- Add dependency on IO::Path::AutoDecompress to make
--auto-decompress option an option that is always available
- Bump dependency on String::Utils to get "non-word"
- Make regexes that consist of a literal string of word characters
only, use the much faster .contains logic on the literal string,
Expand Down
4 changes: 2 additions & 2 deletions META6.json
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.17>:auth<zef:lizmat>",
"highlighter:ver<0.0.18>: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.2"
"version": "0.2.1"
}
66 changes: 45 additions & 21 deletions README.md
Expand Up @@ -41,11 +41,47 @@ POSITIONAL ARGUMENTS
pattern
-------

The pattern to search for. This can either be a literal string, or a [Raku regular expression](https://docs.raku.org/language/regexes) (indicated by a string starting and ending with `/`), a `Callable` (indicated by a string starting with `{` and ending with `}`), or a result of [`Whatever` currying](https://docs.raku.org/type/Whatever) (indicated by a string starting with `*.`).
The pattern to search for.

Can also be specified with the `--pattern` option, in which case **all** the positional arguments are considered to be a path specification.

If the pattern is a `Callable`, then the dynamic variable `$*SOURCE` will contain the `IO::Path` object of the file being processed. Note that pattern `Callable`s will be called in a thread **unsafe** manner.
Patterns will be interpreted in the following ways if **no** `--type` has been specified, or `--type=auto` has been specified.

Multiple patterns, stored in a file or read from STDIN, can also be specified with the <C--patterns-from> argument.

### / regex /

If the pattern starts and ends with `/`, then it indicates a Raku [regex](https://docs.raku.org/language/regexes). **No** special processing of the given string between slashes will be done: the given pattern will be parsed as a regex verbatim. During the search process, each item will be matched against this regex. Any `--ignorecase` or `--ignoremark` arguments will be honoured.

### { code }

If the pattern starts with `{` and ends with `}`, then it indicates Raku code to be executed. **No** special processing of the given string between the curly braces will be done: the given code will be compiled as Raku code. During the search process, this code will be run for each item, available in `$_`.

The dynamic variable `$*SOURCE` will contain the `IO::Path` object of the file being processed. Note that the Raku code will be called in a thread **unsafe** manner.

### *code

If the pattern starts with `*`, then this is a short way of specifying Raku code as a pattern, using [Whatever-currying](https://docs.raku.org/type/Whatever#index-entry-Whatever-currying). Otherwise the same as `{ code }`.

### ^string

If the pattern starts with `^`, then it indicates the string should be at the **start** of each item. Basically a shortcut to specifying `string --type=starts-with`. Any `--smartcase`, `--ignorecase` or `--ignoremark` arguments will be honoured.

### string$

If the pattern ends with `$`, then it indicates the string should be at the **end** of each item. Basically a shortcut to specifying `string --type=ends-with`. Any `--smartcase`, `--ignorecase` or `--ignoremark` arguments will be honoured.

### ^string$

If the pattern starts with `^` and ends with `$`, then it indicates that the string should be equal to the item. Basically a shortcut to specifying `string --type=equal`. Any `--smartcase`, `--ignorecase` or `--ignoremark` arguments will be honoured.

### §string

If the pattern starts with `§`, then it indicates that the string should occur as a word (with word-boundaris on both ends) in the item. Basically a shortcut to specifying `string --type=words`. Any `--smartcase`, `--ignorecase` or `--ignoremark` arguments will be honoured.

### string

If there are no special start or end markers, then it indicates that the string should occur somewhere in the item. Basically a shortcut to specifying `string --type=contains`. Any `--smartcase`, `--ignorecase` or `--ignoremark` arguments will be honoured.

path(s)
-------
Expand All @@ -59,7 +95,7 @@ Paths can also be specified with the `--paths` option, in which case there shoul
ON CALLABLES AS PATTERN
=======================

`Callables` can be specfied by a string starting with `*.` (so-called [Whatever currying](https://docs.raku.org/type/Whatever), or as a string starting with `{` and ending with `}`.
`Callables` can be specified by a string starting with `*.` (so-called [Whatever currying](https://docs.raku.org/type/Whatever), or as a string starting with `{` and ending with `}`.

Note that if a `Callable` is specified as a pattern, then no highlighting can be performed as it cannot signal why or where a match occurred.

Expand Down Expand Up @@ -1116,7 +1152,7 @@ Alternative way to specify the pattern to search for. If (implicitly) specified,
--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.
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. If the file specification is `"-"`, then the patterns will be read from STDIN.

--per-file[=code]
-----------------
Expand Down Expand Up @@ -1344,23 +1380,7 @@ The following strings can be specified:

### auto

If `--type=auto` is (implicitely) specified, will look for cues in a specified pattern to understand what functionality is requested. The following cues are currently supported:

* / regex /

A string starting and ending with a slash `/`, will be interpreted as a Raku regex. This will honour any `--smartcase`, `--ignorecase` and `--ignoremark` specifications.

* { code }

A string starting with a curly brace open `{` and ending with a curly brace close `}`, will be interpreted as Raku source code to be compiled.

* *code

A string starting with an asterisk `*` will be interpreted as Raku source code, assuming Whatever currying semantics.

* literal

Otherwise, the string will be interpreted as a literal string to search for, with `--type=contains` semantics. This will honour any `--smartcase`, `--ignorecase` and `--ignoremark` specifications.
If `--type=auto` is (implicitely) specified, will look for cues in a specified pattern to understand what functionality is requested. See the [pattern](pattern) for more information.

### regex

Expand All @@ -1386,6 +1406,10 @@ If `type=starts-with` is specified, then a pattern will be interpreted as a lite

If `type=ends-with` is specified, then a pattern will be interpreted as a literal string that should occur at the **end** of a line, while honouring any `--smartcase`, `--ignorecase` and `--ignoremark` specifications.

### equal

If `type=equal` is specified, then a pattern will be interpreted as a literal string that should be **equal** to the line, while honouring any `--smartcase`, `--ignorecase` and `--ignoremark` specifications.

--trim
------

Expand Down
13 changes: 5 additions & 8 deletions TODO
Expand Up @@ -5,7 +5,6 @@ Ideas / Todo's
- expose mapper functionality
- create plugin structure
- modify files met csv-per-line
- XPath en XML file support
- support for timezones, selecting on name, but also on properties
- some form if binary support
- search spesh log
Expand All @@ -15,14 +14,12 @@ Ideas / Todo's
- now that we have ngram, perhaps allow for some fuzzy searching?
- support for spreadsheets
- support for colors a la ack
- make use of --type leading: --type=contains would force any pattern to
be considered literally, rather than trying to interpret for regexes or
code. This would make --type=auto the default (trying to interpret).
Other types could be --type=regex and --type=code to interpret the pattern
as a regex or as code respectively, without the /.../ or {...} checks.
And possibly in the future: --type=json-path for the 'jp:' prefix to
interprete the rest of the pattern as a JSON::Path specification.
- add support for --type=json-path for the 'jp:' prefix to interpret
the rest of the pattern as a JSON::Path specification.
- XPath en XML file support
- add Log::Timeline support somehow
- Allow for hypering withing a file if the file is larger than X bytes
(probably 1MB)

Errors
======
Expand Down
114 changes: 79 additions & 35 deletions doc/App-Rak.rakudoc
Expand Up @@ -43,19 +43,78 @@ and bug reports continue to be more than welcome!

=head2 pattern

The pattern to search for. This can either be a literal string, or a
L<Raku regular expression|https://docs.raku.org/language/regexes>
(indicated by a string starting and ending with C</>), a
C<Callable> (indicated by a string starting with C<{> and ending with C<}>),
or a result of L<C<Whatever> currying|https://docs.raku.org/type/Whatever>
(indicated by a string starting with C<*.>).
The pattern to search for.

Can also be specified with the C<--pattern> option, in which case B<all>
the positional arguments are considered to be a path specification.

If the pattern is a C<Callable>, then the dynamic variable C<$*SOURCE> will
contain the C<IO::Path> object of the file being processed. Note that
pattern C<Callable>s will be called in a thread B<unsafe> manner.
Patterns will be interpreted in the following ways if B<no> C<--type>
has been specified, or C<--type=auto> has been specified.

Multiple patterns, stored in a file or read from STDIN, can also be specified
with the <C--patterns-from> argument.

=head3 / regex /

If the pattern starts and ends with C</>, then it indicates a Raku
L<regex|https://docs.raku.org/language/regexes>. B<No> special processing
of the given string between slashes will be done: the given pattern will be
parsed as a regex verbatim. During the search process, each item will be
matched against this regex. Any C<--ignorecase> or C<--ignoremark> arguments
will be honoured.

=head3 { code }

If the pattern starts with C<{> and ends with C<}>, then it indicates
Raku code to be executed. B<No> special processing of the given string
between the curly braces will be done: the given code will be compiled as
Raku code. During the search process, this code will be run for each item,
available in C<$_>.

The dynamic variable C<$*SOURCE> will contain the C<IO::Path> object of the
file being processed. Note that the Raku code will be called in a thread
B<unsafe> manner.

=head3 *code

If the pattern starts with C<*>, then this is a short way of specifying Raku
code as a pattern, using
L<Whatever-currying|https://docs.raku.org/type/Whatever#index-entry-Whatever-currying>. Otherwise the same as C<{ code }>.

=head3 ^string

If the pattern starts with C<^>, then it indicates the string should be at
the B<start> of each item. Basically a shortcut to specifying
C<string --type=starts-with>. Any C<--smartcase>, C<--ignorecase> or
C<--ignoremark> arguments will be honoured.

=head3 string$

If the pattern ends with C<$>, then it indicates the string should be at
the B<end> of each item. Basically a shortcut to specifying
C<string --type=ends-with>. Any C<--smartcase>, C<--ignorecase> or
C<--ignoremark> arguments will be honoured.

=head3 ^string$

If the pattern starts with C<^> and ends with C<$>, then it indicates that
the string should be equal to the item. Basically a shortcut to specifying
C<string --type=equal>. Any C<--smartcase>, C<--ignorecase> or C<--ignoremark>
arguments will be honoured.

=head3 §string

If the pattern starts with C<§>, then it indicates that the string should
occur as a word (with word-boundaris on both ends) in the item. Basically a
shortcut to specifying C<string --type=words>. Any C<--smartcase>,
C<--ignorecase> or C<--ignoremark> arguments will be honoured.

=head3 string

If there are no special start or end markers, then it indicates that the
string should occur somewhere in the item. Basically a shortcut to
specifying C<string --type=contains>. Any C<--smartcase>, C<--ignorecase> or
C<--ignoremark> arguments will be honoured.

=head2 path(s)

Expand All @@ -75,7 +134,7 @@ option was used for the pattern specification.

=head1 ON CALLABLES AS PATTERN

C<Callables> can be specfied by a string starting with C<*.> (so-called
C<Callables> can be specified by a string starting with C<*.> (so-called
L<Whatever currying|https://docs.raku.org/type/Whatever>, or as a string
starting with C<{> and ending with C<}>.

Expand Down Expand Up @@ -1386,7 +1445,8 @@ pattern as part of a custom option.

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.
(implicitly) set with the C<--type> argument. If the file specification is
C<"-">, then the patterns will be read from STDIN.

=head2 --per-file[=code]

Expand Down Expand Up @@ -1669,30 +1729,8 @@ The following strings can be specified:
=head3 auto

If C<--type=auto> is (implicitely) specified, will look for cues in a
specified pattern to understand what functionality is requested. The
following cues are currently supported:

=item / regex /

A string starting and ending with a slash C</>, will be interpreted as a
Raku regex. This will honour any C<--smartcase>, C<--ignorecase> and
C<--ignoremark> specifications.

=item { code }

A string starting with a curly brace open C<{> and ending with a curly
brace close C<}>, will be interpreted as Raku source code to be compiled.

=item *code

A string starting with an asterisk C<*> will be interpreted as Raku source
code, assuming Whatever currying semantics.

=item literal

Otherwise, the string will be interpreted as a literal string to search for,
with C<--type=contains> semantics. This will honour any C<--smartcase>,
C<--ignorecase> and C<--ignoremark> specifications.
specified pattern to understand what functionality is requested. See
the L<pattern> for more information.

=head3 regex

Expand Down Expand Up @@ -1729,6 +1767,12 @@ If C<type=ends-with> is specified, then a pattern will be interpreted as
a literal string that should occur at the B<end> of a line, while honouring
any C<--smartcase>, C<--ignorecase> and C<--ignoremark> specifications.

=head3 equal

If C<type=equal> is specified, then a pattern will be interpreted as a
literal string that should be B<equal> to the line, while honouring
any C<--smartcase>, C<--ignorecase> and C<--ignoremark> specifications.

=head2 --trim

Flag. Indicate whether lines that have the pattern, should have any
Expand Down

0 comments on commit 4ddb32c

Please sign in to comment.