Loess
Loess is a parser library and parser generator for proc macros.
Here's what to expect:
-
Fast builds. Loess's core is compact, language agnostic, and useful without enabling a premade grammar.
That said, even in cases where you do enable a grammar module, builds should still be fairly quick.
-
A simple, flexible API. Loess is relatively unopinionated about how or what you parse, and you can construct (and destructure)
Inputat any time. -
Shallow parsing (by default). For tokens with groups, like
Visibility, you can opt into deeper (or customised!) parsing via generics. -
Public fields and one-time validation. The parser checks token specifics once when processing input, but trusts you otherwise.
-
A reasonably powerful parser-generator.
grammar!can emit documentation (for enums) andPeekFrom,PopFromandIntoTokensimplementations on grammar types in general. -
Really good error reporting from proc macros implemented with Loess, by default.
This includes locating panics relative to the proc macro input, instead of squiggling the whole macro.
-
Lenient and partial parsing. The parsers can continue (after reporting an error) when a repeating parse fails in a delimited group.
You can use this property to still emit as much output as possible, which avoids cascading errors.
-
Low-allocation workflow.
Loess can (usually) move tokens from input to output without cloning them. (You can still clone all included grammar types explicitly.)
-
Some bugs. For example, none-delimited groups aren't handled yet, which can cause issues when generating macro input with a
macro_rules!macro.
Here's what not to expect:
-
Complete coverage of Rust's grammar. In fact, Loess really makes no attempt at all in this regard, since I only implement what I need.
In particular, unstable grammar is generally out of scope of the included parsers. (Loess can help you supply it yourself!)
-
A Syn-replacement (at least not soon). While there's no public interaction with Syn, some optional grammar tokens are for now opaque and do defer to Syn when enabled.
-
Debug-implementations on the included grammars. They aren't that useful here in my experience, but they would increase compile-times. -
Absence of major version bumps. Rust's grammar is a moving target and Loess's grammar tokens aren't marked
#[non_exhaustive]for ease of use.However, shallow parsing should make upgrades fairly painless and errors should alert you specifically to grammar changes that are relevant to you.
Examples
use ;
use ;
// Generates parsers and pasters, according to the traits written after the type name.
//
// (This macro is hygienic, so you don't have to import the traits for this.)
grammar!
// Custom logic can be added through simple traits.
// Loess has a flexible, unopinionated API:
// Alternatively:
Using $crate for full caller independence
loess::IntoTokens-methods take an (optionally empty) root: &TokenStream parameter,
which all emitted fully qualified paths should be prefixed with.
In combination with a wrapper crate: This achieves full isolation regarding caller dependencies:
// wrapper crate
// my_macro_impl (proc macro)
use ;
use ;
// […]