0.6.0
Major improvements
- Replaced build script integration and nightly-only syntax extension with a procedural macro that works on stable Rust. This means that errors both in the PEG grammar and the Rust code embedded from it are reported with source position by rustc. It even works with RLS!
- Add the ability to parse non-
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 fromproc-macro2
. - Add
precedence!{}
block for adding a precedence-climbing expression parser integrated with the surrounding PEG source. - Report errors in left-recursive rules that would cause infinte loops.
- Allow rules to accept value and type parameters, including passing closures to replace the
template
syntax. - Significant performance improvement for input that parses successfully by deferring error handling until parsing has failed.
Upgrade from 0.5.x
- Remove
peg = "0.5"
from[build_dependencies]
inCargo.toml
, and addpeg = "0.6"
under[dependencies]
. - If nothing else is in
build.rs
, delete it and removebuild = "build.rs"
fromCargo.toml
- If using the 2015 edition of Rust, add
extern crate peg;
to your crate root. - Move your grammar from a separate
.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
}}
- Add the
rule
keyword and parentheses to rule declarations.foo = ...
becomesrule foo() = ...
pub bar -> X = ...
becomespub rule bar() -> X = ...
.
- Add parentheses to expressions that invoke another rule.
name:ident
becomesname:ident()
.
- Replace the character set syntax with the pattern matching syntax.
[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.
- If your grammar used templates, replace them with rule arguments.
- Replace
.
with[_]
.#position
withposition!()
#quiet<e>
withquiet!{e}
#expected("foo")
withexpected!("foo")
.