camxes-rs-0.2.0 has been yanked.
camxes-rs
A Parsing Expression Grammar (PEG) parser generator with enhanced error reporting and semantic actions support.
⚠️ Version 0.2.0 Breaking Changes
If you're upgrading from 0.1.x, please read the CHANGELOG.md for migration instructions. The main change is:
ParseResultnow has 4 fields instead of 3 (added error position tracking)- Access parse result at index 3 instead of index 2
Features
- Zero-Copy Parsing: Efficient parsing without unnecessary string allocations
- Enhanced Error Reporting: Track furthest error position for better diagnostics
- Semantic Actions: Build typed ASTs with bottom-up reducers
- Embedded Lojban Grammar: Full camxes-style Lojban PEG included
- Thread-Safe: Designed for concurrent use
- Rich Debugging: Detailed logging via the
logcrate
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
Quick Start
Basic Usage
use Peg;
Using the Embedded Lojban Grammar
use Peg;
use LOJBAN_GRAMMAR;
Semantic Actions (Building ASTs)
use Peg;
use ;
Grammar Syntax
The parser supports standard 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 class | [a-zA-Z0-9] |
. |
Any character | . |
API Reference
ParseResult Structure (v0.2.0)
pub , // parse result
);
ParseNode
; // (start, end)
Key Functions
Peg::new(start_rule, grammar)- Create a parser from grammar textparser.parse(input)- Parse input stringparse_with_semantics(parser, input, reducers)- Parse and build AST
Debugging
Enable debug logging to see detailed parsing information:
RUST_LOG=camxes_rs=debug
Or in code:
builder
.filter_level
.init;
Multi-threaded Usage
For web servers or multi-threaded applications, create one Peg instance per thread:
use HashMap;
use Arc;
use Peg;
use LOJBAN_GRAMMAR;
// In your server initialization
let grammar_texts: = new;
// In each worker thread
let mut parsers = new;
for in grammar_texts.iter
Migration from 0.1.x
See CHANGELOG.md for detailed migration instructions.
Quick summary:
- Change
result.2→result.3to access parse result - Update tuple destructuring:
ParseResult(cost, pos, result)→ParseResult(cost, pos, error_pos, result)
License
MIT
Contributing
Contributions are welcome! This crate is part of the tersmu project.