},
'*' => sub { # typeglob, or multiply?
+ if ( $expecting == UNKNOWN && $last_nonblank_type eq 'Z' ) {
+ if ( $next_type ne 'b' && $next_type ne '(' ) {
+ $expecting = TERM;
+ }
+ }
if ( $expecting == TERM ) {
scan_identifier_fast();
}
},
'%' => sub { # hash or modulo?
- # first guess is hash if no following blank
+ # first guess is hash if no following blank or paren
if ( $expecting == UNKNOWN ) {
- if ( $next_type ne 'b' ) { $expecting = TERM }
+ if ( $next_type ne 'b' && $next_type ne '(' ) {
+ $expecting = TERM;
+ }
}
if ( $expecting == TERM ) {
scan_identifier_fast();
# hash lookup table of operator expected values
my %op_expected_table;
+# exceptions to perl's weird parsing rules after type 'Z'
+my %is_weird_parsing_rule_exception;
+
BEGIN {
# Always expecting TERM following these types:
push @q, ')';
@{op_expected_table}{@q} = (OPERATOR) x scalar(@q);
+ # Fix for git #62: added '*' and '%'
+ @q = qw( < ? * % );
+ @{is_weird_parsing_rule_exception}{@q} = (OPERATOR) x scalar(@q);
+
}
+use constant DEBUG_OPERATOR_EXPECTED => 0;
+
sub operator_expected {
# Returns a parameter indicating what types of tokens can occur next
# The 'weird parsing rules' of next section do not work for '<' and '?'
# It is best to mark them as unknown. Test case:
# print $fh <DATA>;
- elsif ( $tok =~ /^[\<\?]$/ ) {
+ elsif ( $is_weird_parsing_rule_exception{$tok} ) {
$op_expected = UNKNOWN;
}
RETURN:
- # debug and diagnostics can go here..
-
- 0 && do {
+ DEBUG_OPERATOR_EXPECTED && do {
print STDOUT
-"EXPECT: returns $op_expected for last type $last_nonblank_type token $last_nonblank_token\n";
+"OPERATOR_EXPECTED: returns $op_expected for last type $last_nonblank_type token $last_nonblank_token\n";
};
return $op_expected;
# of the sub so the next opening brace can be labeled.
# Setting 'statement_type' causes any ':'s to introduce
# attributes.
- elsif ( $next_nonblank_token eq ':') {
+ elsif ( $next_nonblank_token eq ':' ) {
if ( $call_type == SUB_CALL ) {
$statement_type =
substr( $tok, 0, 3 ) eq 'sub' ? $tok : 'sub';
@is_keyword{@Keywords} = (1) x scalar(@Keywords);
}
1;
+