{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreibbjld4q2nbuqjnuascydux2fisd3kifv66jebwizrzgokcb754gu",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mncrolg62pw2"
  },
  "path": "/t/parser-error-recovery-in-syn-for-better-ide-support-with-proc-macros/24362#post_17",
  "publishedAt": "2026-06-02T13:39:54.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "quite a bit of practical work on this topic",
    "Demo crate here.",
    "You can define recovering sequence and alternatives parsers declaratively.",
    "The main crate will have basic combinators",
    "by default",
    "my own quote macro",
    "its documentation"
  ],
  "textContent": "For what it's worth:\n\nI've done quite a bit of practical work on this topic already. Demo crate here.\n\nYou'll notice that the demo has \"perfect\" recovery, i.e. it'll never cause cascading errors, and can report multiple errors in the macro input (and quoted Rust expressions) at once.\n\nI think the fundamental problems (that aren't easily fixable in Syn) are:\n\n  1. a parsing API that doesn't distinguish errors (as diagnostics) and failure,\n  2. deep, eager validation of any parsed code and\n  3. a few legacy defaults regarding quotes that cause warnings to leak.\n\n\n\n`loess` solves 1. by passing a `&mut Errors` aggregator into parsing routines. You can define recovering sequence and alternatives parsers declaratively.\n(The example isn't quite current. The main crate will have basic combinators so that individual macro crates won't have to create them from scratch.)\n\nFor 2. `loess-rust` by default doesn't recurse into delimited groups. (Specifying another type parameter will take advantage of recovery and fallbacks. I plan to name generic type parameters after the type you'd specify to parse Rust eagerly. The library assumes that errors it emits will be output to stop compilation before the output proper, so parsers try to succeed with plausible stand-ins if they recover.)\nThis is very WIP and as-needed of course! It's not feasible for me to implement the entire Rust grammar there. There's `loess-rust-opaque` as stop-gap which wraps Syn parsers to capture delimiterless Rust grammar, but that too I only extend as I need it.\n\nI made my own quote macro to deal with 3.\nYou can read its documentation on docs.rs. It's a bit fancier because I plan to eventually use it on a fairly complex UI component grammar, but is not a tt-muncher for the same reason. `{#error { … }}` respects `{#located_at(…) { … }}`, so it'll squiggle only the relevant parts of the input if you make use of that.\n(Some rust-analyzer limitations notwithstanding. Last time I tried, it squiggled more than Rustc in some cases.)\n\nI have a few too many irons in the fire at any given time, so to speak, but I can prioritise this if anyone wants to collaborate on filling in the holes and covering more grammar. I think the core is pretty solid now.",
  "title": "Parser error recovery in `syn` for better IDE support with proc-macros"
}