Skip to content

Commit

Permalink
Perlito5 - misc/Perl5_parser error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jul 9, 2024
1 parent cc55a3a commit 27b6ade
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions misc/perl5_parser/perl5_parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ sub tokenize {
'=>' => 1,
);

sub error_message_string_terminator {
my ( $tokens, $index, $quote ) = @_;
if ($quote eq '"') {
return "Can't find string terminator '$quote' anywhere before EOF\n";
}
return "Can't find string terminator \"$quote\" anywhere before EOF\n";
}

sub error_message {
my ( $tokens, $index, $message ) = @_;

Expand Down Expand Up @@ -673,6 +681,7 @@ sub parse_single_quote_string { # 'abc'
$value .= $tokens->[$pos][1];
$pos++;
}
die error_message_string_terminator( $tokens, $index, $quote );
}

sub parse_double_quote_string { # "abc"
Expand Down Expand Up @@ -718,6 +727,7 @@ sub parse_double_quote_string { # "abc"
$value .= $tokens->[$pos][1];
$pos++;
}
die error_message_string_terminator( $tokens, $index, $quote );
}

sub parse_regex_string { # /abc/
Expand Down Expand Up @@ -763,6 +773,7 @@ sub parse_regex_string { # /abc/
$value .= $tokens->[$pos][1];
$pos++;
}
die error_message( $tokens, $index, "Search pattern not terminated" );
}

sub parse_delim_expression {
Expand Down Expand Up @@ -993,6 +1004,7 @@ sub token_as_string {

sub main {
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
binmode( STDOUT, ":utf8" );
my $perl_code = join( '', <DATA> );
my $tokens = tokenize($perl_code);
Expand Down

0 comments on commit 27b6ade

Please sign in to comment.