| Crates.io | camxes-rs |
| lib.rs | camxes-rs |
| version | 0.1.2 |
| created_at | 2025-02-02 09:58:41.973172+00 |
| updated_at | 2025-04-19 12:30:07.643694+00 |
| description | A Parsing Expression Grammar (PEG) parser generator with zero-copy parsing and rich debugging capabilities |
| homepage | |
| repository | https://github.com/lojban/camxes.rs |
| max_upload_size | |
| id | 1539427 |
| size | 98,298 |
A lightning-fast Parsing Expression Grammar (PEG) parser generator implemented in Rust. This tool helps you create parsers from grammar definitions with minimal hassle.
Full API documentation is available on docs.rs
Add this to your Cargo.toml:
[dependencies]
camxes-rs = "0.1.1"
You must have latest Rust installed.
Go to the project directory and run cargo run --example cmaxes-test.
It will run the PEG grammar specified in src/examples/cmaxes-test.rs file against a sample input.
The grammar supports these PEG operators:
| Operator | Description | Example |
|---|---|---|
<- |
Definition | rule <- expression |
/ |
Ordered choice | a / b |
* |
Zero or more | [0-9]* |
+ |
One or more | [a-z]+ |
? |
Optional | [A-Z]? |
& |
And-predicate | &[a-z] |
! |
Not-predicate | ![0-9] |
() |
Grouping | (a / b) |
[] |
Character range / class | [abd] and [a-zA-Z] |
. |
Any character | . |
Enable debug logging to see detailed parsing information:
// Initialize logging (using env_logger)
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
.init();
Or set the environment variable:
RUST_LOG=debug cargo run
let calc_grammar = (
"calc",
r#"
calc <- additive
additive <- multiplicative (('+' / '-') multiplicative)*
multiplicative <- primary (('*' / '/') primary)*
primary <- number / '(' additive ')'
number <- [0-9]+
"#
);
let json_grammar = (
"json",
r#"
json <- spacing value spacing
value <- object / array / string / number / true / false / null
object <- '{' spacing (pair (',' pair)*)? '}'
pair <- string spacing ':' spacing value
array <- '[' spacing (value (',' value)*)? ']'
string <- '"' (!'"' .)* '"'
number <- '-'? ([0-9] / [1-9][0-9]*) ('.' [0-9]+)? ([eE][-+]?[0-9]+)?
true <- 'true'
false <- 'false'
null <- 'null'
spacing <- [ \t\n\r]*
"#
);
Contributions are welcome! Here's how you can help:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for the Rust community