Loess
Loess is a parser library and parser generator for proc macros.
For a simple but representative example of using Loess, see the inline-json5 crate.
Premade Rust grammar implementations can be found in loess-rust, with additional temporary wrappers available in loess-rust-opaque.
Here's what to expect:
-
Fast builds. Loess's core is compact and language agnostic. Direct grammar implementations like loess-rust should compile fairly quickly too.
-
A simple, flexible API. Loess is relatively unopinionated about how or what you parse, and you can construct (and destructure)
Inputat any time. -
Really good error reporting from proc macros implemented with Loess, by default.
Many parsing errors are easily or automatically recoverable, which means multiple errors can be reported at once while preserving as much regular output as possible (which means no or much fewer cascading errors!).
Panics inside your parser can also be caught and reported as located errors with the original panic message.
-
A reasonably powerful parser-generator.
grammar!can emit documentation (for enums) andPeekFrom,PopFromandIntoTokensimplementations on grammar types in general. -
Powerful
quote_intomacros that expand efficiently and are language-agnostic.You can cleanly loop and/or branch within the template.
-
Low-allocation workflow.
Loess can (usually) move tokens from input to output without cloning them. (You can still clone all included grammar types explicitly, including when pasting in quotes.)
Here's what not to expect:
-
A general Syn-replacement (at least not soon).
Loess is mainly aimed at implementing domain-specific languages that may cite fragments of Rust verbatim in their output. There is currently no focus on parsing Rust code or transforming it in-depth.
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 ;
// […]