Rust Peg Versions Save

Parsing Expression Grammar (PEG) parser generator for Rust

0.8.2

6 months ago
  • Allow expected!() to accept a &'static str expression, not just a literal. (#361)
  • Use BTreeSet`` in ExpectedSet`` for deterministic ordering. (#336)
  • Add enabled-by-default std feature that can be disabled to build on no-std + alloc (#336)
  • Fix regression with impl Trait return types (#319)

Contributors

@stevefan1999-personal @Flamenco @tchajed @kevinmehall

0.8.1

1 year ago

Fixes

  • Fix type inference for generic argument in rule's return position (#317)
  • Fix parsing of &'a mut T in type grammar (#304)

Improvements

  • Made LineCol Copy (#298)

Contributors

@kevinmehall @plaflamme @zsol @Kile-Asmussen @kw217

0.8.0

2 years ago

New Features

  • #[cache_left_rec] annotation to allow left recursion (#266)
  • Return matched token/character from [ ] pattern expression (#234)

Fixes

  • Fix Rust grammar for arguments (#261) and type bounds (#279)
  • Fix trace feature when using infix!{} (#277)
  • Fix #[cache] with grammar lifetime parameters
  • Allow clippy::redundant_closure_call lint in generated grammar (#258)

Breaking changes

Most users will not require changes to upgrade from 0.7 to 0.8; these only affect advanced use cases.

  • Allow only lifetime, not type, parameters at the grammar level. (type parameters were never properly supported)
  • Add 'input lifetime parameter to ParseElem trait so implementations can return tokens by reference. (#268)
  • Require Copy on ParseElem::Element to better represent the expectation that they are cheap to copy/move.

Contributors: @kevinmehall @zsol @neunenak @fgasperij

0.7.0

3 years ago

New features

  • Significantly improved compile-time error messages for invalid grammars
  • Support [MyToken(x)] syntax for capturing variables from pattern expressions (#245)
  • Restore support for [^ ] inverted pattern syntax
  • Add #[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)
  • Allow rule _ = without parentheses when defining special underscore rule (#243)
  • Add grammar-level type and lifetime parameters (#254)
  • Compile-time check for repeat expressions that infinite-loop without consuming input (#210)
  • Implement PartialEq, PartialOrd, Eq, Ord, Debug, Hash for RuleResult (#217)

Fixes

  • Extend detection of infinite-loop left recursion to check inside precedence!() (#238)
  • Wrap user-supplied code in immediately-invoked closure so that return and ? behave as expected (#246)
  • Remove overzealous error checks to allow passing rule closure arguments as parameters to another call (#226)

Breaking changes

  • Add required is_eof() method to Parse trait (#252)
  • Certain patterns that would infinite-loop or stack overflow if executed are now a compile-time error
  • mixed_site hygiene prevents action code from accessing internal parser state variables such as __input, __pos, etc.

Contributors

@kevinmehall @dario23 @bgw @adrianwn

0.6.3

3 years ago
  • Fix multiline doc-comments (#232)
  • Documentation improvements

Contributors: @dario23 @kevinmehall

0.6.2

4 years ago
  • Derive PartialEq, PartialOrd, Eq, Ord, Debug, Hash for RuleResult (#217)
  • Documentation improvements

Contributors: @dario23 @kevinmehall

0.6.1

4 years ago
  • Use fully qualified Result path to avoid problems if Result is shadowed (#214)
  • Update to 2018 edition for more consistent behavior when the peg name is shadowed
  • Allow crate-relative imports in grammars (#213)
  • Documentation improvements
  • Fix rule arguments on pub rule
  • Forbid #[cache] on rules with arguments

Contributors: @dario23 @kevinmehall

0.6.0

4 years ago

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 from proc-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

  1. Remove peg = "0.5" from [build_dependencies] in Cargo.toml, and add peg = "0.6" under [dependencies].
  2. If nothing else is in build.rs, delete it and remove build = "build.rs" from Cargo.toml
  3. If using the 2015 edition of Rust, add extern crate peg; to your crate root.
  4. 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
}}
  1. Add the rule keyword and parentheses to rule declarations.
    • foo = ... becomes rule foo() = ...
    • pub bar -> X = ... becomes pub rule bar() -> X = ....
  2. Add parentheses to expressions that invoke another rule.
    • name:ident becomes name:ident().
  3. 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.
  4. If your grammar used templates, replace them with rule arguments.
  5. Replace
    • . with [_].
    • #position with position!()
    • #quiet<e> with quiet!{e}
    • #expected("foo") with expected!("foo").

0.5.7

5 years ago
  • Use ? instead of try!() for compatibility with Rust 2018.
  • Add support for dyn and impl in rule return types
  • Fix peg-syntax-ext for changes in Rust nightly (0.6 will replace peg-syntax-ext with a proc-macro for stable Rust)

0.5.6

5 years ago

Fix for libsyntax OneVector rename