Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raquentin/dyck
💀 A derive macro for constructing Dyck languages from proprietary enums.
https://github.com/raquentin/dyck
dyck static-analysis
Last synced: 16 days ago
JSON representation
💀 A derive macro for constructing Dyck languages from proprietary enums.
- Host: GitHub
- URL: https://github.com/raquentin/dyck
- Owner: raquentin
- License: mit
- Created: 2024-04-07T22:06:16.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-03T18:36:50.000Z (8 months ago)
- Last Synced: 2024-12-24T00:35:15.057Z (18 days ago)
- Topics: dyck, static-analysis
- Language: Rust
- Homepage: https://crates.io/crates/dyck
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Dyck ()[]{}
This is a Rust crate for defining Dyck languages from ASCII characters (like the traditional ()[]{}) or from instanced of an enum deriving the exported `DyckToken` trait.
## Features
- Functions for verifying Dyck words, finding Dyck prefixes, finding smallest Dyck-verifying appendages, and more.
- A `#[derive(DyckToken)]` procedural macro for constructing languages and Dyck words from any struct or primitive.
- Zero dependencies in the `dyck` core (`dyck-derive` needs `syn` and `quote` for the `DyckToken` macro).## Usage
You can use this crate with either `&str` string slices or with custom user-defined enum instance tokens.
The former allows for easy construction of typical Dyck alphabets consisting of "()", "[]", "{}", and even custom string pairs like "<>" or "<3":
```rust
let pairs = vec![("(", ")"), ("[", "]"), ("{", "}")];
let language = dyck::Language::new_from_vec(&pairs).unwrap("");
let word: dyck::Word<&str> = vec!["(", "[", "]", "(", ")", ")"];
assert_eq!(language.is_valid(&word), true);
```The latter is more practical for use with existing programming languages or static analysis tools with lexers defining tokens as instances of a custom Token enum:
```rust
// requires features = ["derive"] in Cargo.toml
#[derive(dyck::DyckToken)]
enum Token {
OpenParen,
CloseParen,
OpenBracket,
CloseBracket,
}let pairs = vec![
(Token::OpenParen, Token::CloseParen),
(Token::OpenBracket, Token::CloseBracket),
];let language = dyck::Language::new_from_vec(&pairs);
assert_eq!(language.get_k(), 2);
```Either way, the all `dyck` functions and objects are built for a generic `T: DyckToken` and will run identically regardless of token type.
## License
This crate is licensed under the MIT License, see `LICENSE.md`.