NAME
Gherkin::Parser - Gherkin feature file parser
SYNOPSIS
use Gherkin::Parser;
open my $fh, '<:encoding(UTF-8)', 'my.feature'
or die "Error opening 'my.feature': $!;
my $content = do { local $/ = undef; <$fh> }; # slurp file content
close $fh or warn "Error closing 'my.feature': $!";
my $parser = Gherkin::Parser->new();
my $document_envelope = $parser->parse( \$content );
DESCRIPTION
This module implements a Gherkin feature file parser for Perl based on the canonical Gherkin grammar, building an AST (abstract syntax tree) from the provided input.
METHODS
new( [$ast_builder], [$token_matcher] )
Constructor. Returns a new Gherkin::Parser
instance. When the AST builder instance is not provided, one with default settings will be created. The same applies to the token matcher.
parse( $token_scanner, [$uri] )
Parses the content provided through the <$token_scanner>. Returns an Envelope message wrapping a GherkinDocument message.
The value provided for the token scanner can be one of three cases:
- A reference to a Gherkin::TokenScanner instance
- A reference to a scalar
-
In this case, the parameter is assumed to reference the content to be parsed.
- A scalar value
-
In this case, the parameter is assumed to be a filename. The file will be opened for input and parsed as a feature file.
The $uri
parameter is expected to be passed in all but the third case.
SEE ALSO
LICENSE
See Gherkin.