1 unstable release
0.1.0 | Apr 11, 2024 |
---|
#2078 in Rust patterns
9KB
135 lines
A library for running Dyck algorithms over languages of generic string slice types.
This module provides functionalities to create and manipulate languages based on user-defined tokens, allowing for the evaluation and transformation of sequences of tokens (words) according to the rules of Dyck languages.
Usage
Add dyck
to your Cargo.toml
:
[dependencies]
dyck = "0.1"
Example: Creating a Dyck language and checking if a word is valid.
use dyck::{Language, Word};
// define pairs of tokens for the language
let pairs = vec![("(", ")"), ("[", "]"), ("{", "}")];
let language = Language::new_from_vec(&pairs).expect("Failed to create language");
// define a word to check
let word: Word<&str> = vec!["(", "[", "]", "(", ")", ")"];
// check if the word is a valid Dyck word
if language.is_valid(&word) {
println!("The word is a valid Dyck word.");
} else {
println!("The word is not a valid Dyck word.");
}
See /examples in the repository root for more examples.
Dependencies
~105KB