Skip to content

[Feature Request] Position-Aware Parsing #6

@bhavyakukkar

Description

@bhavyakukkar

I require the EDN tree to have span information associated with each node. I started working on this feature already in a fork, but I cannot find a "clean" enough solution and was hoping to hear your advice if you have any, in case you are interested in merging such a feature.

  1. Adding a span field to each enum variant of Edn makes the use of the Edn's impls function slightly annoying since they are not designed to be aware of spans.
    examples/get-nth.rs:15:

      edn
    -    .get(&Edn::Key("foo"))?
    -    .get(&Edn::Symbol("猫"))?
    -    .get(&Edn::Map(BTreeMap::from([(Edn::Key("foo"), Edn::Key("bar"))])))?
    +    .get(&Edn::Key("foo", new_span()))?
    +    .get(&Edn::Symbol("猫", new_span()))?
    +    .get(&Edn::Map(
    +      BTreeMap::from([(Edn::Key("foo", new_span()), Edn::Key("bar", new_span()))]),
    +      new_span(),
    +    ))?
        .nth(2)

    Already added a manual Hash impl so hash of Edn doesn't depend on spans

  2. If each of the atom variants held a raw string-slice like Key, Symbol & Str do, it would be possible to produce a better spanned tree from the implementor's side by reverse-engineering it using <*const str>::addr, thought its a hacky solution for something that could be provided by the library

Is having two different enums, Edn and EdnSpanned feasible? In this case the Edn impl functions would remain on Edn, but the parser would produce EdnSpanneds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions