Pegy - derive based Parser in Rust
Features
- derive based parser generation
- async api for parsing
- parse input from str, async readers or custom input types.
- AST generation on the run
- meaningful error messages for errors in grammar definition
- supports no_std
MSRV
The current MSRV supported is 1.75
Example
use Parse;
;
;
;
Comparison with similar traits
crate | action code | integration | input type | streaming input |
---|---|---|---|---|
pegy | in grammar | proc macro(derive) | &str , AsyncRead , custom |
Yes |
peg | in grammar | proc macro(block) | &str , &[T] , custom |
No |
pest | external | proc macro(file) | &str |
No |
Expression Reference
Term
"some string"
- string literal: matches a str slice. returns&'static str
.'c'
- character literal: matches a character. returnschar
.Ident
- rule: matches a Parse rule. It must be a valid type and imlplementspegy::Parse
. returnsIdent
type.['a'-'z''A'-'Z''$']
- character class: matches a range of characters. returnschar
.
Quantifier
?
- optional: matches zero or one term. returnsOption<T>
*
- repeat: matches zero or more terms. returnsVec<T>
+
- repeat atleast: matches one or more terms. returnsVec<T>
.{min, max}
- repeat range: matches at leastmin
and at mostmax
number of terms. returnsVec<T>
Special
$ident:term
- field binding: bind the result of the term to the fieldident
of result. returns()
.( alternatives )
- group: matches the terms and returns aSpan
.terms | terms | terms
- alternatives: trys to match the first terms, if failed, matches the second one and so on until a match is found. returns aSpan
.!term
- negative lookahead: matches the term without consuming any characters._ term
- quiet: matches the term and returns()
.