Skip to content

Commit

Permalink
Perlito5 - misc/perl5_parser refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jul 12, 2024
1 parent 2d8ffeb commit 808ea18
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions misc/perl5_parser/perl5_parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,8 @@ sub parse_number {
my $pos = $index;
if ( $tokens->[$pos][0] == DOT() ) {
$pos++; # .
if ( $tokens->[$pos][0] == NUMBER() ) {
$pos++; # .123
}
else {
return parse_fail();
}
return parse_fail() if $tokens->[$pos][0] != NUMBER();
$pos++; # .123
}
elsif ( $tokens->[$pos][0] == NUMBER() ) {
$pos++; # 123
Expand All @@ -819,31 +815,22 @@ sub parse_number {
$pos++; # 123.456
}
}
else {
if ( $tokens->[$pos][0] != IDENTIFIER() ) {
return { type => 'INTEGER', index => $index, value => join( '', map { $tokens->[$_][1] } $index .. $pos - 1 ), next => $pos };
}
elsif ( $tokens->[$pos][0] != IDENTIFIER() ) { # no exponent
return { type => 'INTEGER', index => $index, value => join( '', map { $tokens->[$_][1] } $index .. $pos - 1 ), next => $pos };
}
}
else {
return parse_fail();
}

if ( $tokens->[$pos][0] == IDENTIFIER() && $tokens->[$pos][1] =~ /^e([0-9]*)$/i ) {
if ( $tokens->[$pos][0] == IDENTIFIER() && $tokens->[$pos][1] =~ /^e([0-9]*)$/i ) { # exponent
if ($1) {
$pos++; # E10
$pos++; # E10
}
else {
$pos++; # 123E-10
if ( $tokens->[$pos][0] == MINUS() ) {
$pos++; # -
}
if ( $tokens->[$pos][0] == NUMBER() ) {
$pos++; # 123
}
else {
return parse_fail();
}
$pos++; # 123E-10
$pos++ if $tokens->[$pos][0] == MINUS(); # -
return parse_fail() if $tokens->[$pos][0] != NUMBER();
$pos++; # 123
}
}
return { type => 'NUMBER', index => $index, value => join( '', map { $tokens->[$_][1] } $index .. $pos - 1 ), next => $pos };
Expand Down

0 comments on commit 808ea18

Please sign in to comment.