| 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package Cucumber::TagExpressions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Cucumber::TagExpressions::VERSION = '11.2.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | Cucumber::TagExpressions - Tag expression parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | use Cucumber::TagExpressions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | my $expr = Cucumber::TagExpressions->parse( '@a and @b' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | if ( $expr->evaluate( qw/x y z/ ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | say "The evaluation returned false"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | Cucumber tag expressions allow users to define the subset of Gherkin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | scenarios they want to run. This library parses the expression and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | returns an evaluator object which can be used to test the tags specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | on a scenario against the filter expression. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use Cucumber::TagExpressions::Node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub _expect_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expect_token: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my ( $state, $token ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $actual = _get_token( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | die "Expecting token '$token' but found '$actual'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | if $token ne $actual; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 237 | ▶ | sub _consume_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_consume_char: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 237 | my ( $state, $allow_eof ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 237 | ▶ | if ( length($state->{text}) <= $state->{pos} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 43 | ▶ | return if $allow_eof; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die "Unexpected end of string parsing tag expression: $state->{text}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 194 | return substr( $state->{text}, $state->{pos}++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 103 | ▶ | sub _get_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_token: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 103 | my ( $state ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 103 | ▶ | return delete $state->{saved_token} if defined $state->{saved_token}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 94 | my $token = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 94 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 233 | my $char = _consume_char( $state, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 233 | ▶ | return ($token ? $token : undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | if not defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 191 | ▶ | if ( $char =~ m/\s/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 42 | ▶ | if ( $token ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 41 | return $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ▶ | elsif ( $char eq '(' or $char eq ')' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$char eq "(" or $char eq ")"
MC/DC100%2/2
$char eq "(" or $char eq ")"
$char eq "("
$char eq ")"
Truth table100%3/3
A or B
A= $char eq "("B= $char eq ")"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 10 | ▶ | if ( $token ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | _save_token( $state, $char ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | return $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 139 | ▶ | if ( $char eq "\\" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | ▶ | $char = _consume_char( $state, 1 ) // '<end-of-input>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
_consume_char($state, 1) // "<end-of-input>"
MC/DC100%1/1
_consume_char($state, 1) // "<end-of-input>"
_consume_char($state, 1)
Truth table100%2/2
A
A= _consume_char($state, 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | if ( $char eq '(' or $char eq ')' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$char eq "(" or $char eq ")" or $char eq "\\" or $char =~ /\s/
$char eq "(" or $char eq ")" or $char eq "\\"
$char eq "(" or $char eq ")"
MC/DC50%2/4
$char eq "(" or $char eq ")" or $char eq "\\" or $char =~ /\s/
$char eq "("
$char eq ")"
$char eq "\\"
$char =~ /\s/
Truth table60%3/5
A or B or C or D
A= $char eq "("B= $char eq ")"C= $char eq "\\"D= $char =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | or $char eq "\\" or $char =~ /\s/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | $token .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | die qq{Tag expression "$state->{text}" could not be parsed because of syntax error: Illegal escape before "$char".}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 135 | $token .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | ▶ | sub _save_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_save_token: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | my ( $state, $token ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 9 | $state->{saved_token} = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 47 | ▶ | sub _term_expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_term_expr: called CC=9 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 47 | my ( $state ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 47 | my $token = _get_token( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 46 | ▶ | die qq{Tag expression "$state->{text}" could not be parsed because of syntax error: Expected operand.} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | if not defined $token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 44 | ▶ | if ( $token eq '(' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | my $expr = _expr( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | my $token = _get_token( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | ▶ | if ( not $token or $token ne ')' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $token or $token ne ")"
MC/DC0%0/2
not $token or $token ne ")"
not $token
$token ne ")"
Truth table33%1/3
not(A) or B
A= not $tokenB= $token ne ")"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | die qq{Tag expression "$state->{text}" could not be parsed because of syntax error: Unmatched (.} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | return $expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif ( $token eq 'not' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | return Cucumber::TagExpressions::NotNode->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | expression => _term_expr( $state ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 34 | ▶ | if ( $token eq 'and' or $token eq 'or' or $token eq 'not' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$token eq "and" or $token eq "or" or $token eq "not"
$token eq "and" or $token eq "or"
MC/DC0%0/3
$token eq "and" or $token eq "or" or $token eq "not"
$token eq "and"
$token eq "or"
$token eq "not"
Truth table25%1/4
A or B or C
A= $token eq "and"B= $token eq "or"C= $token eq "not"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | die qq{Tag expression "$state->{text}" could not be parsed because of syntax error: Expected operand."}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 34 | return Cucumber::TagExpressions::LiteralNode->new( tag => $token ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 25 | ▶ | sub _expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expr: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 25 | my ( $state ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 25 | my @terms = ( _term_expr( $state ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 23 | ▶ | while ( my $token = _get_token( $state ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 25 | ▶ | if ( not defined $token or $token eq ')' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $token or $token eq ")"
MC/DC50%1/2
not defined $token or $token eq ")"
not defined $token
$token eq ")"
Truth table66%2/3
not(A) or B
A= not defined $tokenB= $token eq ")"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | _save_token( $state, $token ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 20 | ▶ | if ( not ( $token eq 'or' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token eq "or" or $token eq "and"
MC/DC100%2/2
$token eq "or" or $token eq "and"
$token eq "or"
$token eq "and"
Truth table100%3/3
A or B
A= $token eq "or"B= $token eq "and"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | or $token eq 'and' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | die qq{Tag expression "$state->{text}" could not be parsed because of syntax error: Expected operator.} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 17 | my $term = _term_expr( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | ▶ | if ( $token eq 'and' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # immediately combine _and_ terms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 7 | push @terms, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | Cucumber::TagExpressions::AndNode->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | terms => [ pop(@terms), $term ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # collect _or_ terms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | push @terms, $term; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 18 | ▶ | if ( scalar(@terms) > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | return Cucumber::TagExpressions::OrNode->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | terms => \@terms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # don't wrap a single-term expression in an Or node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | return $terms[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | =head2 $class->parse( $expression ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Parses the string specified in C<$expression> and returns a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | L<Cucumber::TagExpressions::ExpressionNode> instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 20 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 20 | my ( $class, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 20 | ▶ | return Cucumber::TagExpressions::ExpressionNode->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | sub_expression => undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | if $text =~ /^\s*$/; # match the empty string or space-only string as "constant true" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 20 | my $state = { pos => 0, text => $text, saved_token => undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 20 | my $expr = _expr( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 14 | my $token = _get_token( $state ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 14 | ▶ | if ( defined $token ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | if ( $token eq ')' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | die qq{Tag expression "$state->{text}" could not be parsed because of syntax error: Unmatched ).}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | die "Junk at end of expression: $token"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 13 | return Cucumber::TagExpressions::ExpressionNode->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub_expression => $expr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||