- 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
The current MSRV supported is 1.75
use pegy::Parse;
#[derive(Debug, Default, Parse)]
#[grammar($item0:['a'-'z''A'-'Z''0'-'9'])]
pub struct AlphaDigit(char);
#[derive(Debug, Default, Parse)]
#[grammar($item0:['0'-'9'])]
pub struct Digit(char);
#[derive(Debug, Default, Parse)]
#[grammar(!Digit $item0:AlphaDigit+)]
pub struct Ident(Vec<AlphaDigit>);
pub fn main(){
let re: pegy::Result<Ident> = pegy::parse_blocking::<Ident, _>("myIdent");
assert!(re.is_ok());
}
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 |
"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
.
?
- 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>
$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()
.