NAME
Gherkin - a parser and compiler for the Gherkin language
SYNOPSIS
use Gherkin;
sub sink {
my $msg = shift;
use Data::Dumper;
print Dumper($msg);
}
my $id = 0;
my gen { $id++ };
Gherkin->from_paths( [ 'your.feature' ],
\&gen, \&sink );
DESCRIPTION
This is the Perl implementation of the Gherkin language parser and compiler as developed by the Cucumber project (https://github.com/cucumber).
Gherkin is a simple language, with a formal specification. The parser in this implementation is generated off the official language grammar.
OVERVIEW
The Cucumber toolkit consists of a set of tools which form a pipe line: each consumes and produces protobuf messages (https://github.com/cucumber/messages/messages.proto). These messages are either use ndjson or binary formatting.
The start of the pipeline is the Gherkin language parser. Gherkin
implements that functionality in Perl. It's the first building block in the pipe line and intended to be used to build further tooling upon.
CLASS METHODS
new(%options)
Constructor.
Accepted %options
are:
- include_source
-
Boolean. Indicates whether the text of the source document is to be included in the output stream using a Source message.
- include_ast
-
Boolean. Indicates whether the parsed source (AST or Abstract Syntax Tree) is to be included in the output stream using a GherkinDocument message.
- include_pickles
-
Boolean. Indicates whether the expanded-and-interpolated (executable) scenarios are to be included in the output stream using Pickle messages.
from_paths($paths, $id_gen, $sink, %options)
Constructs a Gherkin instance and calls its from_source
method for each of the paths in the arrayref $paths
.
$id_gen
is a coderef to a function generating unique IDs which messages in the output stream can use to refer to other content in the stream. $sink
is a coderef to a function taking the next message in the stream as its argument.
%options
are passed to new
.
METHODS
from_source($source_msg, $id_gen, $sink)
Generates a stream of AST and pickle messages sent to $sink
. The source text in the message's data
attribute is assumed to be utf8
or UTF-8
encoded. The document header is scanned for an # encoding: ...
instruction. If one is found, the text is recoded from that encoding into UTF-8.
The data in the source
message sent to the sink always is UTF-8 encoded.
$source_msg
is a hash with the following structure:
{
source => {
data => 'feature content',
uri => 'e.g. path to source',
media_type => 'text/x.cucumber.gherkin+plain',
}
}
$id_gen
and $sink
are as documented in from_paths
.
LICENSE
Please see the included LICENSE.txt for the canonical version. In summary:
The MIT License (MIT)
Copyright (c) 2020-2021 Erik Huelsmann Copyright (c) 2016 Peter Sergeant
This work is a derivative of work that is: Copyright (c) 2014-2016 Cucumber Ltd, Gaspar Nagy