Skip to content

Parser and formatter should share a single ExtensionRegistry #94

@wackywendell

Description

@wackywendell

Problem

The current API requires callers to create two separate ExtensionRegistry instances — one for parsing and one for formatting — even though they register the same extensions. This is because Parser::with_extension_registry consumes the registry by value, making it unavailable for the subsequent format_with_registry call.

Example invocation:

let mut parse_registry = ExtensionRegistry::new();
parse_registry.register_enhancement::<ReadRelEnhancementWrapper>().unwrap();

let mut format_registry = ExtensionRegistry::new();
format_registry.register_enhancement::<ReadRelEnhancementWrapper>().unwrap();

let plan = Parser::new()
    .with_extension_registry(parse_registry)
    .parse_plan(input)?;

let (output, errors) = format_with_registry(&plan, &opts, &format_registry);

Proposed fix

Either:

  1. Have Parser::with_extension_registry take &ExtensionRegistry (or Arc<ExtensionRegistry>) instead of consuming it, so callers can reuse the same registry for formatting, or
  2. Return the registry from the parser after parsing so it can be passed to the formatter.

This would let callers set up extensions once and use the same registry for both parsing and formatting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions