Parsing Expression Grammar (PEG) parser generator for Rust
expected!()
to accept a &'static str
expression, not just a literal. (#361)BTreeSet`` in
ExpectedSet`` for deterministic ordering. (#336)std
feature that can be disabled to build on no-std + alloc (#336)impl Trait
return types (#319)@stevefan1999-personal @Flamenco @tchajed @kevinmehall
#[cache_left_rec]
annotation to allow left recursion (#266)[ ]
pattern expression (#234)trace
feature when using infix!{}
(#277)#[cache]
with grammar lifetime parametersclippy::redundant_closure_call
lint in generated grammar (#258)Most users will not require changes to upgrade from 0.7 to 0.8; these only affect advanced use cases.
'input
lifetime parameter to ParseElem
trait so implementations can return tokens by reference. (#268)Copy
on ParseElem::Element
to better represent the expectation that they are cheap to copy/move.Contributors: @kevinmehall @zsol @neunenak @fgasperij
[MyToken(x)]
syntax for capturing variables from pattern expressions (#245)[^ ]
inverted pattern syntax#[no_eof] pub rule() = ...
syntax to allow matching a prefix of the input rather than reporting a parse error if the rule does not reach end-of-file (#233)rule _ =
without parentheses when defining special underscore rule (#243)PartialEq, PartialOrd, Eq, Ord, Debug, Hash
for RuleResult
(#217)precedence!()
(#238)return
and ?
behave as expected (#246)is_eof()
method to Parse
trait (#252)mixed_site
hygiene prevents action code from accessing internal parser state variables such as __input
, __pos
, etc.@kevinmehall @dario23 @bgw @adrianwn
Contributors: @dario23 @kevinmehall
PartialEq, PartialOrd, Eq, Ord, Debug, Hash
for RuleResult (#217)Contributors: @dario23 @kevinmehall
Result
path to avoid problems if Result
is shadowed (#214)peg
name is shadowedpub rule
#[cache]
on rules with argumentsContributors: @dario23 @kevinmehall
str
input by implementing traits. It comes with an implementation for [T]
(including [u8]
), but you can define the traits for your own types. In fact, the rust-peg grammar is parsed with rust-peg via an implementation for token trees from proc-macro2
.precedence!{}
block for adding a precedence-climbing expression parser integrated with the surrounding PEG source.template
syntax.peg = "0.5"
from [build_dependencies]
in Cargo.toml
, and add peg = "0.6"
under [dependencies]
.build.rs
, delete it and remove build = "build.rs"
from Cargo.toml
extern crate peg;
to your crate root..rustpeg
file into a Rust source file. Remove the
mod somename { include!(...) }
and replace it with:peg::parser!{grammar somename() for str {
// grammar goes here
}}
rule
keyword and parentheses to rule declarations.
foo = ...
becomes rule foo() = ...
pub bar -> X = ...
becomes pub rule bar() -> X = ...
.name:ident
becomes name:ident()
.[a-zA-Z]
becomes ['a'..='z' | 'A'..='Z']
.[^X]
becomes (!['X'][_])
-- the inverted character set syntax was removed, but can be substituted with a negative lookahead followed by [_]
to match and consume the character..
with [_]
.#position
with position!()
#quiet<e>
with quiet!{e}
#expected("foo")
with expected!("foo")
.?
instead of try!()
for compatibility with Rust 2018.dyn
and impl
in rule return typesFix for libsyntax OneVector
rename