| 1 | # cmdline.yp: Parse::Yapp file for the command-line parser for App::GitFind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2019 Christopher White. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 2019 D3 Engineering, LLC. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Licensed MIT. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | %{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Imports {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use App::GitFind::Base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use App::GitFind::Actions (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Hash::Merge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Documentation {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | App::GitFind::cmdline - Command-line parser for git-find | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | Generate the .pm file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | yapp -m App::GitFind::cmdline -o lib/App/GitFind/cmdline.pm support/cmdline.yp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | And then: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | use App::GitFind::cmdline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | App::GitFind::cmdline::Parse(\@ARGV); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # Helpers for the parser {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # Merge any number of hashrefs together and return a hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub _merge { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | state $merger = Hash::Merge->new('RETAINMENT_PRECEDENT'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $merger->set_clone_behavior(false); # No cloning | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $retval = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | for(@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | next unless ref eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $retval = $merger->merge($retval, $_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return $retval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | %} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | # Token and precedence definitions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | %token SWITCH # flags controlling the operation of git-find | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | %token REV # a git ref or rev | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # elements of expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | %token COMMA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | %token OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | %token AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | %token NOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | %token LPAREN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | %token RPAREN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | %token TEST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | %token ACTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | %left COMMA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | %left OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | %left AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | %left NOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | %% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Rules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | cmdline: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | { +{} } # empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | | expr { +{ expr => $_[1] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | | switches_and_revs maybeexprplus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | { _merge($_[1], $_[2]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Switches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | switches_and_revs: SWITCH { +{ switches => {$_[1]=>[true]} } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # arrayref so @{{switches}->{foo}} will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # always work. That way we can test for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # switches specified multiple times. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | | REV { +{ revs => [$_[1]] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | | switches_and_revs SWITCH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | { _merge($_[1], +{ switches => {$_[2]=>[true]} }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | | switches_and_revs REV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | { _merge($_[1], +{ revs => [$_[2]] }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Expressions. Since "and", "or", and "not" are keywords in Perl, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | maybeexprplus: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | { +{} } # empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | | expr { +{ expr => $_[1] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | | expr switches_and_revs { +{ expr => $_[1], %{$_[2]} } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # %$_[2]: inline the switches and revs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # TODO once the parser is solid and the tests are written: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # collapse consecutive elements of the same type into flat lists. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | expr: element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | | expr COMMA expr { +{ SEQ => [@_[1,3]] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | | expr OR expr { +{ OR => [@_[1,3]] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # "OR" because "or" is a Perl keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # subsequent_expr is used so the parser will know when to reduce. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # The rule "expr expr %prec AND" was right-associative | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # even though explicit-AND was left-associative because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # the parser did not start reducing until after anything that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # could be an expr. A subsequent_expr cannot start with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # a plain expr, so the parser has a reason to reduce the expr. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | | expr subsequent_expr %prec AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | { +{ AND => [@_[1,2]] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | | expr AND expr { +{ AND => [@_[1,3]] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | | NOT expr4 { +{ NOT => $_[2] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | | LPAREN expr RPAREN { $_[2] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | subsequent_expr: # Everything higher-precedence than AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | | NOT expr4 { +{ NOT => $_[2] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | | LPAREN expr RPAREN { $_[2] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | element: TEST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | | ACTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $_[0]->YYData->{SAW_NON_PRUNE_ACTION} = true if $_[1] ne 'prune'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | %% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Footer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # Helpers for the tokenizer {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Flag a ref as invalid without using regexes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Implements https://git-scm.com/docs/git-check-ref-format as archived at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # https://web.archive.org/web/20190725153529/https://git-scm.com/docs/git-check-ref-format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | sub _is_ref_ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $arg = @_ ? $_[0] : $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_ref_ok: not called CC=16 SCAR=56.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return false unless defined $arg and length($arg)>0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $arg and length $arg > 0
MC/DC0%0/2
defined $arg and length $arg > 0
defined $arg
length $arg > 0
Truth table0%0/3
A and B
A= defined $argB= length $arg > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | #1 - restrictions on slash-separated components | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if(index($arg, '/') != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return false if index($arg, '/.') != -1 #internal components | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
index($arg, "/.") != -1 or index($arg, ".lock/") != -1 or substr($arg, 0, 1) eq "." or substr($arg, -5) eq ".lock"
index($arg, "/.") != -1 or index($arg, ".lock/") != -1 or substr($arg, 0, 1) eq "."
index($arg, "/.") != -1 or index($arg, ".lock/") != -1
MC/DC0%0/4
index($arg, "/.") != -1 or index($arg, ".lock/") != -1 or substr($arg, 0, 1) eq "." or substr($arg, -5) eq ".lock"
index($arg, "/.") != -1
index($arg, ".lock/") != -1
substr($arg, 0, 1) eq "."
substr($arg, -5) eq ".lock"
Truth table0%0/5
A or B or C or D
A= index($arg, "/.") != -1B= index($arg, ".lock/") != -1C= substr($arg, 0, 1) eq "."D= substr($arg, -5) eq ".lock"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | || index($arg, '.lock/') != -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | || substr($arg, 0, 1) eq '.' #components at start/end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | || substr($arg, -5) eq '.lock'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # Ignore #2 - assume --allow-onelevel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | #3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return false if index($arg, '..') != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | #4 - require the caller to check that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | #5 - require the caller to check that - assume NOT --refspec-pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | #6 - assume NOT --normalize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | return false if substr($arg, 0, 1) eq '/' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
substr($arg, 0, 1) eq "/" or substr($arg, -1) eq "/" or index($arg, "//") != -1
substr($arg, 0, 1) eq "/" or substr($arg, -1) eq "/"
MC/DC0%0/3
substr($arg, 0, 1) eq "/" or substr($arg, -1) eq "/" or index($arg, "//") != -1
substr($arg, 0, 1) eq "/"
substr($arg, -1) eq "/"
index($arg, "//") != -1
Truth table0%0/4
A or B or C
A= substr($arg, 0, 1) eq "/"B= substr($arg, -1) eq "/"C= index($arg, "//") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | || substr($arg, -1) eq '/' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | || index($arg, '//') != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # #7. Also prohibits ".", which is OK for git-find since it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # fairly ambiguous between a ref/rev and a path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | return false if substr($arg, -1) eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | #8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | return false if index($arg, '@{') != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | #9 ('@') - ignore this one for simplicity in the rev test below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | #10 - require the caller to check that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Extra: Prohibit refs that start with '--' since they are arguably | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # ambiguous with command-line options (and I can't make them work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # with git anyway). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | return false if substr($arg, 0, 2) eq '--'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return true; # It's OK if we got here | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } #_is_ref_ok() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | #use re 'debug'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Regex to match a rev or range of revs, i.e., something we should pass to git | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | my $_rev_regex = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | qr`(?xi) # backtick delimiter because it doesn't occur in the regex text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | (?&RevRange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | (?(DEFINE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | (?<RevRange> ^(?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # :/text, :/!-text, :/!!text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | (?::/ #(?{ print "# saw colon slash\n"; }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 |  #(?{print "# 4\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | | [^!].* #(?{print "# 5\u";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # :[n:]path. NOTE: we prohibit starting the path with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # / if there is no number, in order to disambiguate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # the :/ text-search cases. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | | :\d+:(?:.+) #(?{print "# 2\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | | :[^/].* #(?{print "# 3\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # ^<rev> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | | \^(?&Rev) #(?{print "# 6\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # rev:path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | | (?&Rev):(?:.+) #(?{print "# 7\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # .. and ... differences, including x.., x..., x..y, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # and x...y. Also handles the fallthrough | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # of revrange->rev->ref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | | (?&Rev)(?:\.{2,3}(?&Rev)?)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | #(?{print "# 8\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # ..rev and ...rev | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | | \.{2,3}(?&Rev) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # at sign followed by braced item, and possibly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # preceded by a REF (not a rev). E.g., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # HEAD@{1}@{1} doesn't work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # refname - at sign - braced item (date, #, branch, "push") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | | (?&Ref)?\@\{[^\}]+\} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | #(?{print "# 9\n";}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # git-rev-parse "Options for Objects" forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | | --all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | | --(?:branches|tags|remotes)(?:=.+)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | | --(?:glob|exclude)=.+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | | --disambiguate=[0-9a-f]{4,40} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # git-rev-parse "Other Options" forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | | --(since|after|until|before)=.+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | )$) # End of RevRange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | (?<Rev> (?&Ref)(?&RefTrailer)* ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # This handles most of the cases. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # SHA1s, possibly abbreviated, are refs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # as are git-describe outputs, whence RefTrailer* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # instead of RefTrailer+. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | (?<RefTrailer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # For rev^[#] and rev~[#] forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | [~\^]\d* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # For rev^{} forms (empty braces OK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | | \^\{[^\}]*\} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # For rev^[@!] and rev^-n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | | \^(?: \@ | ! | -\d* ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | ) # End of RefTrailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | (?<Ref> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ( \@ # '@' from git-rev-parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | | (?:[^\000-\037\177\ ~\^:\\?*\[.@/] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # git-check-ref-format #4, #5. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # [.@/] are handled below | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | | \.(?!\.) # . ok, but .. prohibited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | | \@(?!\{) # @ ok, but @{ prohibited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | | /(?!/) # / ok, but // prohibited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | )+? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | (?(?{ _is_ref_ok($+) })|(?!)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # NOTE: $+ used since I couldn't get named capture groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # with either %+ or %- to work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | ) # End of <Ref> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ) #End of (DEFINE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | `xi; # End of qr`...` and an extra backtick to unconfuse vim-eyapp: ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | sub _is_valid_rev { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my $arg = @_ ? $_[0] : $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_valid_rev: not called CC=4 SCAR=30.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | return false unless defined $arg and length($arg)>0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $arg and length $arg > 0
MC/DC0%0/2
defined $arg and length $arg > 0
defined $arg
length $arg > 0
Truth table0%0/3
A and B
A= defined $argB= length $arg > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return scalar($arg =~ m{$_rev_regex}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } #_is_valid_rev() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Get an expression element from the array passed in $_[0]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | my $ARGTEST_cached = App::GitFind::Actions::ARGTEST(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | sub _consume_expression_element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | my $lrArgv = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_consume_expression_element: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my @retval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | #say STDERR "# Trying >>$lrArgv->[0]<<"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # TODO find(1) positional options, global options? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Regular options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if($lrArgv->[0] =~ $ARGTEST_cached) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | #say STDERR "# - matched"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $arg = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my %opts = %{App::GitFind::Actions::argdetails($arg)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # No-argument tests or actions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | unless($opts{nparam}>0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | #say STDERR "# - No parameters"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | shift @$lrArgv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return ($opts{token} => $arg) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Consume additional arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | #say STDERR "# - $opts{nparam} parameters"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | die "Not enough parameters after --$arg (need $opts{nparam})" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | unless @$lrArgv >= ($opts{nparam}+1); # +1 for $arg itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | @retval = ($opts{token} => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | name => $arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | params => [ @{$lrArgv}[1..$opts{nparam}] ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | splice @$lrArgv, 0, $opts{nparam}+1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | return @retval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # Operators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $arg = $lrArgv->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | @retval = (COMMA => ',') if $arg eq ','; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | @retval = (OR => '-o') if $arg =~ /^(?:-o|--o|-or|--or|\|\|)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | @retval = (AND => '-a') if $arg =~ /^(?:-a|--a|-and|--and|&&)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | @retval = (NOT => '!') if $arg =~ /^(?:-not|--not|!|\^)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | @retval = (LPAREN => '(') if $arg =~ /^[([]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | @retval = (RPAREN => ')') if $arg =~ /^[])]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if(@retval) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | shift @$lrArgv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | return @retval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return (); # Not an expression element | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } #_consume_expression_element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # Get a switch from the array passed in $_[0], if any. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Removes the switch from the array if successful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # Returns the token on success, and () on failure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # TODO un-bundle switches; handle switches with args. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | sub _consume_switch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | my $lrArgv = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_consume_switch: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | if($lrArgv->[0] =~ /^-([a-zA-z0-9\?])$/) { # non-bundled switch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | shift @$lrArgv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return (SWITCH => $1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } elsif($lrArgv->[0] =~ /^--?(help|man|usage|version)$/) { # long switch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | shift @$lrArgv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | return (SWITCH => $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } #_consume_switch() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # Consume a rev from the array in $_[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | sub _consume_rev { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $lrArgv = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_consume_rev: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $arg = $lrArgv->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if(_is_valid_rev($arg)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | shift @$lrArgv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | return (REV => $arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } #_consume_rev() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # Tokenizer and error-reporting routine for Parse::Yapp {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # The lexer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | sub _next_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | my $parser = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_token: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my $lrArgv = $parser->YYData->{ARGV}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | return ('', undef) unless @$lrArgv; # EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my @retval; # The eventual token we will return | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # TODO? in the expression, split trailing commas into their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # own arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # Check for '--' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if($lrArgv->[0] eq '--') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $parser->YYData->{ONLY_EXPRESSIONS} = true; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | return ('', undef) unless @$lrArgv > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # We are about to shift, so return EOF if this was the last arg. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | shift(@$lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if($parser->YYData->{HAS_DASH_DASH}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # Split-arg mode: don't look for expressions before '--', or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # for switches or refs after '--'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | if(!$parser->YYData->{ONLY_EXPRESSIONS}) { # Look for switches/refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | @retval = _consume_switch($lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | return @retval if @retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | @retval = _consume_rev($lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | return @retval if @retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | die "I don't understand argument '$lrArgv->[0]' before --"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } else { # Look for expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | @retval = _consume_expression_element($lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | return @retval if @retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | die "I don't understand argument '$lrArgv->[0]' after --"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # Merged-arg mode: any arg could be anything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Check for expressions. Look for these before checking for refs so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # that an expression that happens to look like a ref will be considered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # an expression instead of a ref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my @retval = _consume_expression_element($lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | return @retval if @retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Next, look for switches. These are after expression elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # so that -a and -o will not be parsed as switches. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | @retval = _consume_switch($lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | return @retval if @retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # Last of all, revs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | @retval = _consume_rev($lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | return @retval if @retval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | die "I don't understand argument $lrArgv->[0]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | die "Unexpected error while processing argument $lrArgv->[0]"; # Shouldn't happen | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } #_next_token() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # Report an error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | sub _report_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | my $parser = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_error: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | my $got = $parser->YYCurtok || '<end of input>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$parser->YYCurtok || '<end of input>'
MC/DC0%0/1
$parser->YYCurtok || '<end of input>'
$parser->YYCurtok
Truth table0%0/2
A
A= $parser->YYCurtok
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $val=''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | $val = ' (' . $parser->YYCurval . ')' if $parser->YYCurval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | print 'Syntax error: could not understand ', $got, $val, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if(ref($parser->YYExpect) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | print 'Expected one of: ', join(',', @{$parser->YYExpect}), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } #_report_error() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # Top-level parse function {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | =head2 Parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | Parse arguments. Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | my $hrArgs = App::GitFind::cmdline::Parse(\@ARGV); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | sub Parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | my $lrArgv = shift or croak 'Parse: Need an argument list'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Parse: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $parser = __PACKAGE__->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my $hrData = $parser->YYData; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $hrData->{HAS_DASH_DASH} = !!(scalar grep { $_ eq '--' } @$lrArgv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $hrData->{ONLY_EXPRESSIONS} = false; # true once we hit '--' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | $hrData->{ARGV} = $lrArgv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # Keep track of whether an action other than -prune has been seen. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # If not, -print is added automatically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $hrData->{SAW_NON_PRUNE_ACTION} = false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $hrRetval = $parser->YYParse(yylex => \&_next_token, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | yyerror => \&_report_error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | (@_ ? (yydebug => $_[0]) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | $hrRetval->{sawnpa} = $hrData->{SAW_NON_PRUNE_ACTION} if $hrRetval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | return $hrRetval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } #Parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # Rest of the docs {{{1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | Christopher White C<< <cxw@cpan.org> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | MIT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # vi: set fdm=marker: # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||