Skip to content

Commit

Permalink
Merge pull request #1286 from ehuelsmann/update-perl
Browse files Browse the repository at this point in the history
gherkin-perl: Update Perl Gherkin implementation
  • Loading branch information
ehuelsmann committed Jan 10, 2021
2 parents 2978153 + f3781ec commit 5a23af9
Show file tree
Hide file tree
Showing 11 changed files with 2,221 additions and 868 deletions.
17 changes: 9 additions & 8 deletions gherkin/perl/bin/gherkin-generate-ast
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ package App::GherkinGenerateAst;

sub run {
my ($class, $fh, @file_list) = @_;
my $next_id = 0;

my $json = Cpanel::JSON::XS->new->utf8->canonical;

my $parser = Gherkin::Parser->new();
my $parser = Gherkin::Parser->new(
Gherkin::AstBuilder->new(
sub {
my $id = $next_id++;
return "$id";
})
);

for my $file (@file_list) {
my $gherkin_document = $parser->parse($file);
my $event = {
type => 'gherkin-document',
uri => $file,
document => $gherkin_document
};
print $fh $json->encode( $event );
print $fh $json->encode( $parser->parse($file, $file) );
print "\n"
}

Expand Down
19 changes: 11 additions & 8 deletions gherkin/perl/bin/gherkin-generate-pickles
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ sub run {
my ( $class, $fh, @file_list ) = @_;
my $json = Cpanel::JSON::XS->new->utf8->canonical;

my $parser = Gherkin::Parser->new();
my $next_id = 0;
my $id_generator =
sub {
my $id = $next_id++;
return "$id";
};
my $parser = Gherkin::Parser->new(
Gherkin::AstBuilder->new($id_generator)
);

for my $file (@file_list) {
my $pickles = Gherkin::Pickles::Compiler->compile(
$parser->parse($file)
$parser->parse($file, $file), $id_generator
);
for my $pickle (@$pickles) {
my $event = {
type => 'pickle',
uri => $file,
pickle => $pickle
};
print $fh $json->encode($event);
print $fh $json->encode($pickle);
print "\n"
}
}
Expand Down
7 changes: 3 additions & 4 deletions gherkin/perl/gherkin-perl.razor
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ our %states_to_match_names = (
);

sub parse {
my ( $self, $token_scanner, $token_matcher ) = @@_;
my ( $self, $token_scanner, $uri ) = @@_;

$token_matcher ||= Gherkin::TokenMatcher->new();
$token_scanner = Gherkin::TokenScanner->new($token_scanner)
unless ref $token_scanner && (ref $token_scanner ne 'SCALAR');

$self->ast_builder->reset();
$self->ast_builder->reset($uri);
$token_matcher->reset();

my $context = Gherkin::ParserContext->new(
{
token_scanner => $token_scanner,
token_matcher => $token_matcher,
token_matcher => $self->token_matcher,
}
);

Expand Down

0 comments on commit 5a23af9

Please sign in to comment.