https://github.com/cucumber-rs/cucumber-expressions
Rust implementation of Cucumber Expressions.
https://github.com/cucumber-rs/cucumber-expressions
cucumber cucumber-expressions cucumber-rust rust
Last synced: 17 days ago
JSON representation
Rust implementation of Cucumber Expressions.
- Host: GitHub
- URL: https://github.com/cucumber-rs/cucumber-expressions
- Owner: cucumber-rs
- License: apache-2.0
- Created: 2021-11-05T17:44:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-21T22:43:10.000Z (2 months ago)
- Last Synced: 2025-04-02T20:08:05.560Z (24 days ago)
- Topics: cucumber, cucumber-expressions, cucumber-rust, rust
- Language: Rust
- Homepage: https://cucumber.github.io/cucumber-expressions
- Size: 121 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
- Security: SECURITY.md
Awesome Lists containing this project
README
[Cucumber Expressions] for Rust
===============================[](https://crates.io/crates/cucumber-expressions)
[](https://blog.rust-lang.org/2025/02/20/Rust-1.85.0.html)
[](https://github.com/rust-secure-code/safety-dance)
[](https://github.com/cucumber-rs/cucumber-expressions/actions?query=workflow%3ACI+branch%3Amain)
[](https://docs.rs/cucumber-expressions)- [Changelog](https://github.com/cucumber-rs/cucumber-expressions/blob/v0.4.0/CHANGELOG.md)
Rust implementation of [Cucumber Expressions].
This crate provides [AST] parser, and [`Regex`] expansion of [Cucumber Expressions].
```rust
# // `Regex` expansion requires `into-regex` feature.
# #[cfg(feature = "into-regex")] {
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][1]. 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:
```ebnf
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][2].
## License
This project is licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](https://github.com/cucumber-rs/cucumber-expressions/blob/v0.4.0/LICENSE-APACHE) or )
* MIT license ([LICENSE-MIT](https://github.com/cucumber-rs/cucumber-expressions/blob/v0.4.0/LICENSE-MIT) or )at your option.
[`Regex`]: https://docs.rs/regex
[AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
[Cucumber Expressions]: https://github.com/cucumber/cucumber-expressions#readme
[EBNF]: https://en.wikipedia.org/wiki/Extended_Backus–Naur_form[1]: https://github.com/cucumber/cucumber-expressions/issues/41
[2]: https://github.com/cucumber/cucumber-expressions/blob/main/ARCHITECTURE.md#production-rules