or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdlanguages.mdparsing.md
tile.json

tessl/maven-io-cucumber--gherkin

Gherkin parser and compiler for Java providing complete parsing of Gherkin feature files into AST and executable Pickles for BDD testing frameworks

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.cucumber/gherkin@31.0.x

To install, run

npx @tessl/cli install tessl/maven-io-cucumber--gherkin@31.0.0

index.mddocs/

Gherkin Java Parser

Gherkin is a comprehensive parser and compiler for the Gherkin language used by Cucumber for behavior-driven development (BDD). It parses Gherkin feature files into Abstract Syntax Trees (AST) and compiles them into executable 'Pickles' for test automation frameworks, supporting internationalization with multiple language keywords and providing streaming APIs for efficient processing.

Package Information

  • Package Name: gherkin
  • Package Type: maven
  • Language: Java
  • Installation: <dependency><groupId>io.cucumber</groupId><artifactId>gherkin</artifactId><version>31.0.0</version></dependency>

Core Imports

import io.cucumber.gherkin.GherkinParser;
import io.cucumber.gherkin.GherkinDialectProvider;
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.GherkinDocument;
import io.cucumber.messages.types.Pickle;

Basic Usage

import io.cucumber.gherkin.GherkinParser;
import io.cucumber.messages.types.Envelope;
import java.nio.file.Paths;
import java.util.stream.Stream;

// Parse a Gherkin feature file
GherkinParser parser = GherkinParser.builder().build();
Stream<Envelope> messages = parser.parse(Paths.get("features/example.feature"));

// Process the parsed messages
messages.forEach(envelope -> {
    if (envelope.getGherkinDocument().isPresent()) {
        System.out.println("Feature: " + 
            envelope.getGherkinDocument().get().getFeature().get().getName());
    }
    if (envelope.getPickle().isPresent()) {
        System.out.println("Scenario: " + 
            envelope.getPickle().get().getName());
    }
});

Architecture

Gherkin Java is built around several key components:

  • GherkinParser: High-level streaming parser with builder configuration pattern
  • Language Support: Multi-language keyword support through dialect providers
  • Token Processing: Internal tokenization and parsing pipeline for grammar recognition
  • AST Generation: Abstract Syntax Tree creation from parsed tokens
  • Pickle Compilation: Conversion of AST scenarios into executable test units
  • Cucumber Messages: Integration with Cucumber's messaging protocol for interoperability

Capabilities

High-Level Parsing

Main entry point for parsing Gherkin files with configurable options for output formats and content inclusion.

public final class GherkinParser {
    public static Builder builder();
    public Stream<Envelope> parse(Path source) throws IOException;
    public Stream<Envelope> parse(String uri, InputStream source) throws IOException;
    public Stream<Envelope> parse(String uri, byte[] source);
    public Stream<Envelope> parse(Envelope envelope);
}

public static final class Builder {
    public Builder includeSource(boolean includeSource);
    public Builder includeGherkinDocument(boolean includeGherkinDocument);
    public Builder includePickles(boolean includePickles);
    public Builder idGenerator(IdGenerator idGenerator);
    public GherkinParser build();
}

High-Level Parsing

Language Support

Comprehensive support for Gherkin in multiple languages with keyword translation and dialect management.

public final class GherkinDialectProvider {
    public GherkinDialectProvider();
    public GherkinDialectProvider(String defaultDialectName);
    public GherkinDialect getDefaultDialect();
    public Optional<GherkinDialect> getDialect(String language);
    public Set<String> getLanguages();
}

public final class GherkinDialect {
    public String getLanguage();
    public String getName();
    public String getNativeName();
    public List<String> getFeatureKeywords();
    public List<String> getRuleKeywords();
    public List<String> getScenarioKeywords();
    public List<String> getScenarioOutlineKeywords();
    public List<String> getBackgroundKeywords();
    public List<String> getExamplesKeywords();
    public List<String> getGivenKeywords();
    public List<String> getWhenKeywords();
    public List<String> getThenKeywords();
    public List<String> getAndKeywords();
    public List<String> getButKeywords();
    public List<String> getStepKeywords();
    public List<StepKeywordType> getStepKeywordTypes(String keyword);
}

Language Support

Types

// Cucumber Messages integration types (external dependency)
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.GherkinDocument;
import io.cucumber.messages.types.Pickle;
import io.cucumber.messages.types.PickleStep;
import io.cucumber.messages.types.PickleTag;
import io.cucumber.messages.types.Source;
import io.cucumber.messages.types.ParseError;
import io.cucumber.messages.types.Feature;
import io.cucumber.messages.types.Scenario;
import io.cucumber.messages.types.Step;
import io.cucumber.messages.types.Background;
import io.cucumber.messages.types.Rule;
import io.cucumber.messages.types.Tag;
import io.cucumber.messages.types.Comment;
import io.cucumber.messages.types.TableRow;
import io.cucumber.messages.types.TableCell;
import io.cucumber.messages.types.DataTable;
import io.cucumber.messages.types.DocString;
import io.cucumber.messages.types.Examples;
import io.cucumber.messages.types.StepKeywordType;
import io.cucumber.messages.types.Location;
import io.cucumber.messages.IdGenerator;

// StepKeywordType enum values (from io.cucumber.messages.types)
StepKeywordType.CONTEXT    // Given steps
StepKeywordType.ACTION     // When steps
StepKeywordType.OUTCOME    // Then steps  
StepKeywordType.CONJUNCTION // And, But steps
StepKeywordType.UNKNOWN    // Ambiguous steps

// Exception types (from io.cucumber.gherkin package)
// These are package-private but thrown from public APIs
ParserException.NoSuchLanguageException    // Unsupported language
ParserException.UnexpectedTokenException   // Parse syntax errors
ParserException.UnexpectedEOFException     // Premature end of file
ParserException.CompositeParserException   // Multiple parse errors
ParserException.AstBuilderException        // AST construction errors
GherkinException                           // General processing errors