Skip to content

Commit

Permalink
0.2.22
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 8, 2024
1 parent 2803820 commit 8ee3dbe
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 44 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
1
2
HN
pdf
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Revision history for App-Rak

{{$NEXT}}

0.2.22 2024-05-08T22:15:02+02:00
- Upped dependency on "rak" to fix issue with --is-moarvm
- Add support for --mbc-frames and --mbc-strings options to
allow searches in MoarVM bytecode files
- Add tests for --pdf-xxx options

0.2.21 2024-05-08T15:44:12+02:00
- Upped dependency on "rak"
- Fix --paths argument: can now specify multiple paths
Expand Down
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>",
"JSON::Fast::Hyper:ver<0.0.5>:auth<zef:lizmat>",
"META::constants:ver<0.0.3>:auth<zef:lizmat>",
"rak:ver<0.0.50>:auth<zef:lizmat>",
"rak:ver<0.0.51>:auth<zef:lizmat>",
"String::Utils:ver<0.0.22+>:auth<zef:lizmat>"
],
"description": "21st century grep / find / ack / ag / rg on steroids",
Expand Down Expand Up @@ -59,5 +59,5 @@
],
"test-depends": [
],
"version": "0.2.21"
"version": "0.2.22"
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,20 @@ Flag. Indicate whether only the matched pattern should be produced, rather than

Indicate the maximum number of matches that should be produced per file. If specified as a flag, will assume **1** for its value. By default, will produce **all** possible matches in a file.

--mbc-frames
------------

Flag. Indicates that the frames in a MoarVM bytecode file should be produced as a [`MoarVM::Bytecode::Frame`ihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame](`MoarVM::Bytecode::Frame`ihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame) to the matcher. Only makes sense if the pattern is a `Callable`. Will also set the `is-moarvm` flag to only select MoarVM bytecode files, unless reading from STDIN.

