Crate cucumber_expressions

Source
Expand description

§Cucumber Expressions for Rust

crates.io Rust 1.81+ Unsafe Forbidden
CI Rust docs

Rust implementation of Cucumber Expressions.

This crate provides AST parser, and Regex expansion of Cucumber Expressions.

use cucumber_expressions::Expression;

let re = Expression::regex("I have {int} cucumbers in my belly").unwrap();
let caps = re.captures("I have 42 cucumbers in my belly").unwrap();

assert_eq!(&caps[0], "I have 42 cucumbers in my belly");
assert_eq!(&caps[1], "42");

§Cargo features

  • into-regex: Enables expansion into Regex.

§Grammar

This implementation follows a context-free grammar, which isn’t yet merged. Original grammar is impossible to follow while creating a performant parser, as it consists errors and describes not an exact Cucumber Expressions language, but rather some superset language, while being also context-sensitive. In case you’ve found some inconsistencies between this implementation and the ones in other languages, please file an issue!

EBNF spec of the current context-free grammar implemented by this crate:

expression              = single-expression*

single-expression       = alternation
                           | optional
                           | parameter
                           | text-without-whitespace+
                           | whitespace+
text-without-whitespace = (- (text-to-escape | whitespace))
                           | ('\', text-to-escape)
text-to-escape          = '(' | '{' | '/' | '\'

alternation             = single-alternation, (`/`, single-alternation)+
single-alternation      = ((text-in-alternative+, optional*)
                            | (optional+, text-in-alternative+))+
text-in-alternative     = (- alternative-to-escape)
                           | ('\', alternative-to-escape)
alternative-to-escape   = whitespace | '(' | '{' | '/' | '\'
whitespace              = ' '

optional                = '(' text-in-optional+ ')'
text-in-optional        = (- optional-to-escape) | ('\', optional-to-escape)
optional-to-escape      = '(' | ')' | '{' | '/' | '\'

parameter               = '{', name*, '}'
name                    = (- name-to-escape) | ('\', name-to-escape)
name-to-escape          = '{' | '}' | '(' | '/' | '\'

§Regex Production Rules

Follows original production rules.

§License

This project is licensed under either of

at your option.

Modules§

ast
Cucumber Expressions AST.
expandinto-regex
Cucumber Expressions AST into Regex expansion.
parse
Cucumber Expressions AST parser.

Structs§

Alternation
alternation defined in the grammar spec, allowing to match one of SingleAlternations.
Expression
Top-level expression defined in the grammar spec.
Optional
optional defined in the grammar spec, allowing to match an optional Input.
Parameter
parameter defined in the grammar spec, allowing to match some special Input described by a Parameter name.

Enums§

Alternative
alternative defined in the grammar spec.
SingleExpression
single-expression defined in the grammar spec, representing a single entry of an Expression.

Type Aliases§

SingleAlternation
single-alternation defined in the grammar spec, representing a building block of an Alternation.
Spanned
str along with its location information in the original input.