The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

use strict;
$Gherkin::Exceptions::VERSION = '32.0.0';
sub stringify { my $self = shift; $self->message }
sub throw { my $class = shift; die $class->new(@_) }
# Parent of single and composite exceptions
$Gherkin::Exceptions::Parser::VERSION = '32.0.0';
# Composite exceptions
$Gherkin::Exceptions::CompositeParser::VERSION = '32.0.0';
use Class::XSAccessor accessors => [qw/errors/];
sub new {
my ( $class, @errors ) = @_;
bless { errors => \@errors }, $class;
}
sub message {
my $self = shift;
return join "\n",
( 'Parser errors:', map { $_->message } @{ $self->errors } );
}
sub throw { my $class = shift; die $class->new(@_) }
#
# Various non-composite exceptions
#
$Gherkin::Exceptions::SingleParser::VERSION = '32.0.0';
use Class::XSAccessor accessors => [qw/detailed_message location/];
sub new {
my ( $class, %args ) = @_;
bless { %args }, $class;
}
sub message {
my $self = shift;
return sprintf( '(%i:%i): %s',
$self->location->{'line'},
( $self->location->{'column'} || 0 ),
$self->detailed_message );
}
$Gherkin::Exceptions::NoSuchLanguage::VERSION = '32.0.0';
use Class::XSAccessor accessors => [qw/language location/];
sub new {
my ( $class, $language, $location ) = @_;
return bless { language => $language, location => $location }, $class;
}
sub detailed_message {
my $self = shift;
return "Language not supported: " . $self->language;
}
$Gherkin::Exceptions::AstBuilder::VERSION = '32.0.0';
use Class::XSAccessor accessors => [qw/location ast_message/];
sub new {
my ( $class, $ast_message, $location ) = @_;
return bless { ast_message => $ast_message, location => $location },
$class;
}
sub detailed_message {
my $self = shift;
return $self->ast_message;
}
$Gherkin::Exceptions::UnexpectedEOF::VERSION = '32.0.0';
use Class::XSAccessor accessors => [qw/location expected_token_types/];
sub new {
my ( $class, $received_token, $expected_token_types ) = @_;
return bless {
location => $received_token->location,
received_token => $received_token,
expected_token_types => $expected_token_types
}, $class;
}
sub detailed_message {
my $self = shift;
return "unexpected end of file, expected: " . join ', ',
@{ $self->expected_token_types };
}
$Gherkin::Exceptions::UnexpectedToken::VERSION = '32.0.0';
use Class::XSAccessor accessors =>
[qw/location received_token_value expected_token_types state_comment/];
sub new {
my ( $class, $received_token, $expected_token_types, $state_comment )
= @_;
my $received_token_value = $received_token->token_value;
$received_token_value =~ s/^\s+//;
$received_token_value =~ s/\s+$//;
my %location = %{ $received_token->location };
$location{'column'} = $received_token->line->indent + 1
unless defined $location{'column'};
return bless {
location => \%location,
received_token_value => $received_token_value,
expected_token_types => $expected_token_types,
state_comment => $state_comment,
}, $class;
}
sub detailed_message {
my $self = shift;
return sprintf(
"expected: %s, got '%s'",
( join ', ', @{ $self->expected_token_types } ),
$self->received_token_value,
);
}
1;