From df9c906ae0b45aaa2366812e892cfde150ec52c1 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Fri, 28 Oct 2022 13:45:08 +0200 Subject: [PATCH] 0.2 --- Changes | 6 ++- META6.json | 4 +- README.md | 9 +++- doc/App-Rak.rakudoc | 6 +++ lib/App/Rak.rakumod | 4 +- resources/help.txt | 14 +++--- resources/help/pattern.txt | 92 +++++++++++++++++++++++++++----------- xt/02-simple.rakutest | 14 +++--- 8 files changed, 105 insertions(+), 44 deletions(-) diff --git a/Changes b/Changes index f5f3045..85dc524 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/META6.json b/META6.json index 57034f2..d518ea7 100644 --- a/META6.json +++ b/META6.json @@ -9,7 +9,7 @@ "as-cli-arguments:ver<0.0.7>:auth", "CLI::Version:ver<0.0.8>:auth", "has-word:ver<0.0.3>:auth", - "highlighter:ver<0.0.16>:auth", + "highlighter:ver<0.0.17>:auth", "IO::Path::AutoDecompress:ver<0.0.2>:auth", "JSON::Fast::Hyper:ver<0.0.3>:auth", "META::constants:ver<0.0.3>:auth", @@ -58,5 +58,5 @@ ], "test-depends": [ ], - "version": "0.1.12" + "version": "0.2" } diff --git a/README.md b/README.md index 47930d9..1c7b7c3 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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] ----------------- diff --git a/doc/App-Rak.rakudoc b/doc/App-Rak.rakudoc index 7da5998..09b91ac 100644 --- a/doc/App-Rak.rakudoc +++ b/doc/App-Rak.rakudoc @@ -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. diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index 304d8c3..b7e0590 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -1,7 +1,7 @@ # The modules that we need here, with their full identities use as-cli-arguments:ver<0.0.7>:auth; # as-cli-arguments use has-word:ver<0.0.3>:auth; # has-word -use highlighter:ver<0.0.16>:auth; # columns highlighter matches +use highlighter:ver<0.0.17>:auth; # columns highlighter matches use IO::Path::AutoDecompress:ver<0.0.2>:auth; # IOAD use JSON::Fast::Hyper:ver<0.0.3>:auth; # from-json to-json use META::constants:ver<0.0.3>:auth $?DISTRIBUTION; @@ -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 = ; #- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE diff --git a/resources/help.txt b/resources/help.txt index d719881..ef116e3 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -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 diff --git a/resources/help/pattern.txt b/resources/help/pattern.txt index 24cfd55..e1d247d 100644 --- a/resources/help/pattern.txt +++ b/resources/help/pattern.txt @@ -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 @@ -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: @@ -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". @@ -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. diff --git a/xt/02-simple.rakutest b/xt/02-simple.rakutest index 34f4638..33d514c 100644 --- a/xt/02-simple.rakutest +++ b/xt/02-simple.rakutest @@ -80,6 +80,8 @@ my sub query-ok( # Checks for "ine" my @ine = ( , + , + , , , <ïñę --type=ends-with --ignoremark>, @@ -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 , :head(2), ok => qq:to/OK/; seven @@ -211,7 +215,7 @@ for , <*.words.Slip> { OK } -for <*.&defined>, <{$_}> { +for <*.defined>, <{$_}> { query-ok $_, '--frequencies', ok => q:to/OK/; 10:zero 9:one @@ -240,7 +244,7 @@ nine OK } -for <*.&defined>, <{$_}> { +for <*.defined>, <{$_}> { query-ok $_, '--unique', ok => q:to/OK/; zero one