Requires the [`MoarVM::Bytecode`](https://raku.land/zef:lizmat/MoarVM::Bytecode) Raku module to be installed.

--mbc-strings
-------------

Flag. Indicates that the strings in the string hap in a MoarVM bytecode file should be produced to the matcher. Will also set the `is-moarvm` flag to only select MoarVM bytecode files, unless reading from STDIN.

Requires the [`MoarVM::Bytecode`](https://raku.land/zef:lizmat/MoarVM::Bytecode) Raku module to be installed.

---meta-modified=condition
--------------------------

Expand Down
20 changes: 20 additions & 0 deletions doc/App-Rak.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,26 @@ Indicate the maximum number of matches that should be produced per file.
If specified as a flag, will assume B<1> for its value. By default, will
produce B<all> possible matches in a file.

=head2 --mbc-frames

Flag. Indicates that the frames in a MoarVM bytecode file should be
produced as a L<C<MoarVM::Bytecode::Frame>ihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame>
to the matcher. Only makes sense if the pattern is a C<Callable>. Will
also set the C<is-moarvm> flag to only select MoarVM bytecode files,
unless reading from STDIN.

Requires the L<C<MoarVM::Bytecode>|https://raku.land/zef:lizmat/MoarVM::Bytecode>
Raku module to be installed.

=head2 --mbc-strings

Flag. Indicates that the strings in the string hap in a MoarVM bytecode
file should be produced to the matcher. Will also set the C<is-moarvm>
flag to only select MoarVM bytecode files, unless reading from STDIN.

Requires the L<C<MoarVM::Bytecode>|https://raku.land/zef:lizmat/MoarVM::Bytecode>
Raku module to be installed.

=head2 ---meta-modified=condition

If specified, indicates the C<Callable> that should return True to include a
Expand Down
62 changes: 40 additions & 22 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use highlighter:ver<0.0.18>:auth<zef:lizmat>; # columns highlighter matches Type
use IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>; # IOAD
use JSON::Fast::Hyper:ver<0.0.5>:auth<zef:lizmat>; # from-json to-json
use META::constants:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION;
use rak:ver<0.0.50>:auth<zef:lizmat>; # rak Rak
use rak:ver<0.0.51>:auth<zef:lizmat>; # rak Rak

use Backtrace::Files:ver<0.0.3>:auth<zef:lizmat> <
backtrace-files
Expand All @@ -22,9 +22,9 @@ my constant BON = "\e[1m"; # BOLD ON
my constant BOFF = "\e[22m"; # BOLD OFF

#- start of available options --------------------------------------------------
#- Generated on 2024-05-08T15:38:31+02:00 by tools/makeOPTIONS.raku
#- Generated on 2024-05-08T19:41:02+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 execute-raku extensions file file-separator-null files-from files-with-matches files-without-matches filesize find formula frequencies gid group group-matches hard-links has-setgid has-setuid headers 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-moarvm is-owned-by-group is-owned-by-user is-owner-executable is-owner-readable is-owner-writable is-pdf is-readable is-sticky is-symbolic-link is-text is-world-executable is-world-readable is-world-writable is-writable json-per-elem json-per-file json-per-line keep-meta 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 pdf-info pdf-per-file pdf-per-line 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 smartmark sourcery stats stats-only strict summary-if-larger-than trim type uid under-version-control unicode unique user verbose version vimgrep with-line-endings>;
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 execute-raku extensions file file-separator-null files-from files-with-matches files-without-matches filesize find formula frequencies gid group group-matches hard-links has-setgid has-setuid headers 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-moarvm is-owned-by-group is-owned-by-user is-owner-executable is-owner-readable is-owner-writable is-pdf is-readable is-sticky is-symbolic-link is-text is-world-executable is-world-readable is-world-writable is-writable json-per-elem json-per-file json-per-line keep-meta list-custom-options list-expanded-options list-known-extensions matches-only max-matches-per-file mbc-frames mbc-strings 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 pdf-info pdf-per-file pdf-per-line 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 smartmark 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
#- end of available options ----------------------------------------------------

Expand Down Expand Up @@ -1943,6 +1943,16 @@ my sub option-max-matches-per-file($value --> Nil) {
set-result-flag-or-Int('max-matches-per-file', $value);
}
my sub option-mbc-frames($value --> Nil) {
check-MoarVMBytecode('mbc-frames');
set-action('mbc-frames', $value);
}
my sub option-mbc-strings($value --> Nil) {
check-MoarVMBytecode('mbc-strings');
set-action('mbc-strings', $value);
}
my sub option-meta-modified($value --> Nil) {
set-filesystem-Instant('meta-modified', $value);
}
Expand Down Expand Up @@ -2366,7 +2376,7 @@ my sub move-filesystem-options-to-rak(--> Nil) {
%rak<is-text> := True
unless $reading-from-stdin || (%rak<
file is-text under-version-control is-pdf
file is-text under-version-control is-pdf is-moarvm
>:k) || %result<find>;
}
Expand Down Expand Up @@ -3081,49 +3091,57 @@ my sub action-modify-files(--> Nil) {
rak-stats;
}
my sub action-pdf-info(--> Nil) {
meh-for 'pdf-info', <modify>;
my sub handle-mbc(str $what, &handler --> Nil) {
meh-for $what, <modify>;
prepare-needle;
%filesystem<is-pdf> //= True unless $reading-from-stdin;
%filesystem<is-moarvm> //= True unless $reading-from-stdin;
move-filesystem-options-to-rak;
move-result-options-to-rak;
%rak<produce-one> := -> $file { $PDFExtract.new(:$file).info }
%rak<produce-many> := &handler;
activate-output-options;
run-rak;
rak-results;
rak-stats;
}
my sub action-pdf-per-file(--> Nil) {
meh-for 'pdf-per-file', <modify>;
my sub action-mbc-frames(--> Nil) {
handle-mbc 'mbc-frames', -> $io { $MoarVMBytecode.new($io).frames }
}
my sub action-mbc-strings(--> Nil) {
handle-mbc 'mbc-strings', -> $io { $MoarVMBytecode.new($io).strings }
}
my sub handle-pdf(str $what, str $producer, &handler --> Nil) {
meh-for $what, <modify>;
prepare-needle;
%filesystem<is-pdf> //= True unless $reading-from-stdin;
move-filesystem-options-to-rak;
move-result-options-to-rak;
%rak<produce-one> := -> $file { $PDFExtract.new(:$file).text }
%rak{$producer} := &handler;
activate-output-options;
run-rak;
rak-results;
rak-stats;
}
my sub action-pdf-per-line(--> Nil) {
meh-for 'pdf-per-line', <modify>;
my sub action-pdf-info(--> Nil) {
handle-pdf 'pdf-info', 'produce-one',
-> $file { $PDFExtract.new(:$file).info }
}
prepare-needle;
%filesystem<is-pdf> //= True unless $reading-from-stdin;
move-filesystem-options-to-rak;
move-result-options-to-rak;
%rak<produce-many> := -> $file { $PDFExtract.new(:$file).text.lines }
my sub action-pdf-per-file(--> Nil) {
handle-pdf 'pdf-per-file', 'produce-one',
-> $file { $PDFExtract.new(:$file).text }
}
activate-output-options;
run-rak;
rak-results;
rak-stats;
my sub action-pdf-per-line(--> Nil) {
handle-pdf 'pdf-per-line', 'produce-many',
-> $file { $PDFExtract.new(:$file).text.lines }
}
my sub action-per-file(--> Nil) {
Expand Down
Binary file added mbc/eigenstates.mbc
Binary file not shown.
2 changes: 2 additions & 0 deletions resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Item producers:
--json-per-line Interpret each line as JSON for pattern matching
--blame-per-file Produce Git::Blame::File object for pattern matcing
--blame-per-line Produce Git::Blame::Line objects for pattern matching
--mbc-frames Produce MoarVM::Bytecode::Frame objects for matching
--mbc-strings Produce MoarVM::Bytecode string-heap strings for matching
--unicode Produce names of codepoints for pattern matching

Code pattern helpers:
Expand Down
50 changes: 31 additions & 19 deletions resources/help/item.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,6 @@ Requires that the Text::CSV module is installed.
For more information about Text::CSV, see
https://raku.land/github:Tux/Text::CSV .

--pdf-info

Attempt to interprete file as a PDF file, and by pass its meta-information
as a single hash to the pattern matcher. Only makes sense if the pattern
is a Callable pattern Only looks at PDF files (as if --is-pdf has been
specified).

--pdf-per-file

Attempt to interprete file as a PDF file, and by pass its text as a single
string to the pattern matcher. Only looks at PDF files (as if --is-pdf
has been specified).

--pdf-per-line

Attempt to interprete file as a PDF file, and by pass its text contents
as lines to the pattern matcher. Only looks at PDF files (as if
--is-pdf has been specified).

--headers

Only applicable when --csv-per-line is also specified. It defaults to
Expand All @@ -223,6 +204,37 @@ $ rak --csv-per-line --headers='<a b>' '{.<a> if .<n> eq "foo"}' info.csv
# Use alternate column names using mapping
$ rak --csv-per-line --headers=':foo<a>, :bar<b>' '{.<a> if .<n> eq "foo"}' info.csv

--pdf-info

Attempt to interprete file as a PDF file, and by pass its meta-information
as a single hash to the pattern matcher. Only makes sense if the pattern
is a Callable pattern Only looks at PDF files (as if --is-pdf has been
specified).

--pdf-per-file

Attempt to interprete file as a PDF file, and by pass its text as a single
string to the pattern matcher. Only looks at PDF files (as if --is-pdf
has been specified).

--pdf-per-line

Attempt to interprete file as a PDF file, and by pass its text contents
as lines to the pattern matcher. Only looks at PDF files (as if
--is-pdf has been specified).

--mbc-frames

Attempt to interprete files as a MoarVM bytecode file and pass
MoarVM::Bytecode::Frame objects to the pattern matcher. Only looks at
MoarVM bytecode files (as if --is-moarvm has been specified).

--mbc-strings

Attempt to interprete files as a MoarVM bytecode file and pass each
string in its string heap to the pattern matcher. Only looks at
MoarVM bytecode files (as if --is-moarvm has been specified).

--unicode

Produce the names of all Unicode defined codepoints (built into Raku)
Expand Down
53 changes: 53 additions & 0 deletions xt/05-mbc.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
BEGIN %*ENV<RAKU_TEST_DIE_ON_FAIL> = 1;
use Test;

plan 4;

my $dir = $*PROGRAM.parent;
my $dira = $dir.absolute ~ $*SPEC.dir-sep;
my $rel := $dir.relative ~ $*SPEC.dir-sep;
my $dot = $?FILE.IO.parent.parent;
my $rak := $dot.add("bin").add("rak").relative;

# using paths from here on out
$dot .= relative;
$dir .= absolute;

my sub query-ok(
*@query, # the actual parameters
:$ok is copy, # the expected result
:$head = 1, # whether to do the --only-first test with this number
:$add-human = True, # add human specification
) is test-assertion {
my @args = $*EXECUTABLE.absolute, "-I$dot", $rak, @query.Slip;
@args.push: "--human" if $add-human;
$ok .= chomp;

# Logic to run the query
my sub run-query() {
my $proc := run @args, :out, :err;
my $key = "huh?";

is $proc.err.slurp(:close), "", "is '@query[]' STDERR clean?";
$proc.out.lines.map(*.subst($rel, :g)).join("\n")
}

# Base query
is run-query, $ok, "is '@query[]' result ok?";
}

query-ok '--mbc-frames', Q/*.name/, 'mbc', '--unique', ok => qq:to/OK/;
<unit-outer>
<unit>
eigenstates
<dependencies+deserialize>

<load>
OK

query-ok <--mbc-strings distribution mbc --/highlight>, ok => qq:to/OK/;
mbc/eigenstates.mbc
55:The eigenstates distribution exports a single subroutine called
OK

# vim: expandtab shiftwidth=4

0 comments on commit 8ee3dbe

Please sign in to comment.